Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Laser & Data pipe every 32 tick connection update #3259

Merged
merged 22 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
80e4c4d
Fixed Laser pipe every 32 tick connection update
dagger8243 Sep 22, 2024
db30814
Merge branch 'master' into master
Dream-Master Sep 23, 2024
cccff5e
Merge branch 'master' into master
Dream-Master Sep 23, 2024
acbdcd3
Merge branch 'master' into master
Dream-Master Sep 23, 2024
c4b52be
Merge branch 'master' into master
Dream-Master Sep 23, 2024
2dc10da
sa
Dream-Master Sep 23, 2024
4e38652
Merge branch 'master' into master
Dream-Master Sep 24, 2024
5cd1197
Merge branch 'master' into master
Dream-Master Sep 25, 2024
65972e7
Merge branch 'master' into master
Dream-Master Sep 28, 2024
fe34805
Merge branch 'GTNewHorizons:master' into master
dagger8243 Sep 29, 2024
d52566a
Actually working now, applied to data pipes as well
dagger8243 Sep 29, 2024
5246f46
SpotlessApply
dagger8243 Sep 29, 2024
a1d5784
Cleaner Code, Wrench interaction implemented & SpotlessApply
dagger8243 Sep 29, 2024
83624c9
Merge branch 'master' into master
Dream-Master Sep 30, 2024
3f1ebef
Merge remote-tracking branch 'upstream/master'
dagger8243 Oct 1, 2024
99e6bf4
Duct-taped fix for data and laser endpoint connectors
dagger8243 Oct 1, 2024
bbcda41
Merge remote-tracking branch 'refs/remotes/origin/master'
dagger8243 Oct 1, 2024
f2c9a0a
Merge branch 'master' into master
Dream-Master Oct 1, 2024
3f6e59c
Merge branch 'master' into master
Dream-Master Oct 2, 2024
a41e1a6
Merge branch 'master' into master
Dream-Master Oct 2, 2024
23ed274
Merge branch 'master' into master
Dream-Master Oct 2, 2024
5745bdb
Merge branch 'master' into master
Dream-Master Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
}

Expand Down
173 changes: 127 additions & 46 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 @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}
}
Expand All @@ -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;
Expand Down
Loading