From 3a186c128667eb42736ce11993432e23916b72a4 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 23 Oct 2021 01:56:15 +0200 Subject: [PATCH] More Calls - Fixed dist error spam with Contraption interaction on servers --- .../MovingInteractionBehaviour.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovingInteractionBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovingInteractionBehaviour.java index 67eeb10ff..8165150b7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovingInteractionBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovingInteractionBehaviour.java @@ -8,6 +8,9 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.feature.template.Template.BlockInfo; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.DistExecutor; public abstract class MovingInteractionBehaviour { @@ -17,12 +20,19 @@ public abstract class MovingInteractionBehaviour { MovementContext ctx) { contraptionEntity.contraption.actors.remove(index); contraptionEntity.contraption.actors.add(index, MutablePair.of(info, ctx)); - ContraptionRenderDispatcher.invalidate(contraptionEntity.contraption); + if (contraptionEntity.level.isClientSide) + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> invalidate(contraptionEntity.contraption)); } protected void setContraptionBlockData(AbstractContraptionEntity contraptionEntity, BlockPos pos, BlockInfo info) { contraptionEntity.contraption.blocks.put(pos, info); - ContraptionRenderDispatcher.invalidate(contraptionEntity.contraption); + if (contraptionEntity.level.isClientSide) + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> invalidate(contraptionEntity.contraption)); + } + + @OnlyIn(Dist.CLIENT) + protected void invalidate(Contraption contraption) { + ContraptionRenderDispatcher.invalidate(contraption); } public boolean handlePlayerInteraction(PlayerEntity player, Hand activeHand, BlockPos localPos,