diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/ColorSprayBehaviour.java b/src/main/java/com/gregtechceu/gtceu/common/item/ColorSprayBehaviour.java index e9951d4a7c..ed2d4a4916 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/ColorSprayBehaviour.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/ColorSprayBehaviour.java @@ -41,6 +41,7 @@ import net.minecraft.world.level.block.state.properties.Property; import net.minecraftforge.common.Tags; +import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.blockentity.networking.CableBusBlockEntity; import com.google.common.collect.ImmutableMap; @@ -207,7 +208,6 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List 45F) { return Direction.DOWN; } else if (player.getXRot() < -45F) { @@ -250,13 +262,14 @@ private Direction getPaintDirection(Player player) { return player.getDirection(); } - private boolean tryPaintBlock(Player player, Level world, BlockPos pos, Direction side) { + private boolean tryPaintBlock(Player player, Level world, BlockPos pos, Direction side, BlockEntity first) { var blockState = world.getBlockState(pos); var block = blockState.getBlock(); if (color == null) { - return tryStripBlockColor(player, world, pos, block, side); + return tryStripBlockColor(player, world, pos, block, side, first); } - return recolorBlockState(world, pos, side, this.color) || tryPaintSpecialBlock(player, world, pos, block); + return recolorBlockState(world, pos, side, this.color) || + tryPaintSpecialBlock(player, world, pos, block, first); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -271,7 +284,7 @@ private static boolean recolorBlockState(Level level, BlockPos pos, Direction si return false; } - private boolean tryPaintSpecialBlock(Player player, Level world, BlockPos pos, Block block) { + private boolean tryPaintSpecialBlock(Player player, Level world, BlockPos pos, Block block, BlockEntity first) { if (block.defaultBlockState().is(Tags.Blocks.GLASS)) { if (recolorBlockNoState(GLASS_MAP, this.color, world, pos, Blocks.GLASS)) { return true; @@ -329,10 +342,12 @@ private boolean tryPaintSpecialBlock(Player player, Level world, BlockPos pos, B // MTE special case BlockEntity be = world.getBlockEntity(pos); - if (be instanceof IMachineBlockEntity machineBe) { + if (be instanceof IMachineBlockEntity machineBe && first instanceof IMachineBlockEntity og) { MetaMachine mte = machineBe.getMetaMachine(); - if (mte != null) { - if (mte.getPaintingColor() != this.color.getTextColor()) { + MetaMachine ogMte = og.getMetaMachine(); + if (mte != null && ogMte != null) { + if (mte.getPaintingColor() != this.color.getTextColor() && + mte.getPaintingColor() == ogMte.getPaintingColor()) { mte.setPaintingColor(this.color.getTextColor()); return true; } else return false; @@ -340,17 +355,27 @@ private boolean tryPaintSpecialBlock(Player player, Level world, BlockPos pos, B } // PipeBlockEntity special case - if (be instanceof PipeBlockEntity pipe) { - if (pipe.getPaintingColor() != this.color.getTextColor()) { + if (be instanceof PipeBlockEntity pipe && first instanceof PipeBlockEntity og) { + var side = getPaintDirection(player).getOpposite(); + if (!first.getBlockPos().equals(be.getBlockPos()) && (!pipe.isConnected(side))) { + return false; + } + if (pipe.getPaintingColor() != this.color.getTextColor() && + pipe.getPaintingColor() == og.getPaintingColor()) { pipe.setPaintingColor(this.color.getTextColor()); return true; } else return false; } if (GTCEu.isAE2Loaded()) { - if (be instanceof CableBusBlockEntity cable) { + if (be instanceof CableBusBlockEntity cable && first instanceof CableBusBlockEntity og) { + var side = getPaintDirection(player).getOpposite(); + if (!first.getBlockPos().equals(be.getBlockPos()) && + (cable.getPart(side) != null || cable.getCableConnectionType(side) == AECableType.NONE)) { + return false; + } // do not try to recolor if it already is this color - if (cable.getColor().ordinal() != color.ordinal()) { + if (cable.getColor().ordinal() != color.ordinal() && cable.getColor() == og.getColor()) { cable.recolourBlock(null, AEColor.values()[color.ordinal()], player); return true; } @@ -382,7 +407,8 @@ private static boolean recolorBlockNoState(Map map, DyeColor co } @SuppressWarnings({ "rawtypes", "unchecked" }) - private static boolean tryStripBlockColor(Player player, Level world, BlockPos pos, Block block, Direction side) { + private static boolean tryStripBlockColor(Player player, Level world, BlockPos pos, Block block, Direction side, + BlockEntity first) { // MC special cases if (block instanceof StainedGlassBlock) { world.setBlock(pos, Blocks.GLASS.defaultBlockState(), 3); @@ -432,10 +458,11 @@ private static boolean tryStripBlockColor(Player player, Level world, BlockPos p // MTE special case BlockEntity be = world.getBlockEntity(pos); - if (be instanceof IMachineBlockEntity machineBe) { + if (be instanceof IMachineBlockEntity machineBe && first instanceof IMachineBlockEntity og) { MetaMachine mte = machineBe.getMetaMachine(); - if (mte != null) { - if (mte.isPainted()) { + MetaMachine ogMte = og.getMetaMachine(); + if (mte != null && ogMte != null) { + if (mte.isPainted() && mte.getPaintingColor() == ogMte.getPaintingColor()) { mte.setPaintingColor(mte.getDefaultPaintingColor()); return true; } else return false; @@ -443,8 +470,11 @@ private static boolean tryStripBlockColor(Player player, Level world, BlockPos p } // PipeBlockEntity special case - if (be instanceof PipeBlockEntity pipe) { - if (pipe.isPainted()) { + if (be instanceof PipeBlockEntity pipe && first instanceof PipeBlockEntity og) { + if (!first.getBlockPos().equals(be.getBlockPos()) && (!pipe.isConnected(side))) { + return false; + } + if (pipe.isPainted() && pipe.getPaintingColor() == og.getPaintingColor()) { pipe.setPaintingColor(pipe.getDefaultPaintingColor()); return true; } else return false; @@ -452,9 +482,13 @@ private static boolean tryStripBlockColor(Player player, Level world, BlockPos p // AE2 cable special case if (GTCEu.isAE2Loaded()) { - if (be instanceof CableBusBlockEntity cable) { - // do not try to strip color if it is already colorless - if (cable.getColor() != AEColor.TRANSPARENT) { + if (be instanceof CableBusBlockEntity cable && first instanceof CableBusBlockEntity og) { + if (!first.getBlockPos().equals(be.getBlockPos()) && + (cable.getPart(side) != null || cable.getCableConnectionType(side) == AECableType.NONE)) { + return false; + } + // do not try to recolor if it already is this color + if (cable.getColor() != AEColor.TRANSPARENT && cable.getColor() == og.getColor()) { cable.recolourBlock(null, AEColor.TRANSPARENT, player); return true; } else return false;