Trigger classloading of Items when deferring blockstate cache rebuild

This commit is contained in:
embeddedt 2025-05-01 15:18:15 -04:00
parent 1b37c9da66
commit 536eb03b50
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.embeddedt.modernfix.blockstate.BlockStateCacheHandler;
@ -22,6 +23,8 @@ public class BlocksMixin {
// 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) {
// Trigger classloading of Items in case a mod expects it.
Items.AIR.asItem();
// Mark the cache as invalid
((IBlockState)state).clearCache();
}