Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
someaddons committed Dec 1, 2021
1 parent bd5a1b7 commit fd0e12b
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G -Djava.net.preferIPv4Stack=true
org.gradle.daemon=false
mod_version=2.9
mod_version=1.1
modid=betterfpsdist
mc_version=1.16.5
forge_version=36.1.0
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/betterfpsdist/BetterfpsdistMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void clientSetup(FMLClientSetupEvent event)
{
// Side safe client event handler
Mod.EventBusSubscriber.Bus.FORGE.bus().get().register(ClientEventHandler.class);
;
}

private void setup(final FMLCommonSetupEvent event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

public class CommonConfiguration
{
public final ForgeConfigSpec ForgeConfigSpecBuilder;
public final ForgeConfigSpec.ConfigValue<Boolean> printDragonPhases;
public final ForgeConfigSpec ForgeConfigSpecBuilder;
public final ForgeConfigSpec.ConfigValue<Double> stretch;

protected CommonConfiguration(final ForgeConfigSpec.Builder builder)
{
builder.push("Config category");

builder.comment("Prints the dragon phase in chat if enabled: default:false");
printDragonPhases = builder.define("printDragonPhases", false);
builder.comment("The amount by which the chunk render distance sphere is stretched in horizontal direction."
+ " default:false");
stretch = builder.defineInRange("stretch", 2.0, 0.5, 10d);

// Escapes the current category level
builder.pop();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/betterfpsdist/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.betterfpsdist.config;

import com.betterfpsdist.betterfpsdistMod;
import com.betterfpsdist.BetterfpsdistMod;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import net.minecraftforge.common.ForgeConfigSpec;
Expand All @@ -26,7 +26,7 @@ public class Configuration
public Configuration()
{
commonConfig = new CommonConfiguration(new ForgeConfigSpec.Builder());
loadConfig(commonConfig.ForgeConfigSpecBuilder, FMLPaths.CONFIGDIR.get().resolve(betterfpsdistMod.MODID + "-common.toml"));
loadConfig(commonConfig.ForgeConfigSpecBuilder, FMLPaths.CONFIGDIR.get().resolve(BetterfpsdistMod.MODID + "-common.toml"));
}

public static void loadConfig(ForgeConfigSpec spec, Path path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.betterfpsdist.config;

public class ConfigurationCache
{
public static double stretch = 1;
}
44 changes: 43 additions & 1 deletion src/main/java/com/betterfpsdist/event/ClientEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
package com.betterfpsdist.event;

import com.betterfpsdist.BetterfpsdistMod;
import com.betterfpsdist.config.ConfigurationCache;
import net.minecraft.client.AbstractOption;
import net.minecraft.client.gui.screen.VideoSettingsScreen;
import net.minecraft.client.settings.SliderPercentageOption;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ClientEventHandler
{

public static final SliderPercentageOption RenderSizeStretch = new SliderPercentageOption("options.renderDistance", 0.5D, 10.0D, 0.25F, (value) -> {
return ConfigurationCache.stretch;
}, (setting, value) -> {
ConfigurationCache.stretch = value;
BetterfpsdistMod.config.getCommonConfig().stretch.set(value);
}, (settings, value) -> {
return new StringTextComponent("HRdistStretch:" + ConfigurationCache.stretch);
});
static
{
try
{
final List<AbstractOption> options = new ArrayList<>(Arrays.asList(VideoSettingsScreen.OPTIONS));
options.add(options.indexOf(AbstractOption.GUI_SCALE) + 1, RenderSizeStretch);
VideoSettingsScreen.OPTIONS = options.toArray(new AbstractOption[0]);
}
catch (Throwable e)
{
BetterfpsdistMod.LOGGER.error("Error trying to add an option Button to video settings, likely optifine is present which removes vanilla functionality required."
+ " The mod still works, but you'll need to manually adjust the config to get different Render distance stretch values as the button could not be added.");
}
}
@SubscribeEvent
public static void on(GuiOpenEvent event)
{
if (event.isCanceled())
{
return;
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/betterfpsdist/event/ModEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.betterfpsdist.event;

import com.betterfpsdist.BetterfpsdistMod;
import com.betterfpsdist.config.ConfigurationCache;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.config.ModConfig;

Expand All @@ -8,5 +10,6 @@ public class ModEventHandler
@SubscribeEvent
public static void onConfigChanged(ModConfig.ModConfigEvent event)
{
ConfigurationCache.stretch = BetterfpsdistMod.config.getCommonConfig().stretch.get();
}
}
64 changes: 64 additions & 0 deletions src/main/java/com/betterfpsdist/mixin/LevelRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.betterfpsdist.mixin;

import com.betterfpsdist.config.ConfigurationCache;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.util.math.vector.Vector3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(WorldRenderer.class)
public class LevelRendererMixin
{
@Shadow
@Final
private Minecraft minecraft;
private ChunkRenderDispatcher.ChunkRender current = null;
//private HashSet<BlockPos> renderedPositions = new HashSet<>();
//private long nextUpdate = 0;

@Redirect(method = "renderChunkLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$ChunkRender;getCompiledChunk()Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;"))
public ChunkRenderDispatcher.CompiledChunk on(final ChunkRenderDispatcher.ChunkRender instance)
{
current = instance;
return instance.getCompiledChunk();
}

@Redirect(method = "renderChunkLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;isEmpty(Lnet/minecraft/client/renderer/RenderType;)Z"))
public boolean on(final ChunkRenderDispatcher.CompiledChunk instance, final RenderType type)
{
boolean returnv =
minecraft.cameraEntity != null &&
distSqr(minecraft.cameraEntity.position(), new Vector3d(current.getOrigin().getX(), current.getOrigin().getY(), current.getOrigin().getZ()))
> (Minecraft.getInstance().options.renderDistance * 16) * (Minecraft.getInstance().options.renderDistance * 16)
|| instance.isEmpty(type);

/*
if (Minecraft.getInstance().player.level.getGameTime() > nextUpdate)
{
nextUpdate = Minecraft.getInstance().player.level.getGameTime() + 20 * 60;
BetterfpsdistMod.LOGGER.warn("Rendered Sections:" + renderedPositions.size());
renderedPositions.clear();
}
if (!returnv)
{
renderedPositions.add(current.getOrigin());
}*/

return returnv;
}

private double distSqr(Vector3d from, Vector3d to)
{
double d0 = from.x - to.x;
double d1 = from.y - to.y;
double d2 = from.z - to.z;
return d0 * d0 + ConfigurationCache.stretch * (d1 * d1) + d2 * d2;
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
public net.minecraft.entity.LivingEntity func_184583_d(Lnet/minecraft/util/DamageSource;)Z # isDamageSourceBlocked
public net.minecraft.world.end.DragonFightManager field_186109_c # dragonEvent
public net.minecraft.entity.monster.IllusionerEntity$MirrorSpellGoal
public-f net.minecraft.client.gui.screen.VideoSettingsScreen field_213107_d # OPTIONS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
],
"client": [
"LevelRendererMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit fd0e12b

Please sign in to comment.