Merge 1.19.4 into 1.20

This commit is contained in:
embeddedt 2023-07-28 16:40:02 -04:00
commit 1884996e53
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.FluidState;
import org.embeddedt.modernfix.duck.IBlockState;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Dynamic;
@ -17,6 +18,8 @@ public abstract class BlockStateBaseMixin implements IBlockState {
@Shadow public abstract void initCache();
@Shadow private BlockBehaviour.BlockStateBase.Cache cache;
@Shadow private FluidState fluidState;
@Shadow private boolean isRandomlyTicking;
private volatile boolean cacheInvalid = false;
private static boolean buildingCache = false;
@ -62,9 +65,26 @@ public abstract class BlockStateBaseMixin implements IBlockState {
return generateCache(base);
}
@Inject(method = { "getFluidState", "isRandomlyTicking" }, at = @At("HEAD"))
private void generateCacheFluidStateTicking(CallbackInfoReturnable<?> cir) {
generateCache((BlockBehaviour.BlockStateBase)(Object)this);
@Redirect(method = "*", at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;fluidState:Lnet/minecraft/world/level/material/FluidState;",
ordinal = 0
))
private FluidState genCacheBeforeGettingFluid(BlockBehaviour.BlockStateBase base) {
generateCache(base);
return this.fluidState;
}
@Redirect(method = "*", at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;isRandomlyTicking:Z",
ordinal = 0
))
private boolean genCacheBeforeGettingTicking(BlockBehaviour.BlockStateBase base) {
generateCache(base);
return this.isRandomlyTicking;
}
@Dynamic

View File

@ -18,7 +18,8 @@ public class BlocksMixin {
return o -> {};
}
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;initCache()V"))
// require = 0 due to Forge removing the BLOCK_STATE_REGISTRY init here
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;initCache()V"), require = 0)
private static void skipCacheInit(BlockState state) {
/* no-op, our dynamic logic handles everything properly (including the 1.19.4+ fluidState, etc. caching) */
}