This only took 20 years

Prepared for 1.11 ItemStack updates
This commit is contained in:
Ellpeck 2016-11-16 16:59:00 +01:00
parent a94a49f9c9
commit 6e34f9e345
77 changed files with 668 additions and 732 deletions

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase;
@ -70,11 +71,11 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
if(!world.isRemote){
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor)world.getTileEntity(pos);
if(reconstructor != null){
if(heldItem != null){
if(StackUtil.isValid(heldItem)){
Item item = heldItem.getItem();
if(item instanceof ILensItem && reconstructor.getStackInSlot(0) == null){
if(item instanceof ILensItem && !StackUtil.isValid(reconstructor.getStackInSlot(0))){
ItemStack toPut = heldItem.copy();
toPut.stackSize = 1;
toPut = StackUtil.setStackSize(toPut, 1);
reconstructor.setInventorySlotContents(0, toPut);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
@ -86,9 +87,9 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
}
else{
ItemStack slot = reconstructor.getStackInSlot(0);
if(slot != null){
if(StackUtil.isValid(slot)){
player.inventory.setInventorySlotContents(player.inventory.currentItem, slot.copy());
reconstructor.setInventorySlotContents(0, null);
reconstructor.setInventorySlotContents(0, StackUtil.getNull());
}
}
}

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
@ -92,20 +93,20 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
if(stackPlayer != null){
CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer);
if(recipeHand != null && (recipeIn == null || recipeIn == recipeHand)){
int maxAdd = Math.min(recipeHand.input.stackSize, stackPlayer.stackSize);
int maxAdd = Math.min(StackUtil.getStackSize(recipeHand.input), StackUtil.getStackSize(stackPlayer));
if(slot == null){
ItemStack stackToAdd = stackPlayer.copy();
stackToAdd.stackSize = maxAdd;
stackToAdd = StackUtil.setStackSize(stackToAdd, maxAdd);
compost.setInventorySlotContents(0, stackToAdd);
player.inventory.decrStackSize(player.inventory.currentItem, maxAdd);
return true;
}
else{
ItemStack stackIn = slot.copy();
if(stackIn.stackSize < recipeHand.input.stackSize){
int sizeAdded = Math.min(maxAdd, recipeHand.input.stackSize-stackIn.stackSize);
stackIn.stackSize += sizeAdded;
if(StackUtil.getStackSize(stackIn) < StackUtil.getStackSize(recipeHand.input)){
int sizeAdded = Math.min(maxAdd, StackUtil.getStackSize(recipeHand.input)-StackUtil.getStackSize(stackIn));
stackIn = StackUtil.addStackSize(stackIn, sizeAdded);
compost.setInventorySlotContents(0, stackIn);
player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded);
return true;
@ -121,9 +122,9 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
return true;
}
else if(ItemUtil.canBeStacked(stackPlayer, slot)){
int addedStackSize = Math.min(slot.stackSize, stackPlayer.getMaxStackSize()-stackPlayer.stackSize);
int addedStackSize = Math.min(StackUtil.getStackSize(slot), stackPlayer.getMaxStackSize()-StackUtil.getStackSize(stackPlayer));
ItemStack stackToAdd = stackPlayer.copy();
stackToAdd.stackSize += addedStackSize;
stackToAdd = StackUtil.addStackSize(stackToAdd, addedStackSize);
player.inventory.setInventorySlotContents(player.inventory.currentItem, stackToAdd);
compost.decrStackSize(0, addedStackSize);
return true;

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
@ -54,29 +55,29 @@ public class BlockDisplayStand extends BlockContainerBase{
TileEntityDisplayStand stand = (TileEntityDisplayStand)world.getTileEntity(pos);
if(stand != null){
ItemStack display = stand.getStackInSlot(0);
if(heldItem != null){
if(display == null){
if(StackUtil.isValid(heldItem)){
if(!StackUtil.isValid(display)){
ItemStack toPut = heldItem.copy();
toPut.stackSize = 1;
toPut = StackUtil.setStackSize(toPut, 1);
stand.setInventorySlotContents(0, toPut);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, -1));
return true;
}
else if(ItemUtil.canBeStacked(heldItem, display)){
int maxTransfer = Math.min(display.stackSize, heldItem.getMaxStackSize()-heldItem.stackSize);
int maxTransfer = Math.min(StackUtil.getStackSize(display), heldItem.getMaxStackSize()-StackUtil.getStackSize(heldItem));
if(maxTransfer > 0){
heldItem.stackSize += maxTransfer;
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, maxTransfer));
ItemStack newDisplay = display.copy();
newDisplay.stackSize -= maxTransfer;
stand.setInventorySlotContents(0, newDisplay.stackSize <= 0 ? null : newDisplay);
newDisplay = StackUtil.addStackSize(newDisplay, -maxTransfer);
stand.setInventorySlotContents(0, StackUtil.validateCheck(newDisplay));
return true;
}
}
}
else{
if(display != null){
player.inventory.setInventorySlotContents(player.inventory.currentItem, display.copy());
stand.setInventorySlotContents(0, null);
if(StackUtil.isValid(display)){
player.setHeldItem(hand, display.copy());
stand.setInventorySlotContents(0, StackUtil.getNull());
return true;
}
}

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
@ -54,29 +55,29 @@ public class BlockEmpowerer extends BlockContainerBase{
TileEntityEmpowerer empowerer = (TileEntityEmpowerer)world.getTileEntity(pos);
if(empowerer != null){
ItemStack stackThere = empowerer.getStackInSlot(0);
if(heldItem != null){
if(stackThere == null && !TileEntityEmpowerer.getRecipesForInput(heldItem).isEmpty()){
if(StackUtil.isValid(heldItem)){
if(!StackUtil.isValid(stackThere) && !TileEntityEmpowerer.getRecipesForInput(heldItem).isEmpty()){
ItemStack toPut = heldItem.copy();
toPut.stackSize = 1;
toPut = StackUtil.setStackSize(toPut, 1);
empowerer.setInventorySlotContents(0, toPut);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, -1));
return true;
}
else if(ItemUtil.canBeStacked(heldItem, stackThere)){
int maxTransfer = Math.min(stackThere.stackSize, heldItem.getMaxStackSize()-heldItem.stackSize);
int maxTransfer = Math.min(StackUtil.getStackSize(stackThere), heldItem.getMaxStackSize()-StackUtil.getStackSize(heldItem));
if(maxTransfer > 0){
heldItem.stackSize += maxTransfer;
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, maxTransfer));
ItemStack newStackThere = stackThere.copy();
newStackThere.stackSize -= maxTransfer;
empowerer.setInventorySlotContents(0, newStackThere.stackSize <= 0 ? null : newStackThere);
StackUtil.addStackSize(newStackThere, -maxTransfer);
empowerer.setInventorySlotContents(0, StackUtil.validateCheck(newStackThere));
return true;
}
}
}
else{
if(stackThere != null){
player.inventory.setInventorySlotContents(player.inventory.currentItem, stackThere.copy());
empowerer.setInventorySlotContents(0, null);
if(StackUtil.isValid(stackThere)){
player.setHeldItem(hand, stackThere.copy());
empowerer.setInventorySlotContents(0, StackUtil.getNull());
return true;
}
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyInteger;
@ -118,7 +119,7 @@ public class BlockSlabs extends BlockBase{
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
if(stack.stackSize != 0 && playerIn.canPlayerEdit(pos.offset(facing), facing, stack)){
if(StackUtil.isValid(stack) && playerIn.canPlayerEdit(pos.offset(facing), facing, stack)){
IBlockState state = worldIn.getBlockState(pos);
if(state.getBlock() == this.block){
@ -130,14 +131,14 @@ public class BlockSlabs extends BlockBase{
if(bound != Block.NULL_AABB && worldIn.checkNoEntityCollision(bound.offset(pos)) && worldIn.setBlockState(pos, newState, 11)){
SoundType soundtype = theBlock.fullBlock.getSoundType();
worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F);
--stack.stackSize;
playerIn.setHeldItem(hand, StackUtil.addStackSize(stack, -1));
}
return EnumActionResult.SUCCESS;
}
}
return this.tryPlace(playerIn, stack, worldIn, pos.offset(facing)) ? EnumActionResult.SUCCESS : super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
return this.tryPlace(playerIn, stack, hand, worldIn, pos.offset(facing)) ? EnumActionResult.SUCCESS : super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
else{
return EnumActionResult.FAIL;
@ -158,7 +159,7 @@ public class BlockSlabs extends BlockBase{
return worldIn.getBlockState(pos.offset(side)).getBlock() == this.block || super.canPlaceBlockOnSide(worldIn, pos, side, player, stack);
}
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos){
private boolean tryPlace(EntityPlayer player, ItemStack stack, EnumHand hand, World worldIn, BlockPos pos){
IBlockState iblockstate = worldIn.getBlockState(pos);
if(iblockstate.getBlock() == this.block){
@ -169,7 +170,8 @@ public class BlockSlabs extends BlockBase{
if(bound != Block.NULL_AABB && worldIn.checkNoEntityCollision(bound.offset(pos)) && worldIn.setBlockState(pos, newState, 11)){
SoundType soundtype = theBlock.fullBlock.getSoundType();
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F);
--stack.stackSize;
player.setHeldItem(hand, StackUtil.addStackSize(stack, -1));
}
return true;

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.TreasureChestLoot;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
@ -103,18 +104,17 @@ public class BlockTreasureChest extends BlockBase{
for(int i = 0; i < MathHelper.getRandomIntegerInRange(world.rand, 3, 6); i++){
TreasureChestLoot theReturn = WeightedRandom.getRandomItem(world.rand, ActuallyAdditionsAPI.TREASURE_CHEST_LOOT);
ItemStack itemStack = theReturn.returnItem.copy();
itemStack.stackSize = MathHelper.getRandomIntegerInRange(world.rand, theReturn.minAmount, theReturn.maxAmount);
itemStack = StackUtil.setStackSize(itemStack, MathHelper.getRandomIntegerInRange(world.rand, theReturn.minAmount, theReturn.maxAmount));
float dX = world.rand.nextFloat()*0.8F+0.1F;
float dY = world.rand.nextFloat()*0.8F+0.1F;
float dZ = world.rand.nextFloat()*0.8F+0.1F;
EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, itemStack.copy());
EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, itemStack);
float factor = 0.05F;
entityItem.motionX = world.rand.nextGaussian()*factor;
entityItem.motionY = world.rand.nextGaussian()*factor+0.2F;
entityItem.motionZ = world.rand.nextGaussian()*factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockRedstoneTorch;
@ -97,7 +98,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
public void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos){
ItemStack stack = tile.getStackInSlot(i);
if(stack != null && stack.stackSize > 0){
if(StackUtil.isValid(stack)){
float dX = world.rand.nextFloat()*0.8F+0.1F;
float dY = world.rand.nextFloat()*0.8F+0.1F;
float dZ = world.rand.nextFloat()*0.8F+0.1F;
@ -112,7 +113,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
public boolean tryToggleRedstone(World world, BlockPos pos, EntityPlayer player){
ItemStack stack = player.getHeldItemMainhand();
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
if(StackUtil.isValid(stack) && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityBase){
TileEntityBase base = (TileEntityBase)tile;

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.blocks.base;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
@ -96,13 +97,13 @@ public class BlockPlant extends BlockCrops implements ItemBlockBase.ICustomRarit
List<ItemStack> drops = this.getDrops(world, pos, state, 0);
boolean deductedSeedSize = false;
for(ItemStack drop : drops){
if(drop != null){
if(StackUtil.isValid(drop)){
if(drop.getItem() == this.seedItem && !deductedSeedSize){
drop.stackSize--;
StackUtil.addStackSize(drop, -1);
deductedSeedSize = true;
}
if(drop.stackSize > 0){
if(StackUtil.isValid(drop)){
EntityItem entity = new EntityItem(world, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, drop);
world.spawnEntityInWorld(entity);
}

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
@ -29,23 +30,23 @@ public class RenderCompost extends TileEntitySpecialRenderer{
TileEntityCompost compost = (TileEntityCompost)te;
ItemStack slot = compost.getStackInSlot(0);
if(slot != null){
if(StackUtil.isValid(slot)){
Block display = null;
int maxAmount = 0;
for(CompostRecipe aRecipe : ActuallyAdditionsAPI.COMPOST_RECIPES){
if(slot.isItemEqual(aRecipe.input)){
display = aRecipe.inputDisplay;
maxAmount = aRecipe.input.stackSize;
maxAmount = StackUtil.getStackSize(aRecipe.input);
break;
}
else if(slot.isItemEqual(aRecipe.output)){
display = aRecipe.outputDisplay;
maxAmount = aRecipe.output.stackSize;
maxAmount = StackUtil.getStackSize(aRecipe.output);
break;
}
}
if(display != null){
float i = (float)slot.stackSize/(float)maxAmount;
float i = (float)StackUtil.getStackSize(slot)/(float)maxAmount;
GlStateManager.pushMatrix();
GlStateManager.translate((float)x+0.5F, (float)y+(i/3F)+0.01F, (float)z+0.5F);
//Hehe

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.booklet.page;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.client.renderer.GlStateManager;
@ -162,9 +163,9 @@ public class PageCrafting extends BookletPage{
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
ItemStack stack = stacks[y*width+x];
if(stack != null){
if(StackUtil.isValid(stack)){
ItemStack copy = stack.copy();
copy.stackSize = 1;
copy = StackUtil.setStackSize(copy, 1);
if(copy.getItemDamage() == Util.WILDCARD){
copy.setItemDamage(0);
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.gen;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheJams;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.passive.EntityVillager.ITradeList;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@ -30,15 +31,11 @@ public class JamVillagerTradeList implements ITradeList{
if(random.nextFloat() >= 0.65F){
//Jam as input
jam.stackSize = random.nextInt(3)+1;
emerald.stackSize = random.nextInt(2)+1;
recipeList.add(new MerchantRecipe(jam, emerald));
recipeList.add(new MerchantRecipe(StackUtil.setStackSize(jam, random.nextInt(3)+1), StackUtil.setStackSize(emerald, random.nextInt(2)+1)));
}
else{
//Emeralds as input
jam.stackSize = random.nextInt(4)+2;
emerald.stackSize = random.nextInt(6)+2;
recipeList.add(new MerchantRecipe(emerald, jam));
recipeList.add(new MerchantRecipe(StackUtil.setStackSize(emerald, random.nextInt(6)+2), StackUtil.setStackSize(jam, random.nextInt(4)+2)));
}
}
}

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.items.ItemBag;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
@ -27,6 +28,8 @@ import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Arrays;
public class ContainerBag extends Container implements IButtonReactor{
@ -152,35 +155,35 @@ public class ContainerBag extends Container implements IButtonReactor{
if(this.isVoid || !this.filter.check(newStack, this.bagInventory.slots) || !this.mergeItemStack(newStack, 4, 32, false)){
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
//
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override
@ -230,6 +233,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public InventoryBag(boolean isVoid){
this.slots = new ItemStack[getSlotAmount(isVoid)];
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
@ -286,6 +290,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public void clear(){
int length = this.slots.length;
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
@ -304,35 +309,35 @@ public class ContainerBag extends Container implements IButtonReactor{
if(i < this.getSizeInventory()){
return this.slots[i];
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
ItemStack stackAt;
if(this.slots[i].stackSize <= j){
if(StackUtil.getStackSize(this.slots[i]) <= j){
stackAt = this.slots[i];
this.slots[i] = null;
this.slots[i] = StackUtil.getNull();
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots[i].splitStack(j);
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
if(StackUtil.getStackSize(this.slots[i]) <= 0){
this.slots[i] = StackUtil.getNull();
}
this.markDirty();
return stackAt;
}
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index];
this.slots[index] = null;
this.slots[index] = StackUtil.getNull();
return stack;
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -59,39 +60,39 @@ public class ContainerBioReactor extends Container{
//Shift from Inventory
if(TileEntityBioReactor.isValidItem(newStack)){
if(!this.mergeItemStack(newStack, 0, 8, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBreaker;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -62,33 +63,33 @@ public class ContainerBreaker extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCanolaPress;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -58,39 +59,39 @@ public class ContainerCanolaPress extends Container{
//Shift from Inventory
if(newStack.getItem() == InitItems.itemMisc && newStack.getItemDamage() == TheMiscItems.CANOLA.ordinal()){
if(!this.mergeItemStack(newStack, 0, 1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoalGenerator;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -57,39 +58,39 @@ public class ContainerCoalGenerator extends Container{
//Shift from Inventory
if(TileEntityFurnace.getItemBurnTime(newStack) > 0){
if(!this.mergeItemStack(newStack, 0, 1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.items.ItemCoffee;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoffeeMachine;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -66,7 +67,7 @@ public class ContainerCoffeeMachine extends Container{
//Slots in Inventory to shift from
if(slot == TileEntityCoffeeMachine.SLOT_OUTPUT){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -75,49 +76,49 @@ public class ContainerCoffeeMachine extends Container{
//Shift from Inventory
if(newStack.getItem() == InitItems.itemMisc && newStack.getItemDamage() == TheMiscItems.CUP.ordinal()){
if(!this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_INPUT, TileEntityCoffeeMachine.SLOT_INPUT+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(ItemCoffee.getIngredientFromStack(newStack) != null){
if(!this.mergeItemStack(newStack, 3, 11, false)){
return null;
return StackUtil.getNull();
}
}
else if(newStack.getItem() == InitItems.itemCoffeeBean){
if(!this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS+1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
@ -51,7 +52,7 @@ public class ContainerCrafter extends Container{
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index){
ItemStack itemstack = null;
ItemStack itemstack = StackUtil.getNull();
Slot slot = this.inventorySlots.get(index);
if(slot != null && slot.getHasStack()){
@ -60,34 +61,34 @@ public class ContainerCrafter extends Container{
if(index == 0){
if(!this.mergeItemStack(itemstack1, 10, 46, true)){
return null;
return StackUtil.getNull();
}
slot.onSlotChange(itemstack1, itemstack);
}
else if(index >= 10 && index < 37){
if(!this.mergeItemStack(itemstack1, 37, 46, false)){
return null;
return StackUtil.getNull();
}
}
else if(index >= 37 && index < 46){
if(!this.mergeItemStack(itemstack1, 10, 37, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(itemstack1, 10, 46, false)){
return null;
return StackUtil.getNull();
}
if(itemstack1.stackSize <= 0){
slot.putStack(null);
if(!StackUtil.isValid(itemstack1)){
slot.putStack(StackUtil.getNull());
}
else{
slot.onSlotChanged();
}
if(itemstack1.stackSize == itemstack.stackSize){
return null;
if(StackUtil.getStackSize(itemstack1) == StackUtil.getStackSize(itemstack)){
return StackUtil.getNull();
}
slot.onPickupFromSlot(player, itemstack1);

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDirectionalBreaker;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -62,33 +63,33 @@ public class ContainerDirectionalBreaker extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemDrillUpgrade;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -26,6 +27,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import java.util.Arrays;
public class ContainerDrill extends Container{
@ -84,39 +87,39 @@ public class ContainerDrill extends Container{
//Shift from Inventory
if(newStack.getItem() instanceof ItemDrillUpgrade || newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaProducer, null))){
if(!this.mergeItemStack(newStack, 0, 5, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override
@ -147,6 +150,10 @@ public class ContainerDrill extends Container{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
public InventoryDrill(){
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
public String getName(){
return "drill";
@ -201,6 +208,7 @@ public class ContainerDrill extends Container{
public void clear(){
int length = this.slots.length;
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
@ -219,35 +227,35 @@ public class ContainerDrill extends Container{
if(i < this.getSizeInventory()){
return this.slots[i];
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
ItemStack stackAt;
if(this.slots[i].stackSize <= j){
if(StackUtil.getStackSize(this.slots[i]) <= j){
stackAt = this.slots[i];
this.slots[i] = null;
this.slots[i] = StackUtil.getNull();
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots[i].splitStack(j);
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
if(StackUtil.getStackSize(this.slots[i]) <= 0){
this.slots[i] = StackUtil.getNull();
}
this.markDirty();
return stackAt;
}
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index];
this.slots[index] = null;
this.slots[index] = StackUtil.getNull();
return stack;
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDropper;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -62,33 +63,33 @@ public class ContainerDropper extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnergizer;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -86,7 +87,7 @@ public class ContainerEnergizer extends Container{
//Slots in Inventory to shift from
if(slot == 1){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -95,39 +96,39 @@ public class ContainerEnergizer extends Container{
//Shift from Inventory
if(newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaConsumer, null))){
if(!this.mergeItemStack(newStack, 0, 1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEnervator;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -85,7 +86,7 @@ public class ContainerEnervator extends Container{
//Slots in Inventory to shift from
if(slot == 1){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -94,39 +95,39 @@ public class ContainerEnervator extends Container{
//Shift from Inventory
if(newStack.getItem() instanceof IEnergyContainerItem || (ActuallyAdditions.teslaLoaded && newStack.hasCapability(TeslaUtil.teslaProducer, null))){
if(!this.mergeItemStack(newStack, 0, 1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -66,39 +67,39 @@ public class ContainerFarmer extends Container{
//Shift from Inventory
if(newStack.getItem() instanceof IPlantable){
if(!this.mergeItemStack(newStack, 0, 6, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFeeder;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -57,33 +58,33 @@ public class ContainerFeeder extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFermentingBarrel;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -53,32 +54,32 @@ public class ContainerFermentingBarrel extends Container{
if(slot >= inventoryStart){
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -24,6 +25,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import java.util.Arrays;
public class ContainerFilter extends Container{
@ -80,32 +83,32 @@ public class ContainerFilter extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize == 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override
@ -140,6 +143,10 @@ public class ContainerFilter extends Container{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
public InventoryFilter(){
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
public String getName(){
return "filter";
@ -194,6 +201,7 @@ public class ContainerFilter extends Container{
public void clear(){
int length = this.slots.length;
this.slots = new ItemStack[length];
Arrays.fill(this.slots, StackUtil.getNull());
}
@Override
@ -212,35 +220,35 @@ public class ContainerFilter extends Container{
if(i < this.getSizeInventory()){
return this.slots[i];
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
ItemStack stackAt;
if(this.slots[i].stackSize <= j){
if(StackUtil.getStackSize(this.slots[i]) <= j){
stackAt = this.slots[i];
this.slots[i] = null;
this.slots[i] = StackUtil.getNull();
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots[i].splitStack(j);
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
if(StackUtil.getStackSize(this.slots[i]) <= 0){
this.slots[i] = StackUtil.getNull();
}
this.markDirty();
return stackAt;
}
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index];
this.slots[index] = null;
this.slots[index] = StackUtil.getNull();
return stack;
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFluidCollector;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -52,7 +53,7 @@ public class ContainerFluidCollector extends Container{
//Slots in Inventory to shift from
if(slot == 1){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -60,32 +61,32 @@ public class ContainerFluidCollector extends Container{
else if(slot >= inventoryStart){
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFurnaceDouble;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -59,7 +60,7 @@ public class ContainerFurnaceDouble extends Container{
//Slots in Inventory to shift from
if(slot == TileEntityFurnaceDouble.SLOT_OUTPUT_1 || slot == TileEntityFurnaceDouble.SLOT_OUTPUT_2){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -69,7 +70,7 @@ public class ContainerFurnaceDouble extends Container{
if(FurnaceRecipes.instance().getSmeltingResult(newStack) != null){
if(!this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_1, TileEntityFurnaceDouble.SLOT_INPUT_1+1, false)){
if(!this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_2, TileEntityFurnaceDouble.SLOT_INPUT_2+1, false)){
return null;
return StackUtil.getNull();
}
}
}
@ -77,32 +78,32 @@ public class ContainerFurnaceDouble extends Container{
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChest;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import invtweaks.api.container.ChestContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -63,33 +64,33 @@ public class ContainerGiantChest extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGrinder;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -65,7 +66,7 @@ public class ContainerGrinder extends Container{
//Slots in Inventory to shift from
if(slot == TileEntityGrinder.SLOT_OUTPUT_1_1 || slot == TileEntityGrinder.SLOT_OUTPUT_1_2 || (this.isDouble && (slot == TileEntityGrinder.SLOT_OUTPUT_2_1 || slot == TileEntityGrinder.SLOT_OUTPUT_2_2))){
if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)){
return null;
return StackUtil.getNull();
}
theSlot.onSlotChange(newStack, currentStack);
}
@ -76,11 +77,11 @@ public class ContainerGrinder extends Container{
if(!this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_1, TileEntityGrinder.SLOT_INPUT_1+1, false)){
if(this.isDouble){
if(!this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_2, TileEntityGrinder.SLOT_INPUT_2+1, false)){
return null;
return StackUtil.getNull();
}
}
else{
return null;
return StackUtil.getNull();
}
}
}
@ -88,32 +89,32 @@ public class ContainerGrinder extends Container{
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiInputter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInputter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -74,33 +75,33 @@ public class ContainerInputter extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -63,32 +64,32 @@ public class ContainerLaserRelayItemWhitelist extends Container{
if(slot >= inventoryStart){
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityMiner;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -62,33 +63,33 @@ public class ContainerMiner extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityOilGenerator;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -52,32 +53,32 @@ public class ContainerOilGenerator extends Container{
if(slot >= inventoryStart){
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomPlacer;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -62,33 +63,33 @@ public class ContainerPhantomPlacer extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityRangedCollector;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -69,33 +70,33 @@ public class ContainerRangedCollector extends Container{
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemRepairer;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -58,39 +59,39 @@ public class ContainerRepairer extends Container{
//Shift from Inventory
if(TileEntityItemRepairer.canBeRepaired(newStack)){
if(!this.mergeItemStack(newStack, TileEntityItemRepairer.SLOT_INPUT, TileEntityItemRepairer.SLOT_INPUT+1, false)){
return null;
return StackUtil.getNull();
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotOutput;
import de.ellpeck.actuallyadditions.mod.items.ItemSolidifiedExperience;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityXPSolidifier;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -58,37 +59,37 @@ public class ContainerXPSolidifier extends Container{
if(slot >= inventoryStart){
if(newStack.getItem() instanceof ItemSolidifiedExperience){
if(!this.mergeItemStack(newStack, 1, 2, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
return StackUtil.getNull();
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
return StackUtil.getNull();
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
if(!StackUtil.isValid(newStack)){
theSlot.putStack(StackUtil.getNull());
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
if(StackUtil.getStackSize(newStack) == StackUtil.getStackSize(currentStack)){
return StackUtil.getNull();
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.inventory.slot;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
@ -39,7 +40,7 @@ public class SlotFilter extends Slot{
else{
if(heldStack != null){
ItemStack stack = heldStack.copy();
stack.stackSize = 1;
stack = StackUtil.setStackSize(stack, 1);
this.putStack(stack);
}
}

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -81,7 +82,7 @@ public class ItemBag extends ItemBase{
filter.readFromNBT(invStack.getTagCompound(), "Filter");
if(filter.check(stack, inventory)){
if(isVoid){
stack.stackSize = 0;
stack = StackUtil.setStackSize(stack, 0);
changed = true;
}
else{
@ -89,21 +90,21 @@ public class ItemBag extends ItemBase{
ItemStack bagStack = inventory[j];
if(bagStack != null){
if(ItemUtil.canBeStacked(bagStack, stack)){
int maxTransfer = Math.min(stack.stackSize, stack.getMaxStackSize()-bagStack.stackSize);
int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack));
if(maxTransfer > 0){
bagStack.stackSize += maxTransfer;
stack.stackSize -= maxTransfer;
inventory[j] = StackUtil.addStackSize(bagStack, maxTransfer);
stack = StackUtil.addStackSize(stack, -maxTransfer);
changed = true;
}
}
}
else{
inventory[j] = stack.copy();
stack.stackSize = 0;
stack = StackUtil.setStackSize(stack, 0);
changed = true;
}
if(stack.stackSize <= 0){
if(!StackUtil.isValid(stack)){
break;
}
}
@ -120,11 +121,12 @@ public class ItemBag extends ItemBase{
}
}
if(stack.stackSize <= 0){
if(!StackUtil.isValid(stack)){
break;
}
}
}
item.setEntityItemStack(stack);
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -71,7 +72,7 @@ public class ItemChestToCrateUpgrade extends ItemBase{
}
if(!player.capabilities.isCreativeMode){
heldStack.stackSize--;
player.setHeldItem(hand, StackUtil.addStackSize(heldStack, -1));
}
}
return EnumActionResult.SUCCESS;

View file

@ -21,6 +21,7 @@ import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaProducer;
@ -105,11 +106,11 @@ public class ItemDrill extends ItemEnergy{
//Places Blocks if the Placing Upgrade is installed
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ){
ItemStack upgrade = this.getHasUpgradeAsStack(stack, ItemDrillUpgrade.UpgradeType.PLACER);
if(upgrade != null){
if(StackUtil.isValid(upgrade)){
int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade);
if(slot >= 0 && slot < InventoryPlayer.getHotbarSize()){
ItemStack anEquip = player.inventory.getStackInSlot(slot);
if(anEquip != null && anEquip != stack){
if(StackUtil.isValid(anEquip) && anEquip != stack){
ItemStack equip = anEquip.copy();
if(!world.isRemote){
//tryPlaceItemIntoWorld could throw an Exception
@ -117,7 +118,7 @@ public class ItemDrill extends ItemEnergy{
//Places the Block into the World
if(equip.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
if(!player.capabilities.isCreativeMode){
player.inventory.setInventorySlotContents(slot, equip.stackSize <= 0 ? null : equip.copy());
player.inventory.setInventorySlotContents(slot, StackUtil.validateCopy(equip));
}
//Synchronizes the Client
player.inventoryContainer.detectAndSendChanges();
@ -149,21 +150,21 @@ public class ItemDrill extends ItemEnergy{
public ItemStack getHasUpgradeAsStack(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade){
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
return null;
return StackUtil.getNull();
}
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT];
loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){
for(ItemStack slotStack : slots){
if(slotStack != null && slotStack.getItem() instanceof ItemDrillUpgrade){
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){
return slotStack;
}
}
}
}
return null;
return StackUtil.getNull();
}
@Override
@ -195,7 +196,7 @@ public class ItemDrill extends ItemEnergy{
loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){
for(ItemStack slotStack : slots){
if(slotStack != null){
if(StackUtil.isValid(slotStack)){
Item item = slotStack.getItem();
int extracted = 0;
@ -352,7 +353,7 @@ public class ItemDrill extends ItemEnergy{
* @return Is the Upgrade applied?
*/
public boolean getHasUpgrade(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade){
return this.getHasUpgradeAsStack(stack, upgrade) != null;
return StackUtil.isValid(this.getHasUpgradeAsStack(stack, upgrade));
}
@Override

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
@ -191,7 +192,7 @@ public class ItemFillingWand extends ItemEnergy{
if(state != null){
Block block = state.getBlock();
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
if(blockStack.getItem() != null){
if(StackUtil.isValid(blockStack)){
display = blockStack.getDisplayName();
}
}
@ -203,13 +204,13 @@ public class ItemFillingWand extends ItemEnergy{
Block block = state.getBlock();
ItemStack stack = new ItemStack(block, 1, block.damageDropped(state));
if(stack != null && stack.getItem() != null){
if(StackUtil.isValid(stack)){
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
ItemStack slot = player.inventory.getStackInSlot(i);
if(slot != null && slot.isItemEqual(stack) && slot.stackSize > 0){
slot.stackSize--;
if(slot.stackSize <= 0){
player.inventory.setInventorySlotContents(i, null);
if(StackUtil.isValid(slot) && slot.isItemEqual(stack)){
slot = StackUtil.addStackSize(slot, -1);
if(!StackUtil.isValid(slot)){
player.inventory.setInventorySlotContents(i, StackUtil.getNull());
}
return true;

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
@ -62,7 +63,7 @@ public class ItemHairyBall extends ItemBase{
entityItem.setPickupDelay(0);
player.worldObj.spawnEntityInWorld(entityItem);
}
stack.stackSize--;
stack = StackUtil.addStackSize(stack, -1);
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, world.rand.nextFloat()*0.1F+0.9F);
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import com.google.common.collect.Multimap;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.inventory.EntityEquipmentSlot;
@ -54,7 +55,6 @@ public class ItemKnife extends ItemBase{
public ItemStack getContainerItem(ItemStack stack){
ItemStack theStack = stack.copy();
theStack.setItemDamage(theStack.getItemDamage()+1);
theStack.stackSize = 1;
return theStack;
return StackUtil.setStackSize(theStack, 1);
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -39,7 +40,7 @@ public class ItemMagnetRing extends ItemEnergy{
if(!items.isEmpty()){
for(EntityItem item : items){
if(!item.isDead && !item.cannotPickup()){
int energyForItem = 350*item.getEntityItem().stackSize;
int energyForItem = 350*StackUtil.getStackSize(item.getEntityItem());
if(this.getEnergyStored(stack) >= energyForItem){
item.onCollideWithPlayer(player);

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
@ -29,7 +30,7 @@ public class ItemResonantRice extends ItemBase{
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!world.isRemote){
stack.stackSize--;
stack = StackUtil.addStackSize(stack, 1);
world.createExplosion(null, player.posX, player.posY, player.posZ, 0.5F, true);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
@ -57,13 +58,13 @@ public class ItemSolidifiedExperience extends ItemBase{
if(!player.isSneaking()){
amount = SOLID_XP_AMOUNT;
if(!player.capabilities.isCreativeMode){
stack.stackSize--;
stack = StackUtil.addStackSize(stack, -1);
}
}
else{
amount = SOLID_XP_AMOUNT*stack.stackSize;
amount = SOLID_XP_AMOUNT*StackUtil.getStackSize(stack);
if(!player.capabilities.isCreativeMode){
stack.stackSize = 0;
stack = StackUtil.setStackSize(stack, 0);
}
}

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList;
@ -85,7 +86,7 @@ public class ItemSpawnerChanger extends ItemBase{
ItemPhantomConnector.clearStorage(stack, "Entity");
if(!player.capabilities.isCreativeMode){
stack.stackSize--;
player.setHeldItem(hand, StackUtil.addStackSize(stack, -1));
}
return EnumActionResult.SUCCESS;

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
@ -44,7 +45,7 @@ public class ItemWaterBowl extends ItemBase{
public void onPlayerInteractEvent(PlayerInteractEvent.RightClickItem event){
if(event.getWorld() != null){
if(ConfigBoolValues.WATER_BOWL.isEnabled()){
if(event.getItemStack() != null && event.getItemStack().getItem() == Items.BOWL){
if(StackUtil.isValid(event.getItemStack()) && event.getItemStack().getItem() == Items.BOWL){
RayTraceResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(event.getWorld(), event.getEntityPlayer(), true, false, false);
ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(event.getEntityPlayer(), event.getWorld(), event.getItemStack(), trace);
if(result == null && trace != null && trace.getBlockPos() != null){
@ -57,10 +58,10 @@ public class ItemWaterBowl extends ItemBase{
if(!event.getWorld().isRemote){
event.getWorld().setBlockState(trace.getBlockPos(), Blocks.AIR.getDefaultState(), 11);
event.getItemStack().stackSize--;
ItemStack reduced = StackUtil.addStackSize(event.getItemStack(), -1);
ItemStack bowl = new ItemStack(InitItems.itemWaterBowl);
if(event.getItemStack().stackSize <= 0){
if(!StackUtil.isValid(reduced)){
event.getEntityPlayer().setHeldItem(event.getHand(), bowl);
}
else if(!event.getEntityPlayer().inventory.addItemStackToInventory(bowl.copy())){

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.entity.EntityWorm;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
@ -50,7 +51,7 @@ public class ItemWorm extends ItemBase{
worm.setPosition(pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5);
world.spawnEntityInWorld(worm);
stack.stackSize--;
player.setHeldItem(hand, StackUtil.addStackSize(stack, -1));
}
return EnumActionResult.SUCCESS;
}

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items.lens;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
@ -36,7 +37,7 @@ public class LensDisruption extends Lens{
ArrayList<EntityItem> items = (ArrayList<EntityItem>)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range));
for(EntityItem item : items){
ItemStack stack = item.getEntityItem();
if(!item.isDead && stack != null){
if(!item.isDead && StackUtil.isValid(stack)){
if(!stack.hasTagCompound() || !stack.getTagCompound().getBoolean(ModUtil.MOD_ID+"DisruptedAlready")){
ItemStack newStack;
@ -48,9 +49,9 @@ public class LensDisruption extends Lens{
newStack = new ItemStack(Block.REGISTRY.getRandomObject(tile.getWorldObject().rand));
}
}
while(newStack == null || newStack.getItem() == null);
while(!StackUtil.isValid(newStack));
newStack.stackSize = stack.stackSize;
newStack = StackUtil.setStackSize(newStack, StackUtil.getStackSize(stack));
if(!newStack.hasTagCompound()){
newStack.setTagCompound(new NBTTagCompound());

View file

@ -25,6 +25,7 @@ import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture;
import de.ellpeck.actuallyadditions.mod.booklet.page.PageTextOnly;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
@ -177,25 +178,25 @@ public class MethodHandler implements IMethodHandler{
ArrayList<EntityItem> items = (ArrayList<EntityItem>)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range));
for(EntityItem item : items){
ItemStack stack = item.getEntityItem();
if(!item.isDead && stack != null){
if(!item.isDead && StackUtil.isValid(stack)){
List<LensConversionRecipe> recipes = LensRecipeHandler.getRecipesFor(stack);
for(LensConversionRecipe recipe : recipes){
if(recipe != null && recipe.type == tile.getLens()){
int itemsPossible = Math.min(tile.getEnergy()/recipe.energyUse, stack.stackSize);
int itemsPossible = Math.min(tile.getEnergy()/recipe.energyUse, StackUtil.getStackSize(stack));
if(itemsPossible > 0){
item.setDead();
if(stack.stackSize-itemsPossible > 0){
if(StackUtil.getStackSize(stack)-itemsPossible > 0){
ItemStack stackCopy = stack.copy();
stackCopy.stackSize -= itemsPossible;
stackCopy = StackUtil.addStackSize(stackCopy, -itemsPossible);
EntityItem inputLeft = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, stackCopy);
tile.getWorldObject().spawnEntityInWorld(inputLeft);
}
ItemStack outputCopy = recipe.outputStack.copy();
outputCopy.stackSize = itemsPossible;
outputCopy = StackUtil.setStackSize(outputCopy, itemsPossible);
EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy);
tile.getWorldObject().spawnEntityInWorld(newItem);
@ -216,21 +217,21 @@ public class MethodHandler implements IMethodHandler{
public boolean addCrusherRecipes(List<ItemStack> inputs, List<ItemStack> outputOnes, int outputOneAmounts, List<ItemStack> outputTwos, int outputTwoAmounts, int outputTwoChance){
boolean hasWorkedOnce = false;
for(ItemStack input : inputs){
if(input != null && CrusherRecipeRegistry.getRecipeFromInput(input) == null){
if(StackUtil.isValid(input) && CrusherRecipeRegistry.getRecipeFromInput(input) == null){
for(ItemStack outputOne : outputOnes){
if(outputOne != null && !CrusherRecipeRegistry.hasBlacklistedOutput(outputOne)){
if(StackUtil.isValid(outputOne) && !CrusherRecipeRegistry.hasBlacklistedOutput(outputOne)){
ItemStack outputOneCopy = outputOne.copy();
outputOneCopy.stackSize = outputOneAmounts;
outputOneCopy = StackUtil.setStackSize(outputOneCopy, outputOneAmounts);
if(outputTwos == null || outputTwos.isEmpty()){
ActuallyAdditionsAPI.addCrusherRecipe(input, outputOneCopy, null, 0);
ActuallyAdditionsAPI.addCrusherRecipe(input, outputOneCopy, StackUtil.getNull(), 0);
hasWorkedOnce = true;
}
else{
for(ItemStack outputTwo : outputTwos){
if(outputTwo != null && !CrusherRecipeRegistry.hasBlacklistedOutput(outputTwo)){
if(StackUtil.isValid(outputTwo) && !CrusherRecipeRegistry.hasBlacklistedOutput(outputTwo)){
ItemStack outputTwoCopy = outputTwo.copy();
outputTwoCopy.stackSize = outputTwoAmounts;
outputTwoCopy = StackUtil.setStackSize(outputTwoCopy, outputTwoAmounts);
ActuallyAdditionsAPI.addCrusherRecipe(input, outputOneCopy, outputTwoCopy, outputTwoChance);
hasWorkedOnce = true;

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
@ -51,9 +52,9 @@ public class FilterSettings{
}
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, int oredict){
if(stack != null){
if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){
if(slots[i] != null){
if(StackUtil.isValid(slots[i])){
if(areEqualEnough(slots[i], stack, meta, nbt, oredict)){
return whitelist;
}
@ -62,7 +63,7 @@ public class FilterSettings{
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){
for(ItemStack filterSlot : filterSlots){
if(filterSlot != null && areEqualEnough(filterSlot, stack, meta, nbt, oredict)){
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, oredict)){
return whitelist;
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.IGrowable;
import net.minecraft.item.Item;
@ -40,7 +41,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
}
public static boolean isValidItem(ItemStack stack){
if(stack != null){
if(StackUtil.isValid(stack)){
Item item = stack.getItem();
if(isValid(item)){
return true;
@ -66,7 +67,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
for(int i = 0; i < this.slots.length; i++){
ItemStack stack = this.slots[i];
if(stack != null){
if(StackUtil.isValid(stack)){
Item item = stack.getItem();
if(isValidItem(stack) && (types == null || !types.contains(item))){
if(types == null){
@ -74,10 +75,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
}
types.add(item);
stack.stackSize--;
if(stack.stackSize <= 0){
this.slots[i] = null;
}
this.slots[i] = StackUtil.addStackSize(stack, -1);
}
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
@ -100,8 +101,8 @@ 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(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
if(!StackUtil.isValid(this.slots[theSlot])){
this.slots[theSlot] = StackUtil.getNull();
}
}
}

View file

@ -14,6 +14,7 @@ import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -91,10 +92,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
if(this.currentProcessTime >= TIME){
this.currentProcessTime = 0;
this.slots[0].stackSize--;
if(this.slots[0].stackSize == 0){
this.slots[0] = null;
}
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.markDirty();
@ -119,7 +117,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC
}
public boolean isCanola(int slot){
return this.slots[slot] != null && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal();
return StackUtil.isValid(this.slots[slot]) && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal();
}
@Override

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
@ -73,15 +74,12 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
this.storage.receiveEnergy(PRODUCE, false);
}
if(this.currentBurnTime <= 0 && this.slots[0] != null && TileEntityFurnace.getItemBurnTime(this.slots[0]) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
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]);
this.maxBurnTime = burnTime;
this.currentBurnTime = burnTime;
this.slots[0].stackSize--;
if(this.slots[0].stackSize == 0){
this.slots[0] = this.slots[0].getItem().getContainerItem(this.slots[0]);
}
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
}
if(flag != this.currentBurnTime > 0){

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.items.ItemCoffee;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -132,10 +133,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
if(this.slots[SLOT_COFFEE_BEANS] != null && this.slots[SLOT_COFFEE_BEANS].getItem() == InitItems.itemCoffeeBean){
int toAdd = 2;
if(toAdd <= COFFEE_CACHE_MAX_AMOUNT-this.coffeeCacheAmount){
this.slots[SLOT_COFFEE_BEANS].stackSize--;
if(this.slots[SLOT_COFFEE_BEANS].stackSize <= 0){
this.slots[SLOT_COFFEE_BEANS] = null;
}
this.slots[SLOT_COFFEE_BEANS] = StackUtil.addStackSize(this.slots[SLOT_COFFEE_BEANS], -1);
this.coffeeCacheAmount += toAdd;
}
}
@ -143,7 +141,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
public void brew(){
if(!this.worldObj.isRemote){
if(this.slots[SLOT_INPUT] != null && this.slots[SLOT_INPUT].getItem() == InitItems.itemMisc && this.slots[SLOT_INPUT].getItemDamage() == TheMiscItems.CUP.ordinal() && this.slots[SLOT_OUTPUT] == null && this.coffeeCacheAmount >= CACHE_USE && this.tank.getFluid() != null && this.tank.getFluid().getFluid() == FluidRegistry.WATER && this.tank.getFluidAmount() >= WATER_USE){
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(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);
@ -155,23 +153,17 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
this.brewTime = 0;
ItemStack output = new ItemStack(InitItems.itemCoffee);
for(int i = 3; i < this.slots.length; i++){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
CoffeeIngredient ingredient = ItemCoffee.getIngredientFromStack(this.slots[i]);
if(ingredient != null){
if(ingredient.effect(output)){
this.slots[i].stackSize--;
if(this.slots[i].stackSize <= 0){
this.slots[i] = this.slots[i].getItem().getContainerItem(this.slots[i]);
}
this.slots[i] = StackUtil.addStackSize(this.slots[i], 1);
}
}
}
}
this.slots[SLOT_OUTPUT] = output.copy();
this.slots[SLOT_INPUT].stackSize--;
if(this.slots[SLOT_INPUT].stackSize <= 0){
this.slots[SLOT_INPUT] = null;
}
this.slots[SLOT_INPUT] = StackUtil.addStackSize(this.slots[SLOT_INPUT], -1);
this.coffeeCacheAmount -= CACHE_USE;
this.tank.drainInternal(WATER_USE, true);
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@ -62,9 +63,9 @@ public class TileEntityCompost extends TileEntityInventoryBase{
if(!this.worldObj.isRemote){
boolean theFlag = this.conversionTime > 0;
if(this.slots[0] != null){
if(StackUtil.isValid(this.slots[0])){
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
if(recipe != null && this.slots[0].isItemEqual(recipe.input) && this.slots[0].stackSize >= recipe.input.stackSize){
if(recipe != null && this.slots[0].isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots[0]) >= StackUtil.getStackSize(recipe.input)){
this.conversionTime++;
if(this.conversionTime >= 3000){
this.slots[0] = recipe.output.copy();
@ -98,8 +99,8 @@ public class TileEntityCompost extends TileEntityInventoryBase{
public int getInventoryStackLimit(){
if(this.slots[0] != null){
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
if(recipe != null && recipe.input != null){
return recipe.input.stackSize;
if(recipe != null && StackUtil.isValid(recipe.input)){
return StackUtil.getStackSize(recipe.input);
}
}
return super.getInventoryStackLimit();

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -42,26 +43,26 @@ public class TileEntityDistributorItem extends TileEntityInventoryBase{
for(int i = 0; i < handlerUp.getSlots(); i++){
ItemStack pullable = handlerUp.extractItem(i, 1, true);
if(pullable != null && (this.slots[0] == null || ItemUtil.canBeStacked(this.slots[0], pullable))){
if(StackUtil.isValid(pullable) && (!StackUtil.isValid(this.slots[0]) || ItemUtil.canBeStacked(this.slots[0], pullable))){
ItemStack pulled = handlerUp.extractItem(i, 1, false);
if(pulled != null){
if(this.slots[0] == null){
if(StackUtil.isValid(pulled)){
if(!StackUtil.isValid(this.slots[0])){
this.slots[0] = pulled.copy();
}
else{
this.slots[0].stackSize += pulled.stackSize;
this.slots[0] = StackUtil.addStackSize(this.slots[0], StackUtil.getStackSize(pulled));
}
shouldMarkDirty = true;
}
}
if(this.slots[0] != null && this.slots[0].stackSize >= this.slots[0].getMaxStackSize()){
if(StackUtil.isValid(this.slots[0]) && StackUtil.getStackSize(this.slots[0]) >= this.slots[0].getMaxStackSize()){
break;
}
}
}
if(!this.handlersAround.isEmpty() && (!this.handlersAround.containsKey(EnumFacing.UP) || this.handlersAround.size() >= 2) && this.slots[0] != null){
if(!this.handlersAround.isEmpty() && (!this.handlersAround.containsKey(EnumFacing.UP) || this.handlersAround.size() >= 2) && StackUtil.isValid(this.slots[0])){
EnumFacing[] allFacings = EnumFacing.values();
do{
this.putSide++;
@ -76,33 +77,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 = this.slots[0].stackSize/aroundAmount;
int amount = StackUtil.getStackSize(this.slots[0])/aroundAmount;
if(amount <= 0){
amount = this.slots[0].stackSize;
amount = StackUtil.getStackSize(this.slots[0]);
}
if(amount > 0){
ItemStack toInsert = this.slots[0].copy();
toInsert.stackSize = amount;
toInsert = StackUtil.setStackSize(toInsert, amount);
for(int i = 0; i < handler.getSlots(); i++){
ItemStack notInserted = handler.insertItem(i, toInsert.copy(), false);
if(notInserted == null){
this.slots[0].stackSize -= amount;
if(!StackUtil.isValid(notInserted)){
this.slots[0] = StackUtil.addStackSize(this.slots[0], -amount);
shouldMarkDirty = true;
break;
}
else if(notInserted.stackSize != this.slots[0].stackSize){
this.slots[0].stackSize -= notInserted.stackSize;
else if(StackUtil.getStackSize(notInserted) != StackUtil.getStackSize(this.slots[0])){
this.slots[0] = StackUtil.addStackSize(this.slots[0], -StackUtil.getStackSize(notInserted));
toInsert = notInserted;
shouldMarkDirty = true;
}
}
if(this.slots[0].stackSize <= 0){
this.slots[0] = null;
if(!StackUtil.isValid(this.slots[0])){
this.slots[0] = StackUtil.getNull();
shouldMarkDirty = true;
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
@ -64,9 +65,9 @@ public class TileEntityDropper extends TileEntityInventoryBase{
}
private void doWork(){
if(this.removeFromInventory(false) != null){
if(StackUtil.isValid(this.removeFromInventory(false))){
ItemStack stack = this.removeFromInventory(true);
stack.stackSize = 1;
stack = StackUtil.setStackSize(stack, 1);
IBlockState state = this.worldObj.getBlockState(this.pos);
WorldUtil.dropItemAtSide(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)), this.worldObj, this.pos, stack);
}
@ -74,19 +75,16 @@ public class TileEntityDropper extends TileEntityInventoryBase{
public ItemStack removeFromInventory(boolean actuallyDo){
for(int i = 0; i < this.slots.length; i++){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
ItemStack slot = this.slots[i].copy();
if(actuallyDo){
this.slots[i].stackSize--;
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
}
this.slots[i] = StackUtil.addStackSize(this.slots[i], -1);
this.markDirty();
}
return slot;
}
}
return null;
return StackUtil.getNull();
}
@Override

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer;
import net.darkhax.tesla.api.ITeslaHolder;
@ -47,7 +48,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.slots[0] != null && this.slots[1] == null){
if(StackUtil.isValid(this.slots[0]) && !StackUtil.isValid(this.slots[1])){
if(this.storage.getEnergyStored() > 0){
int received = 0;
boolean canTakeUp = false;
@ -77,10 +78,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus
if(canTakeUp){
this.slots[1] = this.slots[0].copy();
this.slots[0].stackSize--;
if(this.slots[0].stackSize <= 0){
this.slots[0] = null;
}
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
}
}
}

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaHolder;
import net.darkhax.tesla.api.ITeslaProducer;
@ -47,7 +48,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.slots[0] != null && this.slots[1] == null){
if(StackUtil.isValid(this.slots[0]) && !StackUtil.isValid(this.slots[1])){
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int extracted = 0;
boolean canTakeUp = false;
@ -78,10 +79,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
if(canTakeUp){
this.slots[1] = this.slots[0].copy();
this.slots[0].stackSize--;
if(this.slots[0].stackSize <= 0){
this.slots[0] = null;
}
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
}
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.init.Items;
@ -73,16 +74,13 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
if(this.currentAnimalAmount < THRESHOLD){
if(this.currentTimer >= TIME){
this.currentTimer = 0;
if(this.slots[0] != null){
if(StackUtil.isValid(this.slots[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))){
this.feedAnimal(randomAnimal);
this.slots[0].stackSize--;
if(this.slots[0].stackSize == 0){
this.slots[0] = this.slots[0].getItem().getContainerItem(this.slots[0]);
}
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
}
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
@ -88,8 +89,8 @@ public class TileEntityFishingNet extends TileEntityBase{
for(int i = 0; i < cap.getSlots(); i++){
stack = cap.insertItem(i, stack, false);
if(stack == null || stack.stackSize <= 0){
return null;
if(!StackUtil.isValid(stack)){
return StackUtil.getNull();
}
}
}

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -48,27 +49,26 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
ItemStack first = slots[slot1];
ItemStack second = slots[slot2];
if(first != null || second != null){
ItemStack toSplit = null;
if(first == null && second != null){
if(StackUtil.isValid(first) || StackUtil.isValid(second)){
ItemStack toSplit = StackUtil.getNull();
if(!StackUtil.isValid(first) && StackUtil.isValid(second)){
toSplit = second;
}
else if(second == null && first != null){
else if(!StackUtil.isValid(second) && StackUtil.isValid(first)){
toSplit = first;
}
else if(ItemUtil.canBeStacked(first, second)){
if(first.stackSize < first.getMaxStackSize() || second.stackSize < second.getMaxStackSize()){
if(!((first.stackSize <= second.stackSize+1 && first.stackSize >= second.stackSize-1) || (second.stackSize <= first.stackSize+1 && second.stackSize >= first.stackSize-1))){
if(StackUtil.getStackSize(first) < first.getMaxStackSize() || StackUtil.getStackSize(second) < second.getMaxStackSize()){
if(!((StackUtil.getStackSize(first) <= StackUtil.getStackSize(second)+1 && StackUtil.getStackSize(first) >= StackUtil.getStackSize(second)-1) || (StackUtil.getStackSize(second) <= StackUtil.getStackSize(first)+1 && StackUtil.getStackSize(second) >= StackUtil.getStackSize(first)-1))){
toSplit = first;
toSplit.stackSize += second.stackSize;
toSplit = StackUtil.addStackSize(toSplit, StackUtil.getStackSize(second));
}
}
}
if(toSplit != null && toSplit.stackSize > 1){
if(StackUtil.isValid(toSplit)){
ItemStack splitFirst = toSplit.copy();
ItemStack secondSplit = splitFirst.splitStack(splitFirst.stackSize/2);
ItemStack secondSplit = splitFirst.splitStack(StackUtil.getStackSize(splitFirst)/2);
slots[slot1] = splitFirst;
slots[slot2] = secondSplit;
}
@ -168,32 +168,28 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
}
public boolean canSmeltOn(int theInput, int theOutput){
if(this.slots[theInput] != null){
if(StackUtil.isValid(this.slots[theInput])){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]);
if(this.slots[theInput] != null){
if(output != null){
if(this.slots[theOutput] == null || (this.slots[theOutput].isItemEqual(output) && this.slots[theOutput].stackSize <= this.slots[theOutput].getMaxStackSize()-output.stackSize)){
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))){
return true;
}
}
}
}
return false;
}
public void finishBurning(int theInput, int theOutput){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots[theInput]);
if(this.slots[theOutput] == null){
if(!StackUtil.isValid(this.slots[theOutput])){
this.slots[theOutput] = output.copy();
}
else if(this.slots[theOutput].getItem() == output.getItem()){
this.slots[theOutput].stackSize += output.stackSize;
this.slots[theOutput] = StackUtil.addStackSize(this.slots[theOutput], StackUtil.getStackSize(output));
}
this.slots[theInput].stackSize--;
if(this.slots[theInput].stackSize <= 0){
this.slots[theInput] = null;
}
this.slots[theInput] = StackUtil.addStackSize(this.slots[theInput], -1);
}
@SideOnly(Side.CLIENT)

View file

@ -15,6 +15,7 @@ import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -184,17 +185,17 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
}
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){
if(this.slots[theInput] != null){
if(StackUtil.isValid(this.slots[theInput])){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]);
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]);
if(outputOne != null){
if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0);
}
if(outputTwo != null && outputTwo.getItemDamage() == Util.WILDCARD){
if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){
outputTwo.setItemDamage(0);
}
if((this.slots[theFirstOutput] == null || (this.slots[theFirstOutput].isItemEqual(outputOne) && this.slots[theFirstOutput].stackSize <= this.slots[theFirstOutput].getMaxStackSize()-outputOne.stackSize)) && (outputTwo == null || (this.slots[theSecondOutput] == null || (this.slots[theSecondOutput].isItemEqual(outputTwo) && this.slots[theSecondOutput].stackSize <= this.slots[theSecondOutput].getMaxStackSize()-outputTwo.stackSize)))){
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))))){
return true;
}
}
@ -208,38 +209,35 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]);
if(outputOne != null){
if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0);
}
if(this.slots[theFirstOutput] == null){
if(!StackUtil.isValid(this.slots[theFirstOutput])){
this.slots[theFirstOutput] = outputOne.copy();
}
else if(this.slots[theFirstOutput].getItem() == outputOne.getItem()){
this.slots[theFirstOutput].stackSize += outputOne.stackSize;
this.slots[theFirstOutput] = StackUtil.addStackSize(this.slots[theFirstOutput], StackUtil.getStackSize(outputOne));
}
}
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]);
if(outputTwo != null){
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(this.slots[theSecondOutput] == null){
if(!StackUtil.isValid(this.slots[theSecondOutput])){
this.slots[theSecondOutput] = outputTwo.copy();
}
else if(this.slots[theSecondOutput].getItem() == outputTwo.getItem()){
this.slots[theSecondOutput].stackSize += outputTwo.stackSize;
this.slots[theSecondOutput] = StackUtil.addStackSize(this.slots[theSecondOutput], StackUtil.getStackSize(outputTwo));
}
}
}
this.slots[theInput].stackSize--;
if(this.slots[theInput].stackSize <= 0){
this.slots[theInput] = null;
}
this.slots[theInput] = StackUtil.addStackSize(this.slots[theInput], -1);
}
@SideOnly(Side.CLIENT)

View file

@ -14,6 +14,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@ -121,194 +122,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
return false;
}
/**
* Pulls Items from the specified Slots on the specified Side
*/
private void pull(){
if(this.newPulling() || !(this.placeToPull instanceof IInventory)){
return;
}
//The Inventory to pull from
IInventory theInventory = (IInventory)this.placeToPull;
//Does the Inventory even have Slots!?
if(theInventory.getSizeInventory() > 0){
//The slot currently pulling from (for later)
int theSlotToPull = this.slotToPullStart;
//The amount of Items that can fit into one slot of the inventory
int maxSize = theInventory.getInventoryStackLimit();
//If the Inventory is ISided, deal with that
ISidedInventory theSided = null;
if(theInventory instanceof ISidedInventory){
theSided = (ISidedInventory)theInventory;
}
//If can be pulled (for later)
boolean can = false;
//The Stack that is pulled (for later)
ItemStack theStack = null;
//Go through all of the specified Slots
for(int i = Math.max(theSlotToPull, 0); i < Math.min(this.slotToPullEnd, theInventory.getSizeInventory()); i++){
//Temporary Stack for storage
ItemStack tempStack = theInventory.getStackInSlot(i);
if(tempStack != null){
//Set maxSize to the max Size of the temporary stack if it's smaller than the Inventory's Max Size
if(tempStack.getMaxStackSize() < this.getInventoryStackLimit()){
maxSize = tempStack.getMaxStackSize();
}
else{
maxSize = this.getInventoryStackLimit();
}
}
//If ESD has enough Space & Item in question is on whitelist
if(tempStack != null && (this.slots[0] == null || (ItemUtil.canBeStacked(tempStack, this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkBothFilters(tempStack, false)){
//Deal with ISided
if(theSided != null){
//Check if Item can be inserted from any Side (Because Sidedness gets ignored!)
for(int j = 0; j <= 5; j++){
if(theSided.canExtractItem(i, tempStack, EnumFacing.values()[j])){
theStack = tempStack;
theSlotToPull = i;
can = true;
break;
}
}
}
//Deal with IInventory
else{
theStack = tempStack;
theSlotToPull = i;
can = true;
}
}
//Stop if it can already pull
if(can){
break;
}
}
//If pull can be done
if(can){
//If ESD already has Items
if(this.slots[0] != null){
if(ItemUtil.canBeStacked(theStack, this.slots[0])){
//If the StackSize is smaller than the space the ESD has left
if(theStack.stackSize <= maxSize-this.slots[0].stackSize){
this.slots[0].stackSize += theStack.stackSize;
theInventory.setInventorySlotContents(theSlotToPull, null);
}
//If the StackSize is bigger than what fits into the Inventory
else if(theStack.stackSize > maxSize-this.slots[0].stackSize){
theInventory.decrStackSize(theSlotToPull, maxSize-this.slots[0].stackSize);
this.slots[0].stackSize = maxSize;
}
}
}
//If ESD is empty
else{
ItemStack toBePut = theStack.copy();
if(maxSize < toBePut.stackSize){
toBePut.stackSize = maxSize;
}
//Actually puts the Item
this.setInventorySlotContents(0, toBePut);
//Removes the Item from the inventory getting pulled from
if(theStack.stackSize == toBePut.stackSize){
theInventory.setInventorySlotContents(theSlotToPull, null);
}
else{
theInventory.decrStackSize(theSlotToPull, toBePut.stackSize);
}
}
}
}
}
/**
* Puts Items into the specified Slots at the specified Side
* (Check pull() for Description, similar to this)
*/
private void put(){
if(this.newPutting() || !(this.placeToPut instanceof IInventory)){
return;
}
IInventory theInventory = (IInventory)this.placeToPut;
if(theInventory.getSizeInventory() > 0){
int theSlotToPut = this.slotToPutStart;
int maxSize = theInventory.getInventoryStackLimit();
ISidedInventory theSided = null;
if(theInventory instanceof ISidedInventory){
theSided = (ISidedInventory)theInventory;
}
boolean can = false;
if(this.slots[0] != null){
ItemStack theStack = null;
for(int i = Math.max(theSlotToPut, 0); i < Math.min(this.slotToPutEnd, theInventory.getSizeInventory()); i++){
ItemStack tempStack = theInventory.getStackInSlot(i);
if(tempStack != null){
if(tempStack.getMaxStackSize() < theInventory.getInventoryStackLimit()){
maxSize = tempStack.getMaxStackSize();
}
else{
maxSize = theInventory.getInventoryStackLimit();
}
}
if(theInventory.isItemValidForSlot(i, this.slots[0]) && (tempStack == null || (ItemUtil.canBeStacked(tempStack, this.slots[0]) && tempStack.stackSize < maxSize)) && this.checkBothFilters(this.slots[0], true)){
if(theSided != null){
for(int j = 0; j <= 5; j++){
if(theSided.canInsertItem(i, this.slots[0], EnumFacing.values()[j])){
theStack = tempStack;
theSlotToPut = i;
can = true;
break;
}
}
}
else{
theStack = tempStack;
theSlotToPut = i;
can = true;
}
}
if(can){
break;
}
}
if(can){
if(theStack != null){
ItemStack copiedStack = theStack.copy();
if(ItemUtil.canBeStacked(copiedStack, this.slots[0])){
if(this.slots[0].stackSize <= maxSize-copiedStack.stackSize){
copiedStack.stackSize += this.slots[0].stackSize;
this.slots[0] = null;
theInventory.setInventorySlotContents(theSlotToPut, copiedStack);
}
else if(this.slots[0].stackSize > maxSize-copiedStack.stackSize){
this.decrStackSize(0, maxSize-copiedStack.stackSize);
copiedStack.stackSize = maxSize;
theInventory.setInventorySlotContents(theSlotToPut, copiedStack);
}
}
}
else{
ItemStack toBePut = this.slots[0].copy();
if(maxSize < toBePut.stackSize){
toBePut.stackSize = maxSize;
}
theInventory.setInventorySlotContents(theSlotToPut, toBePut);
if(this.slots[0].stackSize == toBePut.stackSize){
this.slots[0] = null;
}
else{
this.decrStackSize(0, toBePut.stackSize);
}
}
}
}
}
}
/**
* Checks if one of the filters contains the ItemStack
*
@ -455,10 +268,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if(!this.isRedstonePowered){
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
if(this.sideToPull != -1 && this.placeToPull != null){
this.pull();
this.newPulling();
}
if(this.slots[0] != null && this.sideToPut != -1 && this.placeToPut != null){
this.put();
if(StackUtil.isValid(this.slots[0]) && this.sideToPut != -1 && this.placeToPut != null){
this.newPutting();
}
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@ -20,6 +21,8 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import java.util.Arrays;
public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{
private final SidedInvWrapper[] invWrappers = new SidedInvWrapper[6];
@ -29,6 +32,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
super(name);
this.slots = new ItemStack[slots];
Arrays.fill(this.slots, StackUtil.getNull());
if(this.hasInvWrapperCapabilities()){
this.getInvWrappers(this.invWrappers);
@ -40,7 +44,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
NBTTagList tagList = new NBTTagList();
for(ItemStack slot : slots){
NBTTagCompound tagCompound = new NBTTagCompound();
if(slot != null){
if(StackUtil.isValid(slot)){
slot.writeToNBT(tagCompound);
}
tagList.appendTag(tagCompound);
@ -54,7 +58,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
NBTTagList tagList = compound.getTagList("Items", 10);
for(int i = 0; i < slots.length; i++){
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
slots[i] = tagCompound != null && tagCompound.hasKey("id") ? ItemStack.loadItemStackFromNBT(tagCompound) : null;
slots[i] = tagCompound != null && tagCompound.hasKey("id") ? ItemStack.loadItemStackFromNBT(tagCompound) : StackUtil.getNull();
}
}
}
@ -159,35 +163,35 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
if(i < this.getSizeInventory()){
return this.slots[i];
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.slots[i] != null){
if(StackUtil.isValid(this.slots[i])){
ItemStack stackAt;
if(this.slots[i].stackSize <= j){
if(StackUtil.getStackSize(this.slots[i]) <= j){
stackAt = this.slots[i];
this.slots[i] = null;
this.slots[i] = StackUtil.getNull();
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots[i].splitStack(j);
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
if(StackUtil.getStackSize(this.slots[i]) <= 0){
this.slots[i] = StackUtil.getNull();
}
this.markDirty();
return stackAt;
}
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index];
this.slots[index] = null;
this.slots[index] = StackUtil.getNull();
return stack;
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -59,7 +60,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate){
ItemStack stackIn = TileEntityItemViewer.this.getStackInSlot(slot);
if(stackIn != null){
if(StackUtil.isValid(stackIn)){
if(TileEntityItemViewer.this.canExtractItem(slot, stackIn, direction)){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null){
@ -150,8 +151,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
if(handler != null){
if(this.isWhitelisted(handler, stack, true)){
if(ItemStack.areItemsEqual(handler.handler.getStackInSlot(handler.switchedIndex), stack)){
ItemStack gaveBack = handler.handler.extractItem(handler.switchedIndex, stack.stackSize, true);
return gaveBack != null;
ItemStack gaveBack = handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stack), true);
return StackUtil.isValid(gaveBack);
}
}
}
@ -195,8 +196,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
if(handler != null){
ItemStack toInsert = stack.copy();
ItemStack inSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(inSlot != null){
toInsert.stackSize -= inSlot.stackSize;
if(StackUtil.isValid(inSlot)){
toInsert = StackUtil.addStackSize(toInsert, -StackUtil.getStackSize(inSlot));
}
handler.handler.insertItem(handler.switchedIndex, toInsert, false);
}
@ -243,8 +244,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){
ItemStack stackInSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(stackInSlot != null){
handler.handler.extractItem(handler.switchedIndex, stackInSlot.stackSize, false);
if(StackUtil.isValid(stackInSlot)){
handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stackInSlot), false);
}
return stackInSlot;
}

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -22,6 +23,8 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.items.IItemHandler;
import java.util.Arrays;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
public final IInventory filterInventory;
@ -32,6 +35,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
public TileEntityLaserRelayItemWhitelist(){
super("laserRelayItemWhitelist");
Arrays.fill(this.slots, StackUtil.getNull());
this.filterInventory = new IInventory(){
private TileEntityLaserRelayItemWhitelist tile;
@ -91,6 +95,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
public void clear(){
int length = this.tile.slots.length;
this.tile.slots = new ItemStack[length];
Arrays.fill(this.tile.slots, StackUtil.getNull());
}
@Override
@ -109,35 +114,35 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
if(i < this.getSizeInventory()){
return this.tile.slots[i];
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.tile.slots[i] != null){
if(StackUtil.isValid(this.tile.slots[i])){
ItemStack stackAt;
if(this.tile.slots[i].stackSize <= j){
if(StackUtil.getStackSize(this.tile.slots[i]) <= j){
stackAt = this.tile.slots[i];
this.tile.slots[i] = null;
this.tile.slots[i] = StackUtil.getNull();
this.markDirty();
return stackAt;
}
else{
stackAt = this.tile.slots[i].splitStack(j);
if(this.tile.slots[i].stackSize <= 0){
this.tile.slots[i] = null;
if(StackUtil.getStackSize(this.tile.slots[i]) <= 0){
this.tile.slots[i] = StackUtil.getNull();
}
this.markDirty();
return stackAt;
}
}
return null;
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.tile.slots[index];
this.tile.slots[index] = null;
this.tile.slots[index] = StackUtil.getNull();
return stack;
}
@ -205,13 +210,13 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
for(IItemHandler handler : this.handlersAround.values()){
for(int i = 0; i < handler.getSlots(); i++){
ItemStack stack = handler.getStackInSlot(i);
if(stack != null){
if(StackUtil.isValid(stack)){
ItemStack copy = stack.copy();
copy.stackSize = 1;
copy = StackUtil.setStackSize(copy, 1);
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectOredict)){
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
if(this.slots[k] != null){
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]);
@ -219,7 +224,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
boolean did = false;
if(filterSlots != null && filterSlots.length > 0){
for(int j = 0; j < filterSlots.length; j++){
if(filterSlots[j] == null || filterSlots[j].stackSize <= 0){
if(!StackUtil.isValid(filterSlots[j])){
filterSlots[j] = copy;
did = true;
break;

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@ -148,8 +149,8 @@ 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(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
if(!StackUtil.isValid(this.slots[theSlot])){
this.slots[theSlot] = StackUtil.getNull();
}
}
}

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemSolidifiedExperience;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -122,15 +123,15 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.amount > 0){
if(this.slots[0] == null){
if(!StackUtil.isValid(this.slots[0])){
int toSet = this.amount > 64 ? 64 : this.amount;
this.slots[0] = new ItemStack(InitItems.itemSolidifiedExperience, toSet);
this.amount -= toSet;
}
else if(this.slots[0].stackSize < 64){
int needed = 64-this.slots[0].stackSize;
else if(StackUtil.getStackSize(this.slots[0]) < 64){
int needed = 64-StackUtil.getStackSize(this.slots[0]);
int toAdd = this.amount > needed ? needed : this.amount;
this.slots[0].stackSize += toAdd;
this.slots[0] = StackUtil.addStackSize(this.slots[0], toAdd);
this.amount -= toAdd;
}
}
@ -153,8 +154,8 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
}
}
if(this.slots[1] != null && this.slots[1].getItem() instanceof ItemSolidifiedExperience){
this.amount += this.slots[1].stackSize;
if(StackUtil.isValid(this.slots[1]) && this.slots[1].getItem() instanceof ItemSolidifiedExperience){
this.amount += StackUtil.getStackSize(this.slots[1]);
this.slots[1] = null;
}

View file

@ -0,0 +1,68 @@
/*
* This file ("StackUtil.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.item.ItemStack;
public final class StackUtil{
public static ItemStack validateCopy(ItemStack stack){
if(isValid(stack)){
return stack.copy();
}
else{
return getNull();
}
}
public static ItemStack validateCheck(ItemStack stack){
if(isValid(stack)){
return stack;
}
else{
return getNull();
}
}
public static boolean isValid(ItemStack stack){
return stack != null && !ItemStack.areItemStacksEqual(stack, getNull()) && stack.stackSize > 0 && stack.getItem() != null;
}
public static ItemStack getNull(){
return null;
}
public static int getStackSize(ItemStack stack){
if(!isValid(stack)){
return 0;
}
else{
return stack.stackSize;
}
}
public static ItemStack setStackSize(ItemStack stack, int size){
if(size <= 0){
if(isValid(stack)){
return stack.getItem().getContainerItem(stack);
}
else{
return getNull();
}
}
stack.stackSize = size;
return stack;
}
public static ItemStack addStackSize(ItemStack stack, int size){
return setStackSize(stack, getStackSize(stack)+size);
}
}

View file

@ -63,7 +63,7 @@ public final class WorldUtil{
if(theoreticalExtract != null){
ItemStack remaining = insertCap.insertItem(slotInsert, theoreticalExtract, false);
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){
int toExtract = remaining == null ? theoreticalExtract.stackSize : theoreticalExtract.stackSize-remaining.stackSize;
int toExtract = remaining == null ? StackUtil.getStackSize(theoreticalExtract) : StackUtil.getStackSize(theoreticalExtract)-StackUtil.getStackSize(remaining);
extractCap.extractItem(slotExtract, toExtract, false);
return true;
}
@ -141,7 +141,7 @@ public final class WorldUtil{
}
public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){
if(world instanceof WorldServer && stack != null && stack.getItem() != null && pos != null){
if(world instanceof WorldServer && StackUtil.isValid(stack) && pos != null){
BlockPos offsetPos = pos.offset(side);
IBlockState state = world.getBlockState(offsetPos);
Block block = state.getBlock();
@ -173,16 +173,14 @@ public final class WorldUtil{
//Redstone
if(replaceable && stack.getItem() == Items.REDSTONE){
world.setBlockState(offsetPos, Blocks.REDSTONE_WIRE.getDefaultState(), 2);
stack.stackSize--;
return stack;
return StackUtil.addStackSize(stack, -1);
}
//Plants
if(replaceable && stack.getItem() instanceof IPlantable){
if(((IPlantable)stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)){
if(world.setBlockState(offsetPos, ((IPlantable)stack.getItem()).getPlant(world, offsetPos), 2)){
stack.stackSize--;
return stack;
return StackUtil.addStackSize(stack, -1);
}
}
}
@ -278,12 +276,12 @@ public final class WorldUtil{
for(int i = start; i < end; i++){
if(shouldAlwaysWork || ((!(inventory instanceof ISidedInventory) || ((ISidedInventory)inventory).canInsertItem(i, stackToPutIn, side)) && inventory.isItemValidForSlot(i, stackToPutIn))){
ItemStack stackInQuestion = inventory.getStackInSlot(i);
if(stackToPutIn != null && (stackInQuestion == null || (ItemUtil.canBeStacked(stackInQuestion, stackToPutIn) && stackInQuestion.getMaxStackSize() >= stackInQuestion.stackSize+stackToPutIn.stackSize))){
if(stackInQuestion == null){
if(StackUtil.isValid(stackToPutIn) && (!StackUtil.isValid(stackInQuestion) || (ItemUtil.canBeStacked(stackInQuestion, stackToPutIn) && stackInQuestion.getMaxStackSize() >= StackUtil.getStackSize(stackInQuestion)+StackUtil.getStackSize(stackToPutIn)))){
if(!StackUtil.isValid(stackInQuestion)){
inventory.setInventorySlotContents(i, stackToPutIn.copy());
}
else{
stackInQuestion.stackSize += stackToPutIn.stackSize;
inventory.setInventorySlotContents(i, StackUtil.addStackSize(stackInQuestion, StackUtil.getStackSize(stackToPutIn)));
}
working++;
@ -402,7 +400,7 @@ public final class WorldUtil{
block.onBlockDestroyedByPlayer(world, pos, state);
}
if(stack.stackSize <= 0 && stack == player.getHeldItemMainhand()){
if(StackUtil.getStackSize(stack) <= 0 && stack == player.getHeldItemMainhand()){
ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}