Should remove the last few issues with the power net, closes #924 and #930

This commit is contained in:
modmuss50 2017-01-24 21:21:02 +00:00
parent f2a3e61603
commit 38cad3b0f1
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA

View file

@ -57,25 +57,24 @@ public class TRPowerNet {
} }
@SubscribeEvent @SubscribeEvent
public void tick(PowerTickEvent evt) { public synchronized void tick(PowerTickEvent evt) {
evt.getWorld().theProfiler.startSection("TechRebornPowerNet"); evt.getWorld().theProfiler.startSection("TechRebornPowerNet");
if (tick < 20) { if (tick < 20) {
tick++; tick++;
return; return;
} }
if (tick % 80 == 0) { if (tick % 80 == 0) {
List<CableMultipart> oldCables = new ArrayList<>(); for (Iterator<CableMultipart> it = cables.iterator(); it.hasNext(); ) {
for (CableMultipart cableMultipart : cables) { CableMultipart cableMultipart = it.next();
if (cableMultipart.getWorld() == null || cableMultipart.getPos() == null) { if (cableMultipart.getWorld() == null || cableMultipart.getPos() == null) {
oldCables.add(cableMultipart); it.remove();
} }
CableMultipart mp = cableMultipart.getPartFromWorld(cableMultipart.getWorld(), cableMultipart.getPos(), CableMultipart mp = cableMultipart.getPartFromWorld(cableMultipart.getWorld(), cableMultipart.getPos(),
null); null);
if (mp == null) { if (mp == null) {
oldCables.add(cableMultipart); it.remove();
} }
} }
cables.removeAll(oldCables);
} }
if (!cables.isEmpty()) { if (!cables.isEmpty()) {
ArrayList<EnergyHandler> collectibles = new ArrayList(); ArrayList<EnergyHandler> collectibles = new ArrayList();
@ -106,13 +105,17 @@ public class TRPowerNet {
} }
public void addElement(CableMultipart te) { public void addElement(CableMultipart te) {
if (!cables.contains(te)) { synchronized (cables){
cables.add(te); if (!cables.contains(te)) {
cables.add(te);
}
} }
} }
public void removeElement(CableMultipart te) { public void removeElement(CableMultipart te) {
cables.remove(te); synchronized (cables){
cables.remove(te);
}
this.rebuild(); this.rebuild();
this.checkAndRemoveOldEndpoints(); this.checkAndRemoveOldEndpoints();
} }