Change to using Nonnulllist so that things work

This commit is contained in:
Ellpeck 2016-11-20 20:13:26 +01:00
parent 75a3a91e65
commit 954df33f61
34 changed files with 274 additions and 290 deletions

View file

@ -33,6 +33,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
@ -102,12 +103,12 @@ public class BlockGiantChest extends BlockContainerBase{
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){ if(tile instanceof TileEntityGiantChest){
NBTTagList list = stack.getTagCompound().getTagList("Items", 10); NBTTagList list = stack.getTagCompound().getTagList("Items", 10);
ItemStack[] slots = ((TileEntityGiantChest)tile).slots; NonNullList<ItemStack> slots = ((TileEntityGiantChest)tile).slots;
for(int i = 0; i < list.tagCount(); i++){ for(int i = 0; i < list.tagCount(); i++){
NBTTagCompound compound = list.getCompoundTagAt(i); NBTTagCompound compound = list.getCompoundTagAt(i);
if(compound != null && compound.hasKey("id")){ if(compound != null && compound.hasKey("id")){
slots[i] = new ItemStack(list.getCompoundTagAt(i)); slots.set(i, new ItemStack(list.getCompoundTagAt(i)));
} }
} }
} }
@ -123,16 +124,16 @@ public class BlockGiantChest extends BlockContainerBase{
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){ if(tile instanceof TileEntityGiantChest){
ItemStack[] slots = ((TileEntityGiantChest)tile).slots; List<ItemStack> slots = ((TileEntityGiantChest)tile).slots;
int place = ItemUtil.getPlaceAt(slots, new ItemStack(InitItems.itemCrateKeeper), false); int place = ItemUtil.getPlaceAt(slots, new ItemStack(InitItems.itemCrateKeeper), false);
if(place >= 0){ if(place >= 0){
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++){ for(int i = 0; i < slots.size(); i++){
//Destroy the keeper //Destroy the keeper
if(i != place){ if(i != place){
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
if(StackUtil.isValid(slots[i])){ if(StackUtil.isValid(slots.get(i))){
slots[i].writeToNBT(compound); slots.get(i).writeToNBT(compound);
} }
list.appendTag(compound); list.appendTag(compound);
} }

View file

@ -23,6 +23,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*; import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@ -142,7 +143,7 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){ public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = this.bagInventory.slots.length; int inventoryStart = this.bagInventory.slots.size();
int inventoryEnd = inventoryStart+26; int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1; int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8; int hotbarEnd = hotbarStart+8;
@ -233,11 +234,10 @@ public class ContainerBag extends Container implements IButtonReactor{
public static class InventoryBag implements IInventory{ public static class InventoryBag implements IInventory{
public ItemStack[] slots; public NonNullList<ItemStack> slots;
public InventoryBag(boolean isVoid){ public InventoryBag(boolean isVoid){
this.slots = new ItemStack[getSlotAmount(isVoid)]; this.slots = StackUtil.createSlots(getSlotAmount(isVoid));
Arrays.fill(this.slots, StackUtil.getNull());
} }
@Override @Override
@ -292,20 +292,18 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public void clear(){ public void clear(){
int length = this.slots.length; this.slots.clear();
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
this.slots[i] = stack; this.slots.set(i, stack);
this.markDirty(); this.markDirty();
} }
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.slots.length; return this.slots.size();
} }
@Override @Override
@ -316,25 +314,25 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){ if(i < this.getSizeInventory()){
return this.slots[i]; return this.slots.get(i);
} }
return StackUtil.getNull(); return StackUtil.getNull();
} }
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt; ItemStack stackAt;
if(StackUtil.getStackSize(this.slots[i]) <= j){ if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots[i]; stackAt = this.slots.get(i);
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
} }
else{ else{
stackAt = this.slots[i].splitStack(j); stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots[i]) <= 0){ if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
} }
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
@ -345,8 +343,8 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index]; ItemStack stack = this.slots.get(index);
this.slots[index] = StackUtil.getNull(); this.slots.set(index, StackUtil.getNull());
return stack; return stack;
} }

View file

@ -24,6 +24,7 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
@ -148,11 +149,7 @@ public class ContainerDrill extends Container{
public static class InventoryDrill implements IInventory{ public static class InventoryDrill implements IInventory{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT]; public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
public InventoryDrill(){
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override @Override
public String getName(){ public String getName(){
@ -206,20 +203,18 @@ public class ContainerDrill extends Container{
@Override @Override
public void clear(){ public void clear(){
int length = this.slots.length; this.slots.clear();
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
this.slots[i] = stack; this.slots.set(i, stack);
this.markDirty(); this.markDirty();
} }
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.slots.length; return this.slots.size();
} }
@Override @Override
@ -230,25 +225,25 @@ public class ContainerDrill extends Container{
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){ if(i < this.getSizeInventory()){
return this.slots[i]; return this.slots.get(i);
} }
return StackUtil.getNull(); return StackUtil.getNull();
} }
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt; ItemStack stackAt;
if(StackUtil.getStackSize(this.slots[i]) <= j){ if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots[i]; stackAt = this.slots.get(i);
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
} }
else{ else{
stackAt = this.slots[i].splitStack(j); stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots[i]) <= 0){ if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
} }
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
@ -259,8 +254,8 @@ public class ContainerDrill extends Container{
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index]; ItemStack stack = this.slots.get(index);
this.slots[index] = StackUtil.getNull(); this.slots.set(index, StackUtil.getNull());
return stack; return stack;
} }

View file

@ -22,6 +22,7 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
@ -141,11 +142,7 @@ public class ContainerFilter extends Container{
public static class InventoryFilter implements IInventory{ public static class InventoryFilter implements IInventory{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT]; public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
public InventoryFilter(){
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override @Override
public String getName(){ public String getName(){
@ -199,20 +196,18 @@ public class ContainerFilter extends Container{
@Override @Override
public void clear(){ public void clear(){
int length = this.slots.length; this.slots.clear();
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
this.slots[i] = stack; this.slots.set(i, stack);
this.markDirty(); this.markDirty();
} }
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.slots.length; return this.slots.size();
} }
@Override @Override
@ -223,25 +218,25 @@ public class ContainerFilter extends Container{
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){ if(i < this.getSizeInventory()){
return this.slots[i]; return this.slots.get(i);
} }
return StackUtil.getNull(); return StackUtil.getNull();
} }
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt; ItemStack stackAt;
if(StackUtil.getStackSize(this.slots[i]) <= j){ if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots[i]; stackAt = this.slots.get(i);
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
} }
else{ else{
stackAt = this.slots[i].splitStack(j); stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots[i]) <= 0){ if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
} }
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
@ -252,8 +247,8 @@ public class ContainerFilter extends Container{
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index]; ItemStack stack = this.slots.get(index);
this.slots[index] = StackUtil.getNull(); this.slots.set(index, StackUtil.getNull());
return stack; return stack;
} }

View file

