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

@@ -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);
}
}