mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Cache slot count (#1289)
This avoids having to recalculate it every time .getSlots() is called. The private method getItemHandlerInfos was rendered useless by this change and has been removed. Fixed #1288
This commit is contained in:
parent
35a048de3d
commit
c5010c5d02
1 changed files with 5 additions and 17 deletions
22
src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java
Normal file → Executable file
22
src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java
Normal file → Executable file
|
@ -45,6 +45,7 @@ public class TileEntityItemViewer extends TileEntityBase {
|
||||||
protected final SlotlessableItemHandlerWrapper itemHandler;
|
protected final SlotlessableItemHandlerWrapper itemHandler;
|
||||||
public TileEntityLaserRelayItem connectedRelay;
|
public TileEntityLaserRelayItem connectedRelay;
|
||||||
private int lastNetworkChangeAmount = -1;
|
private int lastNetworkChangeAmount = -1;
|
||||||
|
private int slotCount;
|
||||||
|
|
||||||
public TileEntityItemViewer(String name) {
|
public TileEntityItemViewer(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -52,21 +53,7 @@ public class TileEntityItemViewer extends TileEntityBase {
|
||||||
IItemHandler normalHandler = new IItemHandler() {
|
IItemHandler normalHandler = new IItemHandler() {
|
||||||
@Override
|
@Override
|
||||||
public int getSlots() {
|
public int getSlots() {
|
||||||
int size = 0;
|
return TileEntityItemViewer.this.getSlotCount();
|
||||||
List<GenericItemHandlerInfo> infos = TileEntityItemViewer.this.getItemHandlerInfos();
|
|
||||||
if (infos != null) {
|
|
||||||
for (GenericItemHandlerInfo info : infos) {
|
|
||||||
if (info.isLoaded()) {
|
|
||||||
for (SlotlessableItemHandlerWrapper handler : info.handlers) {
|
|
||||||
IItemHandler normalHandler = handler.getNormalHandler();
|
|
||||||
if (normalHandler != null) {
|
|
||||||
size += normalHandler.getSlots();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,9 +134,9 @@ public class TileEntityItemViewer extends TileEntityBase {
|
||||||
return super.getCapability(capability, facing);
|
return super.getCapability(capability, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<GenericItemHandlerInfo> getItemHandlerInfos() {
|
private int getSlotCount() {
|
||||||
this.queryAndSaveData();
|
this.queryAndSaveData();
|
||||||
return this.genericInfos;
|
return this.slotCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doItemParticle(ItemStack stack, BlockPos input, BlockPos output) {
|
public void doItemParticle(ItemStack stack, BlockPos input, BlockPos output) {
|
||||||
|
@ -206,6 +193,7 @@ public class TileEntityItemViewer extends TileEntityBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.slotCount = slotsQueried;
|
||||||
}
|
}
|
||||||
this.lastNetworkChangeAmount = network.changeAmount;
|
this.lastNetworkChangeAmount = network.changeAmount;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue