aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations
diff options
context:
space:
mode:
authorБатьків Нестор-Євген Васильович <mama040508@gmail.com>2023-12-28 15:37:18 +0200
committerGitHub <noreply@github.com>2023-12-28 14:37:18 +0100
commit90615c78f2219b0fadf50c1c31b9e678ddc808c1 (patch)
tree7cf7cc5c065f1b236761c694fa4585d83357d170 /src/main/java/gregtech/api/metatileentity/implementations
parent91101964b0528a26deb967f4787edb6891138293 (diff)
downloadGT5-Unofficial-90615c78f2219b0fadf50c1c31b9e678ddc808c1.tar.gz
GT5-Unofficial-90615c78f2219b0fadf50c1c31b9e678ddc808c1.tar.bz2
GT5-Unofficial-90615c78f2219b0fadf50c1c31b9e678ddc808c1.zip
Add connect/block to line of fluid pipes (#2407)
* Add connect/block to line of pipes * Oopsie * Add check for same fluid * Add check for same pipe size * Address some reviews * Move to new tool modes * Wildcard reeeeeeeeeeeeeeeee x2 * Adress Miozune`s review * Why not, I like it * AAAAAAAA IM stupid AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java124
1 files changed, 106 insertions, 18 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
index 7162815a17..f604f1583f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
@@ -40,6 +40,8 @@ import org.apache.commons.lang3.tuple.MutableTriple;
import cpw.mods.fml.common.Optional;
import gregtech.GT_Mod;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.ConfigCategories;
import gregtech.api.enums.Dyes;
import gregtech.api.enums.Materials;
import gregtech.api.enums.Mods;
@@ -47,11 +49,13 @@ import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.ParticleFX;
import gregtech.api.enums.SoundResource;
import gregtech.api.enums.Textures;
+import gregtech.api.enums.ToolModes;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
import gregtech.api.metatileentity.MetaPipeEntity;
import gregtech.api.render.TextureFactory;
@@ -474,31 +478,115 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
}
}
+ public void connectPipeOnSide(ForgeDirection side, EntityPlayer entityPlayer) {
+ if (!isConnectedAtSide(side)) {
+ if (connect(side) > 0) GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("214", "Connected"));
+ } else {
+ disconnect(side);
+ GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("215", "Disconnected"));
+ }
+ }
+
+ public void blockPipeOnSide(ForgeDirection side, EntityPlayer entityPlayer, byte mask) {
+ if (isInputDisabledAtSide(side)) {
+ mDisableInput &= ~mask;
+ GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("212", "Input enabled"));
+ if (!isConnectedAtSide(side)) connect(side);
+ } else {
+ mDisableInput |= mask;
+ GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("213", "Input disabled"));
+ }
+ }
+
@Override
public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer,
- float aX, float aY, float aZ) {
+ float aX, float aY, float aZ, ItemStack aTool) {
+
if (GT_Mod.gregtechproxy.gt6Pipe) {
+ final int mode = GT_MetaGenerated_Tool.getToolMode(aTool);
+ IGregTechTileEntity currentPipeBase = getBaseMetaTileEntity();
+ GT_MetaPipeEntity_Fluid currentPipe = (GT_MetaPipeEntity_Fluid) currentPipeBase.getMetaTileEntity();
final ForgeDirection tSide = GT_Utility.determineWrenchingSide(side, aX, aY, aZ);
final byte tMask = (byte) (tSide.flag);
- if (entityPlayer.isSneaking()) {
- if (isInputDisabledAtSide(tSide)) {
- mDisableInput &= ~tMask;
- GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("212", "Input enabled"));
- if (!isConnectedAtSide(tSide)) connect(tSide);
- } else {
- mDisableInput |= tMask;
- GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("213", "Input disabled"));
- }
- } else {
- if (!isConnectedAtSide(tSide)) {
- if (connect(tSide) > 0)
- GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("214", "Connected"));
- } else {
- disconnect(tSide);
- GT_Utility.sendChatToPlayer(entityPlayer, GT_Utility.trans("215", "Disconnected"));
+
+ if (mode == ToolModes.REGULAR.get()) {
+ if (entityPlayer.isSneaking()) {
+ currentPipe.blockPipeOnSide(tSide, entityPlayer, tMask);
+ } else currentPipe.connectPipeOnSide(tSide, entityPlayer);
+ return true;
+ }
+
+ if (mode == ToolModes.WRENCH_LINE.get()) {
+
+ boolean initialState = entityPlayer.isSneaking() ? currentPipe.isInputDisabledAtSide(tSide)
+ : currentPipe.isConnectedAtSide(tSide);
+
+ boolean wasActionPerformed = false;
+
+ int limit = GregTech_API.sSpecialFile.get(ConfigCategories.general, "PipeWrenchingChainRange", 64);
+ for (int connected = 0; connected < limit; connected++) {
+
+ TileEntity nextPipeBaseTile = currentPipeBase.getTileEntityAtSide(tSide);
+
+ // if next tile doesn't exist or if next tile is not GT tile
+ if (!(nextPipeBaseTile instanceof IGregTechTileEntity nextPipeBase)) {
+ return wasActionPerformed;
+ }
+
+ // if next tile is wrong color
+ if (!currentPipe.connectableColor(nextPipeBaseTile)) {
+ return wasActionPerformed;
+ }
+
+ GT_MetaPipeEntity_Fluid nextPipe = nextPipeBase
+ .getMetaTileEntity() instanceof GT_MetaPipeEntity_Fluid
+ ? (GT_MetaPipeEntity_Fluid) nextPipeBase.getMetaTileEntity()
+ : null;
+
+ // if next tile entity is not a pipe
+ if (nextPipe == null) {
+ return wasActionPerformed;
+ }
+
+ // if pipes are same size
+ if (mPipeAmount != nextPipe.mPipeAmount) {
+ return wasActionPerformed;
+ }
+
+ // making sure next pipe has same fluid
+ for (int i = 0; i < mPipeAmount; i++) {
+ if (mFluids[i] != null && nextPipe.mFluids[i] != null) {
+ if (!mFluids[i].isFluidEqual(nextPipe.mFluids[i])) {
+ return wasActionPerformed;
+ }
+ } else if (mFluids[i] != nextPipe.mFluids[i]) {
+ return wasActionPerformed;
+ }
+ }
+
+ boolean currentState = entityPlayer.isSneaking() ? currentPipe.isInputDisabledAtSide(tSide)
+ : currentPipe.isConnectedAtSide(tSide);
+
+ /*
+ * Making sure next pipe will have same action applied to it
+ * e.g. Connecting pipe won`t trigger disconnect if next pipe is already connected
+ */
+ if (currentState != initialState) {
+ return wasActionPerformed;
+ }
+
+ if (entityPlayer.isSneaking()) {
+ currentPipe.blockPipeOnSide(tSide, entityPlayer, tMask);
+ } else currentPipe.connectPipeOnSide(tSide, entityPlayer);
+
+ wasActionPerformed = true;
+
+ currentPipeBase = (IGregTechTileEntity) nextPipeBase;
+ currentPipe = nextPipe;
+
}
+ return wasActionPerformed;
}
- return true;
}
return false;
}