Skip to content

Commit

Permalink
Fix: Crash due to loading client side classes on server
Browse files Browse the repository at this point in the history
Close #147
  • Loading branch information
klikli-dev committed Aug 22, 2023
1 parent 497f241 commit c747e94
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/klikli_dev/theurgy/Theurgy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -108,7 +101,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return BlockEntityRegistry.CALORIC_FLUX_EMITTER.get().create(pPos, pState);
return BlockEntityRegistry.CALORIC_FLUX_EMITTER.get().create(pPos, pState);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class CaloricFluxEmitterBlockEntity extends BlockEntity {
public CaloricFluxEmitterBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(BlockEntityRegistry.CALORIC_FLUX_EMITTER.get(), pPos, pBlockState);


this.mercuryFluxStorage = new MercuryFluxStorage(CAPACITY);
this.mercuryFluxStorageCapability = LazyOptional.of(() -> this.mercuryFluxStorage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(); ) {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c747e94

Please sign in to comment.