mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Change to using Nonnulllist so that things work
This commit is contained in:
parent
75a3a91e65
commit
954df33f61
34 changed files with 274 additions and 290 deletions
|
@ -33,6 +33,7 @@ import net.minecraft.nbt.NBTTagList;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -102,12 +103,12 @@ public class BlockGiantChest extends BlockContainerBase{
|
|||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityGiantChest){
|
||||
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++){
|
||||
NBTTagCompound compound = list.getCompoundTagAt(i);
|
||||
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);
|
||||
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);
|
||||
if(place >= 0){
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(int i = 0; i < slots.length; i++){
|
||||
for(int i = 0; i < slots.size(); i++){
|
||||
//Destroy the keeper
|
||||
if(i != place){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(StackUtil.isValid(slots[i])){
|
||||
slots[i].writeToNBT(compound);
|
||||
if(StackUtil.isValid(slots.get(i))){
|
||||
slots.get(i).writeToNBT(compound);
|
||||
}
|
||||
list.appendTag(compound);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.entity.player.InventoryPlayer;
|
|||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -142,7 +143,7 @@ public class ContainerBag extends Container implements IButtonReactor{
|
|||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
|
||||
int inventoryStart = this.bagInventory.slots.length;
|
||||
int inventoryStart = this.bagInventory.slots.size();
|
||||
int inventoryEnd = inventoryStart+26;
|
||||
int hotbarStart = inventoryEnd+1;
|
||||
int hotbarEnd = hotbarStart+8;
|
||||
|
@ -233,11 +234,10 @@ public class ContainerBag extends Container implements IButtonReactor{
|
|||
|
||||
public static class InventoryBag implements IInventory{
|
||||
|
||||
public ItemStack[] slots;
|
||||
public NonNullList<ItemStack> slots;
|
||||
|
||||
public InventoryBag(boolean isVoid){
|
||||
this.slots = new ItemStack[getSlotAmount(isVoid)];
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.slots = StackUtil.createSlots(getSlotAmount(isVoid));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -292,20 +292,18 @@ public class ContainerBag extends Container implements IButtonReactor{
|
|||
|
||||
@Override
|
||||
public void clear(){
|
||||
int length = this.slots.length;
|
||||
this.slots = new ItemStack[length];
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.slots.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.slots[i] = stack;
|
||||
this.slots.set(i, stack);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.slots.length;
|
||||
return this.slots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -316,25 +314,25 @@ public class ContainerBag extends Container implements IButtonReactor{
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.slots[i];
|
||||
return this.slots.get(i);
|
||||
}
|
||||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
ItemStack stackAt;
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= j){
|
||||
stackAt = this.slots[i];
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
|
||||
stackAt = this.slots.get(i);
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.slots[i].splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= 0){
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
stackAt = this.slots.get(i).splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
|
@ -345,8 +343,8 @@ public class ContainerBag extends Container implements IButtonReactor{
|
|||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.slots[index];
|
||||
this.slots[index] = StackUtil.getNull();
|
||||
ItemStack stack = this.slots.get(index);
|
||||
this.slots.set(index, StackUtil.getNull());
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.inventory.Container;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
|
@ -148,11 +149,7 @@ public class ContainerDrill extends Container{
|
|||
|
||||
public static class InventoryDrill implements IInventory{
|
||||
|
||||
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
|
||||
|
||||
public InventoryDrill(){
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
}
|
||||
public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
|
@ -206,20 +203,18 @@ public class ContainerDrill extends Container{
|
|||
|
||||
@Override
|
||||
public void clear(){
|
||||
int length = this.slots.length;
|
||||
this.slots = new ItemStack[length];
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.slots.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.slots[i] = stack;
|
||||
this.slots.set(i, stack);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.slots.length;
|
||||
return this.slots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -230,25 +225,25 @@ public class ContainerDrill extends Container{
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.slots[i];
|
||||
return this.slots.get(i);
|
||||
}
|
||||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
ItemStack stackAt;
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= j){
|
||||
stackAt = this.slots[i];
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
|
||||
stackAt = this.slots.get(i);
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.slots[i].splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= 0){
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
stackAt = this.slots.get(i).splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
|
@ -259,8 +254,8 @@ public class ContainerDrill extends Container{
|
|||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.slots[index];
|
||||
this.slots[index] = StackUtil.getNull();
|
||||
ItemStack stack = this.slots.get(index);
|
||||
this.slots.set(index, StackUtil.getNull());
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.inventory.Container;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
|
@ -141,11 +142,7 @@ public class ContainerFilter extends Container{
|
|||
|
||||
public static class InventoryFilter implements IInventory{
|
||||
|
||||
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
|
||||
|
||||
public InventoryFilter(){
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
}
|
||||
public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
|
@ -199,20 +196,18 @@ public class ContainerFilter extends Container{
|
|||
|
||||
@Override
|
||||
public void clear(){
|
||||
int length = this.slots.length;
|
||||
this.slots = new ItemStack[length];
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.slots.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.slots[i] = stack;
|
||||
this.slots.set(i, stack);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.slots.length;
|
||||
return this.slots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -223,25 +218,25 @@ public class ContainerFilter extends Container{
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.slots[i];
|
||||
return this.slots.get(i);
|
||||
}
|
||||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
ItemStack stackAt;
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= j){
|
||||
stackAt = this.slots[i];
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
|
||||
stackAt = this.slots.get(i);
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.slots[i].splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= 0){
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
stackAt = this.slots.get(i).splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
|
@ -252,8 +247,8 @@ public class ContainerFilter extends Container{
|
|||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.slots[index];
|
||||
this.slots[index] = StackUtil.getNull();
|
||||
ItemStack stack = this.slots.get(index);
|
||||
this.slots.set(index, StackUtil.getNull());
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public class GuiRepairer extends GuiContainer{
|
|||
this.mc.getTextureManager().bindTexture(RES_LOC);
|
||||
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);
|
||||
this.drawTexturedModalRect(this.guiLeft+73, this.guiTop+52, 176, 28, i, 16);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -75,7 +72,7 @@ public class ItemBag extends ItemBase{
|
|||
boolean changed = false;
|
||||
|
||||
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);
|
||||
|
||||
FilterSettings filter = new FilterSettings(0, 4, false, false, false, false, 0, 0);
|
||||
|
@ -86,20 +83,20 @@ public class ItemBag extends ItemBase{
|
|||
changed = true;
|
||||
}
|
||||
else{
|
||||
for(int j = 4; j < inventory.length; j++){
|
||||
ItemStack bagStack = inventory[j];
|
||||
for(int j = 4; j < inventory.size(); j++){
|
||||
ItemStack bagStack = inventory.get(j);
|
||||
if(StackUtil.isValid(bagStack)){
|
||||
if(ItemUtil.canBeStacked(bagStack, stack)){
|
||||
int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack));
|
||||
if(maxTransfer > 0){
|
||||
inventory[j] = StackUtil.addStackSize(bagStack, maxTransfer);
|
||||
inventory.set(j, StackUtil.addStackSize(bagStack, maxTransfer));
|
||||
stack = StackUtil.addStackSize(stack, -maxTransfer);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
inventory[j] = stack.copy();
|
||||
inventory.set(j, stack.copy());
|
||||
stack = StackUtil.setStackSize(stack, 0);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -147,16 +144,16 @@ public class ItemBag extends ItemBase{
|
|||
if(handler != null){
|
||||
boolean changed = false;
|
||||
|
||||
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(this.isVoid)];
|
||||
NonNullList<ItemStack> inventory = StackUtil.createSlots(ContainerBag.getSlotAmount(this.isVoid));
|
||||
ItemDrill.loadSlotsFromNBT(inventory, stack);
|
||||
|
||||
for(int j = 4; j < inventory.length; j++){
|
||||
ItemStack invStack = inventory[j];
|
||||
for(int j = 4; j < inventory.size(); j++){
|
||||
ItemStack invStack = inventory.get(j);
|
||||
if(StackUtil.isValid(invStack)){
|
||||
for(int i = 0; i < handler.getSlots(); i++){
|
||||
ItemStack remain = handler.insertItem(i, invStack, false);
|
||||
if(!ItemStack.areItemStacksEqual(remain, invStack)){
|
||||
inventory[j] = StackUtil.validateCopy(remain);
|
||||
inventory.set(j, StackUtil.validateCopy(remain));
|
||||
changed = true;
|
||||
|
||||
if(!StackUtil.isValid(remain)){
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ItemDrill extends ItemEnergy{
|
|||
*
|
||||
* @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();
|
||||
if(compound != null){
|
||||
TileEntityInventoryBase.loadSlots(slots, compound);
|
||||
|
@ -93,7 +93,7 @@ public class ItemDrill extends ItemEnergy{
|
|||
* @param slots The Slots
|
||||
* @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();
|
||||
if(compound == null){
|
||||
compound = new NBTTagCompound();
|
||||
|
@ -153,9 +153,9 @@ public class ItemDrill extends ItemEnergy{
|
|||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT];
|
||||
NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerDrill.SLOT_AMOUNT);
|
||||
loadSlotsFromNBT(slots, stack);
|
||||
if(slots != null && slots.length > 0){
|
||||
if(slots != null && slots.size() > 0){
|
||||
for(ItemStack slotStack : slots){
|
||||
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
|
||||
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
|
||||
@Override
|
||||
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);
|
||||
if(slots != null && slots.length > 0){
|
||||
if(slots != null && slots.size() > 0){
|
||||
for(ItemStack slotStack : slots){
|
||||
if(StackUtil.isValid(slotStack)){
|
||||
Item item = slotStack.getItem();
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -47,9 +48,9 @@ public class ItemFilter extends ItemBase{
|
|||
|
||||
@Override
|
||||
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);
|
||||
if(slots != null && slots.length > 0){
|
||||
if(slots != null && slots.size() > 0){
|
||||
for(ItemStack slot : slots){
|
||||
if(StackUtil.isValid(slot)){
|
||||
tooltip.add(slot.getItem().getItemStackDisplayName(slot));
|
||||
|
|
|
@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
@ -61,17 +62,17 @@ public class FilterSettings{
|
|||
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)){
|
||||
for(int i = startSlot; i < endSlot; i++){
|
||||
if(StackUtil.isValid(slots[i])){
|
||||
if(areEqualEnough(slots[i], stack, meta, nbt, mod, oredict)){
|
||||
if(StackUtil.isValid(slots.get(i))){
|
||||
if(areEqualEnough(slots.get(i), stack, meta, nbt, mod, oredict)){
|
||||
return whitelist;
|
||||
}
|
||||
else if(slots[i].getItem() instanceof ItemFilter){
|
||||
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
|
||||
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
|
||||
if(filterSlots != null && filterSlots.length > 0){
|
||||
else if(slots.get(i).getItem() instanceof ItemFilter){
|
||||
NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
|
||||
ItemDrill.loadSlotsFromNBT(filterSlots, slots.get(i));
|
||||
if(filterSlots != null && filterSlots.size() > 0){
|
||||
for(ItemStack filterSlot : filterSlots){
|
||||
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,9 +117,9 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
|||
|
||||
@Override
|
||||
public Lens getLens(){
|
||||
if(StackUtil.isValid(this.slots[0])){
|
||||
if(this.slots[0].getItem() instanceof ILensItem){
|
||||
return ((ILensItem)this.slots[0].getItem()).getLens();
|
||||
if(StackUtil.isValid(this.slots.get(0))){
|
||||
if(this.slots.get(0).getItem() instanceof ILensItem){
|
||||
return ((ILensItem)this.slots.get(0).getItem()).getLens();
|
||||
}
|
||||
}
|
||||
return this.counter >= 500 ? ActuallyAdditionsAPI.lensDisruption : ActuallyAdditionsAPI.lensDefaultConversion;
|
||||
|
|
|
@ -65,8 +65,8 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
|||
List<Item> types = null;
|
||||
|
||||
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
|
||||
for(int i = 0; i < this.slots.length; i++){
|
||||
ItemStack stack = this.slots[i];
|
||||
for(int i = 0; i < this.slots.size(); i++){
|
||||
ItemStack stack = this.slots.get(i);
|
||||
if(StackUtil.isValid(stack)){
|
||||
Item item = stack.getItem();
|
||||
if(isValidItem(stack) && (types == null || !types.contains(item))){
|
||||
|
@ -75,7 +75,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
|
|||
}
|
||||
types.add(item);
|
||||
|
||||
this.slots[i] = StackUtil.addStackSize(stack, -1);
|
||||
this.slots.set(i, StackUtil.addStackSize(stack, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,9 +100,9 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
|
|||
}
|
||||
else if(this.isPlacer){
|
||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
||||
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.worldObj, this.pos, this.slots[theSlot]));
|
||||
if(!StackUtil.isValid(this.slots[theSlot])){
|
||||
this.slots[theSlot] = StackUtil.getNull();
|
||||
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.worldObj, this.pos, this.slots.get(theSlot)));
|
||||
if(!StackUtil.isValid(this.slots.get(theSlot))){
|
||||
this.slots.set(theSlot, StackUtil.getNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
|
|||
if(this.currentProcessTime >= TIME){
|
||||
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.markDirty();
|
||||
|
@ -117,7 +117,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -74,12 +74,12 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
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()){
|
||||
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots[0]);
|
||||
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.get(0));
|
||||
this.maxBurnTime = 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){
|
||||
|
@ -106,7 +106,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -130,10 +130,10 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
|||
|
||||
public void brew(){
|
||||
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.brewTime%30 == 0){
|
||||
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){
|
||||
this.brewTime = 0;
|
||||
ItemStack output = new ItemStack(InitItems.itemCoffee);
|
||||
for(int i = 3; i < this.slots.length; i++){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.slots[i]);
|
||||
for(int i = 3; i < this.slots.size(); i++){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.slots.get(i));
|
||||
if(ingredient != null){
|
||||
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[SLOT_INPUT] = StackUtil.addStackSize(this.slots[SLOT_INPUT], -1);
|
||||
this.slots.set(SLOT_OUTPUT, output.copy());
|
||||
this.slots.set(SLOT_INPUT, StackUtil.addStackSize(this.slots.get(SLOT_INPUT), -1));
|
||||
this.coffeeCacheAmount -= CACHE_USE;
|
||||
this.tank.drainInternal(WATER_USE, true);
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -63,12 +63,12 @@ public class TileEntityCompost extends TileEntityInventoryBase{
|
|||
if(!this.worldObj.isRemote){
|
||||
boolean theFlag = this.conversionTime > 0;
|
||||
|
||||
if(StackUtil.isValid(this.slots[0])){
|
||||
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
|
||||
if(recipe != null && this.slots[0].isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots[0]) >= StackUtil.getStackSize(recipe.input)){
|
||||
if(StackUtil.isValid(this.slots.get(0))){
|
||||
CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
|
||||
if(recipe != null && this.slots.get(0).isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots.get(0)) >= StackUtil.getStackSize(recipe.input)){
|
||||
this.conversionTime++;
|
||||
if(this.conversionTime >= 3000){
|
||||
this.slots[0] = recipe.output.copy();
|
||||
this.slots.set(0, recipe.output.copy());
|
||||
this.conversionTime = 0;
|
||||
this.markDirty();
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ public class TileEntityCompost extends TileEntityInventoryBase{
|
|||
|
||||
@Override
|
||||
public int getInventoryStackLimit(){
|
||||
if(StackUtil.isValid(this.slots[0])){
|
||||
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
|
||||
if(StackUtil.isValid(this.slots.get(0))){
|
||||
CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
|
||||
if(recipe != null && StackUtil.isValid(recipe.input)){
|
||||
return StackUtil.getStackSize(recipe.input);
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
|
|||
super.updateEntity();
|
||||
|
||||
if(!this.worldObj.isRemote){
|
||||
if(StackUtil.isValid(this.slots[0]) && !this.isRedstonePowered){
|
||||
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots[0].getItem());
|
||||
if(StackUtil.isValid(this.slots.get(0)) && !this.isRedstonePowered){
|
||||
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots.get(0).getItem());
|
||||
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(item.update(this.slots[0], this, this.ticksElapsed)){
|
||||
if(item.update(this.slots.get(0), this, this.ticksElapsed)){
|
||||
this.storage.extractEnergy(energy, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,26 +42,26 @@ public class TileEntityDistributorItem extends TileEntityInventoryBase{
|
|||
for(int i = 0; i < handlerUp.getSlots(); i++){
|
||||
|
||||
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);
|
||||
if(StackUtil.isValid(pulled)){
|
||||
if(!StackUtil.isValid(this.slots[0])){
|
||||
this.slots[0] = pulled.copy();
|
||||
if(!StackUtil.isValid(this.slots.get(0))){
|
||||
this.slots.set(0, pulled.copy());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
do{
|
||||
this.putSide++;
|
||||
|
@ -76,33 +76,33 @@ public class TileEntityDistributorItem extends TileEntityInventoryBase{
|
|||
IItemHandler handler = this.handlersAround.get(putFacing);
|
||||
if(handler != null){
|
||||
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){
|
||||
amount = StackUtil.getStackSize(this.slots[0]);
|
||||
amount = StackUtil.getStackSize(this.slots.get(0));
|
||||
}
|
||||
|
||||
if(amount > 0){
|
||||
ItemStack toInsert = this.slots[0].copy();
|
||||
ItemStack toInsert = this.slots.get(0).copy();
|
||||
toInsert = StackUtil.setStackSize(toInsert, amount);
|
||||
|
||||
for(int i = 0; i < handler.getSlots(); i++){
|
||||
ItemStack notInserted = handler.insertItem(i, toInsert.copy(), false);
|
||||
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;
|
||||
break;
|
||||
}
|
||||
else if(StackUtil.getStackSize(notInserted) != StackUtil.getStackSize(this.slots[0])){
|
||||
this.slots[0] = StackUtil.addStackSize(this.slots[0], -StackUtil.getStackSize(notInserted));
|
||||
else if(StackUtil.getStackSize(notInserted) != StackUtil.getStackSize(this.slots.get(0))){
|
||||
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -StackUtil.getStackSize(notInserted)));
|
||||
toInsert = notInserted;
|
||||
|
||||
shouldMarkDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!StackUtil.isValid(this.slots[0])){
|
||||
this.slots[0] = StackUtil.getNull();
|
||||
if(!StackUtil.isValid(this.slots.get(0))){
|
||||
this.slots.set(0, StackUtil.getNull());
|
||||
shouldMarkDirty = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,11 +74,11 @@ public class TileEntityDropper extends TileEntityInventoryBase{
|
|||
}
|
||||
|
||||
public ItemStack removeFromInventory(boolean actuallyDo){
|
||||
for(int i = 0; i < this.slots.length; i++){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
ItemStack slot = this.slots[i].copy();
|
||||
for(int i = 0; i < this.slots.size(); i++){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
ItemStack slot = this.slots.get(i).copy();
|
||||
if(actuallyDo){
|
||||
this.slots[i] = StackUtil.addStackSize(this.slots[i], -1);
|
||||
this.slots.set(i, StackUtil.addStackSize(this.slots.get(i), -1));
|
||||
this.markDirty();
|
||||
}
|
||||
return slot;
|
||||
|
|
|
@ -52,7 +52,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
|
|||
super.updateEntity();
|
||||
|
||||
if(!this.worldObj.isRemote){
|
||||
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots[0]);
|
||||
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots.get(0));
|
||||
if(!recipes.isEmpty()){
|
||||
for(EmpowererRecipe recipe : recipes){
|
||||
TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time);
|
||||
|
@ -78,7 +78,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
|
|||
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);
|
||||
|
||||
this.slots[0] = recipe.output.copy();
|
||||
this.slots.set(0, recipe.output.copy());
|
||||
this.markDirty();
|
||||
|
||||
this.processTime = 0;
|
||||
|
|
|
@ -48,25 +48,25 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
|
|||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
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){
|
||||
int received = 0;
|
||||
boolean canTakeUp = false;
|
||||
|
||||
if(this.slots[0].getItem() instanceof IEnergyContainerItem){
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem();
|
||||
received = (item.receiveEnergy(this.slots[0], this.storage.getEnergyStored(), false));
|
||||
canTakeUp = item.getEnergyStored(this.slots[0]) >= item.getMaxEnergyStored(this.slots[0]);
|
||||
if(this.slots.get(0).getItem() instanceof IEnergyContainerItem){
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)this.slots.get(0).getItem();
|
||||
received = (item.receiveEnergy(this.slots.get(0), this.storage.getEnergyStored(), false));
|
||||
canTakeUp = item.getEnergyStored(this.slots.get(0)) >= item.getMaxEnergyStored(this.slots.get(0));
|
||||
}
|
||||
else if(ActuallyAdditions.teslaLoaded){
|
||||
if(this.slots[0].hasCapability(TeslaUtil.teslaConsumer, null)){
|
||||
ITeslaConsumer cap = this.slots[0].getCapability(TeslaUtil.teslaConsumer, null);
|
||||
if(this.slots.get(0).hasCapability(TeslaUtil.teslaConsumer, null)){
|
||||
ITeslaConsumer cap = this.slots.get(0).getCapability(TeslaUtil.teslaConsumer, null);
|
||||
if(cap != null){
|
||||
received = (int)cap.givePower(this.storage.getEnergyStored(), false);
|
||||
}
|
||||
}
|
||||
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){
|
||||
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null);
|
||||
if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
|
||||
ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
|
||||
if(cap != null){
|
||||
canTakeUp = cap.getStoredPower() >= cap.getCapacity();
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
|
|||
}
|
||||
|
||||
if(canTakeUp){
|
||||
this.slots[1] = this.slots[0].copy();
|
||||
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
|
||||
this.slots.set(1, this.slots.get(0).copy());
|
||||
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,26 +48,26 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
|
|||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
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()){
|
||||
int extracted = 0;
|
||||
boolean canTakeUp = false;
|
||||
|
||||
int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored();
|
||||
if(this.slots[0].getItem() instanceof IEnergyContainerItem){
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)this.slots[0].getItem();
|
||||
extracted = item.extractEnergy(this.slots[0], maxExtract, false);
|
||||
canTakeUp = item.getEnergyStored(this.slots[0]) <= 0;
|
||||
if(this.slots.get(0).getItem() instanceof IEnergyContainerItem){
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)this.slots.get(0).getItem();
|
||||
extracted = item.extractEnergy(this.slots.get(0), maxExtract, false);
|
||||
canTakeUp = item.getEnergyStored(this.slots.get(0)) <= 0;
|
||||
}
|
||||
else if(ActuallyAdditions.teslaLoaded){
|
||||
if(this.slots[0].hasCapability(TeslaUtil.teslaProducer, null)){
|
||||
ITeslaProducer cap = this.slots[0].getCapability(TeslaUtil.teslaProducer, null);
|
||||
if(this.slots.get(0).hasCapability(TeslaUtil.teslaProducer, null)){
|
||||
ITeslaProducer cap = this.slots.get(0).getCapability(TeslaUtil.teslaProducer, null);
|
||||
if(cap != null){
|
||||
extracted = (int)cap.takePower(maxExtract, false);
|
||||
}
|
||||
}
|
||||
if(this.slots[0].hasCapability(TeslaUtil.teslaHolder, null)){
|
||||
ITeslaHolder cap = this.slots[0].getCapability(TeslaUtil.teslaHolder, null);
|
||||
if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
|
||||
ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
|
||||
if(cap != null){
|
||||
canTakeUp = cap.getStoredPower() <= 0;
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
|
|||
}
|
||||
|
||||
if(canTakeUp){
|
||||
this.slots[1] = this.slots[0].copy();
|
||||
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
|
||||
this.slots.set(1, this.slots.get(0).copy());
|
||||
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
|
|||
|
||||
private IBlockState getFirstPlantablePlantFromSlots(BlockPos pos){
|
||||
for(int i = 0; i < 6; i++){
|
||||
ItemStack stack = this.slots[i];
|
||||
ItemStack stack = this.slots.get(i);
|
||||
if(StackUtil.isValid(stack)){
|
||||
IPlantable plantable = null;
|
||||
|
||||
|
|
|
@ -74,13 +74,13 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
|
|||
if(this.currentAnimalAmount < THRESHOLD){
|
||||
if(this.currentTimer >= TIME){
|
||||
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));
|
||||
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.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){
|
||||
EntityHorse horse = (EntityHorse)animal;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -45,9 +46,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
|||
super(4, "furnaceDouble");
|
||||
}
|
||||
|
||||
public static void autoSplit(ItemStack[] slots, int slot1, int slot2){
|
||||
ItemStack first = slots[slot1];
|
||||
ItemStack second = slots[slot2];
|
||||
public static void autoSplit(NonNullList<ItemStack> slots, int slot1, int slot2){
|
||||
ItemStack first = slots.get(slot1);
|
||||
ItemStack second = slots.get(slot2);
|
||||
|
||||
if(StackUtil.isValid(first) || StackUtil.isValid(second)){
|
||||
ItemStack toSplit = StackUtil.getNull();
|
||||
|
@ -69,8 +70,8 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
|||
if(StackUtil.isValid(toSplit)){
|
||||
ItemStack splitFirst = toSplit.copy();
|
||||
ItemStack secondSplit = splitFirst.splitStack(StackUtil.getStackSize(splitFirst)/2);
|
||||
slots[slot1] = StackUtil.validateCheck(splitFirst);
|
||||
slots[slot2] = StackUtil.validateCheck(secondSplit);
|
||||
slots.set(slot1, StackUtil.validateCheck(splitFirst));
|
||||
slots.set(slot2, StackUtil.validateCheck(secondSplit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,10 +169,10 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
public boolean canSmeltOn(int theInput, int theOutput){
|
||||
if(StackUtil.isValid(this.slots[theInput])){
|
||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]);
|
||||
if(StackUtil.isValid(this.slots.get(theInput))){
|
||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -181,15 +182,15 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
public void finishBurning(int theInput, int theOutput){
|
||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]);
|
||||
if(!StackUtil.isValid(this.slots[theOutput])){
|
||||
this.slots[theOutput] = output.copy();
|
||||
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
|
||||
if(!StackUtil.isValid(this.slots.get(theOutput))){
|
||||
this.slots.set(theOutput, output.copy());
|
||||
}
|
||||
else if(this.slots[theOutput].getItem() == output.getItem()){
|
||||
this.slots[theOutput] = StackUtil.addStackSize(this.slots[theOutput], StackUtil.getStackSize(output));
|
||||
else if(this.slots.get(theOutput).getItem() == output.getItem()){
|
||||
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)
|
||||
|
|
|
@ -185,9 +185,9 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
|
|||
}
|
||||
|
||||
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){
|
||||
if(StackUtil.isValid(this.slots[theInput])){
|
||||
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]);
|
||||
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]);
|
||||
if(StackUtil.isValid(this.slots.get(theInput))){
|
||||
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.get(theInput));
|
||||
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.get(theInput));
|
||||
if(StackUtil.isValid(outputOne)){
|
||||
if(outputOne.getItemDamage() == Util.WILDCARD){
|
||||
outputOne.setItemDamage(0);
|
||||
|
@ -195,7 +195,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
|
|||
if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -208,36 +208,36 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
|
|||
}
|
||||
|
||||
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(outputOne.getItemDamage() == Util.WILDCARD){
|
||||
outputOne.setItemDamage(0);
|
||||
}
|
||||
if(!StackUtil.isValid(this.slots[theFirstOutput])){
|
||||
this.slots[theFirstOutput] = outputOne.copy();
|
||||
if(!StackUtil.isValid(this.slots.get(theFirstOutput))){
|
||||
this.slots.set(theFirstOutput, outputOne.copy());
|
||||
}
|
||||
else if(this.slots[theFirstOutput].getItem() == outputOne.getItem()){
|
||||
this.slots[theFirstOutput] = StackUtil.addStackSize(this.slots[theFirstOutput], StackUtil.getStackSize(outputOne));
|
||||
else if(this.slots.get(theFirstOutput).getItem() == outputOne.getItem()){
|
||||
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(outputTwo.getItemDamage() == Util.WILDCARD){
|
||||
outputTwo.setItemDamage(0);
|
||||
}
|
||||
int rand = this.worldObj.rand.nextInt(100)+1;
|
||||
if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots[theInput])){
|
||||
if(!StackUtil.isValid(this.slots[theSecondOutput])){
|
||||
this.slots[theSecondOutput] = outputTwo.copy();
|
||||
if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots.get(theInput))){
|
||||
if(!StackUtil.isValid(this.slots.get(theSecondOutput))){
|
||||
this.slots.set(theSecondOutput, outputTwo.copy());
|
||||
}
|
||||
else if(this.slots[theSecondOutput].getItem() == outputTwo.getItem()){
|
||||
this.slots[theSecondOutput] = StackUtil.addStackSize(this.slots[theSecondOutput], StackUtil.getStackSize(outputTwo));
|
||||
else if(this.slots.get(theSecondOutput).getItem() == outputTwo.getItem()){
|
||||
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)
|
||||
|
|
|
@ -99,7 +99,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
}
|
||||
|
||||
private boolean newPutting(){
|
||||
if(this.checkBothFilters(this.slots[0], true)){
|
||||
if(this.checkBothFilters(this.slots.get(0), true)){
|
||||
for(EnumFacing side : EnumFacing.values()){
|
||||
if(this.placeToPut.hasCapability(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){
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,30 +17,29 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{
|
||||
|
||||
private final SidedInvWrapper[] invWrappers = new SidedInvWrapper[6];
|
||||
public ItemStack slots[];
|
||||
public NonNullList<ItemStack> slots;
|
||||
|
||||
public TileEntityInventoryBase(int slots, String name){
|
||||
super(name);
|
||||
|
||||
this.slots = new ItemStack[slots];
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.slots = StackUtil.createSlots(slots);
|
||||
|
||||
if(this.hasInvWrapperCapabilities()){
|
||||
this.getInvWrappers(this.invWrappers);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveSlots(ItemStack[] slots, NBTTagCompound compound){
|
||||
if(slots != null && slots.length > 0){
|
||||
public static void saveSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){
|
||||
if(slots != null && slots.size() > 0){
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for(ItemStack slot : slots){
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
|
@ -53,12 +52,12 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
|
|||
}
|
||||
}
|
||||
|
||||
public static void loadSlots(ItemStack[] slots, NBTTagCompound compound){
|
||||
if(slots != null && slots.length > 0){
|
||||
public static void loadSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){
|
||||
if(slots != null && slots.size() > 0){
|
||||
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);
|
||||
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
|
||||
public void clear(){
|
||||
for(int i = 0; i < this.slots.length; i++){
|
||||
this.removeStackFromSlot(i);
|
||||
}
|
||||
this.slots.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.slots[i] = stack;
|
||||
this.slots.set(i, stack);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.slots.length;
|
||||
return this.slots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.slots[i];
|
||||
return this.slots.get(i);
|
||||
}
|
||||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(StackUtil.isValid(this.slots[i])){
|
||||
if(StackUtil.isValid(this.slots.get(i))){
|
||||
ItemStack stackAt;
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= j){
|
||||
stackAt = this.slots[i];
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
|
||||
stackAt = this.slots.get(i);
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.slots[i].splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots[i]) <= 0){
|
||||
this.slots[i] = StackUtil.getNull();
|
||||
stackAt = this.slots.get(i).splitStack(j);
|
||||
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
|
||||
this.slots.set(i, StackUtil.getNull());
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
|
@ -190,8 +187,8 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
|
|||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.slots[index];
|
||||
this.slots[index] = StackUtil.getNull();
|
||||
ItemStack stack = this.slots.get(index);
|
||||
this.slots.set(index, StackUtil.getNull());
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,11 +77,11 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
|
|||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
if(!this.worldObj.isRemote){
|
||||
ItemStack input = this.slots[SLOT_INPUT];
|
||||
if(!StackUtil.isValid(this.slots[SLOT_OUTPUT]) && canBeRepaired(input)){
|
||||
ItemStack input = this.slots.get(SLOT_INPUT);
|
||||
if(!StackUtil.isValid(this.slots.get(SLOT_OUTPUT)) && canBeRepaired(input)){
|
||||
if(input.getItemDamage() <= 0){
|
||||
this.slots[SLOT_OUTPUT] = input.copy();
|
||||
this.slots[SLOT_INPUT] = StackUtil.getNull();
|
||||
this.slots.set(SLOT_OUTPUT, input.copy());
|
||||
this.slots.set(SLOT_INPUT, StackUtil.getNull());
|
||||
this.nextRepairTick = 0;
|
||||
}
|
||||
else{
|
||||
|
@ -125,8 +125,8 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I
|
|||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getItemDamageToScale(int i){
|
||||
if(StackUtil.isValid(this.slots[SLOT_INPUT])){
|
||||
return (this.slots[SLOT_INPUT].getMaxDamage()-this.slots[SLOT_INPUT].getItemDamage())*i/this.slots[SLOT_INPUT].getMaxDamage();
|
||||
if(StackUtil.isValid(this.slots.get(SLOT_INPUT))){
|
||||
return (this.slots.get(SLOT_INPUT).getMaxDamage()-this.slots.get(SLOT_INPUT).getItemDamage())*i/this.slots.get(SLOT_INPUT).getMaxDamage();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
@ -30,12 +31,11 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
public final IInventory filterInventory;
|
||||
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);
|
||||
private ItemStack[] slots = new ItemStack[24];
|
||||
private NonNullList<ItemStack> slots = StackUtil.createSlots(24);
|
||||
|
||||
public TileEntityLaserRelayItemWhitelist(){
|
||||
super("laserRelayItemWhitelist");
|
||||
|
||||
Arrays.fill(this.slots, StackUtil.getNull());
|
||||
this.filterInventory = new IInventory(){
|
||||
|
||||
private TileEntityLaserRelayItemWhitelist tile;
|
||||
|
@ -93,20 +93,18 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
|
||||
@Override
|
||||
public void clear(){
|
||||
int length = this.tile.slots.length;
|
||||
this.tile.slots = new ItemStack[length];
|
||||
Arrays.fill(this.tile.slots, StackUtil.getNull());
|
||||
this.tile.slots.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack){
|
||||
this.tile.slots[i] = stack;
|
||||
this.tile.slots.set(i, stack);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
return this.tile.slots.length;
|
||||
return this.tile.slots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,25 +115,25 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int i){
|
||||
if(i < this.getSizeInventory()){
|
||||
return this.tile.slots[i];
|
||||
return this.tile.slots.get(i);
|
||||
}
|
||||
return StackUtil.getNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j){
|
||||
if(StackUtil.isValid(this.tile.slots[i])){
|
||||
if(StackUtil.isValid(this.tile.slots.get(i))){
|
||||
ItemStack stackAt;
|
||||
if(StackUtil.getStackSize(this.tile.slots[i]) <= j){
|
||||
stackAt = this.tile.slots[i];
|
||||
this.tile.slots[i] = StackUtil.getNull();
|
||||
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= j){
|
||||
stackAt = this.tile.slots.get(i);
|
||||
this.tile.slots.set(i, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
}
|
||||
else{
|
||||
stackAt = this.tile.slots[i].splitStack(j);
|
||||
if(StackUtil.getStackSize(this.tile.slots[i]) <= 0){
|
||||
this.tile.slots[i] = StackUtil.getNull();
|
||||
stackAt = this.tile.slots.get(i).splitStack(j);
|
||||
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= 0){
|
||||
this.tile.slots.set(i, StackUtil.getNull());
|
||||
}
|
||||
this.markDirty();
|
||||
return stackAt;
|
||||
|
@ -146,8 +144,8 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index){
|
||||
ItemStack stack = this.tile.slots[index];
|
||||
this.tile.slots[index] = StackUtil.getNull();
|
||||
ItemStack stack = this.tile.slots.get(index);
|
||||
this.tile.slots.set(index, StackUtil.getNull());
|
||||
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)){
|
||||
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
|
||||
if(StackUtil.isValid(this.slots[k])){
|
||||
if(this.slots[k].getItem() instanceof ItemFilter){
|
||||
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
|
||||
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots[k]);
|
||||
if(StackUtil.isValid(this.slots.get(k))){
|
||||
if(this.slots.get(k).getItem() instanceof ItemFilter){
|
||||
NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
|
||||
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots.get(k));
|
||||
|
||||
boolean did = false;
|
||||
if(filterSlots != null && filterSlots.length > 0){
|
||||
for(int j = 0; j < filterSlots.length; j++){
|
||||
if(!StackUtil.isValid(filterSlots[j])){
|
||||
filterSlots[j] = copy;
|
||||
if(filterSlots != null && filterSlots.size() > 0){
|
||||
for(int j = 0; j < filterSlots.size(); j++){
|
||||
if(!StackUtil.isValid(filterSlots.get(j))){
|
||||
filterSlots.set(j, copy);
|
||||
did = true;
|
||||
break;
|
||||
}
|
||||
|
@ -243,13 +241,13 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
}
|
||||
|
||||
if(did){
|
||||
ItemDrill.writeSlotsToNBT(filterSlots, this.slots[k]);
|
||||
ItemDrill.writeSlotsToNBT(filterSlots, this.slots.get(k));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.slots[k] = copy;
|
||||
this.slots.set(k, copy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,9 +148,9 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
|||
}
|
||||
else{
|
||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
||||
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots[theSlot]));
|
||||
if(!StackUtil.isValid(this.slots[theSlot])){
|
||||
this.slots[theSlot] = StackUtil.getNull();
|
||||
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.worldObj, this.boundPosition, this.slots.get(theSlot)));
|
||||
if(!StackUtil.isValid(this.slots.get(theSlot))){
|
||||
this.slots.set(theSlot, StackUtil.getNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,16 +123,16 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
|
|||
super.updateEntity();
|
||||
if(!this.worldObj.isRemote){
|
||||
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;
|
||||
this.slots[0] = new ItemStack(InitItems.itemSolidifiedExperience, toSet);
|
||||
this.slots.set(0, new ItemStack(InitItems.itemSolidifiedExperience, toSet));
|
||||
this.amount -= toSet;
|
||||
this.markDirty();
|
||||
}
|
||||
else if(StackUtil.getStackSize(this.slots[0]) < 64){
|
||||
int needed = 64-StackUtil.getStackSize(this.slots[0]);
|
||||
else if(StackUtil.getStackSize(this.slots.get(0)) < 64){
|
||||
int needed = 64-StackUtil.getStackSize(this.slots.get(0));
|
||||
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.markDirty();
|
||||
}
|
||||
|
@ -157,9 +157,9 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
|
|||
}
|
||||
}
|
||||
|
||||
if(StackUtil.isValid(this.slots[1]) && this.slots[1].getItem() instanceof ItemSolidifiedExperience){
|
||||
this.amount += StackUtil.getStackSize(this.slots[1]);
|
||||
this.slots[1] = StackUtil.getNull();
|
||||
if(StackUtil.isValid(this.slots.get(1)) && this.slots.get(1).getItem() instanceof ItemSolidifiedExperience){
|
||||
this.amount += StackUtil.getStackSize(this.slots.get(1));
|
||||
this.slots.set(1, StackUtil.getNull());
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package de.ellpeck.actuallyadditions.mod.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public final class StackUtil{
|
||||
|
||||
|
@ -66,7 +67,7 @@ public final class StackUtil{
|
|||
return setStackSize(stack, getStackSize(stack)+size);
|
||||
}
|
||||
|
||||
public static boolean isIInvEmpty(ItemStack[] slots){
|
||||
public static boolean isIInvEmpty(NonNullList<ItemStack> slots){
|
||||
for(ItemStack stack : slots){
|
||||
if(StackUtil.isValid(stack)){
|
||||
return false;
|
||||
|
@ -75,4 +76,8 @@ public final class StackUtil{
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static NonNullList<ItemStack> createSlots(int size){
|
||||
return NonNullList.func_191197_a(size, getNull());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import cofh.api.energy.IEnergyReceiver;
|
|||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -32,6 +31,7 @@ import net.minecraft.network.play.server.SPacketBlockChange;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
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.FakePlayerFactory;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -230,9 +227,7 @@ public final class WorldUtil{
|
|||
backupSlots = new ItemStack[inventory.getSizeInventory()];
|
||||
for(int i = 0; i < backupSlots.length; i++){
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if(StackUtil.isValid(stack)){
|
||||
backupSlots[i] = stack.copy();
|
||||
}
|
||||
backupSlots[i] = StackUtil.validateCopy(stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,9 +261,9 @@ public final class WorldUtil{
|
|||
return working >= stacks.size();
|
||||
}
|
||||
|
||||
public static int findFirstFilledSlot(ItemStack[] slots){
|
||||
for(int i = 0; i < slots.length; i++){
|
||||
if(StackUtil.isValid(slots[i])){
|
||||
public static int findFirstFilledSlot(NonNullList<ItemStack> slots){
|
||||
for(int i = 0; i < slots.size(); i++){
|
||||
if(StackUtil.isValid(slots.get(i))){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue