allow interface itemstack handler to accept over sized stacks
This commit is contained in:
@@ -191,6 +191,14 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
GlStateManager.disableDepth();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<String> getItemToolTip(@Nonnull ItemStack itemStack) {
|
||||
List<String> l = super.getItemToolTip(itemStack);
|
||||
l.add(1, TextFormatting.GRAY + String.valueOf(itemStack.getCount()));
|
||||
return l;
|
||||
}
|
||||
|
||||
public List<Rectangle> getJEIExclusionArea() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -723,8 +731,14 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
if (slot instanceof SlotFake) {
|
||||
final ItemStack stack = slot.getStack();
|
||||
if (stack != ItemStack.EMPTY) {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.PLACE_SINGLE : InventoryAction.PICKUP_SINGLE;
|
||||
final PacketInventoryAction p = new PacketInventoryAction(direction, slot.slotNumber, 0);
|
||||
final PacketInventoryAction p;
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.DOUBLE : InventoryAction.HALVE;
|
||||
p = new PacketInventoryAction(direction, slot.slotNumber, 0);
|
||||
} else {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.PLACE_SINGLE : InventoryAction.PICKUP_SINGLE;
|
||||
p = new PacketInventoryAction(direction, slot.slotNumber, 0);
|
||||
}
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -52,6 +52,7 @@ import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -213,8 +214,14 @@ public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEI
|
||||
if (slot instanceof SlotDisconnected) {
|
||||
final ItemStack stack = slot.getStack();
|
||||
if (stack != ItemStack.EMPTY) {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.PLACE_SINGLE : InventoryAction.PICKUP_SINGLE;
|
||||
final PacketInventoryAction p = new PacketInventoryAction(direction, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId());
|
||||
final PacketInventoryAction p;
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.DOUBLE : InventoryAction.HALVE;
|
||||
p = new PacketInventoryAction(direction, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId());
|
||||
} else {
|
||||
InventoryAction direction = wheel > 0 ? InventoryAction.PLACE_SINGLE : InventoryAction.PICKUP_SINGLE;
|
||||
p = new PacketInventoryAction(direction, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId());
|
||||
}
|
||||
NetworkHandler.instance().sendToServer(p);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -48,6 +48,7 @@ import appeng.helpers.InventoryAction;
|
||||
import appeng.me.helpers.PlayerSource;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.WrapperCursorItemHandler;
|
||||
import appeng.util.item.AEItemStack;
|
||||
@@ -387,10 +388,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(tis, t)) // t.isItemEqual(tis))
|
||||
{
|
||||
int maxSize = t.getMaxStackSize();
|
||||
if (maxSize > d.getSlotStackLimit()) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
}
|
||||
int maxSize = d.getSlotStackLimit();
|
||||
|
||||
int placeAble = maxSize - t.getCount();
|
||||
|
||||
@@ -406,9 +404,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
if (tis.getCount() <= 0) {
|
||||
clickSlot.putStack(ItemStack.EMPTY);
|
||||
d.onSlotChanged();
|
||||
|
||||
// if ( hasMETiles ) updateClient();
|
||||
|
||||
|
||||
this.updateSlot(clickSlot);
|
||||
this.updateSlot(d);
|
||||
return ItemStack.EMPTY;
|
||||
@@ -589,6 +585,20 @@ public abstract class AEBaseContainer extends Container {
|
||||
s.putStack(is);
|
||||
}
|
||||
break;
|
||||
case HALVE:
|
||||
if (s.getStack().getCount() > 1) {
|
||||
ItemStack halved = s.getStack().copy();
|
||||
halved.setCount(s.getStack().getCount() / 2);
|
||||
s.putStack(halved);
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
ItemStack doubled = s.getStack().copy();
|
||||
if (s.getStack().getCount() * 2 > 0) {
|
||||
doubled.setCount(Math.min(s.getSlotStackLimit(), s.getStack().getCount() * 2));
|
||||
s.putStack(doubled);
|
||||
}
|
||||
break;
|
||||
case CREATIVE_DUPLICATE:
|
||||
case MOVE_REGION:
|
||||
case SHIFT_CLICK:
|
||||
|
||||
+12
@@ -222,6 +222,18 @@ public final class ContainerInterfaceConfigurationTerminal extends AEBaseContain
|
||||
ItemHandlerUtil.setStackInSlot(theSlot, 0, player.inventory.getItemStack().copy());
|
||||
}
|
||||
|
||||
break;
|
||||
case HALVE:
|
||||
if (inSlot.getCount() > 1) {
|
||||
ItemStack halved = inSlot.copy();
|
||||
halved.setCount(inSlot.getCount() / 2);
|
||||
ItemHandlerUtil.setStackInSlot(theSlot, 0, halved);
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
ItemStack doubled = inSlot.copy();
|
||||
doubled.setCount(Math.min(512, inSlot.getCount() * 2));
|
||||
ItemHandlerUtil.setStackInSlot(theSlot, 0, doubled);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -62,6 +62,11 @@ public class OptionalSlotFake extends SlotFake implements IOptionalSlot {
|
||||
return this.host.isSlotEnabled(this.groupNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRenderDisabled() {
|
||||
return this.renderDisabled;
|
||||
|
||||
@@ -27,4 +27,9 @@ public class SlotFakeCraftingMatrix extends SlotFake {
|
||||
public SlotFakeCraftingMatrix(final IItemHandler inv, final int idx, final int x, final int y) {
|
||||
super(inv, idx, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +749,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
// make sure strange things didn't happen...
|
||||
// TODO: check if OK
|
||||
final ItemStack canExtract = adaptor.simulateRemove((int) diff, toStore.getDefinition(), null);
|
||||
if (canExtract.isEmpty() || canExtract.getCount() != diff) {
|
||||
if (canExtract.isEmpty()) {
|
||||
changed = true;
|
||||
throw new GridAccessException();
|
||||
}
|
||||
@@ -766,8 +766,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final ItemStack removed = adaptor.removeItems((int) diff, ItemStack.EMPTY, null);
|
||||
if (removed.isEmpty()) {
|
||||
throw new IllegalStateException("bad attempt at managing inventory. ( removeItems )");
|
||||
} else if (removed.getCount() != diff) {
|
||||
throw new IllegalStateException("bad attempt at managing inventory. ( removeItems )");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,7 @@ public enum InventoryAction {
|
||||
ROLL_DOWN,
|
||||
AUTO_CRAFT,
|
||||
PLACE_SINGLE,
|
||||
DOUBLE,
|
||||
HALVE,
|
||||
PLACE_JEI_GHOST_ITEM
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -86,7 +87,38 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
|
||||
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
|
||||
@@ -99,7 +131,30 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user