Initial 1.11-pre1 update

This commit is contained in:
cpw committed 2016-11-13 17:09:55 -05:00
1 parent c177219ff3
commit 4e6a774075
294 files changed
+3099 -2846

No files matched your search

@@ -72,7 +72,7 @@ public class CapabilityItemHandler
if (j >= 0 && j < instance.getSlots())
{
itemHandlerModifiable.setStackInSlot(j, ItemStack.loadItemStackFromNBT(itemTags));
itemHandlerModifiable.setStackInSlot(j, new ItemStack(itemTags));
}
}
}
@@ -21,6 +21,8 @@ package net.minecraftforge.items;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IItemHandler
{
/**
@@ -49,6 +51,7 @@ public interface IItemHandler
* @param slot Slot to query
* @return ItemStack in given slot. May be null.
**/
@Nonnull
ItemStack getStackInSlot(int slot);
/**
@@ -62,7 +65,8 @@ public interface IItemHandler
* @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return null).
* May be the same as the input ItemStack if unchanged, otherwise a new ItemStack.
**/
ItemStack insertItem(int slot, ItemStack stack, boolean simulate);
@Nonnull
ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate);
/**
* Extracts an ItemStack from the given slot. The returned value must be null
@@ -74,5 +78,6 @@ public interface IItemHandler
* @param simulate If true, the extraction is only simulated
* @return ItemStack extracted from the slot, must be null, if nothing can be extracted
**/
@Nonnull
ItemStack extractItem(int slot, int amount, boolean simulate);
}
@@ -21,6 +21,8 @@ package net.minecraftforge.items;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IItemHandlerModifiable extends IItemHandler
{
/**
@@ -34,5 +36,5 @@ public interface IItemHandlerModifiable extends IItemHandler
* @throws RuntimeException if the handler is called in a way that the handler
* was not expecting.
**/
void setStackInSlot(int slot, ItemStack stack);
void setStackInSlot(int slot, @Nonnull ItemStack stack);
}
@@ -28,19 +28,22 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import javax.annotation.Nonnull;
public class ItemHandlerHelper
{
public static ItemStack insertItem(IItemHandler dest, ItemStack stack, boolean simulate)
@Nonnull
public static ItemStack insertItem(IItemHandler dest, @Nonnull ItemStack stack, boolean simulate)
{
if (dest == null || stack == null)
return stack;
if (dest == null || stack.func_190926_b())
return ItemStack.field_190927_a;
for (int i = 0; i < dest.getSlots(); i++)
{
stack = dest.insertItem(i, stack, simulate);
if (stack == null || stack.stackSize <= 0)
if (stack.func_190926_b())
{
return null;
return ItemStack.field_190927_a;
}
}
@@ -80,13 +83,13 @@ public class ItemHandlerHelper
return (aTag != null || bTag == null) && (aTag == null || aTag.equals(bTag));
}
@Nonnull
public static ItemStack copyStackWithSize(ItemStack itemStack, int size)
{
if (size == 0)
return null;
ItemStack copy = ItemStack.copyItemStack(itemStack);
if (copy != null)
copy.stackSize = size;
return ItemStack.field_190927_a;
ItemStack copy = itemStack.copy();
copy.func_190920_e(size);
return copy;
}
@@ -174,7 +177,7 @@ public class ItemHandlerHelper
}
// play sound if something got picked up
if (remainder == null || remainder.stackSize != stack.stackSize)
if (remainder == null || remainder.func_190916_E() != stack.func_190916_E())
{
world.playSound(player, player.posX, player.posY, player.posZ,
SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
@@ -22,12 +22,15 @@ package net.minecraftforge.items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.INBTSerializable;
import javax.annotation.Nonnull;
public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable<NBTTagCompound>
{
protected ItemStack[] stacks;
protected NonNullList<ItemStack> stacks;
public ItemStackHandler()
{
@@ -36,102 +39,105 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
public ItemStackHandler(int size)
{
stacks = new ItemStack[size];
stacks = NonNullList.func_191196_a();
}
public ItemStackHandler(ItemStack[] stacks)
public ItemStackHandler(NonNullList<ItemStack> stacks)
{
this.stacks = stacks;
}
public void setSize(int size)
{
stacks = new ItemStack[size];
stacks = NonNullList.func_191197_a(size, ItemStack.field_190927_a);
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
validateSlotIndex(slot);
if (ItemStack.areItemStacksEqual(this.stacks[slot], stack))
if (ItemStack.areItemStacksEqual(this.stacks.get(slot), stack))
return;
this.stacks[slot] = stack;
this.stacks.set(slot, stack);
onContentsChanged(slot);
}
@Override
public int getSlots()
{
return stacks.length;
return stacks.size();
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
validateSlotIndex(slot);
return this.stacks[slot];
return this.stacks.get(slot);
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (stack == null || stack.stackSize == 0)
return null;
if (stack.func_190926_b())
return ItemStack.field_190927_a;
validateSlotIndex(slot);
ItemStack existing = this.stacks[slot];
ItemStack existing = this.stacks.get(slot);
int limit = getStackLimit(slot, stack);
if (existing != null)
if (!existing.func_190926_b())
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= existing.stackSize;
limit -= existing.func_190916_E();
}
if (limit <= 0)
return stack;
boolean reachedLimit = stack.stackSize > limit;
boolean reachedLimit = stack.func_190916_E() > limit;
if (!simulate)
{
if (existing == null)
if (existing.func_190926_b())
{
this.stacks[slot] = reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack;
this.stacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
}
else
{
existing.stackSize += reachedLimit ? limit : stack.stackSize;
existing.func_190917_f(reachedLimit ? limit : stack.func_190916_E());
}
onContentsChanged(slot);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - limit) : null;
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.func_190916_E()- limit) : ItemStack.field_190927_a;
}
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
return null;
return ItemStack.field_190927_a;
validateSlotIndex(slot);
ItemStack existing = this.stacks[slot];
ItemStack existing = this.stacks.get(slot);
if (existing == null)
return null;
if (existing.func_190926_b())
return ItemStack.field_190927_a;
int toExtract = Math.min(amount, existing.getMaxStackSize());
if (existing.stackSize <= toExtract)
if (existing.func_190916_E() <= toExtract)
{
if (!simulate)
{
this.stacks[slot] = null;
this.stacks.set(slot, ItemStack.field_190927_a);
onContentsChanged(slot);
}
return existing;
@@ -140,7 +146,7 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
{
if (!simulate)
{
this.stacks[slot] = ItemHandlerHelper.copyStackWithSize(existing, existing.stackSize - toExtract);
this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.func_190916_E() - toExtract));
onContentsChanged(slot);
}
@@ -157,35 +163,35 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
public NBTTagCompound serializeNBT()
{
NBTTagList nbtTagList = new NBTTagList();
for (int i = 0; i < stacks.length; i++)
for (int i = 0; i < stacks.size(); i++)
{
if (stacks[i] != null)
if (!stacks.get(i).func_190926_b())
{
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setInteger("Slot", i);
stacks[i].writeToNBT(itemTag);
stacks.get(i).writeToNBT(itemTag);
nbtTagList.appendTag(itemTag);
}
}
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("Items", nbtTagList);
nbt.setInteger("Size", stacks.length);
nbt.setInteger("Size", stacks.size());
return nbt;
}
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
setSize(nbt.hasKey("Size", Constants.NBT.TAG_INT) ? nbt.getInteger("Size") : stacks.length);
setSize(nbt.hasKey("Size", Constants.NBT.TAG_INT) ? nbt.getInteger("Size") : stacks.size());
NBTTagList tagList = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
int slot = itemTags.getInteger("Slot");
if (slot >= 0 && slot < stacks.length)
if (slot >= 0 && slot < stacks.size())
{
stacks[slot] = ItemStack.loadItemStackFromNBT(itemTags);
stacks.set(slot, new ItemStack(itemTags));
}
}
onLoad();
@@ -193,8 +199,8 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
protected void validateSlotIndex(int slot)
{
if (slot < 0 || slot >= stacks.length)
throw new RuntimeException("Slot " + slot + " not in valid range - [0," + stacks.length + ")");
if (slot < 0 || slot >= stacks.size())
throw new RuntimeException("Slot " + slot + " not in valid range - [0," + stacks.size() + ")");
}
protected void onLoad()
@@ -25,6 +25,8 @@ import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class SlotItemHandler extends Slot
{
private static IInventory emptyInventory = new InventoryBasic("[Null]", true, 0);
@@ -39,9 +41,9 @@ public class SlotItemHandler extends Slot
}
@Override
public boolean isItemValid(ItemStack stack)
public boolean isItemValid(@Nonnull ItemStack stack)
{
if (stack == null)
if (stack.func_190926_b())
return false;
IItemHandler handler = this.getItemHandler();
@@ -51,7 +53,7 @@ public class SlotItemHandler extends Slot
IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable) handler;
ItemStack currentStack = handlerModifiable.getStackInSlot(index);
handlerModifiable.setStackInSlot(index, null);
handlerModifiable.setStackInSlot(index, ItemStack.field_190927_a);
remainder = handlerModifiable.insertItem(index, stack, true);
@@ -61,10 +63,11 @@ public class SlotItemHandler extends Slot
{
remainder = handler.insertItem(index, stack, true);
}
return remainder == null || remainder.stackSize < stack.stackSize;
return remainder == null || remainder.func_190916_E() < stack.func_190916_E();
}
@Override
@Nonnull
public ItemStack getStack()
{
return this.getItemHandler().getStackInSlot(index);
@@ -72,44 +75,44 @@ public class SlotItemHandler extends Slot
// Override if your IItemHandler does not implement IItemHandlerModifiable
@Override
public void putStack(ItemStack stack)
public void putStack(@Nonnull ItemStack stack)
{
((IItemHandlerModifiable) this.getItemHandler()).setStackInSlot(index, stack);
this.onSlotChanged();
}
@Override
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
public void onSlotChange(@Nonnull ItemStack p_75220_1_, @Nonnull ItemStack p_75220_2_)
{
}
@Override
public int getItemStackLimit(ItemStack stack)
public int getItemStackLimit(@Nonnull ItemStack stack)
{
ItemStack maxAdd = stack.copy();
int maxInput = stack.getMaxStackSize();
maxAdd.stackSize = maxInput;
maxAdd.func_190920_e(maxInput);
IItemHandler handler = this.getItemHandler();
ItemStack currentStack = handler.getStackInSlot(index);
if (handler instanceof IItemHandlerModifiable) {
IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable) handler;
handlerModifiable.setStackInSlot(index, null);
handlerModifiable.setStackInSlot(index, ItemStack.field_190927_a);
ItemStack remainder = handlerModifiable.insertItem(index, maxAdd, true);
handlerModifiable.setStackInSlot(index, currentStack);
return maxInput - (remainder != null ? remainder.stackSize : 0);
return maxInput - remainder.func_190916_E();
}
else
{
ItemStack remainder = handler.insertItem(index, maxAdd, true);
int current = currentStack == null ? 0 : currentStack.stackSize;
int added = maxInput - (remainder != null ? remainder.stackSize : 0);
int current = currentStack.func_190916_E();
int added = maxInput - remainder.func_190916_E();
return current + added;
}
}
@@ -117,10 +120,11 @@ public class SlotItemHandler extends Slot
@Override
public boolean canTakeStack(EntityPlayer playerIn)
{
return this.getItemHandler().extractItem(index, 1, true) != null;
return !this.getItemHandler().extractItem(index, 1, true).func_190926_b();
}
@Override
@Nonnull
public ItemStack decrStackSize(int amount)
{
return this.getItemHandler().extractItem(index, amount, false);
@@ -31,6 +31,8 @@ import java.lang.ref.WeakReference;
import com.google.common.base.Objects;
import javax.annotation.Nonnull;
public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest> implements IItemHandlerModifiable
{
// Dummy cache value to signify that we have checked and definitely found no adjacent chests
@@ -102,16 +104,17 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityChest chest = getChest(accessingUpperChest);
return chest != null ? chest.getStackInSlot(targetSlot) : null;
return chest != null ? chest.getStackInSlot(targetSlot) : ItemStack.field_190927_a;
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
@@ -127,7 +130,8 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
@@ -136,12 +140,13 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityChest chest = getChest(accessingUpperChest);
return chest != null ? chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate) : null;
return chest != null ? chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate) : ItemStack.field_190927_a;
}
@Override
@@ -23,6 +23,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraftforge.items.wrapper.InvWrapper;
import javax.annotation.Nonnull;
public class VanillaHopperItemHandler extends InvWrapper
{
private final TileEntityHopper hopper;
@@ -34,19 +36,20 @@ public class VanillaHopperItemHandler extends InvWrapper
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (stack == null)
return null;
if (simulate || !hopper.mayTransfer())
return super.insertItem(slot, stack, simulate);
// if (simulate || !hopper.mayTransfer())
// return super.insertItem(slot, stack, simulate);
int curStackSize = stack.stackSize;
int curStackSize = stack.func_190916_E();
ItemStack itemStack = super.insertItem(slot, stack, false);
if (itemStack == null || curStackSize != itemStack.stackSize)
{
hopper.setTransferCooldown(8);
}
// if (itemStack == null || curStackSize != itemStack.func_190916_E())
// {
// hopper.setTransferCooldown(8);
// }
return itemStack;
}
}
@@ -30,6 +30,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class VanillaInventoryCodeHooks
{
//Return: Null if we did nothing {no IItemHandler}, True if we moved an item, False if we moved no items
@@ -50,14 +52,14 @@ public class VanillaInventoryCodeHooks
for (int j = 0; j < dest.getSizeInventory(); j++)
{
ItemStack destStack = dest.getStackInSlot(j);
if (destStack == null || destStack.stackSize < destStack.getMaxStackSize() && destStack.stackSize < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack))
if (destStack == null || destStack.func_190916_E() < destStack.getMaxStackSize() && destStack.func_190916_E() < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack))
{
extractItem = handler.extractItem(i, 1, false);
if (destStack == null)
dest.setInventorySlotContents(j, extractItem);
else
{
destStack.stackSize++;
destStack.func_190917_f(1);
dest.setInventorySlotContents(j, destStack);
}
dest.markDirty();
@@ -70,7 +72,7 @@ public class VanillaInventoryCodeHooks
return false;
}
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, ItemStack stack)
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, @Nonnull ItemStack stack)
{
EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
BlockPos offsetPos = pos.offset(enumfacing);
@@ -84,14 +86,10 @@ public class VanillaInventoryCodeHooks
ItemStack result = ItemHandlerHelper.insertItem(capability, ItemHandlerHelper.copyStackWithSize(stack, 1), false);
if (result == null)
if (result.func_190926_b())
{
result = stack.copy();
if (--result.stackSize == 0)
{
result = null;
}
result.func_190918_g(1);
}
else
{
@@ -125,9 +123,9 @@ public class VanillaInventoryCodeHooks
if (stackInSlot != null)
{
ItemStack insert = stackInSlot.copy();
insert.stackSize = 1;
insert.func_190920_e(1);
ItemStack newStack = ItemHandlerHelper.insertItem(handler, insert, true);
if (newStack == null || newStack.stackSize == 0)
if (newStack.func_190926_b())
{
ItemHandlerHelper.insertItem(handler, hopper.decrStackSize(i, 1), false);
hopper.markDirty();
@@ -22,6 +22,8 @@ package net.minecraftforge.items.wrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull;
// combines multiple IItemHandlerModifiable into one interface
public class CombinedInvWrapper implements IItemHandlerModifiable
{
@@ -78,7 +80,7 @@ public class CombinedInvWrapper implements IItemHandlerModifiable
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
@@ -93,6 +95,7 @@ public class CombinedInvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
int index = getIndexForSlot(slot);
@@ -102,7 +105,8 @@ public class CombinedInvWrapper implements IItemHandlerModifiable
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
@@ -111,6 +115,7 @@ public class CombinedInvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
int index = getIndexForSlot(slot);
@@ -23,6 +23,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull;
public class EmptyHandler implements IItemHandlerModifiable
{
public static final IItemHandler INSTANCE = new EmptyHandler();
@@ -34,25 +36,28 @@ public class EmptyHandler implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
return null;
return ItemStack.field_190927_a;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
return stack;
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
return null;
return ItemStack.field_190927_a;
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
// nothing to do here
}
@@ -24,6 +24,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
public class InvWrapper implements IItemHandlerModifiable
{
private final IInventory inv;
@@ -60,13 +62,15 @@ public class InvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
return getInv().getStackInSlot(slot);
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (stack == null)
return null;
@@ -77,19 +81,19 @@ public class InvWrapper implements IItemHandlerModifiable
ItemStack stackInSlot = getInv().getStackInSlot(slot);
int m;
if (stackInSlot != null)
if (!stackInSlot.func_190926_b())
{
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
return stack;
m = Math.min(stack.getMaxStackSize(), getInv().getInventoryStackLimit()) - stackInSlot.stackSize;
m = Math.min(stack.getMaxStackSize(), getInv().getInventoryStackLimit()) - stackInSlot.func_190916_E();
if (stack.stackSize <= m)
if (stack.func_190916_E() <= m)
{
if (!simulate)
{
ItemStack copy = stack.copy();
copy.stackSize += stackInSlot.stackSize;
copy.func_190918_g(stackInSlot.func_190916_E());
getInv().setInventorySlotContents(slot, copy);
getInv().markDirty();
}
@@ -103,14 +107,14 @@ public class InvWrapper implements IItemHandlerModifiable
if (!simulate)
{
ItemStack copy = stack.splitStack(m);
copy.stackSize += stackInSlot.stackSize;
copy.func_190917_f(stackInSlot.func_190916_E());
getInv().setInventorySlotContents(slot, copy);
getInv().markDirty();
return stack;
}
else
{
stack.stackSize -= m;
stack.func_190918_g(m);
return stack;
}
}
@@ -118,7 +122,7 @@ public class InvWrapper implements IItemHandlerModifiable
else
{
m = Math.min(stack.getMaxStackSize(), getInv().getInventoryStackLimit());
if (m < stack.stackSize)
if (m < stack.func_190916_E())
{
// copy the stack to not modify the original one
stack = stack.copy();
@@ -130,7 +134,7 @@ public class InvWrapper implements IItemHandlerModifiable
}
else
{
stack.stackSize -= m;
stack.func_190918_g(m);
return stack;
}
}
@@ -148,6 +152,7 @@ public class InvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
@@ -160,20 +165,20 @@ public class InvWrapper implements IItemHandlerModifiable
if (simulate)
{
if (stackInSlot.stackSize < amount)
if (stackInSlot.func_190916_E() < amount)
{
return stackInSlot.copy();
}
else
{
ItemStack copy = stackInSlot.copy();
copy.stackSize = amount;
copy.func_190920_e(amount);
return copy;
}
}
else
{
int m = Math.min(stackInSlot.stackSize, amount);
int m = Math.min(stackInSlot.func_190916_E(), amount);
ItemStack decrStackSize = getInv().decrStackSize(slot, m);
getInv().markDirty();
@@ -23,18 +23,21 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class PlayerArmorInvWrapper extends RangedWrapper
{
private final InventoryPlayer inventoryPlayer;
public PlayerArmorInvWrapper(InventoryPlayer inv)
{
super(new InvWrapper(inv), inv.mainInventory.length, inv.mainInventory.length + inv.armorInventory.length);
super(new InvWrapper(inv), inv.mainInventory.size(), inv.mainInventory.size() + inv.armorInventory.size());
inventoryPlayer = inv;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
EntityEquipmentSlot equ = null;
for (EntityEquipmentSlot s : EntityEquipmentSlot.values())
@@ -46,7 +49,7 @@ public class PlayerArmorInvWrapper extends RangedWrapper
}
}
// check if it's valid for the armor slot
if (slot < 4 && stack != null && stack.getItem().isValidArmor(stack, equ, getInventoryPlayer().player))
if (equ != null && slot < 4 && !stack.func_190926_b() && stack.getItem().isValidArmor(stack, equ, getInventoryPlayer().player))
{
return super.insertItem(slot, stack, simulate);
}
@@ -23,6 +23,8 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
/**
* Exposes the player inventory WITHOUT the armor inventory as IItemHandler.
* Also takes core of inserting/extracting having the same logic as picking up items.
@@ -33,23 +35,24 @@ public class PlayerMainInvWrapper extends RangedWrapper
public PlayerMainInvWrapper(InventoryPlayer inv)
{
super(new InvWrapper(inv), 0, inv.mainInventory.length);
super(new InvWrapper(inv), 0, inv.mainInventory.size());
inventoryPlayer = inv;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
ItemStack rest = super.insertItem(slot, stack, simulate);
if (rest == null || rest.stackSize != stack.stackSize)
if (rest.func_190916_E()!= stack.func_190916_E())
{
// the stack in the slot changed, animate it
ItemStack inSlot = getStackInSlot(slot);
if(inSlot != null)
if(!inSlot.func_190926_b())
{
if (getInventoryPlayer().player.worldObj.isRemote)
{
inSlot.animationsToGo = 5;
inSlot.func_190915_d(5);
}
else if(getInventoryPlayer().player instanceof EntityPlayerMP) {
getInventoryPlayer().player.openContainer.detectAndSendChanges();
@@ -25,7 +25,7 @@ public class PlayerOffhandInvWrapper extends RangedWrapper
{
public PlayerOffhandInvWrapper(InventoryPlayer inv)
{
super(new InvWrapper(inv), inv.mainInventory.length + inv.armorInventory.length,
inv.mainInventory.length + inv.armorInventory.length + inv.offHandInventory.length);
super(new InvWrapper(inv), inv.mainInventory.size() + inv.armorInventory.size(),
inv.mainInventory.size() + inv.armorInventory.size() + inv.offHandInventory.size());
}
}
@@ -23,6 +23,8 @@ import com.google.common.base.Preconditions;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull;
/**
* A wrapper that composes another IItemHandlerModifiable, exposing only a range of the composed slots.
* Shifting of slot indices is handled automatically for you.
@@ -48,6 +50,7 @@ public class RangedWrapper implements IItemHandlerModifiable {
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
if (checkSlot(slot))
@@ -59,7 +62,8 @@ public class RangedWrapper implements IItemHandlerModifiable {
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (checkSlot(slot))
{
@@ -70,6 +74,7 @@ public class RangedWrapper implements IItemHandlerModifiable {
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (checkSlot(slot))
@@ -77,7 +82,7 @@ public class RangedWrapper implements IItemHandlerModifiable {
return compose.extractItem(slot + minSlot, amount, simulate);
}
return null;
return ItemStack.field_190927_a;
}
@Override
@@ -25,6 +25,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
public class SidedInvWrapper implements IItemHandlerModifiable
{
protected final ISidedInventory inv;
@@ -72,18 +74,19 @@ public class SidedInvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
{
int i = getSlot(inv, slot, side);
return i == -1 ? null : inv.getStackInSlot(i);
return i == -1 ? ItemStack.field_190927_a : inv.getStackInSlot(i);
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (stack == null)
return null;
if (stack.func_190926_b())
return ItemStack.field_190927_a;
int slot1 = getSlot(inv, slot, side);
@@ -96,23 +99,23 @@ public class SidedInvWrapper implements IItemHandlerModifiable
ItemStack stackInSlot = inv.getStackInSlot(slot1);
int m;
if (stackInSlot != null)
if (!stackInSlot.func_190926_b())
{
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
return stack;
m = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - stackInSlot.stackSize;
m = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - stackInSlot.func_190916_E();
if (stack.stackSize <= m)
if (stack.func_190916_E() <= m)
{
if (!simulate)
{
ItemStack copy = stack.copy();
copy.stackSize += stackInSlot.stackSize;
copy.func_190917_f(stackInSlot.func_190916_E());
inv.setInventorySlotContents(slot1, copy);
}
return null;
return ItemStack.field_190927_a;
}
else
{
@@ -121,13 +124,13 @@ public class SidedInvWrapper implements IItemHandlerModifiable
if (!simulate)
{
ItemStack copy = stack.splitStack(m);
copy.stackSize += stackInSlot.stackSize;
copy.func_190917_f(stackInSlot.func_190916_E());
inv.setInventorySlotContents(slot1, copy);
return stack;
}
else
{
stack.stackSize -= m;
stack.func_190918_g(m);
return stack;
}
}
@@ -135,7 +138,7 @@ public class SidedInvWrapper implements IItemHandlerModifiable
else
{
m = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
if (m < stack.stackSize)
if (m < stack.func_190916_E())
{
// copy the stack to not modify the original one
stack = stack.copy();
@@ -146,7 +149,7 @@ public class SidedInvWrapper implements IItemHandlerModifiable
}
else
{
stack.stackSize -= m;
stack.func_190918_g(m);
return stack;
}
}
@@ -154,14 +157,14 @@ public class SidedInvWrapper implements IItemHandlerModifiable
{
if (!simulate)
inv.setInventorySlotContents(slot1, stack);
return null;
return ItemStack.field_190927_a;
}
}
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
int slot1 = getSlot(inv, slot, side);
@@ -170,40 +173,41 @@ public class SidedInvWrapper implements IItemHandlerModifiable
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
return null;
return ItemStack.field_190927_a;
int slot1 = getSlot(inv, slot, side);
if (slot1 == -1)
return null;
return ItemStack.field_190927_a;
ItemStack stackInSlot = inv.getStackInSlot(slot1);
if (stackInSlot == null)
return null;
if (stackInSlot.func_190926_b())
return ItemStack.field_190927_a;
if (!inv.canExtractItem(slot1, stackInSlot, side))
return null;
return ItemStack.field_190927_a;
if (simulate)
{
if (stackInSlot.stackSize < amount)
if (stackInSlot.func_190916_E() < amount)
{
return stackInSlot.copy();
}
else
{
ItemStack copy = stackInSlot.copy();
copy.stackSize = amount;
copy.func_190920_e(amount);
return copy;
}
}
else
{
int m = Math.min(stackInSlot.stackSize, amount);
int m = Math.min(stackInSlot.func_190916_E(), amount);
return inv.decrStackSize(slot1, m);
}
}