From 686cdbec74a0e71e214065bc529038f0ac37b4c3 Mon Sep 17 00:00:00 2001 From: FoundationGames <43485105+FoundationGames@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:02:42 -0700 Subject: [PATCH] Redesigned dynamic model update handling - Instead of forcing the game to synchronously update chunks to avoid flashing, the block entity renderer override will continue to render until the updated chunk mesh has been uploaded - This means the game will not freeze when block entities go from static to animated or vice versa, unless fully blocking chunk updates are specified in the game options - Soft-failing mixins to Sodium have been added to allow this change to work with Sodium installed, also eliminating the long-standing issue of block entity animations flashing when using EBE with Sodium --- build.gradle | 3 ++ gradle.properties | 3 ++ .../enhancedblockentities/EBESetup.java | 28 +++++------ .../model/DynamicModelProvidingPlugin.java | 11 +++-- .../client/model/ModelSelector.java | 6 +-- .../model/misc/DecoratedPotModelSelector.java | 4 +- .../render/BlockEntityRenderCondition.java | 6 +-- .../BellBlockEntityRendererOverride.java | 2 +- .../ChestBlockEntityRendererOverride.java | 4 +- ...coratedPotBlockEntityRendererOverride.java | 4 +- .../mixin/BakedModelManagerMixin.java | 2 +- .../mixin/BellBlockEntityMixin.java | 21 +++++++-- .../mixin/BuiltChunkMixin.java | 23 ++++++++++ .../mixin/ChestBlockEntityMixin.java | 26 ++++++++--- .../mixin/DecoratedPotBlockEntityMixin.java | 25 +++++++--- .../mixin/EnderChestBlockEntityMixin.java | 26 ++++++++--- .../mixin/ShulkerBoxBlockEntityMixin.java | 19 ++++++-- .../mixin/WorldRendererMixin.java | 42 ++++++++--------- .../sodium/RenderSectionManagerMixin.java | 46 +++++++++++++++++++ .../compat/sodium/RenderSectionMixin.java | 28 +++++++++++ .../enhancedblockentities/util/ConvUtil.java | 2 +- .../util/ExecutableRunnableHashSet.java | 10 ++++ .../enhancedblockentities/util/WorldUtil.java | 32 ++++++------- .../util/duck/AppearanceStateHolder.java | 24 ++++++++++ .../util/duck/BakedModelManagerAccess.java | 2 +- .../util/duck/ChunkRebuildTaskAccess.java | 17 +++++++ .../util/duck/ModelStateHolder.java | 20 -------- .../enhancedblockentities.mixins.json | 5 +- 28 files changed, 315 insertions(+), 126 deletions(-) create mode 100644 src/main/java/foundationgames/enhancedblockentities/mixin/BuiltChunkMixin.java create mode 100644 src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionManagerMixin.java create mode 100644 src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionMixin.java create mode 100644 src/main/java/foundationgames/enhancedblockentities/util/ExecutableRunnableHashSet.java create mode 100644 src/main/java/foundationgames/enhancedblockentities/util/duck/AppearanceStateHolder.java create mode 100644 src/main/java/foundationgames/enhancedblockentities/util/duck/ChunkRebuildTaskAccess.java delete mode 100644 src/main/java/foundationgames/enhancedblockentities/util/duck/ModelStateHolder.java diff --git a/build.gradle b/build.gradle index f0650ceb..1cb252f6 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,9 @@ dependencies { // Mod Menu because config screen access from another place modApi "com.terraformersmc:modmenu:${project.modmenu_version}" + // Sodium for compatibility + modCompileOnlyApi "maven.modrinth:sodium:${project.sodium_version}" + // a bit less load time modLocalRuntime "maven.modrinth:lazydfu:0.1.3" } diff --git a/gradle.properties b/gradle.properties index c803d9bc..90499015 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,3 +12,6 @@ archives_base_name = enhancedblockentities arrp_version=0.8.1 modmenu_version=9.2.0-beta.2 + +sodium_version=mc1.20.4-0.5.8 +indium_version=1.0.30+mc1.20.4 \ No newline at end of file diff --git a/src/main/java/foundationgames/enhancedblockentities/EBESetup.java b/src/main/java/foundationgames/enhancedblockentities/EBESetup.java index 14b41795..63ffd097 100644 --- a/src/main/java/foundationgames/enhancedblockentities/EBESetup.java +++ b/src/main/java/foundationgames/enhancedblockentities/EBESetup.java @@ -332,12 +332,12 @@ public static void setupChests() { new ChestBlockEntityRendererOverride(() -> { BakedModelManagerAccess manager = (BakedModelManagerAccess) MinecraftClient.getInstance().getBakedModelManager(); return new BakedModel[] { - manager.getModel(ModelIdentifiers.CHEST_CENTER_LID), - manager.getModel(ModelIdentifiers.CHEST_LEFT_LID), - manager.getModel(ModelIdentifiers.CHEST_RIGHT_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_CENTER_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_LEFT_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_RIGHT_LID) + manager.enhanced_bes$getModel(ModelIdentifiers.CHEST_CENTER_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHEST_LEFT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHEST_RIGHT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_CENTER_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_LEFT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_RIGHT_LID) }; }, christmasChestSelector) ); @@ -345,19 +345,19 @@ public static void setupChests() { new ChestBlockEntityRendererOverride(() -> { BakedModelManagerAccess manager = (BakedModelManagerAccess)MinecraftClient.getInstance().getBakedModelManager(); return new BakedModel[] { - manager.getModel(ModelIdentifiers.TRAPPED_CHEST_CENTER_LID), - manager.getModel(ModelIdentifiers.TRAPPED_CHEST_LEFT_LID), - manager.getModel(ModelIdentifiers.TRAPPED_CHEST_RIGHT_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_CENTER_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_LEFT_LID), - manager.getModel(ModelIdentifiers.CHRISTMAS_CHEST_RIGHT_LID) + manager.enhanced_bes$getModel(ModelIdentifiers.TRAPPED_CHEST_CENTER_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.TRAPPED_CHEST_LEFT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.TRAPPED_CHEST_RIGHT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_CENTER_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_LEFT_LID), + manager.enhanced_bes$getModel(ModelIdentifiers.CHRISTMAS_CHEST_RIGHT_LID) }; }, christmasChestSelector) ); EnhancedBlockEntityRegistry.register(Blocks.ENDER_CHEST, BlockEntityType.ENDER_CHEST, BlockEntityRenderCondition.CHEST, new ChestBlockEntityRendererOverride(() -> { BakedModelManagerAccess manager = (BakedModelManagerAccess)MinecraftClient.getInstance().getBakedModelManager(); - return new BakedModel[] { manager.getModel(ModelIdentifiers.ENDER_CHEST_CENTER_LID) }; + return new BakedModel[] { manager.enhanced_bes$getModel(ModelIdentifiers.ENDER_CHEST_CENTER_LID) }; }, entity -> 0) ); } @@ -434,7 +434,7 @@ public static void setupShulkerBoxes() { new ShulkerBoxBlockEntityRendererOverride((map) -> { var models = (BakedModelManagerAccess) MinecraftClient.getInstance().getBakedModelManager(); for (DyeColor dc : EBEUtil.DEFAULTED_DYE_COLORS) { - map.put(dc, models.getModel(ModelIdentifiers.SHULKER_BOX_LIDS.get(dc))); + map.put(dc, models.enhanced_bes$getModel(ModelIdentifiers.SHULKER_BOX_LIDS.get(dc))); } }) ); diff --git a/src/main/java/foundationgames/enhancedblockentities/client/model/DynamicModelProvidingPlugin.java b/src/main/java/foundationgames/enhancedblockentities/client/model/DynamicModelProvidingPlugin.java index 048d6a3e..5b05873e 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/model/DynamicModelProvidingPlugin.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/model/DynamicModelProvidingPlugin.java @@ -1,13 +1,14 @@ package foundationgames.enhancedblockentities.client.model; import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier; +import net.fabricmc.fabric.api.client.model.loading.v1.ModelResolver; import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; -public class DynamicModelProvidingPlugin implements ModelLoadingPlugin, ModelModifier.BeforeBake { +public class DynamicModelProvidingPlugin implements ModelLoadingPlugin, ModelResolver { private final Supplier model; private final Identifier id; @@ -18,12 +19,12 @@ public DynamicModelProvidingPlugin(Identifier id, Supplier @Override public void onInitializeModelLoader(ModelLoadingPlugin.Context ctx) { - ctx.modifyModelBeforeBake().register(this); + ctx.resolveModel().register(this); } @Override - public UnbakedModel modifyModelBeforeBake(UnbakedModel model, ModelModifier.BeforeBake.Context ctx) { + public @Nullable UnbakedModel resolveModel(ModelResolver.Context ctx) { if(ctx.id().equals(this.id)) return this.model.get(); - return model; + return null; } } diff --git a/src/main/java/foundationgames/enhancedblockentities/client/model/ModelSelector.java b/src/main/java/foundationgames/enhancedblockentities/client/model/ModelSelector.java index 84f8b253..81de3e5c 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/model/ModelSelector.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/model/ModelSelector.java @@ -1,7 +1,7 @@ package foundationgames.enhancedblockentities.client.model; import foundationgames.enhancedblockentities.util.DateUtil; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -19,7 +19,7 @@ public abstract class ModelSelector { public static final ModelSelector STATE_HOLDER_SELECTOR = new ModelSelector() { @Override public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier rand, @Nullable RenderContext ctx, int[] indices) { - if(view.getBlockEntity(pos) instanceof ModelStateHolder stateHolder) { + if(view.getBlockEntity(pos) instanceof AppearanceStateHolder stateHolder) { indices[0] = stateHolder.getModelState(); return; } @@ -37,7 +37,7 @@ public int getParticleModelIndex() { @Override public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier rand, @Nullable RenderContext ctx, int[] indices) { - if(view.getBlockEntity(pos) instanceof ModelStateHolder stateHolder) { + if(view.getBlockEntity(pos) instanceof AppearanceStateHolder stateHolder) { indices[0] = stateHolder.getModelState() + this.getParticleModelIndex(); return; } diff --git a/src/main/java/foundationgames/enhancedblockentities/client/model/misc/DecoratedPotModelSelector.java b/src/main/java/foundationgames/enhancedblockentities/client/model/misc/DecoratedPotModelSelector.java index 3065c25f..03d9e634 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/model/misc/DecoratedPotModelSelector.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/model/misc/DecoratedPotModelSelector.java @@ -2,7 +2,7 @@ import foundationgames.enhancedblockentities.client.model.ModelIdentifiers; import foundationgames.enhancedblockentities.client.model.ModelSelector; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.block.BlockState; import net.minecraft.block.DecoratedPotPatterns; @@ -61,7 +61,7 @@ public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos p indices[0] = IDX_BASE_POT; if (view.getBlockEntity(pos) instanceof DecoratedPotBlockEntity pot) { - if (pot instanceof ModelStateHolder ms && ms.getModelState() > 0) { + if (pot instanceof AppearanceStateHolder ms && ms.getModelState() > 0) { Arrays.fill(indices, IDX_EMPTY); return; } diff --git a/src/main/java/foundationgames/enhancedblockentities/client/render/BlockEntityRenderCondition.java b/src/main/java/foundationgames/enhancedblockentities/client/render/BlockEntityRenderCondition.java index 5f9326d5..36beea70 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/render/BlockEntityRenderCondition.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/render/BlockEntityRenderCondition.java @@ -3,7 +3,7 @@ import foundationgames.enhancedblockentities.EnhancedBlockEntities; import foundationgames.enhancedblockentities.config.EBEConfig; import foundationgames.enhancedblockentities.mixin.SignBlockEntityRenderAccessor; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.Vec3d; @@ -11,8 +11,8 @@ @FunctionalInterface public interface BlockEntityRenderCondition { BlockEntityRenderCondition NON_ZERO_STATE = entity -> { - if(entity instanceof ModelStateHolder stateHolder) { - return stateHolder.getModelState() > 0; + if(entity instanceof AppearanceStateHolder stateHolder) { + return stateHolder.getRenderState() > 0; } return false; }; diff --git a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/BellBlockEntityRendererOverride.java b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/BellBlockEntityRendererOverride.java index df65129e..3e82c0c0 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/BellBlockEntityRendererOverride.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/BellBlockEntityRendererOverride.java @@ -50,7 +50,7 @@ public void render(BlockEntityRenderer renderer, BlockEntity blockE private BakedModel getBellModel() { BakedModelManagerAccess manager = (BakedModelManagerAccess)MinecraftClient.getInstance().getBakedModelManager(); - return manager.getModel(ModelIdentifiers.BELL_BODY); + return manager.enhanced_bes$getModel(ModelIdentifiers.BELL_BODY); } @Override diff --git a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/ChestBlockEntityRendererOverride.java b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/ChestBlockEntityRendererOverride.java index 055afa4b..4ba7a4fe 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/ChestBlockEntityRendererOverride.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/ChestBlockEntityRendererOverride.java @@ -34,7 +34,7 @@ public void render(BlockEntityRenderer renderer, BlockEntity blockE if (blockEntity instanceof LidOpenable) { matrices.push(); - LidOpenable chest = getAnimationProgress(blockEntity, tickDelta); + LidOpenable chest = getLidAnimationHolder(blockEntity, tickDelta); matrices.translate(0.5f, 0, 0.5f); Direction dir = blockEntity.getCachedState().get(ChestBlock.FACING); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - dir.asRotation())); @@ -53,7 +53,7 @@ public void render(BlockEntityRenderer renderer, BlockEntity blockE } } - public static LidOpenable getAnimationProgress(BlockEntity blockEntity, float tickDelta) { + public static LidOpenable getLidAnimationHolder(BlockEntity blockEntity, float tickDelta) { LidOpenable chest = (LidOpenable)blockEntity; BlockState state = blockEntity.getCachedState(); diff --git a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/DecoratedPotBlockEntityRendererOverride.java b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/DecoratedPotBlockEntityRendererOverride.java index 5c9e7164..f75c8938 100644 --- a/src/main/java/foundationgames/enhancedblockentities/client/render/entity/DecoratedPotBlockEntityRendererOverride.java +++ b/src/main/java/foundationgames/enhancedblockentities/client/render/entity/DecoratedPotBlockEntityRendererOverride.java @@ -30,7 +30,7 @@ private void tryGetModels() { var models = (BakedModelManagerAccess) MinecraftClient.getInstance().getBakedModelManager(); if (this.baseModel == null) { - this.baseModel = models.getModel(ModelIdentifiers.DECORATED_POT_BASE); + this.baseModel = models.enhanced_bes$getModel(ModelIdentifiers.DECORATED_POT_BASE); } if (this.potPatternModels == null) { @@ -41,7 +41,7 @@ private void tryGetModels() { BakedModel[] patternPerFaceModels = new BakedModel[patternModelIDs.length]; for (int i = 0; i < patternModelIDs.length; i++) { - patternPerFaceModels[i] = models.getModel(patternModelIDs[i]); + patternPerFaceModels[i] = models.enhanced_bes$getModel(patternModelIDs[i]); } builder.put(k, patternPerFaceModels); diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/BakedModelManagerMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/BakedModelManagerMixin.java index 02660de0..f8063abb 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/BakedModelManagerMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/BakedModelManagerMixin.java @@ -23,7 +23,7 @@ public class BakedModelManagerMixin implements BakedModelManagerAccess { @Shadow private Map models; @Override - public BakedModel getModel(Identifier id) { + public BakedModel enhanced_bes$getModel(Identifier id) { return this.models.get(id); } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/BellBlockEntityMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/BellBlockEntityMixin.java index 3059d081..c34954f4 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/BellBlockEntityMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/BellBlockEntityMixin.java @@ -1,7 +1,7 @@ package foundationgames.enhancedblockentities.mixin; import foundationgames.enhancedblockentities.EnhancedBlockEntities; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BellBlockEntity; import net.minecraft.block.entity.BlockEntity; @@ -14,8 +14,9 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(BellBlockEntity.class) -public class BellBlockEntityMixin extends BlockEntity implements ModelStateHolder { +public class BellBlockEntityMixin extends BlockEntity implements AppearanceStateHolder { @Unique private int enhanced_bes$modelState = 0; + @Unique private int enhanced_bes$renderState = 0; public BellBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -28,8 +29,8 @@ public BellBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState st ), index = 3) private static BellBlockEntity enhanced_bes$listenForStopRinging(BellBlockEntity blockEntity) { int mState = blockEntity.ringTicks > 0 ? 1 : 0; - if (EnhancedBlockEntities.CONFIG.renderEnhancedBells && ((ModelStateHolder)blockEntity).getModelState() != mState) { - ((ModelStateHolder)blockEntity).setModelState(mState, blockEntity.getWorld(), blockEntity.getPos()); + if (EnhancedBlockEntities.CONFIG.renderEnhancedBells && ((AppearanceStateHolder)blockEntity).getModelState() != mState) { + ((AppearanceStateHolder)blockEntity).updateAppearanceState(mState, blockEntity.getWorld(), blockEntity.getPos()); } return blockEntity; } @@ -40,7 +41,17 @@ public int getModelState() { } @Override - public void applyModelState(int state) { + public void setModelState(int state) { this.enhanced_bes$modelState = state; } + + @Override + public int getRenderState() { + return enhanced_bes$renderState; + } + + @Override + public void setRenderState(int state) { + this.enhanced_bes$renderState = state; + } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/BuiltChunkMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/BuiltChunkMixin.java new file mode 100644 index 00000000..910d50e1 --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/BuiltChunkMixin.java @@ -0,0 +1,23 @@ +package foundationgames.enhancedblockentities.mixin; + +import foundationgames.enhancedblockentities.util.duck.ChunkRebuildTaskAccess; +import net.minecraft.client.render.chunk.ChunkBuilder; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(ChunkBuilder.BuiltChunk.class) +public class BuiltChunkMixin implements ChunkRebuildTaskAccess { + private @Unique + @Nullable Runnable enhanced_bes$taskAfterRebuild = null; + + @Override + public Runnable enhanced_bes$getTaskAfterRebuild() { + return enhanced_bes$taskAfterRebuild; + } + + @Override + public void enhanced_bes$setTaskAfterRebuild(Runnable task) { + enhanced_bes$taskAfterRebuild = task; + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/ChestBlockEntityMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/ChestBlockEntityMixin.java index b5066f1b..8a5fecc0 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/ChestBlockEntityMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/ChestBlockEntityMixin.java @@ -2,7 +2,7 @@ import foundationgames.enhancedblockentities.EnhancedBlockEntities; import foundationgames.enhancedblockentities.client.render.entity.ChestBlockEntityRendererOverride; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; @@ -16,8 +16,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ChestBlockEntity.class) -public abstract class ChestBlockEntityMixin extends BlockEntity implements ModelStateHolder { +public abstract class ChestBlockEntityMixin extends BlockEntity implements AppearanceStateHolder { @Unique private int enhanced_bes$modelState = 0; + @Unique private int enhanced_bes$renderState = 0; private ChestBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -25,10 +26,11 @@ private ChestBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState @Inject(method = "clientTick", at = @At(value = "TAIL")) private static void enhanced_bes$listenForOpenClose(World world, BlockPos pos, BlockState state, ChestBlockEntity blockEntity, CallbackInfo ci) { - int mState = ChestBlockEntityRendererOverride.getAnimationProgress(blockEntity, 0) - .getAnimationProgress(0) > 0 ? 1 : 0; - if (EnhancedBlockEntities.CONFIG.renderEnhancedChests && ((ModelStateHolder)blockEntity).getModelState() != mState) { - ((ModelStateHolder)blockEntity).setModelState(mState, world, pos); + var lid = ChestBlockEntityRendererOverride.getLidAnimationHolder(blockEntity, 0.5f); + int mState = lid.getAnimationProgress(0.5f) > 0 ? 1 : 0; + + if (EnhancedBlockEntities.CONFIG.renderEnhancedChests && ((AppearanceStateHolder)blockEntity).getModelState() != mState) { + ((AppearanceStateHolder)blockEntity).updateAppearanceState(mState, world, pos); } } @@ -38,7 +40,17 @@ public int getModelState() { } @Override - public void applyModelState(int state) { + public void setModelState(int state) { this.enhanced_bes$modelState = state; } + + @Override + public int getRenderState() { + return enhanced_bes$renderState; + } + + @Override + public void setRenderState(int state) { + this.enhanced_bes$renderState = state; + } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/DecoratedPotBlockEntityMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/DecoratedPotBlockEntityMixin.java index a9cad02f..9c3d4584 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/DecoratedPotBlockEntityMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/DecoratedPotBlockEntityMixin.java @@ -1,7 +1,7 @@ package foundationgames.enhancedblockentities.mixin; import foundationgames.enhancedblockentities.util.WorldUtil; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.entity.DecoratedPotBlockEntity; import net.minecraft.nbt.NbtCompound; import org.spongepowered.asm.mixin.Mixin; @@ -12,15 +12,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(DecoratedPotBlockEntity.class) -public class DecoratedPotBlockEntityMixin implements ModelStateHolder { +public class DecoratedPotBlockEntityMixin implements AppearanceStateHolder { @Unique private int enhanced_bes$modelState = 0; + @Unique private int enhanced_bes$renderState = 0; @Inject(method = "readNbt", at = @At("TAIL")) private void enhanced_bes$updateChunkOnPatternsLoaded(NbtCompound nbt, CallbackInfo ci) { var self = (DecoratedPotBlockEntity)(Object)this; if (self.getWorld() != null && self.getWorld().isClient()) { - WorldUtil.rebuildChunkSynchronously(self.getWorld(), self.getPos(), false); + WorldUtil.rebuildChunk(self.getWorld(), self.getPos()); } } @@ -33,12 +34,12 @@ public class DecoratedPotBlockEntityMixin implements ModelStateHolder { return; } - this.setModelState(1, world, self.getPos()); + this.updateAppearanceState(1, world, self.getPos()); - WorldUtil.schedule(world, self.lastWobbleTime + self.lastWobbleType.lengthInTicks, + WorldUtil.scheduleTimed(world, self.lastWobbleTime + self.lastWobbleType.lengthInTicks, () -> { if (self.getWorld().getTime() >= self.lastWobbleTime + self.lastWobbleType.lengthInTicks) { - this.setModelState(0, world, self.getPos()); + this.updateAppearanceState(0, world, self.getPos()); } }); } @@ -49,7 +50,17 @@ public int getModelState() { } @Override - public void applyModelState(int state) { + public void setModelState(int state) { this.enhanced_bes$modelState = state; } + + @Override + public int getRenderState() { + return enhanced_bes$renderState; + } + + @Override + public void setRenderState(int state) { + this.enhanced_bes$renderState = state; + } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/EnderChestBlockEntityMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/EnderChestBlockEntityMixin.java index 6b8db544..b24c90e9 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/EnderChestBlockEntityMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/EnderChestBlockEntityMixin.java @@ -1,7 +1,8 @@ package foundationgames.enhancedblockentities.mixin; import foundationgames.enhancedblockentities.EnhancedBlockEntities; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.client.render.entity.ChestBlockEntityRendererOverride; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; @@ -15,8 +16,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EnderChestBlockEntity.class) -public abstract class EnderChestBlockEntityMixin extends BlockEntity implements ModelStateHolder { +public abstract class EnderChestBlockEntityMixin extends BlockEntity implements AppearanceStateHolder { @Unique private int enhanced_bes$modelState = 0; + @Unique private int enhanced_bes$renderState = 0; private EnderChestBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -24,9 +26,11 @@ private EnderChestBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockS @Inject(method = "clientTick", at = @At(value = "TAIL")) private static void enhanced_bes$listenForOpenClose(World world, BlockPos pos, BlockState state, EnderChestBlockEntity blockEntity, CallbackInfo ci) { - int mState = blockEntity.getAnimationProgress(0) > 0 ? 1 : 0; - if (EnhancedBlockEntities.CONFIG.renderEnhancedChests && ((ModelStateHolder)blockEntity).getModelState() != mState) { - ((ModelStateHolder)blockEntity).setModelState(mState, world, pos); + var lid = ChestBlockEntityRendererOverride.getLidAnimationHolder(blockEntity, 0.5f); + int mState = lid.getAnimationProgress(0.5f) > 0 ? 1 : 0; + + if (EnhancedBlockEntities.CONFIG.renderEnhancedChests && ((AppearanceStateHolder)blockEntity).getModelState() != mState) { + ((AppearanceStateHolder)blockEntity).updateAppearanceState(mState, world, pos); } } @@ -36,7 +40,17 @@ public int getModelState() { } @Override - public void applyModelState(int state) { + public void setModelState(int state) { this.enhanced_bes$modelState = state; } + + @Override + public int getRenderState() { + return enhanced_bes$renderState; + } + + @Override + public void setRenderState(int state) { + this.enhanced_bes$renderState = state; + } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/ShulkerBoxBlockEntityMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/ShulkerBoxBlockEntityMixin.java index 8dbfb0b0..472076fe 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/ShulkerBoxBlockEntityMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/ShulkerBoxBlockEntityMixin.java @@ -1,6 +1,6 @@ package foundationgames.enhancedblockentities.mixin; -import foundationgames.enhancedblockentities.util.duck.ModelStateHolder; +import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; @@ -15,10 +15,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ShulkerBoxBlockEntity.class) -public abstract class ShulkerBoxBlockEntityMixin extends BlockEntity implements ModelStateHolder { +public abstract class ShulkerBoxBlockEntityMixin extends BlockEntity implements AppearanceStateHolder { @Shadow public abstract float getAnimationProgress(float delta); @Unique private int enhanced_bes$modelState = 0; + @Unique private int enhanced_bes$renderState = 0; public ShulkerBoxBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -27,7 +28,7 @@ public ShulkerBoxBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockSt @Inject(method = "updateAnimation", at = @At("TAIL")) private void enhanced_bes$updateModelState(World world, BlockPos pos, BlockState state, CallbackInfo ci) { int mState = this.getAnimationProgress(0) > 0 ? 1 : 0; - if (mState != enhanced_bes$modelState) setModelState(mState, world, pos); + if (mState != enhanced_bes$modelState) updateAppearanceState(mState, world, pos); } @Override @@ -36,7 +37,17 @@ public int getModelState() { } @Override - public void applyModelState(int state) { + public void setModelState(int state) { this.enhanced_bes$modelState = state; } + + @Override + public int getRenderState() { + return enhanced_bes$renderState; + } + + @Override + public void setRenderState(int state) { + this.enhanced_bes$renderState = state; + } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/WorldRendererMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/WorldRendererMixin.java index 6c146264..8b1e545c 100644 --- a/src/main/java/foundationgames/enhancedblockentities/mixin/WorldRendererMixin.java +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/WorldRendererMixin.java @@ -1,41 +1,37 @@ package foundationgames.enhancedblockentities.mixin; import foundationgames.enhancedblockentities.util.WorldUtil; +import foundationgames.enhancedblockentities.util.duck.ChunkRebuildTaskAccess; import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.render.chunk.ChunkBuilder; import net.minecraft.util.math.ChunkSectionPos; -import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WorldRenderer.class) public class WorldRendererMixin { - private ChunkSectionPos enhanced_bes$updatingChunk = null; @ModifyVariable(method = "updateChunks", - at = @At(value = "INVOKE_ASSIGN", shift = At.Shift.AFTER, target = "Lnet/minecraft/util/math/ChunkSectionPos;from(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/math/ChunkSectionPos;"), - index = 8) - private ChunkSectionPos enhanced_bes$cacheUpdatedChunkPos(ChunkSectionPos c) { - enhanced_bes$updatingChunk = c; - return c; - } - - /* X------------------------updateChunks(Camera camera)-------------------------X - |---> HERE <--- | - | if (bl) { | - | this.client.getProfiler().push("build_near_sync"); | - | this.chunkBuilder.rebuild(builtChunk, chunkRendererRegionBuilder); | - X----------------------------[END: 5 LINES DOWN]-----------------------------X */ - @ModifyVariable(method = "updateChunks", at = @At(value = "JUMP", shift = At.Shift.BEFORE, opcode = Opcodes.IFEQ, ordinal = 4), index = 9) - private boolean enhanced_bes$forceSynchronousChunkRebuild(boolean old) { - if (enhanced_bes$updatingChunk != null && WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.contains(enhanced_bes$updatingChunk)) { - WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.remove(enhanced_bes$updatingChunk); + at = @At(value = "INVOKE", shift = At.Shift.BEFORE, ordinal = 0, target = "Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;"), + index = 7) + private ChunkBuilder.BuiltChunk enhanced_bes$addPostRebuildTask(ChunkBuilder.BuiltChunk chunk) { + if (WorldUtil.CHUNK_UPDATE_TASKS.size() > 0) { + var pos = ChunkSectionPos.from(chunk.getOrigin()); - enhanced_bes$updatingChunk = null; - return true; + if (WorldUtil.CHUNK_UPDATE_TASKS.containsKey(pos)) { + var task = WorldUtil.CHUNK_UPDATE_TASKS.remove(pos); + ((ChunkRebuildTaskAccess) chunk).enhanced_bes$setTaskAfterRebuild(task); + } } - enhanced_bes$updatingChunk = null; - return old; + return chunk; + } + + @Inject(method = "addBuiltChunk", at = @At("HEAD")) + private void enhanced_bes$runPostRebuildTask(ChunkBuilder.BuiltChunk chunk, CallbackInfo ci) { + ((ChunkRebuildTaskAccess) chunk).enhanced_bes$runAfterRebuildTask(); } } diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionManagerMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionManagerMixin.java new file mode 100644 index 00000000..f481ee85 --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionManagerMixin.java @@ -0,0 +1,46 @@ +package foundationgames.enhancedblockentities.mixin.compat.sodium; + +import foundationgames.enhancedblockentities.util.WorldUtil; +import foundationgames.enhancedblockentities.util.duck.ChunkRebuildTaskAccess; +import me.jellysquid.mods.sodium.client.render.chunk.RenderSection; +import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager; +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildOutput; +import net.minecraft.util.math.ChunkSectionPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +/** + *

Adapted from {@link foundationgames.enhancedblockentities.mixin.WorldRendererMixin}

+ */ +@Pseudo +@Mixin(value = RenderSectionManager.class, remap = false) +public class RenderSectionManagerMixin { + @ModifyVariable(method = "submitRebuildTasks", + at = @At(value = "INVOKE", shift = At.Shift.BEFORE, ordinal = 0, target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;isDisposed()Z"), + index = 4, require = 0 + ) + private RenderSection enhanced_bes$compat_sodium$cacheUpdatingChunk(RenderSection section) { + if (WorldUtil.CHUNK_UPDATE_TASKS.size() > 0) { + var pos = ChunkSectionPos.from(section.getChunkX(), section.getChunkY(), section.getChunkZ()); + + if (WorldUtil.CHUNK_UPDATE_TASKS.containsKey(pos)) { + var task = WorldUtil.CHUNK_UPDATE_TASKS.remove(pos); + ((ChunkRebuildTaskAccess) section).enhanced_bes$setTaskAfterRebuild(task); + } + } + + return section; + } + + @ModifyVariable(method = "processChunkBuildResults", + at = @At(value = "INVOKE_ASSIGN", shift = At.Shift.BEFORE, ordinal = 0, target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;getBuildCancellationToken()Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;"), + index = 4, require = 0 + ) + private ChunkBuildOutput enhanced_bes$runPostRebuildTask(ChunkBuildOutput output) { + ((ChunkRebuildTaskAccess) output.render).enhanced_bes$runAfterRebuildTask(); + + return output; + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionMixin.java b/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionMixin.java new file mode 100644 index 00000000..6fcb64d7 --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/mixin/compat/sodium/RenderSectionMixin.java @@ -0,0 +1,28 @@ +package foundationgames.enhancedblockentities.mixin.compat.sodium; + +import foundationgames.enhancedblockentities.util.duck.ChunkRebuildTaskAccess; +import me.jellysquid.mods.sodium.client.render.chunk.RenderSection; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Unique; + + +/** + *

Adapted from {@link foundationgames.enhancedblockentities.mixin.BuiltChunkMixin}

+ */ +@Pseudo +@Mixin(value = RenderSection.class, remap = false) +public class RenderSectionMixin implements ChunkRebuildTaskAccess { + private @Unique @Nullable Runnable enhanced_bes$taskAfterRebuild = null; + + @Override + public Runnable enhanced_bes$getTaskAfterRebuild() { + return enhanced_bes$taskAfterRebuild; + } + + @Override + public void enhanced_bes$setTaskAfterRebuild(Runnable task) { + enhanced_bes$taskAfterRebuild = task; + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/util/ConvUtil.java b/src/main/java/foundationgames/enhancedblockentities/util/ConvUtil.java index b4127619..dadd94b9 100644 --- a/src/main/java/foundationgames/enhancedblockentities/util/ConvUtil.java +++ b/src/main/java/foundationgames/enhancedblockentities/util/ConvUtil.java @@ -2,7 +2,7 @@ public enum ConvUtil {; public static boolean bool(String bool) { - return bool != null && bool.toLowerCase().equals("true"); + return bool != null && bool.equalsIgnoreCase("true"); } public static boolean defaultedBool(String bool, boolean defaultVal) { diff --git a/src/main/java/foundationgames/enhancedblockentities/util/ExecutableRunnableHashSet.java b/src/main/java/foundationgames/enhancedblockentities/util/ExecutableRunnableHashSet.java new file mode 100644 index 00000000..bcaf81ae --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/util/ExecutableRunnableHashSet.java @@ -0,0 +1,10 @@ +package foundationgames.enhancedblockentities.util; + +import java.util.HashSet; + +public class ExecutableRunnableHashSet extends HashSet implements Runnable { + @Override + public void run() { + this.forEach(Runnable::run); + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/util/WorldUtil.java b/src/main/java/foundationgames/enhancedblockentities/util/WorldUtil.java index 75d7cb6e..3f1bc88c 100644 --- a/src/main/java/foundationgames/enhancedblockentities/util/WorldUtil.java +++ b/src/main/java/foundationgames/enhancedblockentities/util/WorldUtil.java @@ -1,6 +1,5 @@ package foundationgames.enhancedblockentities.util; -import foundationgames.enhancedblockentities.EnhancedBlockEntities; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -12,38 +11,35 @@ import net.minecraft.world.World; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; public enum WorldUtil implements ClientTickEvents.EndWorldTick { EVENT_LISTENER; - public static Set FORCE_SYNCHRONOUS_CHUNK_REBUILD = new HashSet<>(); - private static Map, Long2ObjectMap> SCHEDULED_TASKS = new HashMap<>(); + public static final Map CHUNK_UPDATE_TASKS = new HashMap<>(); + private static final Map, Long2ObjectMap> TIMED_TASKS = new HashMap<>(); - public static void rebuildChunkSynchronously(World world, BlockPos pos, boolean forceSync) { + public static void rebuildChunk(World world, BlockPos pos) { var bState = world.getBlockState(pos); - try { - if (forceSync) { - WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.add(ChunkSectionPos.from(pos)); - } - MinecraftClient.getInstance().worldRenderer.updateBlock(world, pos, bState, bState, 8); - } catch (NullPointerException ignored) { - EnhancedBlockEntities.LOG.warn("Error rebuilding chunk at block pos "+pos); - } + MinecraftClient.getInstance().worldRenderer.updateBlock(world, pos, bState, bState, 8); + } + + public static void rebuildChunkAndThen(World world, BlockPos pos, Runnable action) { + var state = world.getBlockState(pos); + CHUNK_UPDATE_TASKS.computeIfAbsent(ChunkSectionPos.from(pos), k -> new ExecutableRunnableHashSet()).add(action); + MinecraftClient.getInstance().worldRenderer.updateBlock(world, pos, state, state, 8); } - public static void schedule(World world, long time, Runnable action) { - SCHEDULED_TASKS.computeIfAbsent(world.getRegistryKey(), k -> new Long2ObjectOpenHashMap<>()).put(time, action); + public static void scheduleTimed(World world, long time, Runnable action) { + TIMED_TASKS.computeIfAbsent(world.getRegistryKey(), k -> new Long2ObjectOpenHashMap<>()).put(time, action); } @Override public void onEndTick(ClientWorld world) { var key = world.getRegistryKey(); - if (SCHEDULED_TASKS.containsKey(key)) { - SCHEDULED_TASKS.get(key).long2ObjectEntrySet().removeIf(entry -> { + if (TIMED_TASKS.containsKey(key)) { + TIMED_TASKS.get(key).long2ObjectEntrySet().removeIf(entry -> { if (world.getTime() >= entry.getLongKey()) { entry.getValue().run(); return true; diff --git a/src/main/java/foundationgames/enhancedblockentities/util/duck/AppearanceStateHolder.java b/src/main/java/foundationgames/enhancedblockentities/util/duck/AppearanceStateHolder.java new file mode 100644 index 00000000..e0d8ddc2 --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/util/duck/AppearanceStateHolder.java @@ -0,0 +1,24 @@ +package foundationgames.enhancedblockentities.util.duck; + +import foundationgames.enhancedblockentities.util.WorldUtil; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public interface AppearanceStateHolder { + int getModelState(); + + void setModelState(int state); + + int getRenderState(); + + void setRenderState(int state); + + default void updateAppearanceState(int state, World world, BlockPos pos) { + if (!world.isClient()) { + return; + } + + this.setModelState(state); + WorldUtil.rebuildChunkAndThen(world, pos, () -> this.setRenderState(state)); + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/util/duck/BakedModelManagerAccess.java b/src/main/java/foundationgames/enhancedblockentities/util/duck/BakedModelManagerAccess.java index 509312df..7662a19c 100644 --- a/src/main/java/foundationgames/enhancedblockentities/util/duck/BakedModelManagerAccess.java +++ b/src/main/java/foundationgames/enhancedblockentities/util/duck/BakedModelManagerAccess.java @@ -4,5 +4,5 @@ import net.minecraft.util.Identifier; public interface BakedModelManagerAccess { - BakedModel getModel(Identifier id); + BakedModel enhanced_bes$getModel(Identifier id); } diff --git a/src/main/java/foundationgames/enhancedblockentities/util/duck/ChunkRebuildTaskAccess.java b/src/main/java/foundationgames/enhancedblockentities/util/duck/ChunkRebuildTaskAccess.java new file mode 100644 index 00000000..e72114f3 --- /dev/null +++ b/src/main/java/foundationgames/enhancedblockentities/util/duck/ChunkRebuildTaskAccess.java @@ -0,0 +1,17 @@ +package foundationgames.enhancedblockentities.util.duck; + +public interface ChunkRebuildTaskAccess { + Runnable enhanced_bes$getTaskAfterRebuild(); + + void enhanced_bes$setTaskAfterRebuild(Runnable task); + + default void enhanced_bes$runAfterRebuildTask() { + var task = this.enhanced_bes$getTaskAfterRebuild(); + + if (task != null) { + task.run(); + + this.enhanced_bes$setTaskAfterRebuild(null); + } + } +} diff --git a/src/main/java/foundationgames/enhancedblockentities/util/duck/ModelStateHolder.java b/src/main/java/foundationgames/enhancedblockentities/util/duck/ModelStateHolder.java deleted file mode 100644 index 8dddf70d..00000000 --- a/src/main/java/foundationgames/enhancedblockentities/util/duck/ModelStateHolder.java +++ /dev/null @@ -1,20 +0,0 @@ -package foundationgames.enhancedblockentities.util.duck; - -import foundationgames.enhancedblockentities.util.WorldUtil; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -public interface ModelStateHolder { - int getModelState(); - - void applyModelState(int state); - - default void setModelState(int state, World world, BlockPos pos) { - if (!world.isClient()) { - return; - } - - this.applyModelState(state); - WorldUtil.rebuildChunkSynchronously(world, pos, true); - } -} diff --git a/src/main/resources/enhancedblockentities.mixins.json b/src/main/resources/enhancedblockentities.mixins.json index 3b91494a..7dc73919 100644 --- a/src/main/resources/enhancedblockentities.mixins.json +++ b/src/main/resources/enhancedblockentities.mixins.json @@ -8,6 +8,7 @@ "BakedModelManagerMixin", "BellBlockEntityMixin", "BlockEntityRenderDispatcherMixin", + "BuiltChunkMixin", "BuiltinModelItemRendererMixin", "ChestBlockEntityMixin", "DecoratedPotBlockEntityMixin", @@ -17,7 +18,9 @@ "SignBlockEntityRenderAccessor", "SignEditScreenMixin", "VideoOptionsScreenMixin", - "WorldRendererMixin" + "WorldRendererMixin", + "compat.sodium.RenderSectionManagerMixin", + "compat.sodium.RenderSectionMixin" ], "injectors": { "defaultRequire": 1