Update blockstate caching logic for vanilla 1.19.4 changes
This commit is contained in:
parent
e45acac6b6
commit
d3ff2823dc
|
|
@ -62,6 +62,11 @@ 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);
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
@Inject(method = "getPathNodeType", at = @At("HEAD"), require = 0, remap = false)
|
||||
private void generateCacheLithium(CallbackInfoReturnable<?> cir) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds;
|
||||
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.embeddedt.modernfix.blockstate.BlockStateCacheHandler;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
|
@ -15,4 +17,9 @@ public class BlocksMixin {
|
|||
BlockStateCacheHandler.rebuildParallel(true);
|
||||
return o -> {};
|
||||
}
|
||||
|
||||
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;initCache()V"))
|
||||
private static void skipCacheInit(BlockState state) {
|
||||
/* no-op, our dynamic logic handles everything properly (including the 1.19.4+ fluidState, etc. caching) */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package net.minecraft.world.level.block.state;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.embeddedt.modernfix.duck.IBlockState;
|
||||
import org.embeddedt.modernfix.testing.util.BootstrapMinecraft;
|
||||
|
|
@ -18,13 +20,14 @@ public class BlockStateCacheTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Initially, the cache should be invalid.
|
||||
* Initially, the cache should be invalid, and null.
|
||||
*/
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testCacheNullInitially() {
|
||||
BlockState stoneBlock = Blocks.STONE.defaultBlockState();
|
||||
assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
|
||||
assertNull(stoneBlock.cache);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,4 +57,22 @@ public class BlockStateCacheTest {
|
|||
assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
|
||||
assertNotNull(stoneBlock.cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the fluidState and isRandomlyTicking caching fields added by Mojang to blockstates are correctly
|
||||
* handled by the dynamic cache system.
|
||||
*/
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testExtraFieldCachingCorrect() {
|
||||
Block[] blocksToCheck = new Block[] { Blocks.WATER, Blocks.FARMLAND };
|
||||
for(Block block : blocksToCheck) {
|
||||
for(BlockState state : block.getStateDefinition().getPossibleStates()) {
|
||||
// check that the fluid states match
|
||||
assertEquals(block.getFluidState(state), state.getFluidState(), "mismatched fluid state on " + state);
|
||||
// check that random ticking flag matches
|
||||
assertEquals(block.isRandomlyTicking(state), state.isRandomlyTicking(), "mismatched random tick state on " + state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user