Utils ported
This commit is contained in:
@@ -280,7 +280,7 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult
|
||||
for (IAEItemStack ais : inv.getAvailableItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())) {
|
||||
ais = ais.copy();
|
||||
ais.setStackSize(ais.getDefinition().getMaxStackSize());
|
||||
ais.setStackSize(ais.getDefinition().getMaxCount());
|
||||
while (true) {
|
||||
final IAEItemStack g = inv.extractItems(ais.copy(), Actionable.MODULATE,
|
||||
this.cluster.getActionSource());
|
||||
|
||||
@@ -160,7 +160,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
private boolean canPush() {
|
||||
return !this.gridInv.getStackInSlot(9).isEmpty();
|
||||
return !this.gridInv.getInvStack(9).isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasMats() {
|
||||
@@ -169,7 +169,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
for (int x = 0; x < this.craftingInv.size(); x++) {
|
||||
this.craftingInv.setStack(x, this.gridInv.getStackInSlot(x));
|
||||
this.craftingInv.setStack(x, this.gridInv.getInvStack(x));
|
||||
}
|
||||
|
||||
return !this.myPlan.getOutput(this.craftingInv, this.getWorld()).isEmpty();
|
||||
@@ -247,7 +247,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack is = this.patternInv.getStackInSlot(0);
|
||||
final ItemStack is = this.patternInv.getInvStack(0);
|
||||
|
||||
if (!is.isEmpty() && is.getItem() instanceof EncodedPatternItem) {
|
||||
if (!ItemStack.areItemsEqual(is, this.myPattern)) {
|
||||
@@ -332,7 +332,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSlots(); h++) {
|
||||
final ItemStack is = this.upgrades.getStackInSlot(h);
|
||||
final ItemStack is = this.upgrades.getInvStack(h);
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
@@ -348,11 +348,11 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, int ticksSinceLastCall) {
|
||||
if (!this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
this.pushOut(this.gridInv.getStackInSlot(9));
|
||||
if (!this.gridInv.getInvStack(9).isEmpty()) {
|
||||
this.pushOut(this.gridInv.getInvStack(9));
|
||||
|
||||
// did it eject?
|
||||
if (this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
if (this.gridInv.getInvStack(9).isEmpty()) {
|
||||
this.saveChanges();
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
|
||||
if (this.progress >= 100) {
|
||||
for (int x = 0; x < this.craftingInv.size(); x++) {
|
||||
this.craftingInv.setStack(x, this.gridInv.getStackInSlot(x));
|
||||
this.craftingInv.setStack(x, this.gridInv.getInvStack(x));
|
||||
}
|
||||
|
||||
this.progress = 0;
|
||||
@@ -441,9 +441,9 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
private void ejectHeldItems() {
|
||||
if (this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
if (this.gridInv.getInvStack(9).isEmpty()) {
|
||||
for (int x = 0; x < 9; x++) {
|
||||
final ItemStack is = this.gridInv.getStackInSlot(x);
|
||||
final ItemStack is = this.gridInv.getInvStack(x);
|
||||
if (!is.isEmpty()) {
|
||||
if (this.myPlan == null || !this.myPlan.isValidItemForSlot(x, is, this.world)) {
|
||||
this.gridInv.setStackInSlot(9, is);
|
||||
|
||||
@@ -81,10 +81,10 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.inv.getStackInSlot(6).isEmpty()) // Add if there isn't one...
|
||||
if (this.inv.getInvStack(6).isEmpty()) // Add if there isn't one...
|
||||
{
|
||||
for (int x = 0; x < 3; x++) {
|
||||
ItemStack item = this.inv.getStackInSlot(x);
|
||||
ItemStack item = this.inv.getInvStack(x);
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
if (r != null) {
|
||||
final ItemStack ais = item.copy();
|
||||
ais.setCount(r.getIngredientCount());
|
||||
item.shrink(r.getIngredientCount());
|
||||
item.decrement(r.getIngredientCount());
|
||||
|
||||
if (item.getCount() <= 0) {
|
||||
item = ItemStack.EMPTY;
|
||||
@@ -117,7 +117,7 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
|
||||
this.points++;
|
||||
|
||||
final ItemStack processing = this.inv.getStackInSlot(SLOT_PROCESSING);
|
||||
final ItemStack processing = this.inv.getInvStack(SLOT_PROCESSING);
|
||||
GrinderRecipe r = GrinderRecipes.findForInput(world, processing);
|
||||
if (r != null) {
|
||||
if (r.getTurns() > this.points) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,15 @@ package appeng.tile.inventory;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.ListenerRemovalToken;
|
||||
import alexiil.mc.lib.attributes.ListenerToken;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.InvMarkDirtyListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
@@ -35,10 +39,9 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.iterators.AEInvIterator;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
|
||||
public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterable<ItemStack> {
|
||||
public class AppEngInternalAEInventory implements FixedItemInv, Iterable<ItemStack> {
|
||||
private final IAEAppEngInventory te;
|
||||
private final IAEItemStack[] inv;
|
||||
private final int size;
|
||||
@@ -103,105 +106,74 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
}
|
||||
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
return Math.min(this.getSlotLimit(slot), stack.getMaxStackSize());
|
||||
return Math.min(this.getMaxAmount(slot, stack), stack.getMaxCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
public ItemStack getInvStack(int slot) {
|
||||
if (this.inv[slot] == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.inv[slot].createItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
|
||||
if (this.te == null || !Platform.isServer()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: We need to implement the actual checks here, stacking /caninsert/canremove
|
||||
if (true) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (simulation == Simulation.SIMULATE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack oldStack = this.getInvStack(slot).copy();
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(to);
|
||||
|
||||
ItemStack newStack = to.copy();
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (ItemStack.areItemsEqual(oldStack, newStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.decrement(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.decrement(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
}
|
||||
this.fireOnChangeInventory(slot, op, oldStack, newStack);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int var1) {
|
||||
if (this.inv[var1] == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.inv[var1].createItemStack();
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
if (stack.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack existing = this.getStackInSlot(slot);
|
||||
int limit = this.getStackLimit(slot, stack);
|
||||
|
||||
if (!existing.isEmpty()) {
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
limit -= existing.getCount();
|
||||
}
|
||||
|
||||
if (limit <= 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
boolean reachedLimit = stack.getCount() > limit;
|
||||
|
||||
if (!simulate) {
|
||||
if (existing.isEmpty()) {
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(reachedLimit ? Platform.copyStackWithSize(stack, limit) : stack);
|
||||
} else {
|
||||
existing.increment(reachedLimit ? limit : stack.getCount());
|
||||
}
|
||||
this.fireOnChangeInventory(slot, InvOperation.INSERT, ItemStack.EMPTY,
|
||||
reachedLimit ? Platform.copyStackWithSize(stack, limit) : stack);
|
||||
}
|
||||
return reachedLimit ? Platform.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
|
||||
public int getChangeValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.inv[slot] != null) {
|
||||
final ItemStack split = this.getStackInSlot(slot);
|
||||
|
||||
if (amount >= split.getCount()) {
|
||||
if (!simulate) {
|
||||
this.inv[slot] = null;
|
||||
this.fireOnChangeInventory(slot, InvOperation.EXTRACT, split, ItemStack.EMPTY);
|
||||
}
|
||||
return split;
|
||||
} else {
|
||||
if (!simulate) {
|
||||
split.increment(-amount);
|
||||
this.fireOnChangeInventory(slot, InvOperation.EXTRACT,
|
||||
Platform.copyStackWithSize(split, amount), ItemStack.EMPTY);
|
||||
}
|
||||
return Platform.copyStackWithSize(split, amount);
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(final int slot, final ItemStack newItemStack) {
|
||||
ItemStack oldStack = this.getStackInSlot(slot).copy();
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(newItemStack);
|
||||
|
||||
if (this.te != null && Platform.isServer()) {
|
||||
ItemStack newStack = newItemStack.copy();
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (ItemStack.areItemsEqual(oldStack, newStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.shrink(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.shrink(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
}
|
||||
this.fireOnChangeInventory(slot, op, oldStack, newStack);
|
||||
}
|
||||
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fireOnChangeInventory(int slot, InvOperation op, ItemStack removed, ItemStack inserted) {
|
||||
@@ -214,8 +186,8 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
public int getMaxAmount(int slot, ItemStack is) {
|
||||
return Math.min(this.maxStack, 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,12 +195,4 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
return new InvIterator(this);
|
||||
}
|
||||
|
||||
public Iterator<IAEItemStack> getNewAEIterator() {
|
||||
return new AEInvIterator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,26 +18,28 @@
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInvView;
|
||||
import alexiil.mc.lib.attributes.item.filter.ConstantItemFilter;
|
||||
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
|
||||
import alexiil.mc.lib.attributes.item.impl.FullFixedItemInv;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack> {
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
// FIXME: the filtering is not correctly implemented and need to be reworked
|
||||
public class AppEngInternalInventory extends FullFixedItemInv implements Iterable<ItemStack> {
|
||||
private boolean enableClientEvents = false;
|
||||
private IAEAppEngInventory te;
|
||||
private final int[] maxStack;
|
||||
private ItemStack previousStack = ItemStack.EMPTY;
|
||||
private IAEItemFilter filter;
|
||||
private boolean dirtyFlag = false;
|
||||
|
||||
@@ -48,6 +50,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
this.setFilter(filter);
|
||||
this.maxStack = new int[size];
|
||||
Arrays.fill(this.maxStack, maxStack);
|
||||
|
||||
setOwnerListener(this::onContentsChanged);
|
||||
}
|
||||
|
||||
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size, final int maxStack) {
|
||||
@@ -63,57 +67,24 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.maxStack[slot];
|
||||
public int getMaxAmount(int slot, ItemStack stack) {
|
||||
return Math.min(maxStack[slot], super.getMaxAmount(slot, stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
super.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (this.filter != null && !this.filter.allowInsert(this, slot, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.filter != null && !this.filter.allowExtract(this, slot, amount)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
protected void onContentsChanged(FixedItemInvView inv, int slot, ItemStack previous, ItemStack current) {
|
||||
if (this.getBlockEntity() != null && this.eventsEnabled() && !this.dirtyFlag) {
|
||||
this.dirtyFlag = true;
|
||||
ItemStack newStack = this.getStackInSlot(slot).copy();
|
||||
ItemStack oldStack = this.previousStack;
|
||||
ItemStack newStack = current.copy();
|
||||
ItemStack oldStack = previous;
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (newStack.isEmpty() || oldStack.isEmpty() || ItemStack.areItemsEqual(newStack, oldStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.shrink(oldStack.getCount());
|
||||
newStack.decrement(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.shrink(newStack.getCount());
|
||||
oldStack.decrement(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
@@ -121,10 +92,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
|
||||
this.getBlockEntity().onChangeInventory(this, slot, op, oldStack, newStack);
|
||||
this.getBlockEntity().saveChanges();
|
||||
this.previousStack = ItemStack.EMPTY;
|
||||
this.dirtyFlag = false;
|
||||
}
|
||||
super.onContentsChanged(slot);
|
||||
}
|
||||
|
||||
protected boolean eventsEnabled() {
|
||||
@@ -136,7 +105,25 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
public ItemFilter getFilterForSlot(int slot) {
|
||||
if (this.maxStack[slot] == 0) {
|
||||
return ConstantItemFilter.NOTHING;
|
||||
}
|
||||
if (this.filter != null) {
|
||||
return stack -> {
|
||||
// FIXME: This is not correct...
|
||||
if (stack == ItemStack.EMPTY) {
|
||||
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
|
||||
} else {
|
||||
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
|
||||
}
|
||||
};
|
||||
}
|
||||
return ConstantItemFilter.ANYTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (this.maxStack[slot] == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -147,7 +134,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
public void writeToNBT(final CompoundTag data, final String name) {
|
||||
data.put(name, this.serializeNBT());
|
||||
data.put(name, this.toTag());
|
||||
}
|
||||
|
||||
public void readFromNBT(final CompoundTag data, final String name) {
|
||||
@@ -158,12 +145,12 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
public void readFromNBT(final CompoundTag data) {
|
||||
this.deserializeNBT(data);
|
||||
this.fromTag(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemStack> iterator() {
|
||||
return Collections.unmodifiableList(super.stacks).iterator();
|
||||
return stackIterable().iterator();
|
||||
}
|
||||
|
||||
private boolean isEnableClientEvents() {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = this.cell.getStackInSlot(0);
|
||||
final ItemStack is = this.cell.getInvStack(0);
|
||||
if (is.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -83,12 +83,12 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
}
|
||||
|
||||
public ICellWorkbenchItem getCell() {
|
||||
if (this.cell.getStackInSlot(0).isEmpty()) {
|
||||
if (this.cell.getInvStack(0).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.cell.getStackInSlot(0).getItem() instanceof ICellWorkbenchItem) {
|
||||
return ((ICellWorkbenchItem) this.cell.getStackInSlot(0).getItem());
|
||||
if (this.cell.getInvStack(0).getItem() instanceof ICellWorkbenchItem) {
|
||||
return ((ICellWorkbenchItem) this.cell.getInvStack(0).getItem());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -183,7 +183,7 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = this.cell.getStackInSlot(0);
|
||||
final ItemStack is = this.cell.getInvStack(0);
|
||||
if (is.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -202,8 +202,8 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
if (this.cell.getStackInSlot(0) != null) {
|
||||
drops.add(this.cell.getStackInSlot(0));
|
||||
if (this.cell.getInvStack(0) != null) {
|
||||
drops.add(this.cell.getInvStack(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
@Override
|
||||
protected void writeToStream(final PacketByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
final AEItemStack is = AEItemStack.fromItemStack(this.inv.getStackInSlot(0));
|
||||
final AEItemStack is = AEItemStack.fromItemStack(this.inv.getInvStack(0));
|
||||
if (is != null) {
|
||||
is.writeToPacket(data);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
public void applyTurn() {
|
||||
this.injectExternalPower(PowerUnits.AE, POWER_PER_CRANK_TURN, Actionable.MODULATE);
|
||||
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
if (this.getInternalCurrentPower() > POWER_THRESHOLD) {
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
if (myItem.isEmpty()) {
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
|
||||
@@ -181,7 +181,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
}
|
||||
|
||||
private boolean doWork() {
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
boolean changed = false;
|
||||
|
||||
if (!myItem.isEmpty()) {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
|
||||
}
|
||||
|
||||
public double getStorage() {
|
||||
final ItemStack is = this.storageSlot.getStackInSlot(0);
|
||||
final ItemStack is = this.storageSlot.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
if (is.getItem() instanceof IStorageComponent) {
|
||||
final IStorageComponent sc = (IStorageComponent) is.getItem();
|
||||
@@ -247,7 +247,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
public int getMaxAmount(int slot, ItemStack is) {
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSlots(); h++) {
|
||||
final ItemStack is = this.upgrades.getStackInSlot(h);
|
||||
final ItemStack is = this.upgrades.getInvStack(h);
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
@@ -249,9 +249,9 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
||||
@Nullable
|
||||
public InscriberRecipe getTask() {
|
||||
if (this.cachedTask == null && world != null) {
|
||||
ItemStack input = this.sideItemHandler.getStackInSlot(0);
|
||||
ItemStack plateA = this.topItemHandler.getStackInSlot(0);
|
||||
ItemStack plateB = this.bottomItemHandler.getStackInSlot(0);
|
||||
ItemStack input = this.sideItemHandler.getInvStack(0);
|
||||
ItemStack plateA = this.topItemHandler.getInvStack(0);
|
||||
ItemStack plateB = this.bottomItemHandler.getInvStack(0);
|
||||
if (input.isEmpty()) {
|
||||
return null; // No input to handle
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SecurityStationBlockEntity extends AENetworkBlockEntity implements
|
||||
@Override
|
||||
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
|
||||
if (!ItemHandlerUtil.isEmpty(this.getConfigSlot())) {
|
||||
drops.add(this.getConfigSlot().getStackInSlot(0));
|
||||
drops.add(this.getConfigSlot().getInvStack(0));
|
||||
}
|
||||
|
||||
for (final IAEItemStack ais : this.inventory.getStoredItems()) {
|
||||
|
||||
@@ -134,7 +134,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
}
|
||||
|
||||
private boolean canEatFuel() {
|
||||
final ItemStack is = this.inv.getStackInSlot(0);
|
||||
final ItemStack is = this.inv.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final int newBurnTime = ForgeHooks.getBurnTime(is);
|
||||
if (newBurnTime > 0 && is.getCount() > 0) {
|
||||
@@ -206,7 +206,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
}
|
||||
|
||||
private void eatFuel() {
|
||||
final ItemStack is = this.inv.getStackInSlot(0);
|
||||
final ItemStack is = this.inv.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final int newBurnTime = ForgeHooks.getBurnTime(is);
|
||||
if (newBurnTime > 0 && is.getCount() > 0) {
|
||||
@@ -214,7 +214,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
this.setMaxBurnTime(this.getBurnTime());
|
||||
|
||||
final Item fuelItem = is.getItem();
|
||||
is.shrink(1);
|
||||
is.decrement(1);
|
||||
|
||||
if (is.isEmpty()) {
|
||||
this.inv.setStackInSlot(0, fuelItem.getRecipeRemainder(is));
|
||||
|
||||
@@ -138,7 +138,7 @@ public class WirelessBlockEntity extends AENetworkInvBlockEntity implements IWir
|
||||
}
|
||||
|
||||
private int getBoosters() {
|
||||
final ItemStack boosters = this.inv.getStackInSlot(0);
|
||||
final ItemStack boosters = this.inv.getInvStack(0);
|
||||
return boosters == null ? 0 : boosters.getCount();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements
|
||||
super.writeToStream(data);
|
||||
int out = this.constructed;
|
||||
|
||||
if (!this.internalInventory.getStackInSlot(0).isEmpty() && this.constructed != -1) {
|
||||
if (!this.internalInventory.getInvStack(0).isEmpty() && this.constructed != -1) {
|
||||
out |= this.hasSingularity;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements
|
||||
}
|
||||
|
||||
public long getQEFrequency() {
|
||||
final ItemStack is = this.internalInventory.getStackInSlot(0);
|
||||
final ItemStack is = this.internalInventory.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final CompoundTag c = is.getTag();
|
||||
if (c != null) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements
|
||||
|
||||
private void triggerTransition() {
|
||||
if (Platform.isServer()) {
|
||||
final ItemStack cell = this.inv.getStackInSlot(0);
|
||||
final ItemStack cell = this.inv.getInvStack(0);
|
||||
if (this.isSpatialCell(cell)) {
|
||||
TickHandler.INSTANCE.addCallable(null, this);// this needs to be cross world synced.
|
||||
}
|
||||
@@ -115,8 +115,8 @@ public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements
|
||||
|
||||
@Override
|
||||
public Void call(final World world) throws Exception {
|
||||
final ItemStack cell = this.inv.getStackInSlot(0);
|
||||
if (this.isSpatialCell(cell) && this.inv.getStackInSlot(1).isEmpty()) {
|
||||
final ItemStack cell = this.inv.getInvStack(0);
|
||||
if (this.isSpatialCell(cell) && this.inv.getInvStack(1).isEmpty()) {
|
||||
final IGrid gi = this.getProxy().getGrid();
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
|
||||
}
|
||||
|
||||
public ItemStack getCell() {
|
||||
return this.cellInventory.getStackInSlot(0);
|
||||
return this.cellInventory.getInvStack(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,7 +471,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
|
||||
if (this.cellHandler != null && this.cellHandler.getChannel() == AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class)) {
|
||||
final IAEItemStack returns = Platform.poweredInsert(this, this.cellHandler,
|
||||
AEItemStack.fromItemStack(this.inputInventory.getStackInSlot(0)), this.mySrc);
|
||||
AEItemStack.fromItemStack(this.inputInventory.getInvStack(0)), this.mySrc);
|
||||
|
||||
if (returns == null) {
|
||||
this.inputInventory.setStackInSlot(0, ItemStack.EMPTY);
|
||||
|
||||
@@ -207,7 +207,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO
|
||||
return cellItems[slot];
|
||||
}
|
||||
|
||||
ItemStack stackInSlot = inv.getStackInSlot(slot);
|
||||
ItemStack stackInSlot = inv.getInvStack(slot);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
return stackInSlot.getItem();
|
||||
}
|
||||
@@ -336,7 +336,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO
|
||||
double power = 2.0;
|
||||
|
||||
for (int x = 0; x < this.inv.getSlots(); x++) {
|
||||
final ItemStack is = this.inv.getStackInSlot(x);
|
||||
final ItemStack is = this.inv.getInvStack(x);
|
||||
this.invBySlot[x] = null;
|
||||
this.handlersBySlot[x] = null;
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
|
||||
try {
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
for (int x = 0; x < NUMBER_OF_CELL_SLOTS; x++) {
|
||||
final ItemStack is = this.inputCells.getStackInSlot(x);
|
||||
final ItemStack is = this.inputCells.getInvStack(x);
|
||||
if (!is.isEmpty()) {
|
||||
boolean shouldMove = true;
|
||||
|
||||
@@ -394,7 +394,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
|
||||
|
||||
private boolean moveSlot(final int x) {
|
||||
final InventoryAdaptor ad = new AdaptorFixedInv(this.outputCells);
|
||||
if (ad.addItems(this.inputCells.getStackInSlot(x)).isEmpty()) {
|
||||
if (ad.addItems(this.inputCells.getInvStack(x)).isEmpty()) {
|
||||
this.inputCells.setStackInSlot(x, ItemStack.EMPTY);
|
||||
return true;
|
||||
}
|
||||
@@ -438,7 +438,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
for (int upgradeIndex = 0; upgradeIndex < this.upgrades.getSlots(); upgradeIndex++) {
|
||||
final ItemStack stackInSlot = this.upgrades.getStackInSlot(upgradeIndex);
|
||||
final ItemStack stackInSlot = this.upgrades.getInvStack(upgradeIndex);
|
||||
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
drops.add(stackInSlot);
|
||||
|
||||
Reference in New Issue
Block a user