fix controller crashing (#2684)
* fix controller crashing fix consuming color without effect * changelog
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
|
### 1.9.7
|
||||||
|
- Fixed crash when opening Controller GUI (Darkere)
|
||||||
|
- Fixed dye being consumed without effect in some cases (Darkere)
|
||||||
|
|
||||||
### 1.9.6
|
### 1.9.6
|
||||||
- Port to Minecraft 1.16.3 (raoulvdberge)
|
- Port to Minecraft 1.16.3 (raoulvdberge)
|
||||||
- Added colored block variants (Darkere)
|
- Added colored block variants (Darkere)
|
||||||
|
@@ -8,6 +8,7 @@ import com.refinedmods.refinedstorage.apiimpl.network.Network;
|
|||||||
import com.refinedmods.refinedstorage.container.ControllerContainer;
|
import com.refinedmods.refinedstorage.container.ControllerContainer;
|
||||||
import com.refinedmods.refinedstorage.tile.ControllerTile;
|
import com.refinedmods.refinedstorage.tile.ControllerTile;
|
||||||
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;
|
||||||
@@ -130,15 +131,13 @@ public class ControllerBlock extends BaseBlock {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ColorMap<ControllerBlock> colorMap = type == NetworkType.CREATIVE ? RSBlocks.CREATIVE_CONTROLLER : RSBlocks.CONTROLLER;
|
||||||
DyeColor color = DyeColor.getColor(player.getHeldItem(hand));
|
DyeColor color = DyeColor.getColor(player.getHeldItem(hand));
|
||||||
|
|
||||||
BlockState newState = type == NetworkType.CREATIVE ?
|
if (color != null && !state.getBlock().equals(colorMap.get(color).get())) {
|
||||||
RSBlocks.CREATIVE_CONTROLLER.get(color).get().getDefaultState().with(ENERGY_TYPE, state.get(ENERGY_TYPE)) :
|
BlockState newState = colorMap.get(color).get().getDefaultState().with(ENERGY_TYPE, state.get(ENERGY_TYPE));
|
||||||
RSBlocks.CONTROLLER.get(color).get().getDefaultState().with(ENERGY_TYPE, state.get(ENERGY_TYPE));
|
|
||||||
|
|
||||||
ActionResultType colorResult = RSBlocks.CONTROLLER.setBlockState(newState, player.getHeldItem(hand), world, pos, player);
|
return RSBlocks.CONTROLLER.setBlockState(newState, player.getHeldItem(hand), world, pos, player);
|
||||||
if (colorResult != ActionResultType.PASS) {
|
|
||||||
return colorResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
|
@@ -103,9 +103,10 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
|||||||
|
|
||||||
public <S extends BaseBlock> ActionResultType changeBlockColor(BlockState state, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {
|
public <S extends BaseBlock> ActionResultType changeBlockColor(BlockState state, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {
|
||||||
DyeColor color = DyeColor.getColor(heldItem);
|
DyeColor color = DyeColor.getColor(heldItem);
|
||||||
if (color == null) {
|
if (color == null || state.getBlock().equals(colorMap.get(color).get())) {
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setBlockState(getNewState((RegistryObject<S>) colorMap.get(color), state), heldItem, world, pos, player);
|
return setBlockState(getNewState((RegistryObject<S>) colorMap.get(color), state), heldItem, world, pos, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +123,7 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
|||||||
heldItem.shrink(1);
|
heldItem.shrink(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user