@ -71,7 +71,7 @@ public class GuiRepairer extends GuiContainer{
this.mc.getTextureManager().bindTexture(RES_LOC); this.mc.getTextureManager().bindTexture(RES_LOC);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93);
if(TileEntityItemRepairer.canBeRepaired(this.tileRepairer.slots[TileEntityItemRepairer.SLOT_INPUT])){ if(TileEntityItemRepairer.canBeRepaired(this.tileRepairer.slots.get(TileEntityItemRepairer.SLOT_INPUT))){
int i = this.tileRepairer.getItemDamageToScale(22); int i = this.tileRepairer.getItemDamageToScale(22);
this.drawTexturedModalRect(this.guiLeft+73, this.guiTop+52, 176, 28, i, 16); this.drawTexturedModalRect(this.guiLeft+73, this.guiTop+52, 176, 28, i, 16);
} }

View file

@ -24,10 +24,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult; import net.minecraft.util.*;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -75,7 +72,7 @@ public class ItemBag extends ItemBase{
boolean changed = false; boolean changed = false;
boolean isVoid = ((ItemBag)invStack.getItem()).isVoid; boolean isVoid = ((ItemBag)invStack.getItem()).isVoid;
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(isVoid)]; NonNullList<ItemStack> inventory = StackUtil.createSlots(ContainerBag.getSlotAmount(isVoid));
ItemDrill.loadSlotsFromNBT(inventory, invStack); ItemDrill.loadSlotsFromNBT(inventory, invStack);
FilterSettings filter = new FilterSettings(0, 4, false, false, false, false, 0, 0); FilterSettings filter = new FilterSettings(0, 4, false, false, false, false, 0, 0);
@ -86,20 +83,20 @@ public class ItemBag extends ItemBase{
changed = true; changed = true;
} }
else{ else{
for(int j = 4; j < inventory.length; j++){ for(int j = 4; j < inventory.size(); j++){
ItemStack bagStack = inventory[j]; ItemStack bagStack = inventory.get(j);
if(StackUtil.isValid(bagStack)){ if(StackUtil.isValid(bagStack)){
if(ItemUtil.canBeStacked(bagStack, stack)){ if(ItemUtil.canBeStacked(bagStack, stack)){
int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack)); int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack));
if(maxTransfer > 0){ if(maxTransfer > 0){
inventory[j] = StackUtil.addStackSize(bagStack, maxTransfer); inventory.set(j, StackUtil.addStackSize(bagStack, maxTransfer));
stack = StackUtil.addStackSize(stack, -maxTransfer); stack = StackUtil.addStackSize(stack, -maxTransfer);
changed = true; changed = true;
} }
} }
} }
else{ else{
inventory[j] = stack.copy(); inventory.set(j, stack.copy());
stack = StackUtil.setStackSize(stack, 0); stack = StackUtil.setStackSize(stack, 0);
changed = true; changed = true;
} }
@ -147,16 +144,16 @@ public class ItemBag extends ItemBase{
if(handler != null){ if(handler != null){
boolean changed = false; boolean changed = false;
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(this.isVoid)]; NonNullList<ItemStack> inventory = StackUtil.createSlots(ContainerBag.getSlotAmount(this.isVoid));
ItemDrill.loadSlotsFromNBT(inventory, stack); ItemDrill.loadSlotsFromNBT(inventory, stack);
for(int j = 4; j < inventory.length; j++){ for(int j = 4; j < inventory.size(); j++){
ItemStack invStack = inventory[j]; ItemStack invStack = inventory.get(j);
if(StackUtil.isValid(invStack)){ if(StackUtil.isValid(invStack)){
for(int i = 0; i < handler.getSlots(); i++){ for(int i = 0; i < handler.getSlots(); i++){
ItemStack remain = handler.insertItem(i, invStack, false); ItemStack remain = handler.insertItem(i, invStack, false);
if(!ItemStack.areItemStacksEqual(remain, invStack)){ if(!ItemStack.areItemStacksEqual(remain, invStack)){
inventory[j] = StackUtil.validateCopy(remain); inventory.set(j, StackUtil.validateCopy(remain));
changed = true; changed = true;
if(!StackUtil.isValid(remain)){ if(!StackUtil.isValid(remain)){

View file

@ -80,7 +80,7 @@ public class ItemDrill extends ItemEnergy{
* *
* @param stack The Drill * @param stack The Drill
*/ */
public static void loadSlotsFromNBT(ItemStack[] slots, ItemStack stack){ public static void loadSlotsFromNBT(NonNullList<ItemStack> slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
if(compound != null){ if(compound != null){
TileEntityInventoryBase.loadSlots(slots, compound); TileEntityInventoryBase.loadSlots(slots, compound);
@ -93,7 +93,7 @@ public class ItemDrill extends ItemEnergy{
* @param slots The Slots * @param slots The Slots
* @param stack The Drill * @param stack The Drill
*/ */
public static void writeSlotsToNBT(ItemStack[] slots, ItemStack stack){ public static void writeSlotsToNBT(NonNullList<ItemStack> slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
if(compound == null){ if(compound == null){
compound = new NBTTagCompound(); compound = new NBTTagCompound();
@ -153,9 +153,9 @@ public class ItemDrill extends ItemEnergy{
return StackUtil.getNull(); return StackUtil.getNull();
} }
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT]; NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerDrill.SLOT_AMOUNT);
loadSlotsFromNBT(slots, stack); loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){ if(slots != null && slots.size() > 0){
for(ItemStack slotStack : slots){ for(ItemStack slotStack : slots){
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){ if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){ if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){
@ -192,9 +192,9 @@ public class ItemDrill extends ItemEnergy{
//Checks for Energy Containers in the Upgrade Slots and charges the Drill from them //Checks for Energy Containers in the Upgrade Slots and charges the Drill from them
@Override @Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT]; NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerDrill.SLOT_AMOUNT);
loadSlotsFromNBT(slots, stack); loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){ if(slots != null && slots.size() > 0){
for(ItemStack slotStack : slots){ for(ItemStack slotStack : slots){
if(StackUtil.isValid(slotStack)){ if(StackUtil.isValid(slotStack)){
Item item = slotStack.getItem(); Item item = slotStack.getItem();

View file

@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
@ -47,9 +48,9 @@ public class ItemFilter extends ItemBase{
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
ItemStack[] slots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(slots, stack); ItemDrill.loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){ if(slots != null && slots.size() > 0){
for(ItemStack slot : slots){ for(ItemStack slot : slots){
if(StackUtil.isValid(slot)){ if(StackUtil.isValid(slot)){
tooltip.add(slot.getItem().getItemStackDisplayName(slot)); tooltip.add(slot.getItem().getItemStackDisplayName(slot));

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -61,17 +62,17 @@ public class FilterSettings{
this.modButtonId = buttonIdStart+4; this.modButtonId = buttonIdStart+4;
} }
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){ public static boolean check(ItemStack stack, NonNullList<ItemStack> slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){ for(int i = startSlot; i < endSlot; i++){
if(StackUtil.isValid(slots[i])){ if(StackUtil.isValid(slots.get(i))){
if(areEqualEnough(slots[i], stack, meta, nbt, mod, oredict)){ if(areEqualEnough(slots.get(i), stack, meta, nbt, mod, oredict)){
return whitelist; return whitelist;
} }
else if(slots[i].getItem() instanceof ItemFilter){ else if(slots.get(i).getItem() instanceof ItemFilter){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]); ItemDrill.loadSlotsFromNBT(filterSlots, slots.get(i));
if(filterSlots != null && filterSlots.length > 0){ if(filterSlots != null && filterSlots.size() > 0){
for(ItemStack filterSlot : filterSlots){ for(ItemStack filterSlot : filterSlots){
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){ if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
return whitelist; return whitelist;
@ -204,7 +205,7 @@ public class FilterSettings{
} }
} }
public boolean check(ItemStack stack, ItemStack[] slots){ public boolean check(ItemStack stack, NonNullList<ItemStack> slots){
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict); return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict);
} }
} }

View file

@ -117,9 +117,9 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
@Override @Override
public Lens getLens(){ public Lens getLens(){
if(StackUtil.isValid(this.slots[0])){ if(StackUtil.isValid(this.slots.get(0))){
if(this.slots[0].getItem() instanceof ILensItem){ if(this.slots.get(0).getItem() instanceof ILensItem){
return ((ILensItem)this.slots[0].getItem()).getLens(); return ((ILensItem)this.slots.get(0).getItem()).getLens();
} }
} }
return this.counter >= 500 ? ActuallyAdditionsAPI.lensDisruption : ActuallyAdditionsAPI.lensDefaultConversion; return this.counter >= 500 ? ActuallyAdditionsAPI.lensDisruption : ActuallyAdditionsAPI.lensDefaultConversion;

View file

@ -65,8 +65,8 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
List<Item> types = null; List<Item> types = null;
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){ if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
for(int i = 0; i < this.slots.length; i++){ for(int i = 0; i < this.slots.size(); i++){
ItemStack stack = this.slots[i]; ItemStack stack = this.slots.get(i);
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
Item item = stack.getItem(); Item item = stack.getItem();
if(isValidItem(stack) && (types == null || !types.contains(item))){ if(isValidItem(stack) && (types == null || !types.contains(item))){
@ -75,7 +75,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
} }
types.add(item); types.add(item);
this.slots[i] = StackUtil.addStackSize(stack, -1); this.slots.set(i, StackUtil.addStackSize(stack, -1));
} }
} }
} }

View file

@ -100,9 +100,9 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
} }
else if(this.isPlacer){ else if(this.isPlacer){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots); int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.worldObj, this.pos, this.slots[theSlot])); this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.worldObj, this.pos, this.slots.get(theSlot)));
if(!StackUtil.isValid(this.slots[theSlot])){ if(!StackUtil.isValid(this.slots.get(theSlot))){
this.slots[theSlot] = StackUtil.getNull(); this.slots.set(theSlot, StackUtil.getNull());
} }
} }
} }

View file

@ -92,7 +92,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
if(this.currentProcessTime >= TIME){ if(this.currentProcessTime >= TIME){
this.currentProcessTime = 0; this.currentProcessTime = 0;
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true); this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.markDirty(); this.markDirty();
@ -117,7 +117,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
} }
public boolean isCanola(int slot){ public boolean isCanola(int slot){
return StackUtil.isValid(this.slots[slot]) && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal(); return StackUtil.isValid(this.slots.get(slot)) && this.slots.get(slot).getItem() == InitItems.itemMisc && this.slots.get(slot).getItemDamage() == TheMiscItems.CANOLA.ordinal();
} }
@Override @Override

View file

@ -74,12 +74,12 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
this.storage.receiveEnergy(PRODUCE, false); this.storage.receiveEnergy(PRODUCE, false);
} }
if(this.currentBurnTime <= 0 && StackUtil.isValid(this.slots[0]) && TileEntityFurnace.getItemBurnTime(this.slots[0]) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){ if(this.currentBurnTime <= 0 && StackUtil.isValid(this.slots.get(0)) && TileEntityFurnace.getItemBurnTime(this.slots.get(0)) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots[0]); int burnTime = TileEntityFurnace.getItemBurnTime(this.slots.get(0));
this.maxBurnTime = burnTime; this.maxBurnTime = burnTime;
this.currentBurnTime = burnTime; this.currentBurnTime = burnTime;
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
} }
if(flag != this.currentBurnTime > 0){ if(flag != this.currentBurnTime > 0){
@ -106,7 +106,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
@Override @Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return TileEntityFurnace.getItemBurnTime(this.slots[0]) <= 0; return TileEntityFurnace.getItemBurnTime(this.slots.get(0)) <= 0;
} }
@Override @Override

View file

@ -130,10 +130,10 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
} }
public void storeCoffee(){ public void storeCoffee(){
if(StackUtil.isValid(this.slots[SLOT_COFFEE_BEANS]) && this.slots[SLOT_COFFEE_BEANS].getItem() == InitItems.itemCoffeeBean){ if(StackUtil.isValid(this.slots.get(SLOT_COFFEE_BEANS)) && this.slots.get(SLOT_COFFEE_BEANS).getItem() == InitItems.itemCoffeeBean){
int toAdd = 2; int toAdd = 2;
if(toAdd <= COFFEE_CACHE_MAX_AMOUNT-this.coffeeCacheAmount){ if(toAdd <= COFFEE_CACHE_MAX_AMOUNT-this.coffeeCacheAmount){
this.slots[SLOT_COFFEE_BEANS] = StackUtil.addStackSize(this.slots[SLOT_COFFEE_BEANS], -1); this.slots.set(SLOT_COFFEE_BEANS, StackUtil.addStackSize(this.slots.get(SLOT_COFFEE_BEANS), -1));
this.coffeeCacheAmount += toAdd; this.coffeeCacheAmount += toAdd;
} }
} }
@ -141,7 +141,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
public void brew(){ public void brew(){
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(StackUtil.isValid(this.slots[SLOT_INPUT]) && this.slots[SLOT_INPUT].getItem() == InitItems.itemMisc && this.slots[SLOT_INPUT].getItemDamage() == TheMiscItems.CUP.ordinal() && !StackUtil.isValid(this.slots[SLOT_OUTPUT]) && this.coffeeCacheAmount >= CACHE_USE && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == FluidRegistry.WATER && this.tank.getFluidAmount() >= WATER_USE){ if(StackUtil.isValid(this.slots.get(SLOT_INPUT)) && this.slots.get(SLOT_INPUT).getItem() == InitItems.itemMisc && this.slots.get(SLOT_INPUT).getItemDamage() == TheMiscItems.CUP.ordinal() && !StackUtil.isValid(this.slots.get(SLOT_OUTPUT)) && this.coffeeCacheAmount >= CACHE_USE && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == FluidRegistry.WATER && this.tank.getFluidAmount() >= WATER_USE){
if(this.storage.getEnergyStored() >= ENERGY_USED){ if(this.storage.getEnergyStored() >= ENERGY_USED){
if(this.brewTime%30 == 0){ if(this.brewTime%30 == 0){
this.worldObj.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.coffeeMachine, SoundCategory.BLOCKS, 0.35F, 1.0F); this.worldObj.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), SoundHandler.coffeeMachine, SoundCategory.BLOCKS, 0.35F, 1.0F);
@ -152,18 +152,18 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
if(this.brewTime >= TIME_USED){ if(this.brewTime >= TIME_USED){
this.brewTime = 0; this.brewTime = 0;
ItemStack output = new ItemStack(InitItems.itemCoffee); ItemStack output = new ItemStack(InitItems.itemCoffee);
for(int i = 3; i < this.slots.length; i++){ for(int i = 3; i < this.slots.size(); i++){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.slots[i]); CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.slots.get(i));
if(ingredient != null){ if(ingredient != null){
if(ingredient.effect(output)){ if(ingredient.effect(output)){
this.slots[i] = StackUtil.addStackSize(this.slots[i], -1); this.slots.set(i, StackUtil.addStackSize(this.slots.get(i), -1));
} }
} }
} }
} }
this.slots[SLOT_OUTPUT] = output.copy(); this.slots.set(SLOT_OUTPUT, output.copy());
this.slots[SLOT_INPUT] = StackUtil.addStackSize(this.slots[SLOT_INPUT], -1); this.slots.set(SLOT_INPUT, StackUtil.addStackSize(this.slots.get(SLOT_INPUT), -1));
this.coffeeCacheAmount -= CACHE_USE; this.coffeeCacheAmount -= CACHE_USE;
this.tank.drainInternal(WATER_USE, true); this.tank.drainInternal(WATER_USE, true);
} }
@ -182,7 +182,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
@Override @Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return slot == SLOT_OUTPUT || (slot >= 3 && slot < this.slots.length && ItemCoffee.getIngredientFromStack(stack) == null); return slot == SLOT_OUTPUT || (slot >= 3 && slot < this.slots.size() && ItemCoffee.getIngredientFromStack(stack) == null);
} }
@Override @Override

View file

@ -63,12 +63,12 @@ public class TileEntityCompost extends TileEntityInventoryBase{
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
boolean theFlag = this.conversionTime > 0; boolean theFlag = this.conversionTime > 0;
if(StackUtil.isValid(this.slots[0])){ if(StackUtil.isValid(this.slots.get(0))){
CompostRecipe recipe = getRecipeForInput(this.slots[0]); CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
if(recipe != null && this.slots[0].isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots[0]) >= StackUtil.getStackSize(recipe.input)){ if(recipe != null && this.slots.get(0).isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots.get(0)) >= StackUtil.getStackSize(recipe.input)){
this.conversionTime++; this.conversionTime++;
if(this.conversionTime >= 3000){ if(this.conversionTime >= 3000){
this.slots[0] = recipe.output.copy(); this.slots.set(0, recipe.output.copy());
this.conversionTime = 0; this.conversionTime = 0;
this.markDirty(); this.markDirty();
} }
@ -97,8 +97,8 @@ public class TileEntityCompost extends TileEntityInventoryBase{
@Override @Override
public int getInventoryStackLimit(){ public int getInventoryStackLimit(){
if(StackUtil.isValid(this.slots[0])){ if(StackUtil.isValid(this.slots.get(0))){
CompostRecipe recipe = getRecipeForInput(this.slots[0]); CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
if(recipe != null && StackUtil.isValid(recipe.input)){ if(recipe != null && StackUtil.isValid(recipe.input)){
return StackUtil.getStackSize(recipe.input); return StackUtil.getStackSize(recipe.input);
} }

View file

@ -34,12 +34,12 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(StackUtil.isValid(this.slots[0]) && !this.isRedstonePowered){ if(StackUtil.isValid(this.slots.get(0)) && !this.isRedstonePowered){
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots[0].getItem()); IDisplayStandItem item = this.convertToDisplayStandItem(this.slots.get(0).getItem());
if(item != null){ if(item != null){
int energy = item.getUsePerTick(this.slots[0], this, this.ticksElapsed); int energy = item.getUsePerTick(this.slots.get(0), this, this.ticksElapsed);
if(this.storage.getEnergyStored() >= energy){ if(this.storage.getEnergyStored() >= energy){
if(item.update(this.slots[0], this, this.ticksElapsed)){ if(item.update(this.slots.get(0), this, this.ticksElapsed)){
this.storage.extractEnergy(energy, false); this.storage.extractEnergy(energy, false);
} }
} }

View file

@ -42,26 +42,26 @@ public class TileEntityDistributorItem extends TileEntityInventoryBase{
for(int i = 0; i < handlerUp.getSlots(); i++){ for(int i = 0; i < handlerUp.getSlots(); i++){
ItemStack pullable = handlerUp.extractItem(i, 1, true); ItemStack pullable = handlerUp.extractItem(i, 1, true);
if(StackUtil.isValid(pullable) && (!StackUtil.isValid(this.slots[0]) || ItemUtil.canBeStacked(this.slots[0], pullable))){ if(StackUtil.isValid(pullable) && (!StackUtil.isValid(this.slots.get(0)) || ItemUtil.canBeStacked(this.slots.get(0), pullable))){
ItemStack pulled = handlerUp.extractItem(i, 1, false); ItemStack pulled = handlerUp.extractItem(i, 1, false);
if(StackUtil.isValid(pulled)){ if(StackUtil.isValid(pulled)){
if(!StackUtil.isValid(this.slots[0])){ if(!StackUtil.isValid(this.slots.get(0))){
this.slots[0] = pulled.copy(); this.slots.set(0, pulled.copy());
} }
else{ else{
this.slots[0] = StackUtil.addStackSize(this.slots[0], StackUtil.getStackSize(pulled)); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), StackUtil.getStackSize(pulled)));
} }
shouldMarkDirty = true; shouldMarkDirty = true;
} }
} }
if(StackUtil.isValid(this.slots[0]) && StackUtil.getStackSize(this.slots[0]) >= this.slots[0].getMaxStackSize()){ if(StackUtil.isValid(this.slots.get(0)) && StackUtil.getStackSize(this.slots.get(0)) >= this.slots.get(0).getMaxStackSize()){
break; break;
} }
} }
} }
if(!this.handlersAround.isEmpty() && (!this.handlersAround.containsKey(EnumFacing.UP) || this.handlersAround.size() >= 2) && StackUtil.isValid(this.slots[0])){ if(!this.handlersAround.isEmpty() && (!this.handlersAround.containsKey(EnumFacing.UP) || this.handlersAround.size() >= 2) && StackUtil.isValid(this.slots.get(0))){
EnumFacing[] allFacings = EnumFacing.values(); EnumFacing[] allFacings = EnumFacing.values();
do{ do{
this.putSide++; this.putSide++;
@ -76,33 +76,33 @@ public class TileEntityDistributorItem extends TileEntityInventoryBase{
IItemHandler handler = this.handlersAround.get(putFacing); IItemHandler handler = this.handlersAround.get(putFacing);
if(handler != null){ if(handler != null){
int aroundAmount = this.handlersAround.containsKey(EnumFacing.UP) ? this.handlersAround.size()-1 : this.handlersAround.size(); int aroundAmount = this.handlersAround.containsKey(EnumFacing.UP) ? this.handlersAround.size()-1 : this.handlersAround.size();
int amount = StackUtil.getStackSize(this.slots[0])/aroundAmount; int amount = StackUtil.getStackSize(this.slots.get(0))/aroundAmount;
if(amount <= 0){ if(amount <= 0){
amount = StackUtil.getStackSize(this.slots[0]); amount = StackUtil.getStackSize(this.slots.get(0));
} }
if(amount > 0){ if(amount > 0){
ItemStack toInsert = this.slots[0].copy(); ItemStack toInsert = this.slots.get(0).copy();
toInsert = StackUtil.setStackSize(toInsert, amount); toInsert = StackUtil.setStackSize(toInsert, amount);
for(int i = 0; i < handler.getSlots(); i++){ for(int i = 0; i < handler.getSlots(); i++){
ItemStack notInserted = handler.insertItem(i, toInsert.copy(), false); ItemStack notInserted = handler.insertItem(i, toInsert.copy(), false);
if(!StackUtil.isValid(notInserted)){ if(!StackUtil.isValid(notInserted)){
this.slots[0] = StackUtil.addStackSize(this.slots[0], -amount); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -amount));
shouldMarkDirty = true; shouldMarkDirty = true;
break; break;
} }
else if(StackUtil.getStackSize(notInserted) != StackUtil.getStackSize(this.slots[0])){ else if(StackUtil.getStackSize(notInserted) != StackUtil.getStackSize(this.slots.get(0))){
this.slots[0] = StackUtil.addStackSize(this.slots[0], -StackUtil.getStackSize(notInserted)); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -StackUtil.getStackSize(notInserted)));
toInsert = notInserted; toInsert = notInserted;
shouldMarkDirty = true; shouldMarkDirty = true;
} }
} }
if(!StackUtil.isValid(this.slots[0])){ if(!StackUtil.isValid(this.slots.get(0))){
this.slots[0] = StackUtil.getNull(); this.slots.set(0, StackUtil.getNull());
shouldMarkDirty = true; shouldMarkDirty = true;
} }
} }

View file

@ -74,11 +74,11 @@ public class TileEntityDropper extends TileEntityInventoryBase{
} }
public ItemStack removeFromInventory(boolean actuallyDo){ public ItemStack removeFromInventory(boolean actuallyDo){
for(int i = 0; i < this.slots.length; i++){ for(int i = 0; i < this.slots.size(); i++){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
ItemStack slot = this.slots[i].copy(); ItemStack slot = this.slots.get(i).copy();
if(actuallyDo){ if(actuallyDo){
this.slots[i] = StackUtil.addStackSize(this.slots[i], -1); this.slots.set(i, StackUtil.addStackSize(this.slots.get(i), -1));
this.markDirty(); this.markDirty();
} }
return slot; return slot;

View file

@ -52,7 +52,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots[0]); List<EmpowererRecipe> recipes = getRecipesForInput(this.slots.get(0));
if(!recipes.isEmpty()){ if(!recipes.isEmpty()){
for(EmpowererRecipe recipe : recipes){ for(EmpowererRecipe recipe : recipes){
TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time); TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time);
@ -78,7 +78,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
if(done){ if(done){
((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 300, 0, 0, 0, 0.25D); ((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 300, 0, 0, 0, 0.25D);
this.slots[0] = recipe.output.copy(); this.slots.set(0, recipe.output.copy());
this.markDirty(); this.markDirty();
this.processTime = 0; this.processTime = 0;

View file

@ -48,25 +48,25 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(StackUtil.isValid(this.slots[0]) && !StackUtil.isValid(this.slots[1])){ if(StackUtil.isValid(this.slots.get(0)) && !StackUtil.isValid(this.slots.get(1))){
if(this.storage.getEnergyStored() > 0){ if(this.storage.getEnergyStored() > 0){
int received = 0; int received = 0;
boolean canTakeUp = false; boolean canTakeUp = false;
if(this.slots[0].getItem() instanceof IEnergyContainerItem){ if(this.slots.get(0).getItem() instanceof IEnergyContainerItem){
IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem(); IEnergyContainerItem item = (IEnergyContainerItem)this.slots.get(0).getItem();
received = (item.receiveEnergy(this.slots[0], this.storage.getEnergyStored(), false)); received = (item.receiveEnergy(this.slots.get(0), this.storage.getEnergyStored(), false));
canTakeUp = item.getEnergyStored(this.slots[0]) >= item.getMaxEnergyStored(this.slots[0]); canTakeUp = item.getEnergyStored(this.slots.get(0)) >= item.getMaxEnergyStored(this.slots.get(0));
} }
else if(ActuallyAdditions.teslaLoaded){ else if(ActuallyAdditions.teslaLoaded){
if(this.slots[0].hasCapability(TeslaUtil.teslaConsumer, null)){ if(this.slots.get(0).hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = this.slots[0].getCapability(TeslaUtil.teslaConsumer, null); ITeslaConsumer cap = this.slots.get(0).getCapability(TeslaUtil.teslaConsumer, null);
if(cap != null){ if(cap != null){
received = (int)cap.givePower(this.storage.getEnergyStored(), false); received = (int)cap.givePower(this.storage.getEnergyStored(), false);
} }
} }
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){ if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null); ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){ if(cap != null){
canTakeUp = cap.getStoredPower() >= cap.getCapacity(); canTakeUp = cap.getStoredPower() >= cap.getCapacity();
} }
@ -77,8 +77,8 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
} }
if(canTakeUp){ if(canTakeUp){
this.slots[1] = this.slots[0].copy(); this.slots.set(1, this.slots.get(0).copy());
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
} }
} }
} }

View file

@ -48,26 +48,26 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(StackUtil.isValid(this.slots[0]) && !StackUtil.isValid(this.slots[1])){ if(StackUtil.isValid(this.slots.get(0)) && !StackUtil.isValid(this.slots.get(1))){
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){ if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int extracted = 0; int extracted = 0;
boolean canTakeUp = false; boolean canTakeUp = false;
int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored(); int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored();
if(this.slots[0].getItem() instanceof IEnergyContainerItem){ if(this.slots.get(0).getItem() instanceof IEnergyContainerItem){
IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem(); IEnergyContainerItem item = (IEnergyContainerItem)this.slots.get(0).getItem();
extracted = item.extractEnergy(this.slots[0], maxExtract, false); extracted = item.extractEnergy(this.slots.get(0), maxExtract, false);
canTakeUp = item.getEnergyStored(this.slots[0]) <= 0; canTakeUp = item.getEnergyStored(this.slots.get(0)) <= 0;
} }
else if(ActuallyAdditions.teslaLoaded){ else if(ActuallyAdditions.teslaLoaded){
if(this.slots[0].hasCapability(TeslaUtil.teslaProducer, null)){ if(this.slots.get(0).hasCapability(TeslaUtil.teslaProducer, null)){
ITeslaProducer cap = this.slots[0].getCapability(TeslaUtil.teslaProducer, null); ITeslaProducer cap = this.slots.get(0).getCapability(TeslaUtil.teslaProducer, null);
if(cap != null){ if(cap != null){
extracted = (int)cap.takePower(maxExtract, false); extracted = (int)cap.takePower(maxExtract, false);
} }
} }
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){ if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null); ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){ if(cap != null){
canTakeUp = cap.getStoredPower() <= 0; canTakeUp = cap.getStoredPower() <= 0;
} }
@ -78,8 +78,8 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
} }
if(canTakeUp){ if(canTakeUp){
this.slots[1] = this.slots[0].copy(); this.slots.set(1, this.slots.get(0).copy());
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
} }
} }
} }

View file

@ -150,7 +150,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
private IBlockState getFirstPlantablePlantFromSlots(BlockPos pos){ private IBlockState getFirstPlantablePlantFromSlots(BlockPos pos){
for(int i = 0; i < 6; i++){ for(int i = 0; i < 6; i++){
ItemStack stack = this.slots[i]; ItemStack stack = this.slots.get(i);
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
IPlantable plantable = null; IPlantable plantable = null;

View file

@ -74,13 +74,13 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
if(this.currentAnimalAmount < THRESHOLD){ if(this.currentAnimalAmount < THRESHOLD){
if(this.currentTimer >= TIME){ if(this.currentTimer >= TIME){
this.currentTimer = 0; this.currentTimer = 0;
if(StackUtil.isValid(this.slots[0])){ if(StackUtil.isValid(this.slots.get(0))){
EntityAnimal randomAnimal = animals.get(this.worldObj.rand.nextInt(this.currentAnimalAmount)); EntityAnimal randomAnimal = animals.get(this.worldObj.rand.nextInt(this.currentAnimalAmount));
if(!randomAnimal.isInLove() && randomAnimal.getGrowingAge() == 0 && (randomAnimal.isBreedingItem(this.slots[0]) || this.canHorseBeFed(randomAnimal))){ if(!randomAnimal.isInLove() && randomAnimal.getGrowingAge() == 0 && (randomAnimal.isBreedingItem(this.slots.get(0)) || this.canHorseBeFed(randomAnimal))){
this.feedAnimal(randomAnimal); this.feedAnimal(randomAnimal);
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
} }
} }
} }
@ -112,7 +112,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
if(animal instanceof EntityHorse){ if(animal instanceof EntityHorse){
EntityHorse horse = (EntityHorse)animal; EntityHorse horse = (EntityHorse)animal;
if(horse.isTame()){ if(horse.isTame()){
Item item = this.slots[0].getItem(); Item item = this.slots.get(0).getItem();
return item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT; return item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT;
} }
} }

View file

@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -45,9 +46,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
super(4, "furnaceDouble"); super(4, "furnaceDouble");
} }
public static void autoSplit(ItemStack[] slots, int slot1, int slot2){ public static void autoSplit(NonNullList<ItemStack> slots, int slot1, int slot2){
ItemStack first = slots[slot1]; ItemStack first = slots.get(slot1);
ItemStack second = slots[slot2]; ItemStack second = slots.get(slot2);
if(StackUtil.isValid(first) || StackUtil.isValid(second)){ if(StackUtil.isValid(first) || StackUtil.isValid(second)){
ItemStack toSplit = StackUtil.getNull(); ItemStack toSplit = StackUtil.getNull();
@ -69,8 +70,8 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
if(StackUtil.isValid(toSplit)){ if(StackUtil.isValid(toSplit)){
ItemStack splitFirst = toSplit.copy(); ItemStack splitFirst = toSplit.copy();
ItemStack secondSplit = splitFirst.splitStack(StackUtil.getStackSize(splitFirst)/2); ItemStack secondSplit = splitFirst.splitStack(StackUtil.getStackSize(splitFirst)/2);
slots[slot1] = StackUtil.validateCheck(splitFirst); slots.set(slot1, StackUtil.validateCheck(splitFirst));
slots[slot2] = StackUtil.validateCheck(secondSplit); slots.set(slot2, StackUtil.validateCheck(secondSplit));
} }
} }
} }
@ -168,10 +169,10 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
} }
public boolean canSmeltOn(int theInput, int theOutput){ public boolean canSmeltOn(int theInput, int theOutput){
if(StackUtil.isValid(this.slots[theInput])){ if(StackUtil.isValid(this.slots.get(theInput))){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]); ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
if(StackUtil.isValid(output)){ if(StackUtil.isValid(output)){
if(!StackUtil.isValid(this.slots[theOutput]) || (this.slots[theOutput].isItemEqual(output) && StackUtil.getStackSize(this.slots[theOutput]) <= this.slots[theOutput].getMaxStackSize()-StackUtil.getStackSize(output))){ if(!StackUtil.isValid(this.slots.get(theOutput)) || (this.slots.get(theOutput).isItemEqual(output) && StackUtil.getStackSize(this.slots.get(theOutput)) <= this.slots.get(theOutput).getMaxStackSize()-StackUtil.getStackSize(output))){
return true; return true;
} }
} }
@ -181,15 +182,15 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
} }
public void finishBurning(int theInput, int theOutput){ public void finishBurning(int theInput, int theOutput){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]); ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
if(!StackUtil.isValid(this.slots[theOutput])){ if(!StackUtil.isValid(this.slots.get(theOutput))){
this.slots[theOutput] = output.copy(); this.slots.set(theOutput, output.copy());
} }
else if(this.slots[theOutput].getItem() == output.getItem()){ else if(this.slots.get(theOutput).getItem() == output.getItem()){
this.slots[theOutput] = StackUtil.addStackSize(this.slots[theOutput], StackUtil.getStackSize(output)); this.slots.set(theOutput, StackUtil.addStackSize(this.slots.get(theOutput), StackUtil.getStackSize(output)));
} }
this.slots[theInput] = StackUtil.addStackSize(this.slots[theInput], -1); this.slots.set(theInput, StackUtil.addStackSize(this.slots.get(theInput), -1));
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)

View file

@ -185,9 +185,9 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
} }
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){ public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){
if(StackUtil.isValid(this.slots[theInput])){ if(StackUtil.isValid(this.slots.get(theInput))){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.get(theInput));
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.get(theInput));
if(StackUtil.isValid(outputOne)){ if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){ if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0); outputOne.setItemDamage(0);
@ -195,7 +195,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){ if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){
outputTwo.setItemDamage(0); outputTwo.setItemDamage(0);
} }
if((!StackUtil.isValid(this.slots[theFirstOutput]) || (this.slots[theFirstOutput].isItemEqual(outputOne) && StackUtil.getStackSize(this.slots[theFirstOutput]) <= this.slots[theFirstOutput].getMaxStackSize()-StackUtil.getStackSize(outputOne))) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.slots[theSecondOutput]) || (this.slots[theSecondOutput].isItemEqual(outputTwo) && StackUtil.getStackSize(this.slots[theSecondOutput]) <= this.slots[theSecondOutput].getMaxStackSize()-StackUtil.getStackSize(outputTwo))))){ if((!StackUtil.isValid(this.slots.get(theFirstOutput)) || (this.slots.get(theFirstOutput).isItemEqual(outputOne) && StackUtil.getStackSize(this.slots.get(theFirstOutput)) <= this.slots.get(theFirstOutput).getMaxStackSize()-StackUtil.getStackSize(outputOne))) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.slots.get(theSecondOutput)) || (this.slots.get(theSecondOutput).isItemEqual(outputTwo) && StackUtil.getStackSize(this.slots.get(theSecondOutput)) <= this.slots.get(theSecondOutput).getMaxStackSize()-StackUtil.getStackSize(outputTwo))))){
return true; return true;
} }
} }
@ -208,36 +208,36 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
} }
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){ public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.get(theInput));
if(StackUtil.isValid(outputOne)){ if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){ if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0); outputOne.setItemDamage(0);
} }
if(!StackUtil.isValid(this.slots[theFirstOutput])){ if(!StackUtil.isValid(this.slots.get(theFirstOutput))){
this.slots[theFirstOutput] = outputOne.copy(); this.slots.set(theFirstOutput, outputOne.copy());
} }
else if(this.slots[theFirstOutput].getItem() == outputOne.getItem()){ else if(this.slots.get(theFirstOutput).getItem() == outputOne.getItem()){
this.slots[theFirstOutput] = StackUtil.addStackSize(this.slots[theFirstOutput], StackUtil.getStackSize(outputOne)); this.slots.set(theFirstOutput, StackUtil.addStackSize(this.slots.get(theFirstOutput), StackUtil.getStackSize(outputOne)));
} }
} }
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.get(theInput));
if(StackUtil.isValid(outputTwo)){ if(StackUtil.isValid(outputTwo)){
if(outputTwo.getItemDamage() == Util.WILDCARD){ if(outputTwo.getItemDamage() == Util.WILDCARD){
outputTwo.setItemDamage(0); outputTwo.setItemDamage(0);
} }
int rand = this.worldObj.rand.nextInt(100)+1; int rand = this.worldObj.rand.nextInt(100)+1;
if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots[theInput])){ if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots.get(theInput))){
if(!StackUtil.isValid(this.slots[theSecondOutput])){ if(!StackUtil.isValid(this.slots.get(theSecondOutput))){
this.slots[theSecondOutput] = outputTwo.copy(); this.slots.set(theSecondOutput, outputTwo.copy());
} }
else if(this.slots[theSecondOutput].getItem() == outputTwo.getItem()){ else if(this.slots.get(theSecondOutput).getItem() == outputTwo.getItem()){
this.slots[theSecondOutput] = StackUtil.addStackSize(this.slots[theSecondOutput], StackUtil.getStackSize(outputTwo)); this.slots.set(theSecondOutput, StackUtil.addStackSize(this.slots.get(theSecondOutput), StackUtil.getStackSize(outputTwo)));
} }
} }
} }
this.slots[theInput] = StackUtil.addStackSize(this.slots[theInput], -1); this.slots.set(theInput, StackUtil.addStackSize(this.slots.get(theInput), -1));
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)

View file

@ -99,7 +99,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
} }
private boolean newPutting(){ private boolean newPutting(){
if(this.checkBothFilters(this.slots[0], true)){ if(this.checkBothFilters(this.slots.get(0), true)){
for(EnumFacing side : EnumFacing.values()){ for(EnumFacing side : EnumFacing.values()){
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){ if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side); IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
@ -268,7 +268,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if(this.sideToPull != -1 && this.placeToPull != null){ if(this.sideToPull != -1 && this.placeToPull != null){
this.newPulling(); this.newPulling();
} }
if(StackUtil.isValid(this.slots[0]) && this.sideToPut != -1 && this.placeToPut != null){ if(StackUtil.isValid(this.slots.get(0)) && this.sideToPut != -1 && this.placeToPut != null){
this.newPutting(); this.newPutting();
} }
} }

View file

@ -17,30 +17,29 @@ 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.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper;
import java.util.List;
import java.util.Arrays;
public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{ public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{
private final SidedInvWrapper[] invWrappers = new SidedInvWrapper[6]; private final SidedInvWrapper[] invWrappers = new SidedInvWrapper[6];
public ItemStack slots[]; public NonNullList<ItemStack> slots;
public TileEntityInventoryBase(int slots, String name){ public TileEntityInventoryBase(int slots, String name){
super(name); super(name);
this.slots = new ItemStack[slots]; this.slots = StackUtil.createSlots(slots);
Arrays.fill(this.slots, StackUtil.getNull());
if(this.hasInvWrapperCapabilities()){ if(this.hasInvWrapperCapabilities()){
this.getInvWrappers(this.invWrappers); this.getInvWrappers(this.invWrappers);
} }
} }
public static void saveSlots(ItemStack[] slots, NBTTagCompound compound){ public static void saveSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){
if(slots != null && slots.length > 0){ if(slots != null && slots.size() > 0){
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for(ItemStack slot : slots){ for(ItemStack slot : slots){
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
@ -53,12 +52,12 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
} }
} }
public static void loadSlots(ItemStack[] slots, NBTTagCompound compound){ public static void loadSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){
if(slots != null && slots.length > 0){ if(slots != null && slots.size() > 0){
NBTTagList tagList = compound.getTagList("Items", 10); NBTTagList tagList = compound.getTagList("Items", 10);
for(int i = 0; i < slots.length; i++){ for(int i = 0; i < slots.size(); i++){
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
slots[i] = tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull(); slots.set(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull());
} }
} }
} }
@ -142,44 +141,42 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
@Override @Override
public void clear(){ public void clear(){
for(int i = 0; i < this.slots.length; i++){ this.slots.clear();
this.removeStackFromSlot(i);
}
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
this.slots[i] = stack; this.slots.set(i, stack);
this.markDirty(); this.markDirty();
} }
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.slots.length; return this.slots.size();
} }
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){ if(i < this.getSizeInventory()){
return this.slots[i]; return this.slots.get(i);
} }
return StackUtil.getNull(); return StackUtil.getNull();
} }
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots[i])){ if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt; ItemStack stackAt;
if(StackUtil.getStackSize(this.slots[i]) <= j){ if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots[i]; stackAt = this.slots.get(i);
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
} }
else{ else{
stackAt = this.slots[i].splitStack(j); stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots[i]) <= 0){ if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots[i] = StackUtil.getNull(); this.slots.set(i, StackUtil.getNull());
} }
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
@ -190,8 +187,8 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index]; ItemStack stack = this.slots.get(index);
this.slots[index] = StackUtil.getNull(); this.slots.set(index, StackUtil.getNull());
return stack; return stack;
} }

