aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java')
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
index 70ae71a719..df603de17b 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
@@ -6,6 +6,7 @@ import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.metatileentity.IConnectable;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IColoredTileEntity;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.objects.GT_ItemStack;
@@ -59,6 +60,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
* This variable tells, which directions the Block is connected to. It is a Bitmask.
*/
public byte mConnections = 0;
+ protected boolean mCheckConnections = false;
/**
* Only assigned for the MetaTileEntity in the List! Also only used to get the localized Name for the ItemStack and for getInvName.
*/
@@ -639,12 +641,16 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
@Override
public void onColorChangeServer(byte aColor) {
- //
+ setCheckConnections();
}
@Override
public void onColorChangeClient(byte aColor) {
- //
+ // Do nothing apparently
+ }
+
+ public void setCheckConnections() {
+ mCheckConnections = true;
}
public long injectEnergyUnits(byte aSide, long aVoltage, long aAmperage) {
@@ -737,7 +743,19 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false);
}
+ private boolean connectableColor(TileEntity tTileEntity) {
+ // Determine if two entities are connectable based on their colorization:
+ // Uncolored can connect to anything
+ // If both are colored they must be the same color to connect.
+ if (tTileEntity instanceof IColoredTileEntity) {
+ if (getBaseMetaTileEntity().getColorization() >= 0) {
+ byte tColor = ((IColoredTileEntity) tTileEntity).getColorization();
+ if (tColor >= 0 && tColor != getBaseMetaTileEntity().getColorization()) return false;
+ }
+ }
+ return true;
+ }
@Override
public int connect(byte aSide) {
@@ -745,7 +763,9 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
final byte tSide = GT_Utility.getOppositeSide(aSide);
final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity();
- final GT_CoverBehavior coverBehavior = getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide);
+ if (baseMetaTile == null) return 0;
+
+ final GT_CoverBehavior coverBehavior = baseMetaTile.getCoverBehaviorAtSide(aSide);
final int coverId = baseMetaTile.getCoverIDAtSide(aSide),
coverData = baseMetaTile.getCoverDataAtSide(aSide);
@@ -755,6 +775,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
// Careful - tTileEntity might be null, and that's ok -- so handle it
TileEntity tTileEntity = baseMetaTile.getTileEntityAtSide(aSide);
+ if (!connectableColor(tTileEntity)) return 0;
if ((alwaysLookConnected || letsIn || letsOut)) {
// Are we trying to connect to a pipe? let's do it!
@@ -767,10 +788,8 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
}
return 1;
}
- else if(((GT_Mod.gregtechproxy.gt6Cable || GT_Mod.gregtechproxy.gt6Pipe) && baseMetaTile.getAirAtSide(aSide)) || canConnect(aSide, tTileEntity)) {
- // Allow open connections to Air, so that it'll connect to the next block placed down next to it
- // NOTE: Will need to check valid connection on a block update because of this, otherwise
- // we might end up connected to silly things
+ else if((getGT6StyleConnection() && baseMetaTile.getAirAtSide(aSide)) || canConnect(aSide, tTileEntity)) {
+ // Allow open connections to Air, if the GT6 style pipe/cables are enabled, so that it'll connect to the next block placed down next to it
connectAtSide(aSide);
return 1;
}
@@ -783,9 +802,15 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
return 0;
}
- public void checkConnections() {
- // Try connecting to connecting to everything around us: Only used when GT6 style cables/pipes are disabled
- for (byte aSide = 0; aSide < 6; aSide++) if (connect(aSide) == 0) disconnect(aSide);
+ protected void checkConnections() {
+ // Verify connections around us. If GT6 style cables are not enabled then revert to old behavior and try
+ // connecting to everything around us
+ for (byte aSide = 0; aSide < 6; aSide++) {
+ if ((!getGT6StyleConnection() || isConnectedAtSide(aSide)) && connect(aSide) == 0) {
+ disconnect(aSide);
+ }
+ }
+ mCheckConnections = false;
}
private void connectAtSide(byte aSide) {
@@ -812,4 +837,5 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
public boolean letsOut(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; }
public boolean canConnect(byte aSide, TileEntity tTileEntity) { return false; }
+ public boolean getGT6StyleConnection() { return false; }
}