Merge 1.19.4 into 1.20
This commit is contained in:
commit
823fa259e9
|
|
@ -1,7 +1,14 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.reduce_blockstate_cache_rebuilds;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateHolder;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import org.embeddedt.modernfix.duck.IBlockState;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Dynamic;
|
||||
|
|
@ -14,13 +21,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
|
||||
|
||||
@Mixin(BlockBehaviour.BlockStateBase.class)
|
||||
public abstract class BlockStateBaseMixin implements IBlockState {
|
||||
public abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState> implements IBlockState {
|
||||
protected BlockStateBaseMixin(Block object, ImmutableMap<Property<?>, Comparable<?>> immutableMap, MapCodec<BlockState> mapCodec) {
|
||||
super(object, immutableMap, mapCodec);
|
||||
}
|
||||
|
||||
private static final FluidState MFIX$VANILLA_DEFAULT_FLUID = Fluids.EMPTY.defaultFluidState();
|
||||
|
||||
@Shadow public abstract void initCache();
|
||||
|
||||
@Shadow private BlockBehaviour.BlockStateBase.Cache cache;
|
||||
@Shadow private FluidState fluidState;
|
||||
@Shadow private boolean isRandomlyTicking;
|
||||
|
||||
@Shadow protected abstract BlockState asState();
|
||||
|
||||
private volatile boolean cacheInvalid = false;
|
||||
private static boolean buildingCache = false;
|
||||
@Override
|
||||
|
|
@ -72,7 +87,11 @@ public abstract class BlockStateBaseMixin implements IBlockState {
|
|||
ordinal = 0
|
||||
), require = 0)
|
||||
private FluidState genCacheBeforeGettingFluid(BlockBehaviour.BlockStateBase base) {
|
||||
generateCache(base);
|
||||
// don't generate the full cache here as mods will iterate for the fluid state a lot
|
||||
// assume blockstates will not change their contained fluidstate at runtime more than once
|
||||
// this is how Lithium's implementation used to work, so it should be fine
|
||||
if(this.cacheInvalid && this.fluidState == MFIX$VANILLA_DEFAULT_FLUID)
|
||||
this.fluidState = this.owner.getFluidState(this.asState());
|
||||
return this.fluidState;
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +102,8 @@ public abstract class BlockStateBaseMixin implements IBlockState {
|
|||
ordinal = 0
|
||||
))
|
||||
private boolean genCacheBeforeGettingTicking(BlockBehaviour.BlockStateBase base) {
|
||||
generateCache(base);
|
||||
if(this.cacheInvalid)
|
||||
return this.owner.isRandomlyTicking(this.asState());
|
||||
return this.isRandomlyTicking;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user