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.java97
1 files changed, 88 insertions, 9 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
index 5f1d7cbd44..df603de17b 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
@@ -2,12 +2,16 @@ package gregtech.api.metatileentity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+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;
import gregtech.api.util.GT_Config;
+import gregtech.api.util.GT_CoverBehavior;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Utility;
import net.minecraft.block.Block;
@@ -20,6 +24,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -55,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.
*/
@@ -635,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) {
@@ -733,18 +743,80 @@ 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) {
if (aSide >= 6) return 0;
- mConnections |= (1 << aSide);
- byte tSide = GT_Utility.getOppositeSide(aSide);
- IGregTechTileEntity tTileEntity = getBaseMetaTileEntity().getIGregTechTileEntityAtSide(aSide);
- IMetaTileEntity tPipe = tTileEntity instanceof IGregTechTileEntity ? ((IGregTechTileEntity) tTileEntity).getMetaTileEntity() : null;
- if (this.getClass().isInstance(tPipe) && !((MetaPipeEntity) tPipe).isConnectedAtSide(tSide))
- ((MetaPipeEntity) tPipe).connect(tSide);
- return 1;
+
+ final byte tSide = GT_Utility.getOppositeSide(aSide);
+ final IGregTechTileEntity baseMetaTile = getBaseMetaTileEntity();
+ if (baseMetaTile == null) return 0;
+
+ final GT_CoverBehavior coverBehavior = baseMetaTile.getCoverBehaviorAtSide(aSide);
+ final int coverId = baseMetaTile.getCoverIDAtSide(aSide),
+ coverData = baseMetaTile.getCoverDataAtSide(aSide);
+
+ boolean alwaysLookConnected = coverBehavior.alwaysLookConnected(aSide, coverId, coverData, baseMetaTile);
+ boolean letsIn = letsIn(coverBehavior, aSide, coverId, coverData, baseMetaTile);
+ boolean letsOut = letsOut(coverBehavior, aSide, coverId, coverData, baseMetaTile);
+
+ // 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!
+ IMetaTileEntity tPipe = tTileEntity instanceof IGregTechTileEntity ? ((IGregTechTileEntity) tTileEntity).getMetaTileEntity() : null;
+ if (getClass().isInstance(tPipe)) {
+ connectAtSide(aSide);
+ if (!((MetaPipeEntity) tPipe).isConnectedAtSide(tSide)) {
+ // Make sure pipes all get together -- connect back to us if we're connecting to a pipe
+ ((MetaPipeEntity) tPipe).connect(tSide);
+ }
+ return 1;
+ }
+ 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;
+ }
+ if (!baseMetaTile.getWorld().getChunkProvider().chunkExists(baseMetaTile.getOffsetX(aSide, 1) >> 4, baseMetaTile.getOffsetZ(aSide, 1) >> 4)) {
+ // Target chunk unloaded
+ return -1;
+ }
+
+ }
+ return 0;
}
+ 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) {
+ mConnections |= (1 << aSide);
+ }
+
@Override
public void disconnect(byte aSide) {
if (aSide >= 6) return;
@@ -759,4 +831,11 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
public boolean isConnectedAtSide(int aSide) {
return (mConnections & (1 << aSide)) != 0;
}
+
+
+ public boolean letsIn(GT_CoverBehavior coverBehavior, byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; }
+ 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; }
}