Utils ported

This commit is contained in:
Sebastian Hartte
2020-06-28 13:28:14 +02:00
parent fee5b7fdfc
commit 46955643b9
105 changed files with 239 additions and 379 deletions
@@ -1,84 +1,42 @@
package appeng.tile.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import alexiil.mc.lib.attributes.Simulation;
import alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv;
import appeng.api.storage.cells.ICellInventory;
import appeng.api.storage.cells.ICellInventoryHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.filter.IAEItemFilter;
import net.minecraft.item.ItemStack;
public class AppEngCellInventory implements IItemHandlerModifiable {
private final AppEngInternalInventory inv;
private final ICellInventoryHandler handlerForSlot[];
public class AppEngCellInventory extends DelegatingFixedItemInv {
private final ICellInventoryHandler<?>[] handlerForSlot;
public AppEngCellInventory(final IAEAppEngInventory host, final int slots) {
this.inv = new AppEngInternalInventory(host, slots, 1);
super(new AppEngInternalInventory(host, slots, 1));
this.handlerForSlot = new ICellInventoryHandler[slots];
}
public void setHandler(final int slot, final ICellInventoryHandler handler) {
public void setHandler(final int slot, final ICellInventoryHandler<?> handler) {
this.handlerForSlot[slot] = handler;
}
public void setFilter(IAEItemFilter filter) {
this.inv.setFilter(filter);
}
@Override
public void setStackInSlot(int slot, ItemStack stack) {
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
this.persist(slot);
this.inv.setStackInSlot(slot, stack);
boolean result = super.setInvStack(slot, to, simulation);
this.cleanup(slot);
return result;
}
@Override
public int getSlots() {
return this.inv.getSlots();
}
@Override
public ItemStack getStackInSlot(int slot) {
public ItemStack getInvStack(int slot) {
this.persist(slot);
return this.inv.getStackInSlot(slot);
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
this.persist(slot);
final ItemStack ret = this.inv.insertItem(slot, stack, simulate);
this.cleanup(slot);
return ret;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
this.persist(slot);
final ItemStack ret = this.inv.extractItem(slot, amount, simulate);
this.cleanup(slot);
return ret;
}
@Override
public int getSlotLimit(int slot) {
return this.inv.getSlotLimit(slot);
}
@Override
public boolean isItemValid(int slot, ItemStack stack) {
return this.inv.isItemValid(slot, stack);
}
public void persist() {
for (int i = 0; i < this.getSlots(); ++i) {
this.persist(i);
}
return super.getInvStack(slot);
}
private void persist(int slot) {
if (this.handlerForSlot[slot] != null) {
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
final ICellInventory<?> ci = this.handlerForSlot[slot].getCellInv();
if (ci != null) {
ci.persist();
}
@@ -87,9 +45,9 @@ public class AppEngCellInventory implements IItemHandlerModifiable {
private void cleanup(int slot) {
if (this.handlerForSlot[slot] != null) {
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
final ICellInventory<?> ci = this.handlerForSlot[slot].getCellInv();
if (ci == null || ci.getItemStack() != this.inv.getStackInSlot(slot)) {
if (ci == null || ci.getItemStack() != super.getInvStack(slot)) {
this.handlerForSlot[slot] = null;
}
}