Skip to content

Commit

Permalink
Fix too early light initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru committed Jan 5, 2023
1 parent 1412652 commit 6dfe97b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class LoadingConfig {
public boolean optimizeASMDataTable;
public boolean optimizeIc2ReactorInventoryAccess;
public boolean optimizeTileentityRemoval;
public boolean optimizeWorldUpdateLight;
public boolean preventPickupLoot;
public boolean removeUpdateChecks;
public boolean speedupAnimations;
Expand Down Expand Up @@ -213,6 +214,7 @@ public LoadingConfig(File file) {
optimizeASMDataTable = config.get(Category.SPEEDUPS.toString(), "optimizeASMDataTable", true, "Optimize ASMDataTable getAnnotationsFor for faster startup").getBoolean();
optimizeIc2ReactorInventoryAccess = config.get(Category.FIXES.toString(), "optimizeIc2ReactorInventoryAccess", true, "Optimize inventory access to IC2 nuclear reactor").getBoolean();
optimizeTileentityRemoval = config.get(Category.SPEEDUPS.toString(), "optimizeTileentityRemoval", true, "Optimize tileEntity removal in World.class").getBoolean();
optimizeWorldUpdateLight = config.get(Category.FIXES.toString(), "optimizeWorldUpdateLight", true, "Fix too early light initialization").getBoolean();
particleLimit = Math.max(Math.min(config.get(Category.TWEAKS.toString(), "particleLimit", 8000, "Particle limit [4000-16000]").getInt(), 16000), 4000);
preventPickupLoot = config.get(Category.TWEAKS.toString(), "preventPickupLoot", true, "Prevent monsters from picking up loot.").getBoolean();
removeUpdateChecks = config.get(Category.FIXES.toString(), "removeUpdateChecks", true, "Remove old/stale/outdated update checks.").getBoolean();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

public enum Mixins {
// Vanilla Fixes
OPTIMIZE_WORLD_UPDATE_LIGHT(new Builder("Optimize world updateLightByType method")
.setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinWorld_FixLightUpdateLag")
.setSide(Side.BOTH)
.addTargetedMod(TargetedMod.VANILLA)
.setApplyIf(() -> Common.config.optimizeWorldUpdateLight)),
FIX_FRIENDLY_CREATURE_SOUNDS(new Builder("Fix Friendly Creature Sounds")
.setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinSoundHandler")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* This mixin is a backport of a Forge fix https://github.com/MinecraftForge/MinecraftForge/pull/4729
*/
@Mixin(World.class)
public abstract class MixinWorld_FixLightUpdateLag {

private int hodgepodge$updateRange = 17;

@Shadow
public abstract boolean doChunksNearChunkExist(int p_72873_1_, int p_72873_2_, int p_72873_3_, int p_72873_4_);

@ModifyConstant(method = "updateLightByType", constant = @Constant(intValue = 17, ordinal = 0))
public int hodgepodge$modifyRangeCheck1(int cst) {
return 16;
}

@Inject(
method = "updateLightByType",
at =
@At(
value = "FIELD",
target = "Lnet/minecraft/world/World;theProfiler:Lnet/minecraft/profiler/Profiler;",
shift = At.Shift.BEFORE,
ordinal = 0))
public void hodgepodge$modifyUpdateRange(
EnumSkyBlock p_147463_1_, int x, int y, int z, CallbackInfoReturnable<Boolean> callback) {
this.hodgepodge$updateRange = this.doChunksNearChunkExist(x, y, z, 18) ? 17 : 15;
}

@ModifyConstant(
method = "updateLightByType",
constant = {@Constant(intValue = 17, ordinal = 1), @Constant(intValue = 17, ordinal = 2)})
public int hodgepodge$modifyRangeCheck2(int cst) {
return this.hodgepodge$updateRange;
}
}

0 comments on commit 6dfe97b

Please sign in to comment.