Merge 1.19.4 into 1.20

This commit is contained in:
embeddedt 2023-07-28 16:07:14 -04:00
commit e1fdca5f41
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 34 additions and 1 deletions

View File

@ -62,6 +62,11 @@ public abstract class BlockStateBaseMixin implements IBlockState {
return generateCache(base); return generateCache(base);
} }
@Inject(method = { "getFluidState", "isRandomlyTicking" }, at = @At("HEAD"))
private void generateCacheFluidStateTicking(CallbackInfoReturnable<?> cir) {
generateCache((BlockBehaviour.BlockStateBase)(Object)this);
}
@Dynamic @Dynamic
@Inject(method = "getPathNodeType", at = @At("HEAD"), require = 0, remap = false) @Inject(method = "getPathNodeType", at = @At("HEAD"), require = 0, remap = false)
private void generateCacheLithium(CallbackInfoReturnable<?> cir) { private void generateCacheLithium(CallbackInfoReturnable<?> cir) {

View File

@ -1,10 +1,12 @@
package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds; package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.embeddedt.modernfix.blockstate.BlockStateCacheHandler; import org.embeddedt.modernfix.blockstate.BlockStateCacheHandler;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -15,4 +17,9 @@ public class BlocksMixin {
BlockStateCacheHandler.rebuildParallel(true); BlockStateCacheHandler.rebuildParallel(true);
return o -> {}; 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) */
}
} }

View File

@ -1,7 +1,9 @@
package net.minecraft.world.level.block.state; package net.minecraft.world.level.block.state;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import org.embeddedt.modernfix.duck.IBlockState; import org.embeddedt.modernfix.duck.IBlockState;
import org.embeddedt.modernfix.testing.util.BootstrapMinecraft; 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 @Test
@Order(1) @Order(1)
public void testCacheNullInitially() { public void testCacheNullInitially() {
BlockState stoneBlock = Blocks.STONE.defaultBlockState(); BlockState stoneBlock = Blocks.STONE.defaultBlockState();
assertTrue(((IBlockState)stoneBlock).isCacheInvalid()); assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
assertNull(stoneBlock.cache);
} }
/** /**
@ -54,4 +57,22 @@ public class BlockStateCacheTest {
assertTrue(((IBlockState)stoneBlock).isCacheInvalid()); assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
assertNotNull(stoneBlock.cache); 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);
}
}
}
} }