Skip to content

Commit

Permalink
Don't allow using a wrench to dismantle blocks that currently contain…
Browse files Browse the repository at this point in the history
… radioactive substances
  • Loading branch information
pupnewfster committed Mar 12, 2024
1 parent 164bb5a commit 2aa0e29
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 25 deletions.
Expand Up @@ -2,7 +2,6 @@

import mekanism.common.block.prefab.BlockTile.BlockTileModel;
import mekanism.common.content.blocktype.BlockTypeTile;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.util.WorldUtils;
import mekanism.generators.common.item.ItemTurbineBlade;
import mekanism.generators.common.registries.GeneratorsBlockTypes;
Expand Down Expand Up @@ -34,9 +33,11 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
if (tile == null) {
return InteractionResult.PASS;
} else if (world.isClientSide) {
return genericClientActivated(player, hand);
} else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
return genericClientActivated(player, hand, tile);
}
InteractionResult wrenchResult = tile.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
ItemStack stack = player.getItemInHand(hand);
if (!player.isShiftKeyDown()) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/mekanism/common/block/BlockMekanism.java
Expand Up @@ -276,8 +276,13 @@ public void animateTick(@NotNull BlockState state, @NotNull Level world, @NotNul
}
}

protected InteractionResult genericClientActivated(@NotNull Player player, @NotNull InteractionHand hand) {
if (Attribute.has(this, AttributeGui.class) || MekanismUtils.canUseAsWrench(player.getItemInHand(hand))) {
protected InteractionResult genericClientActivated(@NotNull Player player, @NotNull InteractionHand hand, BlockEntity blockEntity) {
if (Attribute.has(this, AttributeGui.class)) {
return InteractionResult.SUCCESS;
} else if (MekanismUtils.canUseAsWrench(player.getItemInHand(hand))) {
if (blockEntity instanceof ITileRadioactive tileRadioactive && tileRadioactive.getRadiationScale() > 0) {
return InteractionResult.FAIL;
}
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/mekanism/common/block/basic/BlockBin.java
Expand Up @@ -7,7 +7,6 @@
import mekanism.common.content.blocktype.BlockTypeTile;
import mekanism.common.inventory.slot.BinInventorySlot;
import mekanism.common.tile.TileEntityBin;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.WorldUtils;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -79,8 +78,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
TileEntityBin bin = WorldUtils.getTileEntity(TileEntityBin.class, world, pos);
if (bin == null) {
return InteractionResult.PASS;
} else if (bin.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
}
InteractionResult wrenchResult = bin.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
ItemStack stack = player.getItemInHand(hand);
if (stack.isEmpty() && player.isShiftKeyDown() && hit.getDirection() == bin.getDirection()) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/mekanism/common/block/basic/BlockFluidTank.java
Expand Up @@ -5,7 +5,6 @@
import mekanism.common.content.blocktype.Machine;
import mekanism.common.resource.BlockResourceInfo;
import mekanism.common.tile.TileEntityFluidTank;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.util.FluidUtils;
import mekanism.common.util.WorldUtils;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -52,9 +51,11 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
if (tile == null) {
return InteractionResult.PASS;
} else if (world.isClientSide) {
return genericClientActivated(player, hand);
} else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
return genericClientActivated(player, hand, tile);
}
InteractionResult wrenchResult = tile.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
//Handle filling fluid tank
if (!player.isShiftKeyDown()) {
Expand Down
@@ -1,5 +1,6 @@
package mekanism.common.block.basic;

import mekanism.api.radiation.IRadiationManager;
import mekanism.api.security.IBlockSecurityUtils;
import mekanism.common.block.attribute.Attribute;
import mekanism.common.block.prefab.BlockTile.BlockTileModel;
Expand Down Expand Up @@ -66,7 +67,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
if (tile == null) {
return InteractionResult.PASS;
} else if (world.isClientSide) {
return genericClientActivated(player, hand);
return genericClientActivated(player, hand, tile);
}
//TODO: Make this be moved into the logistical sorter tile
ItemStack stack = player.getItemInHand(hand);
Expand All @@ -75,6 +76,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
return InteractionResult.FAIL;
}
if (player.isShiftKeyDown()) {
if (IRadiationManager.INSTANCE.isRadiationEnabled() && tile.getRadiationScale() > 0) {
//Note: This should always be false for the logistical sorter, but we keep it here for good measure
return InteractionResult.FAIL;
}
WorldUtils.dismantleBlock(state, world, pos, player);
return InteractionResult.SUCCESS;
}
Expand Down
Expand Up @@ -2,7 +2,6 @@

import mekanism.common.block.prefab.BlockTileGlass;
import mekanism.common.content.blocktype.BlockTypeTile;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.tile.prefab.TileEntityStructuralMultiblock;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.WorldUtils;
Expand Down Expand Up @@ -38,8 +37,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
}
}
return InteractionResult.SUCCESS;
} else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
}
InteractionResult wrenchResult = tile.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
return tile.onActivate(player, hand, player.getItemInHand(hand));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mekanism/common/block/prefab/BlockBase.java
Expand Up @@ -117,6 +117,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world
public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand hand,
@NotNull BlockHitResult hit) {
if (player.isShiftKeyDown() && MekanismUtils.canUseAsWrench(player.getItemInHand(hand))) {
//Note: We don't handle checking if it is radioactive here, as the assumption is it doesn't have a tile so won't have that information
if (!world.isClientSide) {
WorldUtils.dismantleBlock(state, world, pos, player);
}
Expand Down
Expand Up @@ -3,7 +3,6 @@
import java.util.function.UnaryOperator;
import mekanism.common.content.blocktype.BlockTypeTile;
import mekanism.common.tile.base.TileEntityMekanism;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.tile.prefab.TileEntityMultiblock;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.WorldUtils;
Expand Down Expand Up @@ -43,8 +42,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
}
}
return InteractionResult.SUCCESS;
} else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
}
InteractionResult wrenchResult = tile.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
return tile.onActivate(player, hand, player.getItemInHand(hand));
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/mekanism/common/block/prefab/BlockTile.java
Expand Up @@ -13,7 +13,6 @@
import mekanism.common.content.blocktype.BlockTypeTile;
import mekanism.common.registration.impl.TileEntityTypeRegistryObject;
import mekanism.common.tile.base.TileEntityMekanism;
import mekanism.common.tile.base.WrenchResult;
import mekanism.common.util.WorldUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -55,9 +54,11 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N
if (tile == null) {
return InteractionResult.PASS;
} else if (world.isClientSide) {
return genericClientActivated(player, hand);
} else if (tile.tryWrench(state, player, hand, hit) != WrenchResult.PASS) {
return InteractionResult.SUCCESS;
return genericClientActivated(player, hand, tile);
}
InteractionResult wrenchResult = tile.tryWrench(state, player, hand, hit).getInteractionResult();
if (wrenchResult != InteractionResult.PASS) {
return wrenchResult;
}
return type.has(AttributeGui.class) ? tile.openGui(player) : InteractionResult.PASS;
}
Expand Down
Expand Up @@ -501,6 +501,10 @@ public WrenchResult tryWrench(BlockState state, Player player, InteractionHand h
return WrenchResult.NO_SECURITY;
}
if (player.isShiftKeyDown()) {
if (IRadiationManager.INSTANCE.isRadiationEnabled() && getRadiationScale() > 0) {
//Don't allow dismantling radioactive blocks
return WrenchResult.RADIOACTIVE;
}
WorldUtils.dismantleBlock(state, getLevel(), worldPosition, this, player);
return WrenchResult.DISMANTLED;
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/mekanism/common/tile/base/WrenchResult.java
@@ -1,9 +1,20 @@
package mekanism.common.tile.base;

import net.minecraft.world.InteractionResult;

//TODO: Move this to a different package
public enum WrenchResult {
DISMANTLED,
SUCCESS,
PASS,
NO_SECURITY
NO_SECURITY,
RADIOACTIVE;

public InteractionResult getInteractionResult() {
return switch (this) {
case PASS -> InteractionResult.PASS;
case RADIOACTIVE -> InteractionResult.FAIL;
default -> InteractionResult.SUCCESS;
};
}
}

0 comments on commit 2aa0e29

Please sign in to comment.