fix detector crashing when dyed and deactivating powered state (#2974)
This commit is contained in:
@@ -5,11 +5,13 @@ import com.refinedmods.refinedstorage.container.DetectorContainer;
|
|||||||
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
|
import com.refinedmods.refinedstorage.container.factory.PositionalTileContainerProvider;
|
||||||
import com.refinedmods.refinedstorage.tile.DetectorTile;
|
import com.refinedmods.refinedstorage.tile.DetectorTile;
|
||||||
import com.refinedmods.refinedstorage.util.BlockUtils;
|
import com.refinedmods.refinedstorage.util.BlockUtils;
|
||||||
|
import com.refinedmods.refinedstorage.util.ColorMap;
|
||||||
import com.refinedmods.refinedstorage.util.NetworkUtils;
|
import com.refinedmods.refinedstorage.util.NetworkUtils;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
|
import net.minecraft.item.DyeColor;
|
||||||
import net.minecraft.state.BooleanProperty;
|
import net.minecraft.state.BooleanProperty;
|
||||||
import net.minecraft.state.StateContainer;
|
import net.minecraft.state.StateContainer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@@ -68,9 +70,13 @@ public class DetectorBlock extends ColoredNetworkBlock {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
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);
|
ColorMap<DetectorBlock> colorMap = RSBlocks.DETECTOR;
|
||||||
if (result != ActionResultType.PASS) {
|
DyeColor color = DyeColor.getColor(player.getHeldItem(hand));
|
||||||
return result;
|
|
||||||
|
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) {
|
if (!world.isRemote) {
|
||||||
|
|||||||
@@ -112,15 +112,16 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <S extends BaseBlock> BlockState getNewState(RegistryObject<S> block, BlockState state) {
|
private <S extends BaseBlock> BlockState getNewState(RegistryObject<S> block, BlockState state) {
|
||||||
if (block.get().getDirection() == BlockDirection.NONE) {
|
BlockState newState = block.get().getDefaultState();
|
||||||
return block.get().getDefaultState()
|
|
||||||
.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED));
|
if (((NetworkNodeBlock) block.get()).hasConnectedState()) {
|
||||||
} else {
|
newState = newState.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED));
|
||||||
return block.get().getDefaultState()
|
}
|
||||||
.with(NetworkNodeBlock.CONNECTED, state.get(NetworkNodeBlock.CONNECTED))
|
if (block.get().getDirection() != BlockDirection.NONE) {
|
||||||
.with(block.get().getDirection().getProperty(), state.get(block.get().getDirection().getProperty()));
|
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) {
|
public ActionResultType setBlockState(BlockState newState, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {
|
||||||
|
|||||||
Reference in New Issue
Block a user