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