Compare commits

...
4 Commits
Author SHA1 Message Date
D-Cysteine 52563aa5c2 Try to fix energy overflow 2023-03-26 18:09:42 -06: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
5 changed files with 57 additions and 1 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
@@ -174,6 +174,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());
@@ -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);