fix detector crashing when dyed and deactivating powered state (#2974)

This commit is contained in:
Darkere
2021-06-09 17:56:57 +02:00
committed by GitHub
parent 7a888aaf3e
commit e372c150b0
2 changed files with 17 additions and 10 deletions

View File

@@ -5,11 +5,13 @@ import com.refinedmods.refinedstorage.container.DetectorContainer;
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.refinedmods.refinedstorage.tile.DetectorTile;
import com.refinedmods.refinedstorage.util.BlockUtils;
import com.refinedmods.refinedstorage.util.ColorMap;
import com.refinedmods.refinedstorage.util.NetworkUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
@@ -68,9 +70,13 @@ public class DetectorBlock extends ColoredNetworkBlock {
@Override
@SuppressWarnings("deprecation")
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
ActionResultType result = RSBlocks.DETECTOR.changeBlockColor(state, player.getHeldItem(hand), world, pos, player);
if (result != ActionResultType.PASS) {
return result;
ColorMap<DetectorBlock> colorMap = RSBlocks.DETECTOR;
DyeColor color = DyeColor.getColor(player.getHeldItem(hand));
if (color != null && !state.getBlock().equals(colorMap.get(color).get())) {
BlockState newState = colorMap.get(color).get().getDefaultState().with(POWERED, state.get(POWERED));
return RSBlocks.DETECTOR.setBlockState(newState, player.getHeldItem(hand), world, pos, player);
}
if (!world.isRemote) {

View File

@@ -112,15 +112,16 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
}
private <S extends BaseBlock> BlockState getNewState(RegistryObject<S> block, BlockState state) {
if (block.get().getDirection() == BlockDirection.NONE) {
return block.get().getDefaultState()
.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED));
} else {
return block.get().getDefaultState()
.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED))
.with(block.get().getDirection().getProperty(), state.get(block.get().getDirection().getProperty()));
BlockState newState = block.get().getDefaultState();
if (((NetworkNodeBlock) block.get()).hasConnectedState()) {
newState = newState.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED));
}
if (block.get().getDirection() != BlockDirection.NONE) {
newState = newState.with(block.get().getDirection().getProperty(), state.get(block.get().getDirection().getProperty()));
}
return newState;
}
public ActionResultType setBlockState(BlockState newState, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {