Skip to content

Commit

Permalink
Cleaner Code, Wrench interaction implemented & SpotlessApply
Browse files Browse the repository at this point in the history
  • Loading branch information
dagger8243 committed Sep 29, 2024
1 parent 5246f46 commit a1d5784
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 56 deletions.
96 changes: 66 additions & 30 deletions src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,19 +125,18 @@ 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);
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();

if (active) {
active = false;
}
active = false;

mConnections = 0;
connectionCount = 0;
Expand All @@ -149,23 +149,23 @@ public void updateNetwork(boolean nestedCall) {
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 (tTileEntity instanceof IConnectsToDataPipe pipe) {
byte tColor = pipe.getColorization();
if (tColor != myColor) {
continue;
}
if (((IConnectsToDataPipe) tTileEntity).canConnectData(oppositeSide)) {
if (pipe.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();
} else if (tTileEntity instanceof IGregTechTileEntity gregTechTileEntity) {
IMetaTileEntity meta = gregTechTileEntity.getMetaTileEntity();
if (meta instanceof IConnectsToDataPipe pipe) {
byte tColor = pipe.getColorization();
if (tColor != myColor) {
continue;
}
if (((IConnectsToDataPipe) meta).canConnectData(oppositeSide)) {
if (pipe.canConnectData(oppositeSide)) {
mConnections |= side.flag;
connectionCount++;
}
Expand All @@ -187,12 +187,11 @@ 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--;
}
IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side);

if (gregTechTileEntity != null && gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeData neighbor) {
neighbor.mConnections &= ~side.getOpposite().flag;
neighbor.connectionCount--;
}
}

Expand Down Expand Up @@ -224,6 +223,37 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@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;
Expand All @@ -235,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;
}
}
}
Expand All @@ -261,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;
Expand Down
85 changes: 59 additions & 26 deletions src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,23 +90,19 @@ public void updateNeighboringNetworks() {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

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);
}
IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side);

if (gregTechTileEntity != null
&& gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) {
neighbor.updateNetwork(true);
}
}
}

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

if (active) {
active = false;
}
active = false;

mConnections = 0;
connectionCount = 0;
Expand All @@ -117,28 +114,26 @@ public void updateNetwork(boolean nestedCall) {
final ForgeDirection oppositeSide = side.getOpposite();

TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side);
if (tTileEntity instanceof IColoredTileEntity) {
byte tColor = ((IColoredTileEntity) tTileEntity).getColorization();
if (tTileEntity instanceof IColoredTileEntity coloredTileEntity) {
byte tColor = coloredTileEntity.getColorization();
if (tColor != aBaseMetaTileEntity.getColorization()) {
continue;
}
}
if (tTileEntity instanceof PowerLogicHost) {
PowerLogic logic = ((PowerLogicHost) tTileEntity).getPowerLogic(oppositeSide);
if (tTileEntity instanceof PowerLogicHost host) {
PowerLogic logic = host.getPowerLogic(oppositeSide);
if (logic != null && logic.canUseLaser()) {
mConnections |= side.flag;
connectionCount++;
continue;
}
}
if (tTileEntity instanceof IConnectsToEnergyTunnel
&& ((IConnectsToEnergyTunnel) tTileEntity).canConnect(oppositeSide)) {
if (tTileEntity instanceof IConnectsToEnergyTunnel tunnel && tunnel.canConnect(oppositeSide)) {
mConnections |= side.flag;
connectionCount++;
} else if (tTileEntity instanceof IGregTechTileEntity
&& ((IGregTechTileEntity) tTileEntity).getMetaTileEntity() instanceof IConnectsToEnergyTunnel) {
if (((IConnectsToEnergyTunnel) ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())
.canConnect(oppositeSide)) {
} else if (tTileEntity instanceof IGregTechTileEntity gregTechTileEntity
&& gregTechTileEntity.getMetaTileEntity() instanceof IConnectsToEnergyTunnel tunnel) {
if (tunnel.canConnect(oppositeSide)) {
mConnections |= side.flag;
connectionCount++;
}
Expand All @@ -159,13 +154,12 @@ public void onBlockDestroyed() {
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();

for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity t = aBaseMetaTileEntity.getTileEntityAtSide(side);
IGregTechTileEntity gregTechTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(side);

if (t instanceof IGregTechTileEntity a) {
if (a.getMetaTileEntity() instanceof MTEPipeEnergy b) {
b.mConnections &= ~side.getOpposite().flag;
connectionCount--;
}
if (gregTechTileEntity != null
&& gregTechTileEntity.getMetaTileEntity() instanceof MTEPipeEnergy neighbor) {
neighbor.mConnections &= ~side.getOpposite().flag;
neighbor.connectionCount--;
}
}

Expand Down Expand Up @@ -197,6 +191,39 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@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");
Expand Down Expand Up @@ -257,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;
Expand Down

0 comments on commit a1d5784

Please sign in to comment.