Skip to content

Commit

Permalink
Actually working now, applied to data pipes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dagger8243 committed Sep 29, 2024
1 parent fe34805 commit d52566a
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 85 deletions.
118 changes: 82 additions & 36 deletions src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,90 @@ public String[] getDescription() {
};
}

public void updateNeighboringNetworks() {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity t = aBaseMetaTileEntity.getTileEntityAtSide(side);
if (t instanceof IGregTechTileEntity a) {
if (a.getMetaTileEntity() instanceof MTEPipeData b)
b.updateNetwork(true);
}
}
}

public void updateNetwork(boolean nestedCall) {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

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 |= side.flag;
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 |= 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) {
TileEntity t = aBaseMetaTileEntity.getTileEntityAtSide(side);
if (t instanceof IGregTechTileEntity a) {
if (a.getMetaTileEntity() instanceof MTEPipeData b) {
b.mConnections &= ~side.getOpposite().flag;
connectionCount--;
}
}
}

super.onBlockDestroyed();
}

@Override
public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
onPostTick(aBaseMetaTileEntity, 31);
this.updateNetwork(false);
super.onFirstTick(aBaseMetaTileEntity);
}

@Override
Expand All @@ -138,41 +219,6 @@ 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();
Expand Down
124 changes: 75 additions & 49 deletions src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tectech.TecTech;
import tectech.loader.NetworkDispatcher;
import tectech.mechanics.pipe.IActivePipe;
import tectech.mechanics.pipe.IConnectsToDataPipe;
import tectech.mechanics.pipe.IConnectsToEnergyTunnel;
import tectech.mechanics.pipe.PipeActivityMessage;
import tectech.util.CommonValues;
Expand Down Expand Up @@ -85,26 +86,31 @@ public boolean allowPullStack(IGregTechTileEntity iGregTechTileEntity, int i, Fo
return false;
}

@Override
public void onBlockDestroyed() {
this.updateNetwork();
super.onBlockDestroyed();
}
public void updateNeighboringNetworks() {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

@Override
public void onServerStart() {
this.updateNetwork();
super.onServerStart();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity t = aBaseMetaTileEntity.getTileEntityAtSide(side);
if (t instanceof IGregTechTileEntity a) {
System.out.println("passed");
if (a.getMetaTileEntity() instanceof MTEPipeEnergy b) {
System.out.println("passed");
b.updateNetwork(true);
}
}
}
}

public void updateNetwork() {
public void updateNetwork(boolean nestedCall) {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

if (active) {
active = false;
}

mConnections = 0;
connectionCount = 0;

if (aBaseMetaTileEntity.getColorization() < 0) {
return;
}
Expand All @@ -118,69 +124,59 @@ public void updateNetwork() {
continue;
}
}

if (tTileEntity instanceof PowerLogicHost) {
PowerLogic logic = ((PowerLogicHost) tTileEntity).getPowerLogic(oppositeSide);
if (logic != null && logic.canUseLaser()) {
mConnections |= 1 << side.ordinal();
mConnections |= side.flag;
connectionCount++;
continue;
}
}

if (tTileEntity instanceof IConnectsToEnergyTunnel
&& ((IConnectsToEnergyTunnel) tTileEntity).canConnect(oppositeSide)) {
mConnections |= 1 << side.ordinal();
mConnections |= side.flag;
connectionCount++;
} else if (tTileEntity instanceof IGregTechTileEntity
&& ((IGregTechTileEntity) tTileEntity).getMetaTileEntity() instanceof IConnectsToEnergyTunnel) {
if (((IConnectsToEnergyTunnel) ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())
.canConnect(oppositeSide)) {
mConnections |= 1 << side.ordinal();
connectionCount++;
}
if (((IConnectsToEnergyTunnel) ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())
.canConnect(oppositeSide)) {
mConnections |= side.flag;
connectionCount++;
}
}
}
}

@Override
public void loadNBTData(NBTTagCompound nbtTagCompound) {
active = nbtTagCompound.getBoolean("eActive");
if (!nestedCall) updateNeighboringNetworks();
}

@Override
public void saveNBTData(NBTTagCompound nbtTagCompound) {
nbtTagCompound.setBoolean("eActive", active);
public void onColorChangeServer(byte aColor) {
this.updateNetwork(false);
super.onColorChangeServer(aColor);
}

@Override
public boolean renderInside(ForgeDirection side) {
return false;
}
public void onBlockDestroyed() {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

@Override
public byte getTileEntityBaseType() {
return 4;
}
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity t = aBaseMetaTileEntity.getTileEntityAtSide(side);

@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
};
if (t instanceof IGregTechTileEntity a) {
if (a.getMetaTileEntity() instanceof MTEPipeEnergy b) {
b.mConnections &= ~side.getOpposite().flag;
connectionCount--;
}
}
}

super.onBlockDestroyed();
}

@Override
public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
this.updateNetwork();
this.updateNetwork(false);
super.onFirstTick(aBaseMetaTileEntity);
}

@Override
Expand All @@ -202,10 +198,40 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}


@Override
public void onColorChangeServer(byte aColor) {
this.updateNetwork();
super.onColorChangeServer(aColor);
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
Expand Down

0 comments on commit d52566a

Please sign in to comment.