From c747e9495db442bf860cdfc1a8197908fe7941fd Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Tue, 22 Aug 2023 19:30:47 +0200 Subject: [PATCH] Fix: Crash due to loading client side classes on server Close #147 --- src/main/java/com/klikli_dev/theurgy/Theurgy.java | 2 +- .../caloricfluxemitter/CaloricFluxEmitterBlock.java | 11 ++--------- .../CaloricFluxEmitterBlockEntity.java | 1 - .../behaviour/interaction/SelectionBehaviour.java | 13 +++---------- .../MessageRequestCaloricFluxEmitterSelection.java | 2 +- 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/klikli_dev/theurgy/Theurgy.java b/src/main/java/com/klikli_dev/theurgy/Theurgy.java index aa8f09f06..5e94c2361 100644 --- a/src/main/java/com/klikli_dev/theurgy/Theurgy.java +++ b/src/main/java/com/klikli_dev/theurgy/Theurgy.java @@ -152,7 +152,7 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } Outliner.get().tick(); - BlockRegistry.CALORIC_FLUX_EMITTER.get().getSelectionBehaviour().tick(); + BlockRegistry.CALORIC_FLUX_EMITTER.get().getSelectionBehaviour().tick(Minecraft.getInstance().player); } public static void onRenderLevelStage(RenderLevelStageEvent event) { diff --git a/src/main/java/com/klikli_dev/theurgy/content/apparatus/caloricfluxemitter/CaloricFluxEmitterBlock.java b/src/main/java/com/klikli_dev/theurgy/content/apparatus/caloricfluxemitter/CaloricFluxEmitterBlock.java index 153a83b62..fdacaa51b 100644 --- a/src/main/java/com/klikli_dev/theurgy/content/apparatus/caloricfluxemitter/CaloricFluxEmitterBlock.java +++ b/src/main/java/com/klikli_dev/theurgy/content/apparatus/caloricfluxemitter/CaloricFluxEmitterBlock.java @@ -2,14 +2,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.klikli_dev.theurgy.Theurgy; -import com.klikli_dev.theurgy.content.apparatus.mercurycatalyst.MercuryCatalystBlockEntity; import com.klikli_dev.theurgy.content.behaviour.interaction.SelectionBehaviour; import com.klikli_dev.theurgy.registry.BlockEntityRegistry; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -20,14 +16,11 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.storage.loot.LootParams; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Map; public class CaloricFluxEmitterBlock extends DirectionalBlock implements EntityBlock { @@ -75,7 +68,7 @@ public BlockState getStateForPlacement(BlockPlaceContext pContext) { public void neighborChanged(BlockState pState, Level pLevel, BlockPos pPos, Block pBlock, BlockPos pFromPos, boolean pIsMoving) { super.neighborChanged(pState, pLevel, pPos, pBlock, pFromPos, pIsMoving); - if(!this.canSurvive(pState, pLevel, pPos)) { + if (!this.canSurvive(pState, pLevel, pPos)) { pLevel.destroyBlock(pPos, true); } } @@ -108,7 +101,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder this.mercuryFluxStorage); diff --git a/src/main/java/com/klikli_dev/theurgy/content/behaviour/interaction/SelectionBehaviour.java b/src/main/java/com/klikli_dev/theurgy/content/behaviour/interaction/SelectionBehaviour.java index bcba15c53..a97a624b4 100644 --- a/src/main/java/com/klikli_dev/theurgy/content/behaviour/interaction/SelectionBehaviour.java +++ b/src/main/java/com/klikli_dev/theurgy/content/behaviour/interaction/SelectionBehaviour.java @@ -4,7 +4,6 @@ import com.klikli_dev.theurgy.content.render.outliner.Outliner; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -69,7 +68,7 @@ public boolean onLeftClickBlock(Level level, Player player, InteractionHand hand return this.remove(pos) != null; } - public void onPlace(BlockPos pos) { + public void onPlace(BlockPos pos, Player player) { int removed = 0; for (var iterator = this.selectedPoints.iterator(); iterator.hasNext(); ) { @@ -80,7 +79,6 @@ public void onPlace(BlockPos pos) { removed++; } - LocalPlayer player = Minecraft.getInstance().player; if (removed > 0) { player.displayClientMessage(this.getOutsideRangeMessage(removed), true); } else { @@ -93,12 +91,7 @@ public void onPlace(BlockPos pos) { this.currentItem = null; } - public void tick() { - Player player = Minecraft.getInstance().player; - - if (player == null) - return; - + public void tick(Player player) { ItemStack heldItem = player.getMainHandItem(); if (!this.isSelectionItem(heldItem)) { this.currentItem = null; @@ -154,7 +147,7 @@ protected T get(BlockPos pos) { return null; } - public boolean isValid(SelectedPoint point){ + public boolean isValid(T point){ point.refreshBlockStateCache(); return this.canCreate(point.getLevel(), point.getBlockPos(), point.getBlockState()); } diff --git a/src/main/java/com/klikli_dev/theurgy/network/messages/MessageRequestCaloricFluxEmitterSelection.java b/src/main/java/com/klikli_dev/theurgy/network/messages/MessageRequestCaloricFluxEmitterSelection.java index 246dfe974..1da4d8624 100644 --- a/src/main/java/com/klikli_dev/theurgy/network/messages/MessageRequestCaloricFluxEmitterSelection.java +++ b/src/main/java/com/klikli_dev/theurgy/network/messages/MessageRequestCaloricFluxEmitterSelection.java @@ -32,6 +32,6 @@ public void decode(FriendlyByteBuf buf) { @Override public void onClientReceived(Minecraft minecraft, Player player, NetworkEvent.Context context) { - BlockRegistry.CALORIC_FLUX_EMITTER.get().getSelectionBehaviour().onPlace(this.blockPos); + BlockRegistry.CALORIC_FLUX_EMITTER.get().getSelectionBehaviour().onPlace(this.blockPos, player); } }