diff options
Diffstat (limited to 'src/main/java')
8 files changed, 69 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index c58db1c81a..2a86b2bbf0 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -50,6 +50,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0};
private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mCoverData = new int[]{0, 0, 0, 0, 0, 0}, mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING];
private boolean mInventoryChanged = false, mWorkUpdate = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false;
+ private boolean mCheckConnections = false;
private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0;
private int oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0;
private short mID = 0;
@@ -1294,8 +1295,9 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override
public byte setColorization(byte aColor) {
if (aColor > 15 || aColor < -1) aColor = -1;
+ mColor = (byte) (aColor + 1);
if (canAccessData()) mMetaTileEntity.onColorChangeServer(aColor);
- return mColor = (byte) (aColor + 1);
+ return mColor;
}
@Override
@@ -1353,6 +1355,18 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mInventoryChanged = true;
}
+ public void onNeighborBlockChange(int aX, int aY, int aZ) {
+ if (canAccessData()) {
+ final IMetaTileEntity meta = getMetaTileEntity();
+ if (meta instanceof MetaPipeEntity) {
+ // Trigger a checking of connections in case someone placed down a block that the pipe/wire shouldn't be connected to.
+ // However; don't do it immediately in case the world isn't finished loading
+ // (This caused issues with AE2 GTEU p2p connections.
+ ((MetaPipeEntity) meta).setCheckConnections();
+ }
+ }
+ }
+
@Override
public int getLightOpacity() {
return mMetaTileEntity == null ? 0 : mMetaTileEntity.getLightOpacity();
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 991fcd6d2a..43c479be70 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1993,8 +1993,9 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte setColorization(byte aColor) { if (aColor > 15 || aColor < -1) aColor = -1; + mColor = (byte) (aColor + 1); if (canAccessData()) mMetaTileEntity.onColorChangeServer(aColor); - return mColor = (byte) (aColor + 1); + return mColor; } @Override diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 70ae71a719..c04dc9d523 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) {
@@ -755,6 +773,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!
@@ -769,8 +788,6 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { }
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
connectAtSide(aSide);
return 1;
}
@@ -783,9 +800,16 @@ 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);
+
+ public 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 ((!GT_Mod.gregtechproxy.gt6Cable || isConnectedAtSide(aSide)) && connect(aSide) == 0) {
+ disconnect(aSide);
+ }
+ }
+ mCheckConnections = false;
}
private void connectAtSide(byte aSide) {
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 7c3df98955..4f627458a4 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -835,12 +835,20 @@ public abstract class MetaTileEntity implements IMetaTileEntity { @Override public void onColorChangeServer(byte aColor) { - // + final IGregTechTileEntity meta = getBaseMetaTileEntity(); + final int aX = meta.getXCoord(), aY = meta.getYCoord(), aZ = meta.getZCoord(); + for (byte aSide = 0; aSide < 6 ; aSide++ ) { + // Flag surrounding pipes/cables to revaluate their connection with us if we got painted + final TileEntity tTileEntity = meta.getTileEntityAtSide(aSide); + if ((tTileEntity instanceof BaseMetaPipeEntity)) { + ((BaseMetaPipeEntity) tTileEntity).onNeighborBlockChange(aX, aY, aZ); + } + } } @Override public void onColorChangeClient(byte aColor) { - // + // Do nothing apparently } @Override diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index a393206257..e59be8921f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -295,7 +295,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile mTransferredVoltageLast20 = 0;
mTransferredAmperageLast20OK=mTransferredAmperageLast20;
mTransferredAmperageLast20 = 0;
- if (!GT_Mod.gregtechproxy.gt6Cable) checkConnections();
+ if (!GT_Mod.gregtechproxy.gt6Cable || mCheckConnections) checkConnections();
}
} else if(aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected==4) aBaseMetaTileEntity.issueTextureUpdate();
}
@@ -347,13 +347,6 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile final byte tSide = GT_Utility.getOppositeSide(aSide);
final ForgeDirection tDir = ForgeDirection.getOrientation(tSide);
- if (tTileEntity instanceof IColoredTileEntity) {
- if (getBaseMetaTileEntity().getColorization() >= 0) {
- byte tColor = ((IColoredTileEntity) tTileEntity).getColorization();
- if (tColor >= 0 && tColor != getBaseMetaTileEntity().getColorization()) return false;
- }
- }
-
// GT Machine handling
if ((tTileEntity instanceof IEnergyConnected) &&
(((IEnergyConnected) tTileEntity).inputEnergyFrom(tSide, false) || ((IEnergyConnected) tTileEntity).outputsEnergyTo(tSide, false)))
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 0644a07de1..b70697556d 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 @@ -227,7 +227,7 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { mLastReceivedFrom = 0;
}
- if (!GT_Mod.gregtechproxy.gt6Pipe) checkConnections();
+ if (!GT_Mod.gregtechproxy.gt6Pipe || mCheckConnections) checkConnections();
boolean shouldDistribute = (oLastReceivedFrom == mLastReceivedFrom);
for (int i = 0, j = aBaseMetaTileEntity.getRandomNumber(mPipeAmount); i < mPipeAmount; i++) {
@@ -387,15 +387,6 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { if (coverBehavior instanceof GT_Cover_Drain) return true;
- if (gTileEntity != null && getBaseMetaTileEntity().getColorization() >= 0) {
- // If we're painted...
- byte tColor = gTileEntity.getColorization();
- if (tColor >= 0 && (tColor & 15) != (getBaseMetaTileEntity().getColorization() & 15)) {
- // and the other tile entity is painted.. then we must both be painted the same color
- return false;
- }
- }
-
// Tinker Construct Faucets return a null tank info, so check the class
if (GregTech_API.mTConstruct && tTileEntity instanceof tconstruct.smeltery.logic.FaucetLogic) return true;
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java index a57e78885b..7cf91b6c86 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java @@ -158,7 +158,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE if (aBaseMetaTileEntity.isServerSide() && aTick % 10 == 0) { if (aTick % mTickTime == 0) mTransferredItems = 0; - if (!GT_Mod.gregtechproxy.gt6Pipe) checkConnections(); + if (!GT_Mod.gregtechproxy.gt6Pipe || mCheckConnections) checkConnections(); if (oLastReceivedFrom == mLastReceivedFrom) { doTickProfilingInThisTick = false; @@ -220,16 +220,8 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE final IGregTechTileEntity gTileEntity = (tTileEntity instanceof IGregTechTileEntity) ? (IGregTechTileEntity) tTileEntity : null; if (gTileEntity != null) { if (gTileEntity.getMetaTileEntity() == null) return false; - connectable = true; - if ( getBaseMetaTileEntity().getColorization() >= 0) { - // If we're painted... - byte tColor = gTileEntity.getColorization(); - if (tColor >= 0 && (tColor & 15) != (getBaseMetaTileEntity().getColorization() & 15)) { - // and the other tile entity is painted.. then we must both be painted the same color - return false; - } - } if (gTileEntity.getMetaTileEntity().connectsToItemPipe(tSide)) return true; + connectable = true; } if (tTileEntity instanceof IInventory) { @@ -239,7 +231,6 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE if (tTileEntity instanceof ISidedInventory) { int[] tSlots = ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(tSide); if (tSlots == null || tSlots.length <= 0) return false; - connectable = true; } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java index 8688fce78f..157a38962a 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java @@ -87,6 +87,13 @@ public class GT_Block_Machines }
}
+ public void onNeighborBlockChange(World aWorld, int aX, int aY, int aZ, Block aBlock) {
+ TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
+ if ((tTileEntity instanceof BaseMetaPipeEntity)) {
+ ((BaseMetaPipeEntity) tTileEntity).onNeighborBlockChange(aX, aY, aZ);
+ }
+ }
+
public void onBlockAdded(World aWorld, int aX, int aY, int aZ) {
super.onBlockAdded(aWorld, aX, aY, aZ);
if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) {
|