From 6955188d7bf46115288fda4021e2782c4d4fbbf8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 25 Nov 2016 15:33:47 +0100 Subject: [PATCH] *Actually* fixed Item Laser Relays leaving phantom connections behind --- .../mod/tile/TileEntityItemViewer.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java index 593a0d492..8485723f8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java @@ -75,32 +75,46 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{ } private void queryAndSaveData(){ - this.genericInfos.clear(); - this.specificInfos.clear(); - if(this.connectedRelay != null){ Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.connectedRelay.getPos(), this.worldObj); - if(network != null && (this.oldNetwork != network || this.lastNetworkChangeAmount != network.changeAmount)){ + if(network != null){ + if(this.oldNetwork != network || this.lastNetworkChangeAmount != network.changeAmount){ + this.clearInfos(); - this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos); - if(!this.genericInfos.isEmpty()){ - Collections.sort(this.genericInfos); + this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos); + if(!this.genericInfos.isEmpty()){ + Collections.sort(this.genericInfos); - int slotsQueried = 0; - for(GenericItemHandlerInfo info : this.genericInfos){ - for(IItemHandler handler : info.handlers){ - for(int i = 0; i < handler.getSlots(); i++){ - this.specificInfos.put(slotsQueried, new SpecificItemHandlerInfo(handler, i, info.relayInQuestion)); - slotsQueried++; + int slotsQueried = 0; + for(GenericItemHandlerInfo info : this.genericInfos){ + for(IItemHandler handler : info.handlers){ + for(int i = 0; i < handler.getSlots(); i++){ + this.specificInfos.put(slotsQueried, new SpecificItemHandlerInfo(handler, i, info.relayInQuestion)); + slotsQueried++; + } } } } + + this.oldNetwork = network; + this.lastNetworkChangeAmount = network.changeAmount; } - this.oldNetwork = network; - this.lastNetworkChangeAmount = network.changeAmount; + return; } } + + this.clearInfos(); + } + + private void clearInfos(){ + if(!this.genericInfos.isEmpty()){ + this.genericInfos.clear(); + } + + if(!this.specificInfos.isEmpty()){ + this.specificInfos.clear(); + } } private SpecificItemHandlerInfo getSwitchedIndexHandler(int i){