Compare commits

..
5 Commits
Author SHA1 Message Date
Martin RobertzandPilzinsel64 985b0f18a5 Prevent ghostloading (#116)
* prevent ghostloading by MEConduit

* prevent more ghostloading by MEConduit

* spottlessApply

* prevent ghostloading by ConduitUtil

---------

Co-authored-by: Pilzinsel64 <[email protected]>
2023-03-29 22:15:12 +02:00
D-Cysteine 4e40230bf3 Try to fix energy overflow (#114) 2023-03-29 17:25:43 +02:00
Pilzinsel64 76708883c0 needUpdateConnections only while updating cons (#113) 2023-03-23 21:12:11 +01:00
Pilzinsel64 0a1ee81780 Add comments for needUpdateConnections (#112)
* imrpove canConnectToExternal()

* needUpdateConnections

* add comments for needUpdateconnections
2023-03-23 06:46:13 +01:00
Pilzinsel64 1fd7ae7567 Improve canConnectToExternal() (#111)
* imrpove canConnectToExternal()

* needUpdateConnections
2023-03-22 23:43:32 +01:00
6 changed files with 79 additions and 5 deletions

No files matched your search

@@ -84,6 +84,18 @@ public abstract class AbstractConduit implements IConduit {
protected boolean connectionsDirty = true;
/**
* This shows if the currently running connection update should not finish with settings connectionsDirty to false.
* If this is true, it will trigger a reconnection on the next Tick.
* <p>
* Use the method needUpdateConnections() instead of setting this to true.
*
* @see needUpdateConnections()
*/
private boolean needUpdateConnections = false;
private boolean isUpdatingConnections = false;
protected AbstractConduit() {}
@Override
@@ -434,10 +446,13 @@ public abstract class AbstractConduit implements IConduit {
}
private void updateConnections() {
if (!connectionsDirty) {
if (!connectionsDirty && !needUpdateConnections) {
return;
}
isUpdatingConnections = true;
needUpdateConnections = false;
boolean externalConnectionsChanged = false;
List<ForgeDirection> copy = new ArrayList<ForgeDirection>(externalConnections);
// remove any no longer valid connections
@@ -462,6 +477,21 @@ public abstract class AbstractConduit implements IConduit {
}
connectionsDirty = false;
isUpdatingConnections = false;
}
/**
* This method prevents connection update from getting completed successfully by not settings connectionsDirty to
* false. This will trigger an connection update at the next Tick.
* <p>
* Only use this while executing updateConnections().
* <p>
* See this PR for more info: https://github.com/GTNewHorizons/EnderIO/pull/111
*/
protected void needUpdateConnections() {
if (isUpdatingConnections) {
needUpdateConnections = true;
}
}
@Override
@@ -248,7 +248,7 @@ public class ConduitUtil {
public static <T extends IConduit> Collection<T> getConnectedConduits(World world, int x, int y, int z,
Class<T> type) {
TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.blockExists(x, y, z) ? world.getTileEntity(x, y, z) : null;
if (!(te instanceof IConduitBundle)) {
return Collections.emptyList();
}
@@ -155,7 +155,16 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
public boolean canConnectToExternal(ForgeDirection dir, boolean ignoreDisabled) {
World world = getBundle().getWorld();
BlockCoord pos = getLocation();
TileEntity te = world.getTileEntity(pos.x + dir.offsetX, pos.y + dir.offsetY, pos.z + dir.offsetZ);
final int exactPosX = pos.x + dir.offsetX;
final int exactPosY = pos.y + dir.offsetY;
final int exactPosZ = pos.z + dir.offsetZ;
if (!world.blockExists(exactPosX, exactPosY, exactPosZ)) {
return false;
}
TileEntity te = world.getTileEntity(exactPosX, exactPosY, exactPosZ);
if (te instanceof TileConduitBundle) {
return false;
@@ -174,6 +183,10 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
if (node == null) {
node = part.getGridNode();
}
if (node == null) {
// The GridNode has not been initialized yet, let's try on the next Tick.
needUpdateConnections();
}
}
} else if (te instanceof IGridHost) {
node = ((IGridHost) te).getGridNode(dir.getOpposite());
@@ -301,7 +314,11 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
private void onNodeChanged(BlockCoord location) {
World world = getBundle().getWorld();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = location.getLocation(dir).getTileEntity(world);
BlockCoord dirLocation = location.getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = location.getLocation(dir).getTileEntity(world);
}
if (te != null && te instanceof IGridHost && !(te instanceof IConduitBundle)) {
IGridNode node = ((IGridHost) te).getGridNode(ForgeDirection.UNKNOWN);
if (node == null) {
@@ -317,7 +334,12 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
@Override
public void onAddedToBundle() {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = getLocation().getLocation(dir).getTileEntity(getBundle().getWorld());
World world = getBundle().getWorld();
BlockCoord dirLocation = getLocation().getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = dirLocation.getTileEntity(world);
}
if (te instanceof TileConduitBundle) {
IMEConduit cond = ((TileConduitBundle) te).getConduit(IMEConduit.class);
if (cond != null) {
@@ -131,6 +131,10 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (maxReceive < 0) {
return 0;
}
int res = super.receiveEnergy(container, maxReceive, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -148,6 +152,10 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
}
public int extractEnergyInternal(ItemStack container, int maxExtract, boolean simulate) {
if (maxExtract < 0) {
return 0;
}
int res = super.extractEnergy(container, maxExtract, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -67,6 +67,12 @@ public class ItemTeleportStaff extends ItemTravelStaff {
return equipped;
}
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
// Don't allow receiving energy, since we have infinite energy.
return 0;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
// Don't allow extracting energy.
@@ -103,6 +103,10 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (maxReceive < 0) {
return 0;
}
int res = super.receiveEnergy(container, maxReceive, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -112,6 +116,10 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (maxExtract < 0) {
return 0;
}
int res = super.extractEnergy(container, maxExtract, simulate);
if (res != 0 && !simulate) {
updateDamage(container);