From ec5b92dd7a9f705164625814e97b4dc1d28512a0 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sat, 5 Aug 2023 19:38:20 -0400 Subject: [PATCH 1/2] Don't trigger full blockstate cache rebuilds when requesting fluid This causes mods to prematurely rebuild the whole cache, which is not what we want --- .../BlockStateBaseMixin.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/reduce_blockstate_cache_rebuilds/BlockStateBaseMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/reduce_blockstate_cache_rebuilds/BlockStateBaseMixin.java index 84acec8a..3d3b3acc 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/reduce_blockstate_cache_rebuilds/BlockStateBaseMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/reduce_blockstate_cache_rebuilds/BlockStateBaseMixin.java @@ -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 implements IBlockState { + protected BlockStateBaseMixin(Block object, ImmutableMap, Comparable> immutableMap, MapCodec 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; } From 795aca19e031707ae66fc0f011b7d3ad1dd8e744 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sat, 5 Aug 2023 19:42:34 -0400 Subject: [PATCH 2/2] Don't enable blast_search_trees with REI present on 1.16 --- .../embeddedt/modernfix/core/config/ModernFixEarlyConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 353919c6..ae5fa9ee 100644 --- a/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -141,7 +141,7 @@ public class ModernFixEarlyConfig { private static final boolean isDevEnv = ModernFixPlatformHooks.INSTANCE.isDevEnv(); static { - shouldReplaceSearchTrees = modPresent("jei"); + shouldReplaceSearchTrees = modPresent("jei") && !modPresent("roughlyenoughitems"); } private static class DefaultSettingMapBuilder extends ImmutableMap.Builder {