View file

@ -77,11 +77,11 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
ItemStack input = this.slots[SLOT_INPUT]; ItemStack input = this.slots.get(SLOT_INPUT);
if(!StackUtil.isValid(this.slots[SLOT_OUTPUT]) && canBeRepaired(input)){ if(!StackUtil.isValid(this.slots.get(SLOT_OUTPUT)) && canBeRepaired(input)){
if(input.getItemDamage() <= 0){ if(input.getItemDamage() <= 0){
this.slots[SLOT_OUTPUT] = input.copy(); this.slots.set(SLOT_OUTPUT, input.copy());
this.slots[SLOT_INPUT] = StackUtil.getNull(); this.slots.set(SLOT_INPUT, StackUtil.getNull());
this.nextRepairTick = 0; this.nextRepairTick = 0;
} }
else{ else{
@ -125,8 +125,8 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getItemDamageToScale(int i){ public int getItemDamageToScale(int i){
if(StackUtil.isValid(this.slots[SLOT_INPUT])){ if(StackUtil.isValid(this.slots.get(SLOT_INPUT))){
return (this.slots[SLOT_INPUT].getMaxDamage()-this.slots[SLOT_INPUT].getItemDamage())*i/this.slots[SLOT_INPUT].getMaxDamage(); return (this.slots.get(SLOT_INPUT).getMaxDamage()-this.slots.get(SLOT_INPUT).getItemDamage())*i/this.slots.get(SLOT_INPUT).getMaxDamage();
} }
return 0; return 0;
} }

View file

@ -19,6 +19,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -30,12 +31,11 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
public final IInventory filterInventory; public final IInventory filterInventory;
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000); public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000); public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000);
private ItemStack[] slots = new ItemStack[24]; private NonNullList<ItemStack> slots = StackUtil.createSlots(24);
public TileEntityLaserRelayItemWhitelist(){ public TileEntityLaserRelayItemWhitelist(){
super("laserRelayItemWhitelist"); super("laserRelayItemWhitelist");
Arrays.fill(this.slots, StackUtil.getNull());
this.filterInventory = new IInventory(){ this.filterInventory = new IInventory(){
private TileEntityLaserRelayItemWhitelist tile; private TileEntityLaserRelayItemWhitelist tile;
@ -93,20 +93,18 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public void clear(){ public void clear(){
int length = this.tile.slots.length; this.tile.slots.clear();
this.tile.slots = new ItemStack[length];
Arrays.fill(this.tile.slots, StackUtil.getNull());
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
this.tile.slots[i] = stack; this.tile.slots.set(i, stack);
this.markDirty(); this.markDirty();
} }
@Override @Override
public int getSizeInventory(){ public int getSizeInventory(){
return this.tile.slots.length; return this.tile.slots.size();
} }
@Override @Override
@ -117,25 +115,25 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){ if(i < this.getSizeInventory()){
return this.tile.slots[i]; return this.tile.slots.get(i);
} }
return StackUtil.getNull(); return StackUtil.getNull();
} }
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.tile.slots[i])){ if(StackUtil.isValid(this.tile.slots.get(i))){
ItemStack stackAt; ItemStack stackAt;
if(StackUtil.getStackSize(this.tile.slots[i]) <= j){ if(StackUtil.getStackSize(this.tile.slots.get(i)) <= j){
stackAt = this.tile.slots[i]; stackAt = this.tile.slots.get(i);
this.tile.slots[i] = StackUtil.getNull(); this.tile.slots.set(i, StackUtil.getNull());
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
} }
else{ else{
stackAt = this.tile.slots[i].splitStack(j); stackAt = this.tile.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.tile.slots[i]) <= 0){ if(StackUtil.getStackSize(this.tile.slots.get(i)) <= 0){
this.tile.slots[i] = StackUtil.getNull(); this.tile.slots.set(i, StackUtil.getNull());
} }
this.markDirty(); this.markDirty();
return stackAt; return stackAt;
@ -146,8 +144,8 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.tile.slots[index]; ItemStack stack = this.tile.slots.get(index);
this.tile.slots[index] = StackUtil.getNull(); this.tile.slots.set(index, StackUtil.getNull());
return stack; return stack;
} }
@ -226,16 +224,16 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){ if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){ for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
if(StackUtil.isValid(this.slots[k])){ if(StackUtil.isValid(this.slots.get(k))){
if(this.slots[k].getItem() instanceof ItemFilter){ if(this.slots.get(k).getItem() instanceof ItemFilter){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots[k]); ItemDrill.loadSlotsFromNBT(filterSlots, this.slots.get(k));
boolean did = false; boolean did = false;
if(filterSlots != null && filterSlots.length > 0){ if(filterSlots != null && filterSlots.size() > 0){
for(int j = 0; j < filterSlots.length; j++){ for(int j = 0; j < filterSlots.size(); j++){
if(!StackUtil.isValid(filterSlots[j])){ if(!StackUtil.isValid(filterSlots.get(j))){
filterSlots[j] = copy; filterSlots.set(j, copy);
did = true; did = true;
break; break;
} }
@ -243,13 +241,13 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
} }
if(did){ if(did){
ItemDrill.writeSlotsToNBT(filterSlots, this.slots[k]); ItemDrill.writeSlotsToNBT(filterSlots, this.slots.get(k));
break; break;
} }
} }
} }
else{ else{
this.slots[k] = copy; this.slots.set(k, copy);
break; break;
} }
} }

