parent
2cdc8b88a5
commit
cc36e0c3f1
|
|
@ -3,10 +3,13 @@ package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuil
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import org.embeddedt.modernfix.duck.IBlockState;
|
import org.embeddedt.modernfix.duck.IBlockState;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.spongepowered.asm.mixin.Dynamic;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
|
||||||
@Mixin(BlockBehaviour.BlockStateBase.class)
|
@Mixin(BlockBehaviour.BlockStateBase.class)
|
||||||
|
|
@ -23,13 +26,7 @@ public abstract class BlockStateBaseMixin implements IBlockState {
|
||||||
cacheInvalid = true;
|
cacheInvalid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "*", at = @At(
|
private BlockBehaviour.BlockStateBase.Cache generateCache(BlockBehaviour.BlockStateBase base) {
|
||||||
value = "FIELD",
|
|
||||||
opcode = Opcodes.GETFIELD,
|
|
||||||
target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;cache:Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase$Cache;",
|
|
||||||
ordinal = 0
|
|
||||||
))
|
|
||||||
private BlockBehaviour.BlockStateBase.Cache initCacheIfNeeded(BlockBehaviour.BlockStateBase base) {
|
|
||||||
if(cacheInvalid) {
|
if(cacheInvalid) {
|
||||||
// Ensure that only one block's cache is built at a time
|
// Ensure that only one block's cache is built at a time
|
||||||
synchronized (BlockBehaviour.BlockStateBase.class) {
|
synchronized (BlockBehaviour.BlockStateBase.class) {
|
||||||
|
|
@ -50,4 +47,32 @@ public abstract class BlockStateBaseMixin implements IBlockState {
|
||||||
}
|
}
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "*", at = @At(
|
||||||
|
value = "FIELD",
|
||||||
|
opcode = Opcodes.GETFIELD,
|
||||||
|
target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;cache:Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase$Cache;",
|
||||||
|
ordinal = 0
|
||||||
|
))
|
||||||
|
private BlockBehaviour.BlockStateBase.Cache dynamicCacheGen(BlockBehaviour.BlockStateBase base) {
|
||||||
|
return generateCache(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dynamic
|
||||||
|
@Inject(method = "getPathNodeType", at = @At("HEAD"), require = 0, remap = false)
|
||||||
|
private void generateCacheLithium(CallbackInfoReturnable<?> cir) {
|
||||||
|
generateCache((BlockBehaviour.BlockStateBase)(Object)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dynamic
|
||||||
|
@Inject(method = "getNeighborPathNodeType", at = @At("HEAD"), require = 0, remap = false)
|
||||||
|
private void generateCacheLithium2(CallbackInfoReturnable<?> cir) {
|
||||||
|
generateCache((BlockBehaviour.BlockStateBase)(Object)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dynamic
|
||||||
|
@Inject(method = "getAllFlags", at = @At("HEAD"), require = 0, remap = false)
|
||||||
|
private void generateCacheLithium3(CallbackInfoReturnable<?> cir) {
|
||||||
|
generateCache((BlockBehaviour.BlockStateBase)(Object)this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user