diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index a0fafe1bcd8..62b722e86d8 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -62,6 +62,8 @@ import gregtech.common.covers.CoverInfo; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; +import tectech.thing.metaTileEntity.pipe.MTEPipeData; +import tectech.thing.metaTileEntity.pipe.MTEPipeEnergy; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -1080,6 +1082,28 @@ public ItemStack[] getRealInventory() { return mInventory; } + @Override + public void onBlockDestroyed() { + final IGregTechTileEntity meta = getBaseMetaTileEntity(); + + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + final IGregTechTileEntity iGregTechTileEntity = meta.getIGregTechTileEntityAtSide(side); + + if (iGregTechTileEntity != null) { + if (iGregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) { + neighbor.mConnections &= ~side.getOpposite().flag; + neighbor.connectionCount--; + } + if (iGregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) { + neighbor.mConnections &= ~side.getOpposite().flag; + neighbor.connectionCount--; + } + } + } + + IMetaTileEntity.super.onBlockDestroyed(); + } + @Override public void onColorChangeServer(byte aColor) { final IGregTechTileEntity meta = getBaseMetaTileEntity(); @@ -1090,6 +1114,12 @@ public void onColorChangeServer(byte aColor) { if (tTileEntity instanceof BaseMetaPipeEntity pipe) { pipe.onNeighborBlockChange(aX, aY, aZ); } + + final IGregTechTileEntity iGregTechTileEntity = meta.getIGregTechTileEntityAtSide(side); + if (iGregTechTileEntity != null) { + if (iGregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy pipe) pipe.updateNetwork(true); + if (iGregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData pipe) pipe.updateNetwork(true); + } } } diff --git a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java index cd9d583c1bd..f78e0b92bbc 100644 --- a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java +++ b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java @@ -4,6 +4,7 @@ import static net.minecraft.util.StatCollector.translateToLocal; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -120,9 +121,87 @@ public String[] getDescription() { }; } + public void updateNeighboringNetworks() { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side); + + if (gregTechTileEntity != null && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) { + neighbor.updateNetwork(true); + } + } + } + + public void updateNetwork(boolean nestedCall) { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + active = false; + + mConnections = 0; + connectionCount = 0; + + byte myColor = aBaseMetaTileEntity.getColorization(); + if (aBaseMetaTileEntity.getColorization() < 0) { + return; + } + + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + final ForgeDirection oppositeSide = side.getOpposite(); + TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side); + if (tTileEntity instanceof IConnectsToDataPipe pipe) { + byte tColor = pipe.getColorization(); + if (tColor != myColor) { + continue; + } + if (pipe.canConnectData(oppositeSide)) { + mConnections |= side.flag; + connectionCount++; + } + } else if (tTileEntity instanceof IGregTechTileEntity gregTechTileEntity) { + IMetaTileEntity meta = gregTechTileEntity.getMetaTileEntity(); + if (meta instanceof IConnectsToDataPipe pipe) { + byte tColor = pipe.getColorization(); + if (tColor != myColor) { + continue; + } + if (pipe.canConnectData(oppositeSide)) { + mConnections |= side.flag; + connectionCount++; + } + } + } + } + + if (!nestedCall) updateNeighboringNetworks(); + } + + @Override + public void onColorChangeServer(byte aColor) { + this.updateNetwork(false); + super.onColorChangeServer(aColor); + } + + @Override + public void onBlockDestroyed() { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side); + + if (gregTechTileEntity != null && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) { + neighbor.mConnections &= ~side.getOpposite().flag; + neighbor.connectionCount--; + } + } + + super.onBlockDestroyed(); + } + @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - onPostTick(aBaseMetaTileEntity, 31); + this.updateNetwork(false); + super.onFirstTick(aBaseMetaTileEntity); } @Override @@ -138,47 +217,43 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { aBaseMetaTileEntity.getZCoord(), 256); } - if (active) { - active = false; - } - mConnections = 0; - connectionCount = 0; - byte myColor = aBaseMetaTileEntity.getColorization(); - if (aBaseMetaTileEntity.getColorization() < 0) { - return; - } - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - final ForgeDirection oppositeSide = side.getOpposite(); - TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side); - if (tTileEntity instanceof IConnectsToDataPipe) { - byte tColor = ((IConnectsToDataPipe) tTileEntity).getColorization(); - if (tColor != myColor) { - continue; - } - if (((IConnectsToDataPipe) tTileEntity).canConnectData(oppositeSide)) { - mConnections |= 1 << side.ordinal(); - connectionCount++; - } - } else if (tTileEntity instanceof IGregTechTileEntity) { - IMetaTileEntity meta = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (meta instanceof IConnectsToDataPipe) { - byte tColor = ((IConnectsToDataPipe) meta).getColorization(); - if (tColor != myColor) { - continue; - } - if (((IConnectsToDataPipe) meta).canConnectData(oppositeSide)) { - mConnections |= 1 << side.ordinal(); - connectionCount++; - } - } - } - } } } else if (aBaseMetaTileEntity.isClientSide() && GTClient.changeDetected == 4) { aBaseMetaTileEntity.issueTextureUpdate(); } } + @Override + public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, float aX, + float aY, float aZ, ItemStack aTool) { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + if (this.isConnectedAtSide(wrenchingSide)) { + this.mConnections &= ~wrenchingSide.flag; + this.connectionCount--; + + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(wrenchingSide); + + if (gregTechTileEntity != null && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) { + neighbor.mConnections &= ~wrenchingSide.getOpposite().flag; + neighbor.connectionCount--; + } + + } else { + this.mConnections |= wrenchingSide.flag; + this.connectionCount++; + + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(wrenchingSide); + + if (gregTechTileEntity != null && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) { + neighbor.mConnections |= wrenchingSide.getOpposite().flag; + neighbor.connectionCount--; + } + } + + return super.onWrenchRightClick(side, wrenchingSide, aPlayer, aX, aY, aZ, aTool); + } + @Override public boolean canConnectData(ForgeDirection side) { return true; @@ -190,23 +265,23 @@ public IConnectsToDataPipe getNext(IConnectsToDataPipe source) { return null; } for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if ((mConnections & 1 << side.ordinal()) == 0) { + if ((mConnections & side.flag) == 0) { continue; // if not connected continue } TileEntity next = getBaseMetaTileEntity().getTileEntityAtSide(side); - if (next instanceof IConnectsToDataPipe && next != source) { - if (((IConnectsToDataPipe) next).isDataInputFacing(side.getOpposite())) { - return (IConnectsToDataPipe) next; + if (next instanceof IConnectsToDataPipe connectsToPipe && next != source) { + if (connectsToPipe.isDataInputFacing(side.getOpposite())) { + return connectsToPipe; } - } else if (next instanceof IGregTechTileEntity) { - IMetaTileEntity meta = ((IGregTechTileEntity) next).getMetaTileEntity(); - if (meta instanceof IConnectsToDataPipe connecsToPipe && meta != source) { + } else if (next instanceof IGregTechTileEntity gregTechTileEntity) { + IMetaTileEntity meta = gregTechTileEntity.getMetaTileEntity(); + if (meta instanceof IConnectsToDataPipe connectsToPipe && meta != source) { if (meta instanceof MTEPipeData pipeData && pipeData.connectionCount == 2) { pipeData.markUsed(); - return connecsToPipe; + return connectsToPipe; } - if (connecsToPipe.isDataInputFacing(side.getOpposite())) { - return connecsToPipe; + if (connectsToPipe.isDataInputFacing(side.getOpposite())) { + return connectsToPipe; } } } @@ -216,6 +291,12 @@ public IConnectsToDataPipe getNext(IConnectsToDataPipe source) { @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { + if (GTMod.instance.isClientSide() && (GTClient.hideValue & 0x2) != 0) + return AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1); + else return getActualCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + + public AxisAlignedBB getActualCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { float tSpace = (1f - 0.375f) / 2; float tSide0 = tSpace; float tSide1 = 1f - tSpace; diff --git a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java index fcd23e50850..33219cb70c3 100644 --- a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java +++ b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java @@ -4,6 +4,7 @@ import static net.minecraft.util.StatCollector.translateToLocal; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -85,44 +86,90 @@ public boolean allowPullStack(IGregTechTileEntity iGregTechTileEntity, int i, Fo return false; } - @Override - public void loadNBTData(NBTTagCompound nbtTagCompound) { - active = nbtTagCompound.getBoolean("eActive"); - } + public void updateNeighboringNetworks() { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - @Override - public void saveNBTData(NBTTagCompound nbtTagCompound) { - nbtTagCompound.setBoolean("eActive", active); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side); + + if (gregTechTileEntity != null + && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) { + neighbor.updateNetwork(true); + } + } } - @Override - public boolean renderInside(ForgeDirection side) { - return false; + public void updateNetwork(boolean nestedCall) { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + active = false; + + mConnections = 0; + connectionCount = 0; + + if (aBaseMetaTileEntity.getColorization() < 0) { + return; + } + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + final ForgeDirection oppositeSide = side.getOpposite(); + + TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side); + if (tTileEntity instanceof IColoredTileEntity coloredTileEntity) { + byte tColor = coloredTileEntity.getColorization(); + if (tColor != aBaseMetaTileEntity.getColorization()) { + continue; + } + } + if (tTileEntity instanceof PowerLogicHost host) { + PowerLogic logic = host.getPowerLogic(oppositeSide); + if (logic != null && logic.canUseLaser()) { + mConnections |= side.flag; + connectionCount++; + continue; + } + } + if (tTileEntity instanceof IConnectsToEnergyTunnel tunnel && tunnel.canConnect(oppositeSide)) { + mConnections |= side.flag; + connectionCount++; + } else if (tTileEntity instanceof IGregTechTileEntity gregTechTileEntity + && gregTechTileEntity.getMetaTileEntity() instanceof IConnectsToEnergyTunnel tunnel) { + if (tunnel.canConnect(oppositeSide)) { + mConnections |= side.flag; + connectionCount++; + } + } + } + + if (!nestedCall) updateNeighboringNetworks(); } @Override - public byte getTileEntityBaseType() { - return 4; + public void onColorChangeServer(byte aColor) { + this.updateNetwork(false); + super.onColorChangeServer(aColor); } @Override - public String[] getDescription() { - return new String[] { CommonValues.TEC_MARK_EM, translateToLocal("gt.blockmachines.pipe.energystream.desc.0"), // Laser - // tunneling - // device. - EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD - + translateToLocal("gt.blockmachines.pipe.energystream.desc.1"), // Bright Vacuum!!! - EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.pipe.energystream.desc.2"), // Must be - // painted to - // work - EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.pipe.energystream.desc.3") // Do not split - // or turn - }; + public void onBlockDestroyed() { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side); + + if (gregTechTileEntity != null + && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) { + neighbor.mConnections &= ~side.getOpposite().flag; + neighbor.connectionCount--; + } + } + + super.onBlockDestroyed(); } @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - onPostTick(aBaseMetaTileEntity, 31); + this.updateNetwork(false); + super.onFirstTick(aBaseMetaTileEntity); } @Override @@ -138,56 +185,80 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { aBaseMetaTileEntity.getZCoord(), 256); } - if (active) { - active = false; - } - mConnections = 0; - connectionCount = 0; - if (aBaseMetaTileEntity.getColorization() < 0) { - return; - } - for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - final ForgeDirection oppositeSide = side.getOpposite(); - // if (!aBaseMetaTileEntity.getCoverBehaviorAtSide(b0).alwaysLookConnected(b0, - // aBaseMetaTileEntity.getCoverIDAtSide(b0), aBaseMetaTileEntity.getCoverDataAtSide(b0), - // aBaseMetaTileEntity)) { - TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side); - if (tTileEntity instanceof IColoredTileEntity) { - // if (aBaseMetaTileEntity.getColorization() >= 0) { - byte tColor = ((IColoredTileEntity) tTileEntity).getColorization(); - if (tColor != aBaseMetaTileEntity.getColorization()) { - continue; - } - // } - } - if (tTileEntity instanceof PowerLogicHost) { - PowerLogic logic = ((PowerLogicHost) tTileEntity).getPowerLogic(oppositeSide); - if (logic != null && logic.canUseLaser()) { - mConnections |= 1 << side.ordinal(); - connectionCount++; - continue; - } - } - if (tTileEntity instanceof IConnectsToEnergyTunnel - && ((IConnectsToEnergyTunnel) tTileEntity).canConnect(oppositeSide)) { - mConnections |= 1 << side.ordinal(); - connectionCount++; - } else if (tTileEntity instanceof IGregTechTileEntity - && ((IGregTechTileEntity) tTileEntity).getMetaTileEntity() instanceof IConnectsToEnergyTunnel) { - if (((IConnectsToEnergyTunnel) ((IGregTechTileEntity) tTileEntity).getMetaTileEntity()) - .canConnect(oppositeSide)) { - mConnections |= 1 << side.ordinal(); - connectionCount++; - } - } - } } - } else if (aBaseMetaTileEntity.isClientSide() && GTClient.changeDetected == 4) { aBaseMetaTileEntity.issueTextureUpdate(); } } + @Override + public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, float aX, + float aY, float aZ, ItemStack aTool) { + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + + if (this.isConnectedAtSide(wrenchingSide)) { + this.mConnections &= ~wrenchingSide.flag; + this.connectionCount--; + + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(wrenchingSide); + + if (gregTechTileEntity != null + && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) { + neighbor.mConnections &= ~wrenchingSide.getOpposite().flag; + neighbor.connectionCount--; + } + + } else { + this.mConnections |= wrenchingSide.flag; + this.connectionCount++; + + IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(wrenchingSide); + + if (gregTechTileEntity != null + && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) { + neighbor.mConnections |= wrenchingSide.getOpposite().flag; + neighbor.connectionCount--; + } + } + + return super.onWrenchRightClick(side, wrenchingSide, aPlayer, aX, aY, aZ, aTool); + } + + @Override + public void loadNBTData(NBTTagCompound nbtTagCompound) { + active = nbtTagCompound.getBoolean("eActive"); + } + + @Override + public void saveNBTData(NBTTagCompound nbtTagCompound) { + nbtTagCompound.setBoolean("eActive", active); + } + + @Override + public boolean renderInside(ForgeDirection side) { + return false; + } + + @Override + public byte getTileEntityBaseType() { + return 4; + } + + @Override + public String[] getDescription() { + return new String[] { CommonValues.TEC_MARK_EM, translateToLocal("gt.blockmachines.pipe.energystream.desc.0"), // Laser + // tunneling + // device. + EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + + translateToLocal("gt.blockmachines.pipe.energystream.desc.1"), // Bright Vacuum!!! + EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.pipe.energystream.desc.2"), // Must be + // painted to + // work + EnumChatFormatting.AQUA + translateToLocal("gt.blockmachines.pipe.energystream.desc.3") // Do not split + // or turn + }; + } + @Override public void setActive(boolean state) { if (state != active) { @@ -213,6 +284,12 @@ public boolean canConnect(ForgeDirection side) { @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { + if (GTMod.instance.isClientSide() && (GTClient.hideValue & 0x2) != 0) + return AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1); + else return getActualCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + + public AxisAlignedBB getActualCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { float tSpace = (1f - 0.5f) / 2; float tSide0 = tSpace; float tSide1 = 1f - tSpace;