View file

@ -148,9 +148,9 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
} }
else{ else{
int theSlot = WorldUtil.findFirstFilledSlot(this.slots); int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot])); this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots.get(theSlot)));
if(!StackUtil.isValid(this.slots[theSlot])){ if(!StackUtil.isValid(this.slots.get(theSlot))){
this.slots[theSlot] = StackUtil.getNull(); this.slots.set(theSlot, StackUtil.getNull());
} }
} }
} }

View file

@ -123,16 +123,16 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(this.amount > 0){ if(this.amount > 0){
if(!StackUtil.isValid(this.slots[0])){ if(!StackUtil.isValid(this.slots.get(0))){
int toSet = this.amount > 64 ? 64 : this.amount; int toSet = this.amount > 64 ? 64 : this.amount;
this.slots[0] = new ItemStack(InitItems.itemSolidifiedExperience, toSet); this.slots.set(0, new ItemStack(InitItems.itemSolidifiedExperience, toSet));
this.amount -= toSet; this.amount -= toSet;
this.markDirty(); this.markDirty();
} }
else if(StackUtil.getStackSize(this.slots[0]) < 64){ else if(StackUtil.getStackSize(this.slots.get(0)) < 64){
int needed = 64-StackUtil.getStackSize(this.slots[0]); int needed = 64-StackUtil.getStackSize(this.slots.get(0));
int toAdd = this.amount > needed ? needed : this.amount; int toAdd = this.amount > needed ? needed : this.amount;
this.slots[0] = StackUtil.addStackSize(this.slots[0], toAdd); this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), toAdd));
this.amount -= toAdd; this.amount -= toAdd;
this.markDirty(); this.markDirty();
} }
@ -157,9 +157,9 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
} }
} }
if(StackUtil.isValid(this.slots[1]) && this.slots[1].getItem() instanceof ItemSolidifiedExperience){ if(StackUtil.isValid(this.slots.get(1)) && this.slots.get(1).getItem() instanceof ItemSolidifiedExperience){
this.amount += StackUtil.getStackSize(this.slots[1]); this.amount += StackUtil.getStackSize(this.slots.get(1));
this.slots[1] = StackUtil.getNull(); this.slots.set(1, StackUtil.getNull());
this.markDirty(); this.markDirty();
} }

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.util; package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
public final class StackUtil{ public final class StackUtil{
@ -66,7 +67,7 @@ public final class StackUtil{
return setStackSize(stack, getStackSize(stack)+size); return setStackSize(stack, getStackSize(stack)+size);
} }
public static boolean isIInvEmpty(ItemStack[] slots){ public static boolean isIInvEmpty(NonNullList<ItemStack> slots){
for(ItemStack stack : slots){ for(ItemStack stack : slots){
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
return false; return false;
@ -75,4 +76,8 @@ public final class StackUtil{
return true; return true;
} }
public static NonNullList<ItemStack> createSlots(int size){
return NonNullList.func_191197_a(size, getNull());
}
} }

View file

@ -15,7 +15,6 @@ import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -32,6 +31,7 @@ import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@ -43,12 +43,9 @@ import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -230,9 +227,7 @@ public final class WorldUtil{
backupSlots = new ItemStack[inventory.getSizeInventory()]; backupSlots = new ItemStack[inventory.getSizeInventory()];
for(int i = 0; i < backupSlots.length; i++){ for(int i = 0; i < backupSlots.length; i++){
ItemStack stack = inventory.getStackInSlot(i); ItemStack stack = inventory.getStackInSlot(i);
if(StackUtil.isValid(stack)){ backupSlots[i] = StackUtil.validateCopy(stack);
backupSlots[i] = stack.copy();
}
} }
} }
@ -266,9 +261,9 @@ public final class WorldUtil{
return working >= stacks.size(); return working >= stacks.size();
} }
public static int findFirstFilledSlot(ItemStack[] slots){ public static int findFirstFilledSlot(NonNullList<ItemStack> slots){
for(int i = 0; i < slots.length; i++){ for(int i = 0; i < slots.size(); i++){
if(StackUtil.isValid(slots[i])){ if(StackUtil.isValid(slots.get(i))){
return i; return i;
} }
} }