aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/items/behaviors
diff options
context:
space:
mode:
authorCaedis <Caedis@users.noreply.github.com>2024-01-31 11:46:38 -0600
committerGitHub <noreply@github.com>2024-01-31 19:46:38 +0200
commit9a427b291b3d84c208de52e043eb75df967069b5 (patch)
tree2af55e57b3ac040b7c07d56e96d0d98ea368b6a3 /src/main/java/gregtech/common/items/behaviors
parent787eba0a15c583b240e96630978b9c3539e55fa4 (diff)
downloadGT5-Unofficial-9a427b291b3d84c208de52e043eb75df967069b5.tar.gz
GT5-Unofficial-9a427b291b3d84c208de52e043eb75df967069b5.tar.bz2
GT5-Unofficial-9a427b291b3d84c208de52e043eb75df967069b5.zip
Add more checking to prevent chaining to different blocks (#2481)
* Add more checking to prevent chaining to different blocks * Remove variable that is only used once
Diffstat (limited to 'src/main/java/gregtech/common/items/behaviors')
-rw-r--r--src/main/java/gregtech/common/items/behaviors/Behaviour_Spray_Color.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/gregtech/common/items/behaviors/Behaviour_Spray_Color.java b/src/main/java/gregtech/common/items/behaviors/Behaviour_Spray_Color.java
index b2f88b58de..cbc698d474 100644
--- a/src/main/java/gregtech/common/items/behaviors/Behaviour_Spray_Color.java
+++ b/src/main/java/gregtech/common/items/behaviors/Behaviour_Spray_Color.java
@@ -23,6 +23,7 @@ import gregtech.api.GregTech_API;
import gregtech.api.enums.ConfigCategories;
import gregtech.api.enums.Dyes;
import gregtech.api.enums.SoundResource;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.items.GT_MetaBase_Item;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Utility;
@@ -108,10 +109,9 @@ public class Behaviour_Spray_Color extends Behaviour_None {
} else {
lookSide = look.zCoord > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH;
}
- Block currentBlock = aWorld.getBlock(aX, aY, aZ);
- int currentBlockMeta = aWorld.getBlockMetadata(aX, aY, aZ);
- Class<? extends TileEntity> currentTE = aWorld.getTileEntity(aX, aY, aZ)
- .getClass();
+ Block initialBlock = aWorld.getBlock(aX, aY, aZ);
+ int initialBlockMeta = aWorld.getBlockMetadata(aX, aY, aZ);
+ TileEntity initialTE = aWorld.getTileEntity(aX, aY, aZ);
while ((GT_Utility.areStacksEqual(aStack, this.mUsed, true)) && (colorize(aWorld, aX, aY, aZ, side, aPlayer))) {
GT_Utility.sendSoundToPlayers(aWorld, SoundResource.IC2_TOOLS_PAINTER, 1.0F, 1.0F, aX, aY, aZ);
if (!aPlayer.capabilities.isCreativeMode) {
@@ -131,9 +131,24 @@ public class Behaviour_Spray_Color extends Behaviour_None {
default -> throw new IllegalArgumentException("Unexpected value: " + lookSide);
}
- if (aWorld.getBlock(aX, aY, aZ) != currentBlock) break;
- if (aWorld.getBlockMetadata(aX, aY, aZ) != currentBlockMeta) break;
- if (!currentTE.isInstance(aWorld.getTileEntity(aX, aY, aZ))) break;
+ if (aWorld.getBlock(aX, aY, aZ) != initialBlock) break;
+ if (aWorld.getBlockMetadata(aX, aY, aZ) != initialBlockMeta) break;
+
+ /*
+ * Check if the initial block had a TE and if the next one does, check if its the same kind.
+ * else one does and the other doesnt, thus stop checking.
+ */
+ TileEntity targetTE = aWorld.getTileEntity(aX, aY, aZ);
+ if (initialTE == null ^ targetTE == null) break;
+ if (initialTE != null && targetTE != null) {
+ if (!initialTE.getClass()
+ .isInstance(targetTE)) break;
+
+ if (initialTE instanceof IGregTechTileEntity currentGTTile
+ && targetTE instanceof IGregTechTileEntity targetGTTile) {
+ if (currentGTTile.getMetaTileID() != targetGTTile.getMetaTileID()) break;
+ }
+ }
}
tNBT.removeTag("GT.RemainingPaint");
if (tUses > 0L) {