isolate the oversized slots and itemhandlers
This commit is contained in:
@@ -404,7 +404,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
if (tis.getCount() <= 0) {
|
||||
clickSlot.putStack(ItemStack.EMPTY);
|
||||
d.onSlotChanged();
|
||||
|
||||
|
||||
this.updateSlot(clickSlot);
|
||||
this.updateSlot(d);
|
||||
return ItemStack.EMPTY;
|
||||
@@ -423,42 +423,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
}
|
||||
|
||||
if (d.isItemValid(tis)) {
|
||||
if (d.getHasStack()) {
|
||||
final ItemStack t = d.getStack().copy();
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(t, tis)) {
|
||||
int maxSize = t.getMaxStackSize();
|
||||
if (d.getSlotStackLimit() < maxSize) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
}
|
||||
|
||||
int placeAble = maxSize - t.getCount();
|
||||
|
||||
if (tis.getCount() < placeAble) {
|
||||
placeAble = tis.getCount();
|
||||
}
|
||||
|
||||
t.setCount(t.getCount() + placeAble);
|
||||
tis.setCount(tis.getCount() - placeAble);
|
||||
|
||||
d.putStack(t);
|
||||
|
||||
if (tis.getCount() <= 0) {
|
||||
clickSlot.putStack(ItemStack.EMPTY);
|
||||
d.onSlotChanged();
|
||||
|
||||
// if ( worldEntity != null )
|
||||
// worldEntity.markDirty();
|
||||
// if ( hasMETiles ) updateClient();
|
||||
|
||||
this.updateSlot(clickSlot);
|
||||
this.updateSlot(d);
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
this.updateSlot(d);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!d.getHasStack()) {
|
||||
int maxSize = tis.getMaxStackSize();
|
||||
if (maxSize > d.getSlotStackLimit()) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
@@ -476,10 +441,6 @@ public abstract class AEBaseContainer extends Container {
|
||||
clickSlot.putStack(ItemStack.EMPTY);
|
||||
d.onSlotChanged();
|
||||
|
||||
// if ( worldEntity != null )
|
||||
// worldEntity.markDirty();
|
||||
// if ( hasMETiles ) updateClient();
|
||||
|
||||
this.updateSlot(clickSlot);
|
||||
this.updateSlot(d);
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
@@ -28,8 +28,13 @@ import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.slot.*;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.AppEngInternalOversizedInventory;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class ContainerInterface extends ContainerUpgradeable implements IOptionalSlotHost {
|
||||
@@ -62,10 +67,23 @@ public class ContainerInterface extends ContainerUpgradeable implements IOptiona
|
||||
}
|
||||
|
||||
for (int x = 0; x < DualityInterface.NUMBER_OF_STORAGE_SLOTS; x++) {
|
||||
this.addSlotToContainer(new SlotNormal(this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18));
|
||||
this.addSlotToContainer(new SlotOversized(this.myDuality.getStorage(), x, 8 + 18 * x, 35 + 18));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
|
||||
if (slotId >= 0 && slotId < this.inventorySlots.size()) {
|
||||
if (this.inventorySlots.get(slotId) instanceof SlotOversized) {
|
||||
((AppEngInternalOversizedInventory) ((SlotOversized) this.inventorySlots.get(slotId)).getItemHandler()).limitExtraction(true);
|
||||
ItemStack ret = super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
((AppEngInternalOversizedInventory) ((SlotOversized) this.inventorySlots.get(slotId)).getItemHandler()).limitExtraction(false);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight() {
|
||||
return 256;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package appeng.container.slot;
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class SlotOversized extends SlotNormal {
|
||||
public SlotOversized(IItemHandler inv, int slot, int xPos, int yPos) {
|
||||
super(inv, slot, xPos, yPos);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.AppEngInternalOversizedInventory;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
@@ -115,7 +116,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
private final IActionSource interfaceRequestSource;
|
||||
private final ConfigManager cm = new ConfigManager(this);
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, NUMBER_OF_CONFIG_SLOTS, 512);
|
||||
private final AppEngInternalInventory storage = new AppEngInternalInventory(this, NUMBER_OF_STORAGE_SLOTS, 512);
|
||||
private final AppEngInternalInventory storage = new AppEngInternalOversizedInventory(this, NUMBER_OF_STORAGE_SLOTS, 512);
|
||||
private final AppEngInternalInventory patterns = new AppEngInternalInventory(this, NUMBER_OF_PATTERN_SLOTS);
|
||||
private final MEMonitorPassThrough<IAEItemStack> items = new MEMonitorPassThrough<>(new NullInventory<IAEItemStack>(), AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
private final MEMonitorPassThrough<IAEFluidStack> fluids = new MEMonitorPassThrough<>(new NullInventory<IAEFluidStack>(), AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
|
||||
@@ -37,12 +37,13 @@ import java.util.Iterator;
|
||||
|
||||
|
||||
public class AppEngInternalInventory extends ItemStackHandler 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;
|
||||
protected boolean enableClientEvents = false;
|
||||
protected IAEAppEngInventory te;
|
||||
protected final int[] maxStack;
|
||||
protected ItemStack previousStack = ItemStack.EMPTY;
|
||||
protected IAEItemFilter filter;
|
||||
protected boolean dirtyFlag = false;
|
||||
protected boolean limitExtraction;
|
||||
|
||||
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size, final int maxStack, IAEItemFilter filter) {
|
||||
super(size);
|
||||
@@ -87,38 +88,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
|
||||
if (stack.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
validateSlotIndex(slot);
|
||||
|
||||
ItemStack existing = this.stacks.get(slot);
|
||||
|
||||
int limit = maxStack[slot];
|
||||
|
||||
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.stacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
|
||||
} else {
|
||||
existing.grow(reachedLimit ? limit : stack.getCount());
|
||||
}
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
|
||||
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,30 +101,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
if (amount == 0)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
validateSlotIndex(slot);
|
||||
|
||||
ItemStack existing = this.stacks.get(slot);
|
||||
|
||||
if (existing.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
if (existing.getCount() <= amount) {
|
||||
if (!simulate) {
|
||||
this.stacks.set(slot, ItemStack.EMPTY);
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
return existing;
|
||||
} else {
|
||||
if (!simulate) {
|
||||
this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - amount));
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(existing, amount);
|
||||
}
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,4 +226,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
public void setTileEntity(final IAEAppEngInventory te) {
|
||||
this.te = te;
|
||||
}
|
||||
|
||||
public void limitExtraction(boolean limitExtraction) {
|
||||
this.limitExtraction = limitExtraction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package appeng.tile.inventory;
|
||||
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AppEngInternalOversizedInventory extends AppEngInternalInventory {
|
||||
public AppEngInternalOversizedInventory(IAEAppEngInventory inventory, int size, int maxStack, IAEItemFilter filter) {
|
||||
super(inventory, size, maxStack, filter);
|
||||
}
|
||||
|
||||
public AppEngInternalOversizedInventory(IAEAppEngInventory inventory, int size, int maxStack) {
|
||||
super(inventory, size, maxStack);
|
||||
}
|
||||
|
||||
public AppEngInternalOversizedInventory(IAEAppEngInventory inventory, int size) {
|
||||
super(inventory, size);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
if (stack.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
validateSlotIndex(slot);
|
||||
|
||||
ItemStack existing = this.stacks.get(slot);
|
||||
|
||||
int limit = maxStack[slot];
|
||||
|
||||
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.stacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
|
||||
} else {
|
||||
existing.grow(reachedLimit ? limit : stack.getCount());
|
||||
}
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
|
||||
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
if (limitExtraction)
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
if (amount == 0)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
validateSlotIndex(slot);
|
||||
|
||||
ItemStack existing = this.stacks.get(slot);
|
||||
|
||||
if (existing.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
if (existing.getCount() <= amount) {
|
||||
if (!simulate) {
|
||||
this.stacks.set(slot, ItemStack.EMPTY);
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
return existing;
|
||||
} else {
|
||||
if (!simulate) {
|
||||
this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - amount));
|
||||
onContentsChanged(slot);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(existing, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super ItemStack> consumer) {
|
||||
super.forEach(consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<ItemStack> spliterator() {
|
||||
return super.spliterator();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user