Dropped IInventory support.

This took ages.
This commit is contained in:
Ellpeck 2016-12-04 00:10:52 +01:00
parent e3cb04ea3a
commit c7697b5665
89 changed files with 851 additions and 1463 deletions

View file

@ -163,7 +163,6 @@ public final class ActuallyAdditionsAPI{
/**
* Adds a new conversion recipe to the compost.
* StackSize is regarded on both input and output and they can be different.
*
* @param input The itemstack to be input into the compost
* @param inputDisplay The block to display when there is input in the compost

View file

@ -75,10 +75,10 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
if(reconstructor != null){
if(StackUtil.isValid(heldItem)){
Item item = heldItem.getItem();
if(item instanceof ILensItem && !StackUtil.isValid(reconstructor.getStackInSlot(0))){
if(item instanceof ILensItem && !StackUtil.isValid(reconstructor.slots.getStackInSlot(0))){
ItemStack toPut = heldItem.copy();
toPut = StackUtil.setStackSize(toPut, 1);
reconstructor.setInventorySlotContents(0, toPut);
reconstructor.slots.setStackInSlot(0, toPut);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
//Shush, don't tell anyone!
@ -88,10 +88,10 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
}
}
else{
ItemStack slot = reconstructor.getStackInSlot(0);
ItemStack slot = reconstructor.slots.getStackInSlot(0);
if(StackUtil.isValid(slot)){
player.setHeldItem(hand, slot.copy());
reconstructor.setInventorySlotContents(0, StackUtil.getNull());
reconstructor.slots.setStackInSlot(0, StackUtil.getNull());
}
}
}
@ -110,7 +110,7 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityAtomicReconstructor){
ItemStack slot = ((TileEntityAtomicReconstructor)tile).getStackInSlot(0);
ItemStack slot = ((TileEntityAtomicReconstructor)tile).slots.getStackInSlot(0);
String strg;
if(!StackUtil.isValid(slot)){
strg = StringUtil.localize("info."+ModUtil.MOD_ID+".noLens");

View file

@ -88,27 +88,27 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityCompost){
TileEntityCompost compost = (TileEntityCompost)tile;
ItemStack slot = compost.getStackInSlot(0);
ItemStack slot = compost.slots.getStackInSlot(0);
CompostRecipe recipeIn = TileEntityCompost.getRecipeForInput(slot);
if(!StackUtil.isValid(slot) || recipeIn != null){
if(StackUtil.isValid(stackPlayer)){
CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer);
if(recipeHand != null && (recipeIn == null || recipeIn == recipeHand)){
int maxAdd = Math.min(StackUtil.getStackSize(recipeHand.input), StackUtil.getStackSize(stackPlayer));
int maxAdd = StackUtil.getStackSize(stackPlayer);
if(!StackUtil.isValid(slot)){
ItemStack stackToAdd = stackPlayer.copy();
stackToAdd = StackUtil.setStackSize(stackToAdd, maxAdd);
compost.setInventorySlotContents(0, stackToAdd);
compost.slots.setStackInSlot(0, stackToAdd);
player.inventory.decrStackSize(player.inventory.currentItem, maxAdd);
return true;
}
else{
ItemStack stackIn = slot.copy();
if(StackUtil.getStackSize(stackIn) < StackUtil.getStackSize(recipeHand.input)){
int sizeAdded = Math.min(maxAdd, StackUtil.getStackSize(recipeHand.input)-StackUtil.getStackSize(stackIn));
if(StackUtil.getStackSize(stackIn) < recipeHand.input.getMaxStackSize()){
int sizeAdded = Math.min(maxAdd, recipeHand.input.getMaxStackSize()-StackUtil.getStackSize(stackIn));
stackIn = StackUtil.addStackSize(stackIn, sizeAdded);
compost.setInventorySlotContents(0, stackIn);
compost.slots.setStackInSlot(0, stackIn);
player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded);
return true;
}
@ -119,7 +119,7 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
else{
if(!StackUtil.isValid(stackPlayer)){
player.setHeldItem(hand, slot.copy());
compost.setInventorySlotContents(0, StackUtil.getNull());
compost.slots.setStackInSlot(0, StackUtil.getNull());
return true;
}
else if(ItemUtil.canBeStacked(stackPlayer, slot)){
@ -127,7 +127,7 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
ItemStack stackToAdd = stackPlayer.copy();
stackToAdd = StackUtil.addStackSize(stackToAdd, addedStackSize);
player.setHeldItem(hand, stackToAdd);
compost.decrStackSize(0, addedStackSize);
compost.slots.decrStackSize(0, addedStackSize);
return true;
}
@ -156,7 +156,7 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityCompost){
ItemStack slot = ((TileEntityCompost)tile).getStackInSlot(0);
ItemStack slot = ((TileEntityCompost)tile).slots.getStackInSlot(0);
String strg;
if(!StackUtil.isValid(slot)){
strg = "Empty";

View file

@ -55,12 +55,12 @@ public class BlockDisplayStand extends BlockContainerBase{
if(!world.isRemote){
TileEntityDisplayStand stand = (TileEntityDisplayStand)world.getTileEntity(pos);
if(stand != null){
ItemStack display = stand.getStackInSlot(0);
ItemStack display = stand.slots.getStackInSlot(0);
if(StackUtil.isValid(heldItem)){
if(!StackUtil.isValid(display)){
ItemStack toPut = heldItem.copy();
toPut = StackUtil.setStackSize(toPut, 1);
stand.setInventorySlotContents(0, toPut);
stand.slots.setStackInSlot(0, toPut);
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, -1));
return true;
}
@ -70,7 +70,7 @@ public class BlockDisplayStand extends BlockContainerBase{
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, maxTransfer));
ItemStack newDisplay = display.copy();
newDisplay = StackUtil.addStackSize(newDisplay, -maxTransfer);
stand.setInventorySlotContents(0, StackUtil.validateCheck(newDisplay));
stand.slots.setStackInSlot(0, StackUtil.validateCheck(newDisplay));
return true;
}
}
@ -78,7 +78,7 @@ public class BlockDisplayStand extends BlockContainerBase{
else{
if(StackUtil.isValid(display)){
player.setHeldItem(hand, display.copy());
stand.setInventorySlotContents(0, StackUtil.getNull());
stand.slots.setStackInSlot(0, StackUtil.getNull());
return true;
}
}

View file

@ -51,7 +51,7 @@ public class BlockDistributorItem extends BlockContainerBase implements IHudDisp
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityDistributorItem){
TileEntityDistributorItem distributor = (TileEntityDistributorItem)tile;
ItemStack slot = distributor.getStackInSlot(0);
ItemStack slot = distributor.slots.getStackInSlot(0);
String strg;
if(!StackUtil.isValid(slot)){

View file

@ -55,12 +55,12 @@ public class BlockEmpowerer extends BlockContainerBase{
if(!world.isRemote){
TileEntityEmpowerer empowerer = (TileEntityEmpowerer)world.getTileEntity(pos);
if(empowerer != null){
ItemStack stackThere = empowerer.getStackInSlot(0);
ItemStack stackThere = empowerer.slots.getStackInSlot(0);
if(StackUtil.isValid(heldItem)){
if(!StackUtil.isValid(stackThere) && !TileEntityEmpowerer.getRecipesForInput(heldItem).isEmpty()){
ItemStack toPut = heldItem.copy();
toPut = StackUtil.setStackSize(toPut, 1);
empowerer.setInventorySlotContents(0, toPut);
empowerer.slots.setStackInSlot(0, toPut);
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, -1));
return true;
}
@ -70,7 +70,7 @@ public class BlockEmpowerer extends BlockContainerBase{
player.setHeldItem(hand, StackUtil.addStackSize(heldItem, maxTransfer));
ItemStack newStackThere = stackThere.copy();
newStackThere = StackUtil.addStackSize(newStackThere, -maxTransfer);
empowerer.setInventorySlotContents(0, StackUtil.validateCheck(newStackThere));
empowerer.slots.setStackInSlot(0, StackUtil.validateCheck(newStackThere));
return true;
}
}
@ -78,7 +78,7 @@ public class BlockEmpowerer extends BlockContainerBase{
else{
if(StackUtil.isValid(stackThere)){
player.setHeldItem(hand, stackThere.copy());
empowerer.setInventorySlotContents(0, StackUtil.getNull());
empowerer.slots.setStackInSlot(0, StackUtil.getNull());
return true;
}
}

View file

@ -18,6 +18,7 @@ import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChest;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChestLarge;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChestMedium;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
@ -26,6 +27,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -103,12 +105,12 @@ public class BlockGiantChest extends BlockContainerBase{
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){
NBTTagList list = stack.getTagCompound().getTagList("Items", 10);
NonNullList<ItemStack> slots = ((TileEntityGiantChest)tile).slots;
ItemStackHandlerCustom slots = ((TileEntityGiantChest)tile).slots;
for(int i = 0; i < list.tagCount(); i++){
NBTTagCompound compound = list.getCompoundTagAt(i);
if(compound != null && compound.hasKey("id")){
slots.set(i, new ItemStack(list.getCompoundTagAt(i)));
slots.setStackInSlot(i, new ItemStack(list.getCompoundTagAt(i)));
}
}
}
@ -124,16 +126,16 @@ public class BlockGiantChest extends BlockContainerBase{
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){
List<ItemStack> slots = ((TileEntityGiantChest)tile).slots;
int place = ItemUtil.getPlaceAt(slots, new ItemStack(InitItems.itemCrateKeeper), false);
ItemStackHandlerCustom slots = ((TileEntityGiantChest)tile).slots;
int place = ItemUtil.getPlaceAt(slots.getItems(), new ItemStack(InitItems.itemCrateKeeper), false);
if(place >= 0){
NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.size(); i++){
for(int i = 0; i < slots.getSlots(); i++){
//Destroy the keeper
if(i != place){
NBTTagCompound compound = new NBTTagCompound();
if(StackUtil.isValid(slots.get(i))){
slots.get(i).writeToNBT(compound);
if(StackUtil.isValid(slots.getStackInSlot(i))){
slots.getStackInSlot(i).writeToNBT(compound);
}
list.appendTag(compound);
}
@ -158,7 +160,7 @@ public class BlockGiantChest extends BlockContainerBase{
public boolean shouldDropInventory(World world, BlockPos pos){
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){
if(ItemUtil.contains(((TileEntityGiantChest)tile).slots, new ItemStack(InitItems.itemCrateKeeper), false)){
if(ItemUtil.contains(((TileEntityGiantChest)tile).slots.getItems(), new ItemStack(InitItems.itemCrateKeeper), false)){
return false;
}
}

View file

@ -85,8 +85,8 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
TileEntity aTile = world.getTileEntity(position);
if(aTile instanceof TileEntityInventoryBase){
TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
if(tile.getSizeInventory() > 0){
for(int i = 0; i < tile.getSizeInventory(); i++){
if(tile.slots.getSlots() > 0){
for(int i = 0; i < tile.slots.getSlots(); i++){
this.dropSlotFromInventory(i, tile, world, position);
}
}
@ -95,7 +95,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
}
private void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos){
ItemStack stack = tile.getStackInSlot(i);
ItemStack stack = tile.slots.getStackInSlot(i);
if(StackUtil.isValid(stack)){
float dX = world.rand.nextFloat()*0.8F+0.1F;
float dY = world.rand.nextFloat()*0.8F+0.1F;

View file

@ -28,7 +28,7 @@ public class RenderCompost extends TileEntitySpecialRenderer{
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage){
if(te instanceof TileEntityCompost){
TileEntityCompost compost = (TileEntityCompost)te;
ItemStack slot = compost.getStackInSlot(0);
ItemStack slot = compost.slots.getStackInSlot(0);
if(StackUtil.isValid(slot)){
Block display = null;
@ -36,12 +36,12 @@ public class RenderCompost extends TileEntitySpecialRenderer{
for(CompostRecipe aRecipe : ActuallyAdditionsAPI.COMPOST_RECIPES){
if(slot.isItemEqual(aRecipe.input)){
display = aRecipe.inputDisplay;
maxAmount = StackUtil.getStackSize(aRecipe.input);
maxAmount = aRecipe.input.getMaxStackSize();
break;
}
else if(slot.isItemEqual(aRecipe.output)){
display = aRecipe.outputDisplay;
maxAmount = StackUtil.getStackSize(aRecipe.output);
maxAmount = aRecipe.output.getMaxStackSize();
break;
}
}

View file

@ -29,7 +29,7 @@ public class RenderDisplayStand extends TileEntitySpecialRenderer{
return;
}
ItemStack stack = ((TileEntityDisplayStand)tile).getStackInSlot(0);
ItemStack stack = ((TileEntityDisplayStand)tile).slots.getStackInSlot(0);
if(StackUtil.isValid(stack)){
GlStateManager.pushMatrix();
GlStateManager.translate((float)x+0.5F, (float)y+1F, (float)z+0.5F);

View file

@ -29,7 +29,7 @@ public class RenderEmpowerer extends TileEntitySpecialRenderer{
return;
}
ItemStack stack = ((TileEntityEmpowerer)tile).getStackInSlot(0);
ItemStack stack = ((TileEntityEmpowerer)tile).slots.getStackInSlot(0);
if(StackUtil.isValid(stack)){
GlStateManager.pushMatrix();
GlStateManager.translate((float)x+0.5F, (float)y+1F, (float)z+0.5F);

View file

@ -28,7 +28,7 @@ public class RenderReconstructorLens extends TileEntitySpecialRenderer{
if(!(tile instanceof TileEntityAtomicReconstructor)){
return;
}
ItemStack stack = ((TileEntityAtomicReconstructor)tile).getStackInSlot(0);
ItemStack stack = ((TileEntityAtomicReconstructor)tile).slots.getStackInSlot(0);
if(StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem){
GlStateManager.pushMatrix();

View file

@ -31,8 +31,8 @@ public final class InitCrafting{
FoodCrafting.init();
ToolCrafting.init();
ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemMisc, 10, TheMiscItems.MASHED_FOOD.ordinal()), Blocks.LEAVES, new ItemStack(InitItems.itemFertilizer, 10), Blocks.DIRT);
ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemCanolaSeed, 20), Blocks.DIRT, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND);
ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.MASHED_FOOD.ordinal()), Blocks.LEAVES, new ItemStack(InitItems.itemFertilizer), Blocks.DIRT);
ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemCanolaSeed), Blocks.DIRT, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCanolaOil.getName(), 40, 100);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidOil.getName(), 60, 150);

View file

@ -109,7 +109,7 @@ public class VillageComponentEngineerHouse extends StructureVillagePieces.House1
if(compost instanceof TileEntityCompost){
TileEntityCompost tile = (TileEntityCompost)compost;
tile.stopFromDropping = true;
tile.setInventorySlotContents(0, new ItemStack(InitItems.itemFertilizer, 10));
tile.slots.setStackInSlot(0, new ItemStack(InitItems.itemFertilizer, 10));
}
}
@ -134,7 +134,7 @@ public class VillageComponentEngineerHouse extends StructureVillagePieces.House1
TileEntityCanolaPress tile = (TileEntityCanolaPress)press;
tile.stopFromDropping = true;
tile.storage.setEnergyStored(world.rand.nextInt(tile.storage.getMaxEnergyStored()/3));
tile.setInventorySlotContents(0, new ItemStack(InitItems.itemMisc, world.rand.nextInt(60)+1, TheMiscItems.CANOLA.ordinal()));
tile.slots.setStackInSlot(0, new ItemStack(InitItems.itemMisc, world.rand.nextInt(60)+1, TheMiscItems.CANOLA.ordinal()));
}
TileEntity crusher = this.getTileAtPos(world, 2, 1, 6, sbb);
@ -143,7 +143,7 @@ public class VillageComponentEngineerHouse extends StructureVillagePieces.House1
tile.stopFromDropping = true;
tile.storage.setEnergyStored(world.rand.nextInt(tile.storage.getMaxEnergyStored()/2));
if(world.rand.nextFloat() >= 0.25F){
tile.setInventorySlotContents(TileEntityGrinder.SLOT_INPUT_1, new ItemStack(InitBlocks.blockMisc, world.rand.nextInt(10)+1, TheMiscBlocks.ORE_QUARTZ.ordinal()));
tile.slots.setStackInSlot(TileEntityGrinder.SLOT_INPUT_1, new ItemStack(InitBlocks.blockMisc, world.rand.nextInt(10)+1, TheMiscBlocks.ORE_QUARTZ.ordinal()));
}
}
@ -151,7 +151,7 @@ public class VillageComponentEngineerHouse extends StructureVillagePieces.House1
if(coal instanceof TileEntityCoalGenerator){
TileEntityCoalGenerator tile = (TileEntityCoalGenerator)coal;
tile.stopFromDropping = true;
tile.setInventorySlotContents(0, new ItemStack(Items.COAL, world.rand.nextInt(25)+3, 1));
tile.slots.setStackInSlot(0, new ItemStack(Items.COAL, world.rand.nextInt(25)+3, 1));
}
TileEntity reconstructor = this.getTileAtPos(world, 8, 4, 3, sbb);

View file

@ -13,27 +13,25 @@ package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
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.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerBag extends Container implements IButtonReactor{
public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000);
private final InventoryBag bagInventory;
private final ItemStackHandlerCustom bagInventory;
private final InventoryPlayer inventory;
private final boolean isVoid;
public boolean autoInsert;
@ -41,7 +39,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public ContainerBag(InventoryPlayer inventory, boolean isVoid){
this.inventory = inventory;
this.bagInventory = new InventoryBag(isVoid);
this.bagInventory = new ItemStackHandlerCustom(getSlotAmount(isVoid));
this.isVoid = isVoid;
for(int i = 0; i < 4; i++){
@ -59,7 +57,7 @@ public class ContainerBag extends Container implements IButtonReactor{
else{
for(int i = 0; i < 4; i++){
for(int j = 0; j < 7; j++){
this.addSlotToContainer(new Slot(this.bagInventory, j+i*7, 10+j*18, 10+i*18){
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.bagInventory, j+i*7, 10+j*18, 10+i*18){
@Override
public boolean isItemValid(ItemStack stack){
return ContainerBag.this.filter.check(stack);
@ -141,7 +139,7 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = this.bagInventory.slots.size()+4;
int inventoryStart = this.bagInventory.getSlots()+4;
int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8;
@ -216,7 +214,7 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.bagInventory.isUsableByPlayer(player);
return true;
}
@Override
@ -228,132 +226,4 @@ public class ContainerBag extends Container implements IButtonReactor{
this.filter.onButtonPressed(buttonID);
}
}
public static class InventoryBag implements IInventory{
public NonNullList<ItemStack> slots;
public InventoryBag(boolean isVoid){
this.slots = StackUtil.createSlots(getSlotAmount(isVoid));
}
@Override
public String getName(){
return "bag";
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public void markDirty(){
}
@Override
public boolean isUsableByPlayer(EntityPlayer player){
return true;
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
@Override
public int getField(int id){
return 0;
}
@Override
public void setField(int id, int value){
}
@Override
public int getFieldCount(){
return 0;
}
@Override
public void clear(){
this.slots.clear();
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.slots.set(i, stack);
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.slots.size();
}
@Override
public boolean isEmpty(){
return StackUtil.isIInvEmpty(this.slots);
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.slots.get(i);
}
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt;
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots.get(i);
this.slots.set(i, StackUtil.getNull());
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots.set(i, StackUtil.getNull());
}
this.markDirty();
return stackAt;
}
}
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots.get(index);
this.slots.set(index, StackUtil.getNull());
return stack;
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public ITextComponent getDisplayName(){
return new TextComponentTranslation(this.getName());
}
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
@ -28,7 +29,7 @@ public class ContainerBioReactor extends Container{
for(int i = 0; i < 4; i++){
for(int j = 0; j < 2; j++){
this.addSlotToContainer(new Slot(this.tile, j+i*2, 50+j*18, 13+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tile.slots, j+i*2, 50+j*18, 13+i*18));
}
}
@ -97,6 +98,6 @@ public class ContainerBioReactor extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tile.isUsableByPlayer(player);
return this.tile.canPlayerUse(player);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerBreaker extends Container{
@ -29,7 +30,7 @@ public class ContainerBreaker extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.breaker, j+i*3, 62+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.breaker.slots, j+i*3, 62+j*18, 21+i*18));
}
}
@ -94,6 +95,6 @@ public class ContainerBreaker extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.breaker.isUsableByPlayer(player);
return this.breaker.canPlayerUse(player);
}
}

View file

@ -20,6 +20,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerCanolaPress extends Container{
@ -29,7 +30,7 @@ public class ContainerCanolaPress extends Container{
public ContainerCanolaPress(InventoryPlayer inventory, TileEntityBase tile){
this.press = (TileEntityCanolaPress)tile;
this.addSlotToContainer(new Slot(this.press, 0, 81, 10));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.press.slots, 0, 81, 10));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -96,6 +97,6 @@ public class ContainerCanolaPress extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.press.isUsableByPlayer(player);
return this.press.canPlayerUse(player);
}
}

View file

@ -19,6 +19,7 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerCoalGenerator extends Container{
@ -28,7 +29,7 @@ public class ContainerCoalGenerator extends Container{
public ContainerCoalGenerator(InventoryPlayer inventory, TileEntityBase tile){
this.generator = (TileEntityCoalGenerator)tile;
this.addSlotToContainer(new Slot(this.generator, 0, 87, 43));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.generator.slots, 0, 87, 43));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -95,6 +96,6 @@ public class ContainerCoalGenerator extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.generator.isUsableByPlayer(player);
return this.generator.canPlayerUse(player);
}
}

View file

@ -22,6 +22,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerCoffeeMachine extends Container{
@ -31,13 +32,13 @@ public class ContainerCoffeeMachine extends Container{
public ContainerCoffeeMachine(InventoryPlayer inventory, TileEntityBase tile){
this.machine = (TileEntityCoffeeMachine)tile;
this.addSlotToContainer(new Slot(this.machine, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS, 37, 6));
this.addSlotToContainer(new Slot(this.machine, TileEntityCoffeeMachine.SLOT_INPUT, 80, 42));
this.addSlotToContainer(new SlotOutput(this.machine, TileEntityCoffeeMachine.SLOT_OUTPUT, 80, 73));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.machine.slots, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS, 37, 6));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.machine.slots, TileEntityCoffeeMachine.SLOT_INPUT, 80, 42));
this.addSlotToContainer(new SlotOutput(this.machine.slots, TileEntityCoffeeMachine.SLOT_OUTPUT, 80, 73));
for(int i = 0; i < 4; i++){
for(int j = 0; j < 2; j++){
this.addSlotToContainer(new Slot(this.machine, j+i*2+3, 125+j*18, 6+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.machine.slots, j+i*2+3, 125+j*18, 6+i*18));
}
}
@ -123,6 +124,6 @@ public class ContainerCoffeeMachine extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.machine.isUsableByPlayer(player);
return this.machine.canPlayerUse(player);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerDirectionalBreaker extends Container{
@ -29,7 +30,7 @@ public class ContainerDirectionalBreaker extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.breaker, j+i*3, 74+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.breaker.slots, j+i*3, 74+j*18, 21+i*18));
}
}
@ -94,6 +95,6 @@ public class ContainerDirectionalBreaker extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.breaker.isUsableByPlayer(player);
return this.breaker.canPlayerUse(player);
}
}

View file

@ -13,31 +13,30 @@ package de.ellpeck.actuallyadditions.mod.inventory;
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.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerDrill extends Container{
public static final int SLOT_AMOUNT = 5;
private final InventoryDrill drillInventory = new InventoryDrill();
private final ItemStackHandlerCustom drillInventory = new ItemStackHandlerCustom(SLOT_AMOUNT);
private final InventoryPlayer inventory;
public ContainerDrill(InventoryPlayer inventory){
this.inventory = inventory;
for(int i = 0; i < SLOT_AMOUNT; i++){
this.addSlotToContainer(new Slot(this.drillInventory, i, 44+i*18, 19){
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.drillInventory, i, 44+i*18, 19){
@Override
public boolean isItemValid(ItemStack stack){
return stack.getItem() instanceof ItemDrillUpgrade;
@ -139,130 +138,6 @@ public class ContainerDrill extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.drillInventory.isUsableByPlayer(player);
}
public static class InventoryDrill implements IInventory{
public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
@Override
public String getName(){
return "drill";
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public void markDirty(){
}
@Override
public boolean isUsableByPlayer(EntityPlayer player){
return true;
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
@Override
public int getField(int id){
return 0;
}
@Override
public void setField(int id, int value){
}
@Override
public int getFieldCount(){
return 0;
}
@Override
public void clear(){
this.slots.clear();
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.slots.set(i, stack);
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.slots.size();
}
@Override
public boolean isEmpty(){
return StackUtil.isIInvEmpty(this.slots);
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.slots.get(i);
}
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt;
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots.get(i);
this.slots.set(i, StackUtil.getNull());
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots.set(i, StackUtil.getNull());
}
this.markDirty();
return stackAt;
}
}
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots.get(index);
this.slots.set(index, StackUtil.getNull());
return stack;
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public ITextComponent getDisplayName(){
return new TextComponentTranslation(this.getName());
}
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerDropper extends Container{
@ -29,7 +30,7 @@ public class ContainerDropper extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.dropper, j+i*3, 62+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.dropper.slots, j+i*3, 62+j*18, 21+i*18));
}
}
@ -94,6 +95,6 @@ public class ContainerDropper extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.dropper.isUsableByPlayer(player);
return this.dropper.canPlayerUse(player);
}
}

View file

@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerEnergizer extends Container{
@ -37,8 +38,8 @@ public class ContainerEnergizer extends Container{
this.energizer = (TileEntityEnergizer)tile;
InventoryPlayer inventory = player.inventory;
this.addSlotToContainer(new Slot(this.energizer, 0, 76, 73));
this.addSlotToContainer(new SlotOutput(this.energizer, 1, 76, 42));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.energizer.slots, 0, 76, 73));
this.addSlotToContainer(new SlotOutput(this.energizer.slots, 1, 76, 42));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -133,6 +134,6 @@ public class ContainerEnergizer extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.energizer.isUsableByPlayer(player);
return this.energizer.canPlayerUse(player);
}
}

View file

@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerEnervator extends Container{
@ -36,8 +37,8 @@ public class ContainerEnervator extends Container{
this.enervator = (TileEntityEnervator)tile;
InventoryPlayer inventory = player.inventory;
this.addSlotToContainer(new Slot(this.enervator, 0, 76, 73));
this.addSlotToContainer(new SlotOutput(this.enervator, 1, 76, 42));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.enervator.slots, 0, 76, 73));
this.addSlotToContainer(new SlotOutput(this.enervator.slots, 1, 76, 42));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -132,6 +133,6 @@ public class ContainerEnervator extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.enervator.isUsableByPlayer(player);
return this.enervator.canPlayerUse(player);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerFarmer extends Container{
@ -29,12 +30,12 @@ public class ContainerFarmer extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++){
this.addSlotToContainer(new Slot(this.farmer, j+i*2, 67+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.farmer.slots, j+i*2, 67+j*18, 21+i*18));
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++){
this.addSlotToContainer(new Slot(this.farmer, 6+j+i*2, 105+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.farmer.slots, 6+j+i*2, 105+j*18, 21+i*18));
}
}
@ -103,6 +104,6 @@ public class ContainerFarmer extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.farmer.isUsableByPlayer(player);
return this.farmer.canPlayerUse(player);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerFeeder extends Container{
@ -26,7 +27,7 @@ public class ContainerFeeder extends Container{
public ContainerFeeder(InventoryPlayer inventory, TileEntityBase tile){
this.tileFeeder = (TileEntityFeeder)tile;
this.addSlotToContainer(new Slot(this.tileFeeder, 0, 80, 45));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileFeeder.slots, 0, 80, 45));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -89,6 +90,6 @@ public class ContainerFeeder extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileFeeder.isUsableByPlayer(player);
return this.tileFeeder.canPlayerUse(player);
}
}

View file

@ -14,24 +14,23 @@ 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.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerFilter extends Container{
public static final int SLOT_AMOUNT = 24;
private final InventoryFilter filterInventory = new InventoryFilter();
private final ItemStackHandlerCustom filterInventory = new ItemStackHandlerCustom(SLOT_AMOUNT);
private final InventoryPlayer inventory;
public ContainerFilter(InventoryPlayer inventory){
@ -134,130 +133,6 @@ public class ContainerFilter extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.filterInventory.isUsableByPlayer(player);
}
public static class InventoryFilter implements IInventory{
public NonNullList<ItemStack> slots = StackUtil.createSlots(SLOT_AMOUNT);
@Override
public String getName(){
return "filter";
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public void markDirty(){
}
@Override
public boolean isUsableByPlayer(EntityPlayer player){
return true;
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
@Override
public int getField(int id){
return 0;
}
@Override
public void setField(int id, int value){
}
@Override
public int getFieldCount(){
return 0;
}
@Override
public void clear(){
this.slots.clear();
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.slots.set(i, stack);
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.slots.size();
}
@Override
public boolean isEmpty(){
return StackUtil.isIInvEmpty(this.slots);
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.slots.get(i);
}
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt;
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots.get(i);
this.slots.set(i, StackUtil.getNull());
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots.set(i, StackUtil.getNull());
}
this.markDirty();
return stackAt;
}
}
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots.get(index);
this.slots.set(index, StackUtil.getNull());
return stack;
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public ITextComponent getDisplayName(){
return new TextComponentTranslation(this.getName());
}
}
}

View file

@ -10,6 +10,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.TileEntityFurnaceDouble;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
@ -20,6 +21,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnaceOutput;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerFurnaceDouble extends Container{
@ -29,10 +31,10 @@ public class ContainerFurnaceDouble extends Container{
public ContainerFurnaceDouble(InventoryPlayer inventory, TileEntityBase tile){
this.tileFurnace = (TileEntityFurnaceDouble)tile;
this.addSlotToContainer(new Slot(this.tileFurnace, TileEntityFurnaceDouble.SLOT_INPUT_1, 51, 21));
this.addSlotToContainer(new SlotFurnaceOutput(inventory.player, this.tileFurnace, TileEntityFurnaceDouble.SLOT_OUTPUT_1, 51, 69));
this.addSlotToContainer(new Slot(this.tileFurnace, TileEntityFurnaceDouble.SLOT_INPUT_2, 109, 21));
this.addSlotToContainer(new SlotFurnaceOutput(inventory.player, this.tileFurnace, TileEntityFurnaceDouble.SLOT_OUTPUT_2, 108, 69));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileFurnace.slots, TileEntityFurnaceDouble.SLOT_INPUT_1, 51, 21));
this.addSlotToContainer(new SlotOutput(this.tileFurnace.slots, TileEntityFurnaceDouble.SLOT_OUTPUT_1, 51, 69));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileFurnace.slots, TileEntityFurnaceDouble.SLOT_INPUT_2, 109, 21));
this.addSlotToContainer(new SlotOutput(this.tileFurnace.slots, TileEntityFurnaceDouble.SLOT_OUTPUT_2, 108, 69));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -108,6 +110,6 @@ public class ContainerFurnaceDouble extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileFurnace.isUsableByPlayer(player);
return this.tileFurnace.canPlayerUse(player);
}
}

View file

@ -19,6 +19,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
@ChestContainer(rowSize = 13, isLargeChest = true)
public class ContainerGiantChest extends Container{
@ -30,7 +31,7 @@ public class ContainerGiantChest extends Container{
for(int i = 0; i < 9; i++){
for(int j = 0; j < 13; j++){
this.addSlotToContainer(new Slot(this.tileChest, (9*13*page)+j+(i*13), 5+j*18, 5+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileChest.slots, (9*13*page)+j+(i*13), 5+j*18, 5+i*18));
}
}
@ -95,6 +96,6 @@ public class ContainerGiantChest extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileChest.isUsableByPlayer(player);
return this.tileChest.canPlayerUse(player);
}
}

View file

@ -20,6 +20,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerGrinder extends Container{
@ -31,13 +32,13 @@ public class ContainerGrinder extends Container{
this.tileGrinder = (TileEntityGrinder)tile;
this.isDouble = isDouble;
this.addSlotToContainer(new Slot(this.tileGrinder, TileEntityGrinder.SLOT_INPUT_1, this.isDouble ? 51 : 80, 21));
this.addSlotToContainer(new SlotOutput(this.tileGrinder, TileEntityGrinder.SLOT_OUTPUT_1_1, this.isDouble ? 37 : 66, 69));
this.addSlotToContainer(new SlotOutput(this.tileGrinder, TileEntityGrinder.SLOT_OUTPUT_1_2, this.isDouble ? 64 : 92, 69));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileGrinder.slots, TileEntityGrinder.SLOT_INPUT_1, this.isDouble ? 51 : 80, 21));
this.addSlotToContainer(new SlotOutput(this.tileGrinder.slots, TileEntityGrinder.SLOT_OUTPUT_1_1, this.isDouble ? 37 : 66, 69));
this.addSlotToContainer(new SlotOutput(this.tileGrinder.slots, TileEntityGrinder.SLOT_OUTPUT_1_2, this.isDouble ? 64 : 92, 69));
if(this.isDouble){
this.addSlotToContainer(new Slot(this.tileGrinder, TileEntityGrinder.SLOT_INPUT_2, 109, 21));
this.addSlotToContainer(new SlotOutput(this.tileGrinder, TileEntityGrinder.SLOT_OUTPUT_2_1, 96, 69));
this.addSlotToContainer(new SlotOutput(this.tileGrinder, TileEntityGrinder.SLOT_OUTPUT_2_2, 121, 69));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileGrinder.slots, TileEntityGrinder.SLOT_INPUT_2, 109, 21));
this.addSlotToContainer(new SlotOutput(this.tileGrinder.slots, TileEntityGrinder.SLOT_OUTPUT_2_1, 96, 69));
this.addSlotToContainer(new SlotOutput(this.tileGrinder.slots, TileEntityGrinder.SLOT_OUTPUT_2_2, 121, 69));
}
for(int i = 0; i < 3; i++){
@ -119,6 +120,6 @@ public class ContainerGrinder extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileGrinder.isUsableByPlayer(player);
return this.tileGrinder.canPlayerUse(player);
}
}

View file

@ -21,6 +21,7 @@ import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerInputter extends Container{
@ -33,7 +34,7 @@ public class ContainerInputter extends Container{
this.tileInputter = (TileEntityInputter)tile;
this.isAdvanced = isAdvanced;
this.addSlotToContainer(new Slot(this.tileInputter, 0, 80, 21+(isAdvanced ? 12 : 0)));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileInputter.slots, 0, 80, 21+(isAdvanced ? 12 : 0)));
if(isAdvanced){
for(int i = 0; i < 2; i++){
@ -116,6 +117,6 @@ public class ContainerInputter extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileInputter.isUsableByPlayer(player);
return this.tileInputter.canPlayerUse(player);
}
}

View file

@ -49,7 +49,7 @@ public class ContainerLaserRelayItemWhitelist extends Container{
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = 0;
int inventoryStart = 24;
int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8;

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerMiner extends Container{
@ -29,7 +30,7 @@ public class ContainerMiner extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.miner, j+i*3, 62+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.miner.slots, j+i*3, 62+j*18, 21+i*18));
}
}
@ -94,6 +95,6 @@ public class ContainerMiner extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.miner.isUsableByPlayer(player);
return this.miner.canPlayerUse(player);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerPhantomPlacer extends Container{
@ -29,7 +30,7 @@ public class ContainerPhantomPlacer extends Container{
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.placer, j+i*3, 62+j*18, 21+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.placer.slots, j+i*3, 62+j*18, 21+i*18));
}
}
@ -94,6 +95,6 @@ public class ContainerPhantomPlacer extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.placer.isUsableByPlayer(player);
return this.placer.canPlayerUse(player);
}
}

View file

@ -20,6 +20,7 @@ import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerRangedCollector extends Container{
@ -31,7 +32,7 @@ public class ContainerRangedCollector extends Container{
for(int i = 0; i < 2; i++){
for(int j = 0; j < 3; j++){
this.addSlotToContainer(new Slot(this.collector, j+i*3, 96+j*18, 24+i*18));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.collector.slots, j+i*3, 96+j*18, 24+i*18));
}
}
for(int i = 0; i < 4; i++){
@ -111,6 +112,6 @@ public class ContainerRangedCollector extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.collector.isUsableByPlayer(player);
return this.collector.canPlayerUse(player);
}
}

View file

@ -19,6 +19,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerRepairer extends Container{
@ -28,8 +29,8 @@ public class ContainerRepairer extends Container{
public ContainerRepairer(InventoryPlayer inventory, TileEntityBase tile){
this.tileRepairer = (TileEntityItemRepairer)tile;
this.addSlotToContainer(new Slot(this.tileRepairer, TileEntityItemRepairer.SLOT_INPUT, 47, 53));
this.addSlotToContainer(new SlotOutput(this.tileRepairer, TileEntityItemRepairer.SLOT_OUTPUT, 109, 53));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.tileRepairer.slots, TileEntityItemRepairer.SLOT_INPUT, 47, 53));
this.addSlotToContainer(new SlotOutput(this.tileRepairer.slots, TileEntityItemRepairer.SLOT_OUTPUT, 109, 53));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -96,6 +97,6 @@ public class ContainerRepairer extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.tileRepairer.isUsableByPlayer(player);
return this.tileRepairer.canPlayerUse(player);
}
}

View file

@ -20,6 +20,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class ContainerXPSolidifier extends Container{
@ -29,8 +30,8 @@ public class ContainerXPSolidifier extends Container{
public ContainerXPSolidifier(InventoryPlayer inventory, TileEntityBase tile){
this.solidifier = (TileEntityXPSolidifier)tile;
this.addSlotToContainer(new SlotOutput(this.solidifier, 0, 95, 8));
this.addSlotToContainer(new Slot(this.solidifier, 1, 65, 8));
this.addSlotToContainer(new SlotOutput(this.solidifier.slots, 0, 95, 8));
this.addSlotToContainer(new SlotItemHandlerUnconditioned(this.solidifier.slots, 1, 65, 8));
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
@ -94,6 +95,6 @@ public class ContainerXPSolidifier extends Container{
@Override
public boolean canInteractWith(EntityPlayer player){
return this.solidifier.isUsableByPlayer(player);
return this.solidifier.canPlayerUse(player);
}
}

View file

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

View file

@ -10,13 +10,15 @@
package de.ellpeck.actuallyadditions.mod.inventory.slot;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class SlotDeletion extends Slot{
public class SlotDeletion extends SlotItemHandlerUnconditioned{
public SlotDeletion(IInventory inv, int slot, int x, int y){
public SlotDeletion(ItemStackHandlerCustom inv, int slot, int x, int y){
super(inv, slot, x, y);
}

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.slot;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
@ -19,10 +20,11 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned;
public class SlotFilter extends Slot{
public class SlotFilter extends SlotItemHandlerUnconditioned{
public SlotFilter(IInventory inv, int slot, int x, int y){
public SlotFilter(ItemStackHandlerCustom inv, int slot, int x, int y){
super(inv, slot, x, y);
}

View file

@ -0,0 +1,77 @@
/*
* This file ("SlotItemHandlerUnconditioned.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.inventory.slot;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import javax.annotation.Nonnull;
public class SlotItemHandlerUnconditioned extends SlotItemHandler{
private final ItemStackHandlerCustom handler;
public SlotItemHandlerUnconditioned(ItemStackHandlerCustom handler, int index, int xPosition, int yPosition){
super(handler, index, xPosition, yPosition);
this.handler = handler;
}
@Override
public boolean isItemValid(ItemStack stack){
if(StackUtil.isValid(stack)){
ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex());
this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY);
ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), stack, true);
this.handler.setStackInSlot(this.getSlotIndex(), currentStack);
return remainder == null || remainder.getCount() < stack.getCount();
}
return false;
}
/**
* Helper fnct to get the stack in the slot.
*/
@Override
@Nonnull
public ItemStack getStack(){
return this.handler.getStackInSlot(this.getSlotIndex());
}
@Override
public void putStack(ItemStack stack){
this.handler.setStackInSlot(this.getSlotIndex(), stack);
this.onSlotChanged();
}
@Override
public int getItemStackLimit(ItemStack stack){
ItemStack maxAdd = stack.copy();
maxAdd.setCount(stack.getMaxStackSize());
ItemStack currentStack = this.handler.getStackInSlot(this.getSlotIndex());
this.handler.setStackInSlot(this.getSlotIndex(), ItemStack.EMPTY);
ItemStack remainder = this.handler.insertItemInternal(this.getSlotIndex(), maxAdd, true);
this.handler.setStackInSlot(this.getSlotIndex(), currentStack);
return stack.getMaxStackSize()-remainder.getCount();
}
@Override
public boolean canTakeStack(EntityPlayer playerIn){
return !this.handler.extractItemInternal(this.getSlotIndex(), 1, true).isEmpty();
}
@Override
public ItemStack decrStackSize(int amount){
return this.handler.extractItemInternal(this.getSlotIndex(), amount, false);
}
}

View file

@ -10,13 +10,12 @@
package de.ellpeck.actuallyadditions.mod.inventory.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import net.minecraft.item.ItemStack;
public class SlotOutput extends Slot{
public class SlotOutput extends SlotItemHandlerUnconditioned{
public SlotOutput(IInventory inventory, int id, int x, int y){
public SlotOutput(ItemStackHandlerCustom inventory, int id, int x, int y){
super(inventory, id, x, y);
}

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler.GuiTypes;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityItem;
@ -53,13 +54,13 @@ public class ItemBag extends ItemBase{
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(this.isVoid));
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerBag.getSlotAmount(this.isVoid));
ItemDrill.loadSlotsFromNBT(inv, stack);
int slotsTotal = inv.getSizeInventory();
int slotsTotal = inv.getSlots();
int slotsFilled = 0;
for(int i = 0; i < inv.getSizeInventory(); i++){
for(int i = 0; i < inv.getSlots(); i++){
if(StackUtil.isValid(inv.getStackInSlot(i))){
slotsFilled++;
}
@ -88,7 +89,7 @@ public class ItemBag extends ItemBase{
boolean changed = false;
boolean isVoid = ((ItemBag)invStack.getItem()).isVoid;
IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(isVoid));
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerBag.getSlotAmount(isVoid));
ItemDrill.loadSlotsFromNBT(inv, invStack);
FilterSettings filter = new FilterSettings(4, false, false, false, false, 0, 0);
@ -99,20 +100,20 @@ public class ItemBag extends ItemBase{
changed = true;
}
else{
for(int j = 0; j < inv.getSizeInventory(); j++){
for(int j = 0; j < inv.getSlots(); j++){
ItemStack bagStack = inv.getStackInSlot(j);
if(StackUtil.isValid(bagStack)){
if(ItemUtil.canBeStacked(bagStack, stack)){
int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack));
if(maxTransfer > 0){
inv.setInventorySlotContents(j, StackUtil.addStackSize(bagStack, maxTransfer));
inv.setStackInSlot(j, StackUtil.addStackSize(bagStack, maxTransfer));
stack = StackUtil.addStackSize(stack, -maxTransfer);
changed = true;
}
}
}
else{
inv.setInventorySlotContents(j, stack.copy());
inv.setStackInSlot(j, stack.copy());
stack = StackUtil.setStackSize(stack, 0);
changed = true;
}
@ -155,16 +156,16 @@ public class ItemBag extends ItemBase{
if(handler != null){
boolean changed = false;
IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(this.isVoid));
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerBag.getSlotAmount(this.isVoid));
ItemDrill.loadSlotsFromNBT(inv, stack);
for(int j = 4; j < inv.getSizeInventory(); j++){
for(int j = 4; j < inv.getSlots(); j++){
ItemStack invStack = inv.getStackInSlot(j);
if(StackUtil.isValid(invStack)){
for(int i = 0; i < handler.getSlots(); i++){
ItemStack remain = handler.insertItem(i, invStack, false);
if(!ItemStack.areItemStacksEqual(remain, invStack)){
inv.setInventorySlotContents(j, StackUtil.validateCopy(remain));
inv.setStackInSlot(j, StackUtil.validateCopy(remain));
changed = true;
if(!StackUtil.isValid(remain)){

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.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -24,13 +25,15 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.InvWrapper;
public class ItemChestToCrateUpgrade extends ItemBase{
private final Class<? extends IInventory> start;
private final Class start;
private final IBlockState end;
public ItemChestToCrateUpgrade(String name, Class<? extends IInventory> start, IBlockState end){
public ItemChestToCrateUpgrade(String name, Class start, IBlockState end){
super(name);
this.start = start;
this.end = end;
@ -45,13 +48,21 @@ public class ItemChestToCrateUpgrade extends ItemBase{
if(!world.isRemote){
//Copy Slots
IInventory chest = (IInventory)tileHit;
ItemStack[] stacks = new ItemStack[chest.getSizeInventory()];
IItemHandlerModifiable chest = null;
if(tileHit instanceof IInventory){
chest = new InvWrapper((IInventory)tileHit);
}
else if(tileHit instanceof TileEntityInventoryBase){
chest = ((TileEntityInventoryBase)tileHit).slots;
}
if(chest != null){
ItemStack[] stacks = new ItemStack[chest.getSlots()];
for(int i = 0; i < stacks.length; i++){
ItemStack aStack = chest.getStackInSlot(i);
if(StackUtil.isValid(aStack)){
stacks[i] = aStack.copy();
chest.setInventorySlotContents(i, StackUtil.getNull());
chest.setStackInSlot(i, StackUtil.getNull());
}
}
@ -61,12 +72,13 @@ public class ItemChestToCrateUpgrade extends ItemBase{
//Copy Items into new Chest
TileEntity newTileHit = world.getTileEntity(pos);
if(newTileHit instanceof IInventory){
IInventory newChest = (IInventory)newTileHit;
if(newTileHit instanceof TileEntityInventoryBase){
IItemHandlerModifiable newChest = ((TileEntityInventoryBase)newTileHit).slots;
for(int i = 0; i < stacks.length; i++){
if(StackUtil.isValid(stacks[i])){
if(newChest.getSizeInventory() > i){
newChest.setInventorySlotContents(i, stacks[i].copy());
if(newChest.getSlots() > i){
newChest.setStackInSlot(i, stacks[i].copy());
}
}
}
@ -76,6 +88,7 @@ public class ItemChestToCrateUpgrade extends ItemBase{
player.setHeldItem(hand, StackUtil.addStackSize(heldStack, -1));
}
}
}
return EnumActionResult.SUCCESS;
}
}

View file

@ -18,10 +18,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
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.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
@ -47,6 +44,9 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import java.util.HashSet;
import java.util.List;
@ -77,7 +77,7 @@ public class ItemDrill extends ItemEnergy{
*
* @param stack The Drill
*/
public static void loadSlotsFromNBT(IInventory slots, ItemStack stack){
public static void loadSlotsFromNBT(ItemStackHandlerCustom slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound();
if(compound != null){
TileEntityInventoryBase.loadSlots(slots, compound);
@ -90,7 +90,7 @@ public class ItemDrill extends ItemEnergy{
* @param slots The Slots
* @param stack The Drill
*/
public static void writeSlotsToNBT(IInventory slots, ItemStack stack){
public static void writeSlotsToNBT(ItemStackHandlerCustom slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
compound = new NBTTagCompound();
@ -150,9 +150,9 @@ public class ItemDrill extends ItemEnergy{
return StackUtil.getNull();
}
InventoryBasic inv = new InventoryBasic("Drill", false, ContainerDrill.SLOT_AMOUNT);
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerDrill.SLOT_AMOUNT);
loadSlotsFromNBT(inv, stack);
for(int i = 0; i < inv.getSizeInventory(); i++){
for(int i = 0; i < inv.getSlots(); i++){
ItemStack slotStack = inv.getStackInSlot(i);
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@ -49,9 +50,9 @@ public class ItemFilter extends ItemBase{
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, stack);
for(int i = 0; i < inv.getSizeInventory(); i++){
for(int i = 0; i < inv.getSlots(); i++){
ItemStack slot = inv.getStackInSlot(i);
if(StackUtil.isValid(slot)){
tooltip.add(slot.getItem().getItemStackDisplayName(slot));

View file

@ -37,7 +37,7 @@ public class FuelHandler implements IFuelHandler{
addFuel(InitItems.itemMisc, TheMiscItems.TINY_CHAR.ordinal(), 200);
addFuel(InitItems.itemMisc, TheMiscItems.TINY_COAL.ordinal(), 200);
addFuel(InitBlocks.blockMisc, TheMiscBlocks.CHARCOAL_BLOCK.ordinal(), 16000);
addFuel(InitItems.itemMisc, TheMiscItems.BIOCOAL.ordinal(), 1450);
addFuel(InitItems.itemMisc, TheMiscItems.BIOCOAL.ordinal(), 80);
}
private static void addFuel(Item item, int meta, int value){

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
@ -21,6 +22,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
@ -44,10 +46,10 @@ public class FilterSettings{
private boolean lastRespectMod;
private int lastRecpectOredict;
public final IInventory filterInventory;
public final ItemStackHandlerCustom filterInventory;
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, boolean defaultRespectMod, int defaultRespectOredict, int buttonIdStart){
this.filterInventory = new InventoryBasic("Filter", false, slots);
this.filterInventory = new ItemStackHandlerCustom(slots);
this.isWhitelist = defaultWhitelist;
this.respectMeta = defaultRespectMeta;
@ -62,9 +64,9 @@ public class FilterSettings{
this.modButtonId = buttonIdStart+4;
}
public static boolean check(ItemStack stack, IInventory filter, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){
public static boolean check(ItemStack stack, ItemStackHandlerCustom filter, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){
if(StackUtil.isValid(stack)){
for(int i = 0; i < filter.getSizeInventory(); i++){
for(int i = 0; i < filter.getSlots(); i++){
ItemStack slot = filter.getStackInSlot(i);
if(StackUtil.isValid(slot)){
@ -72,9 +74,9 @@ public class FilterSettings{
return whitelist;
}
else if(SlotFilter.isFilter(slot)){
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, slot);
for(int k = 0; k < inv.getSizeInventory(); k++){
for(int k = 0; k < inv.getSlots(); k++){
ItemStack filterSlot = inv.getStackInSlot(k);
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
return whitelist;

View file

@ -117,9 +117,9 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
@Override
public Lens getLens(){
if(StackUtil.isValid(this.slots.get(0))){
if(this.slots.get(0).getItem() instanceof ILensItem){
return ((ILensItem)this.slots.get(0).getItem()).getLens();
if(StackUtil.isValid(this.slots.getStackInSlot(0))){
if(this.slots.getStackInSlot(0).getItem() instanceof ILensItem){
return ((ILensItem)this.slots.getStackInSlot(0).getItem()).getLens();
}
}
return this.counter >= 500 ? ActuallyAdditionsAPI.lensDisruption : ActuallyAdditionsAPI.lensDefaultConversion;
@ -168,12 +168,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -38,6 +38,8 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
public abstract class TileEntityBase extends TileEntity implements ITickable{
@ -175,7 +177,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
data.setInteger("X", this.pos.getX());
data.setInteger("Y", this.pos.getY());
data.setInteger("Z", this.pos.getZ());
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.TILE_ENTITY_HANDLER), new NetworkRegistry.TargetPoint(this.world.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 128));
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.TILE_ENTITY_HANDLER), new NetworkRegistry.TargetPoint(this.world.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 64));
}
}
@ -326,6 +328,12 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
IItemHandler handler = this.getItemHandler(facing);
if(handler != null){
return (T)handler;
}
}
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
IFluidHandler tank = this.getFluidHandler(facing);
if(tank != null){
@ -360,6 +368,10 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
return null;
}
public IItemHandler getItemHandler(EnumFacing facing){
return null;
}
public boolean isRedstoneToggle(){
return false;
}

View file

@ -65,8 +65,8 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
List<Item> types = null;
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
for(int i = 0; i < this.slots.size(); i++){
ItemStack stack = this.slots.get(i);
for(int i = 0; i < this.slots.getSlots(); i++){
ItemStack stack = this.slots.getStackInSlot(i);
if(StackUtil.isValid(stack)){
Item item = stack.getItem();
if(isValidItem(stack) && (types == null || !types.contains(item))){
@ -75,7 +75,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
}
types.add(item);
this.slots.set(i, StackUtil.addStackSize(stack, -1));
this.slots.setStackInSlot(i, StackUtil.addStackSize(stack, -1));
}
}
}
@ -128,12 +128,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return this.isItemValidForSlot(index, stack);
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
public boolean canExtractItem(int index, ItemStack stack){
return false;
}

View file

@ -90,30 +90,25 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.world, coordsBlock, this.world.getBlockState(coordsBlock), 0, 1, false, null);
if(this.world.rand.nextFloat() <= chance){
if(WorldUtil.addToInventory(this, drops, false, true)){
if(WorldUtil.addToInventory(this.slots, drops, false)){
this.world.playEvent(2001, coordsBlock, Block.getStateId(stateToBreak));
this.world.setBlockToAir(coordsBlock);
WorldUtil.addToInventory(this, drops, true, true);
WorldUtil.addToInventory(this.slots, drops, true);
this.markDirty();
}
}
}
else if(this.isPlacer){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.world, this.pos, this.slots.get(theSlot)));
if(!StackUtil.isValid(this.slots.get(theSlot))){
this.slots.set(theSlot, StackUtil.getNull());
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.world, this.pos, this.slots.getStackInSlot(theSlot)));
if(!StackUtil.isValid(this.slots.getStackInSlot(theSlot))){
this.slots.setStackInSlot(theSlot, StackUtil.getNull());
}
}
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -91,7 +91,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
if(this.currentProcessTime >= TIME){
this.currentProcessTime = 0;
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1));
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.markDirty();
@ -116,16 +116,11 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IS
}
public boolean isCanola(int slot){
return StackUtil.isValid(this.slots.get(slot)) && this.slots.get(slot).getItem() == InitItems.itemMisc && this.slots.get(slot).getItemDamage() == TheMiscItems.CANOLA.ordinal();
return StackUtil.isValid(this.slots.getStackInSlot(slot)) && this.slots.getStackInSlot(slot).getItem() == InitItems.itemMisc && this.slots.getStackInSlot(slot).getItemDamage() == TheMiscItems.CANOLA.ordinal();
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return false;
}

View file

@ -75,12 +75,12 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
this.storage.receiveEnergyInternal(PRODUCE, false);
}
if(!this.isRedstonePowered && this.currentBurnTime <= 0 && StackUtil.isValid(this.slots.get(0)) && TileEntityFurnace.getItemBurnTime(this.slots.get(0)) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots.get(0));
if(!this.isRedstonePowered && this.currentBurnTime <= 0 && StackUtil.isValid(this.slots.getStackInSlot(0)) && TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0)) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0));
this.maxBurnTime = burnTime;
this.currentBurnTime = burnTime;
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1, true));
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1, true));
}
if(flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()){
@ -109,13 +109,8 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return TileEntityFurnace.getItemBurnTime(this.slots.get(0)) <= 0;
public boolean canExtractItem(int slot, ItemStack stack){
return TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0)) <= 0;
}
@Override

View file

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

View file

@ -16,6 +16,10 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import javax.annotation.Nonnull;
public class TileEntityCompost extends TileEntityInventoryBase{
@ -63,12 +67,13 @@ public class TileEntityCompost extends TileEntityInventoryBase{
if(!this.world.isRemote){
boolean theFlag = this.conversionTime > 0;
if(StackUtil.isValid(this.slots.get(0))){
CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
if(recipe != null && this.slots.get(0).isItemEqual(recipe.input) && StackUtil.getStackSize(this.slots.get(0)) >= StackUtil.getStackSize(recipe.input)){
if(StackUtil.isValid(this.slots.getStackInSlot(0))){
CompostRecipe recipe = getRecipeForInput(this.slots.getStackInSlot(0));
if(recipe != null){
this.conversionTime++;
if(this.conversionTime >= 3000){
this.slots.set(0, recipe.output.copy());
ItemStack output = recipe.output.copy();
this.slots.setStackInSlot(0, StackUtil.setStackSize(output, StackUtil.getStackSize(this.slots.getStackInSlot(0))));
this.conversionTime = 0;
this.markDirty();
}
@ -96,23 +101,7 @@ public class TileEntityCompost extends TileEntityInventoryBase{
}
@Override
public int getInventoryStackLimit(){
if(StackUtil.isValid(this.slots.get(0))){
CompostRecipe recipe = getRecipeForInput(this.slots.get(0));
if(recipe != null && StackUtil.isValid(recipe.input)){
return StackUtil.getStackSize(recipe.input);
}
}
return super.getInventoryStackLimit();
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return getRecipeForInput(stack) == null;
}
}

View file

@ -89,10 +89,10 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.world, coordsBlock, this.world.getBlockState(coordsBlock), 0, 1, false, null);
if(this.world.rand.nextFloat() <= chance){
if(WorldUtil.addToInventory(this, drops, false, true)){
if(WorldUtil.addToInventory(this.slots, drops, false)){
this.world.playEvent(2001, coordsBlock, Block.getStateId(this.world.getBlockState(coordsBlock)));
this.world.setBlockToAir(coordsBlock);
WorldUtil.addToInventory(this, drops, true, true);
WorldUtil.addToInventory(this.slots, drops, true);
this.storage.extractEnergyInternal(ENERGY_USE, false);
this.markDirty();
}
@ -113,12 +113,7 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -34,12 +34,12 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
super.updateEntity();
if(!this.world.isRemote){
if(StackUtil.isValid(this.slots.get(0)) && !this.isRedstonePowered){
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots.get(0).getItem());
if(StackUtil.isValid(this.slots.getStackInSlot(0)) && !this.isRedstonePowered){
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots.getStackInSlot(0).getItem());
if(item != null){
int energy = item.getUsePerTick(this.slots.get(0), this, this.ticksElapsed);
int energy = item.getUsePerTick(this.slots.getStackInSlot(0), this, this.ticksElapsed);
if(this.storage.getEnergyStored() >= energy){
if(item.update(this.slots.get(0), this, this.ticksElapsed)){
if(item.update(this.slots.getStackInSlot(0), this, this.ticksElapsed)){
this.storage.extractEnergyInternal(energy, false);
}
}
@ -68,11 +68,6 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
return true;
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return this.isItemValidForSlot(index, stack);
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
@ -99,7 +94,7 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
public boolean canExtractItem(int index, ItemStack stack){
return true;
}
@ -114,7 +109,7 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I
}
@Override
public int getInventoryStackLimit(){
public int getMaxStackSizePerSlot(int slot, ItemStack stack){
return 1;
}

View file

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

View file

@ -74,11 +74,11 @@ public class TileEntityDropper extends TileEntityInventoryBase{
}
public ItemStack removeFromInventory(boolean actuallyDo){
for(int i = 0; i < this.slots.size(); i++){
if(StackUtil.isValid(this.slots.get(i))){
ItemStack slot = this.slots.get(i).copy();
for(int i = 0; i < this.slots.getSlots(); i++){
if(StackUtil.isValid(this.slots.getStackInSlot(i))){
ItemStack slot = this.slots.getStackInSlot(i).copy();
if(actuallyDo){
this.slots.set(i, StackUtil.addStackSize(this.slots.get(i), -1));
this.slots.setStackInSlot(i, StackUtil.addStackSize(this.slots.getStackInSlot(i), -1));
this.markDirty();
}
return slot;
@ -88,12 +88,7 @@ public class TileEntityDropper extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -52,7 +52,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
super.updateEntity();
if(!this.world.isRemote){
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots.get(0));
List<EmpowererRecipe> recipes = getRecipesForInput(this.slots.getStackInSlot(0));
if(!recipes.isEmpty()){
for(EmpowererRecipe recipe : recipes){
TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time);
@ -65,7 +65,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
stand.storage.extractEnergyInternal(recipe.energyPerStand/recipe.time, false);
if(done){
stand.decrStackSize(0, 1);
stand.slots.decrStackSize(0, 1);
}
AssetUtil.shootParticles(this.world, stand.getPos().getX(), stand.getPos().getY()+0.45F, stand.getPos().getZ(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), recipe.particleColor, 8, 0.5F, 1F);
@ -78,7 +78,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
if(done){
((WorldServer)this.world).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 300, 0, 0, 0, 0.25D);
this.slots.set(0, recipe.output.copy());
this.slots.setStackInSlot(0, recipe.output.copy());
this.markDirty();
this.processTime = 0;
@ -103,7 +103,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
if(tile instanceof TileEntityDisplayStand){
TileEntityDisplayStand stand = (TileEntityDisplayStand)tile;
ItemStack standItem = stand.getStackInSlot(0);
ItemStack standItem = stand.slots.getStackInSlot(0);
int containPlace = ItemUtil.getPlaceAt(itemsStillNeeded, standItem, true);
if(stand.storage.getEnergyStored() >= recipe.energyPerStand/powerDivider && containPlace != -1){
modifierStands[i] = stand;
@ -154,17 +154,12 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return this.isItemValidForSlot(index, stack);
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
public boolean canExtractItem(int index, ItemStack stack){
return getRecipesForInput(stack).isEmpty();
}
@Override
public int getInventoryStackLimit(){
public int getMaxStackSizePerSlot(int slot, ItemStack stack){
return 1;
}
}

View file

@ -48,27 +48,27 @@ public class TileEntityEnergizer extends TileEntityInventoryBase{
public void updateEntity(){
super.updateEntity();
if(!this.world.isRemote){
if(StackUtil.isValid(this.slots.get(0)) && !StackUtil.isValid(this.slots.get(1))){
if(StackUtil.isValid(this.slots.getStackInSlot(0)) && !StackUtil.isValid(this.slots.getStackInSlot(1))){
if(this.storage.getEnergyStored() > 0){
int received = 0;
boolean canTakeUp = false;
if(this.slots.get(0).hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage cap = this.slots.get(0).getCapability(CapabilityEnergy.ENERGY, null);
if(this.slots.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage cap = this.slots.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
if(cap != null){
received = cap.receiveEnergy(this.storage.getEnergyStored(), false);
canTakeUp = cap.getEnergyStored() >= cap.getMaxEnergyStored();
}
}
else if(ActuallyAdditions.teslaLoaded){
if(this.slots.get(0).hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = this.slots.get(0).getCapability(TeslaUtil.teslaConsumer, null);
if(this.slots.getStackInSlot(0).hasCapability(TeslaUtil.teslaConsumer, null)){
ITeslaConsumer cap = this.slots.getStackInSlot(0).getCapability(TeslaUtil.teslaConsumer, null);
if(cap != null){
received = (int)cap.givePower(this.storage.getEnergyStored(), false);
}
}
if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
if(this.slots.getStackInSlot(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots.getStackInSlot(0).getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){
canTakeUp = cap.getStoredPower() >= cap.getCapacity();
}
@ -79,8 +79,8 @@ public class TileEntityEnergizer extends TileEntityInventoryBase{
}
if(canTakeUp){
this.slots.set(1, this.slots.get(0).copy());
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
this.slots.setStackInSlot(1, this.slots.getStackInSlot(0).copy());
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1));
}
}
}
@ -97,12 +97,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == 1;
}

View file

@ -48,28 +48,28 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
public void updateEntity(){
super.updateEntity();
if(!this.world.isRemote){
if(StackUtil.isValid(this.slots.get(0)) && !StackUtil.isValid(this.slots.get(1))){
if(StackUtil.isValid(this.slots.getStackInSlot(0)) && !StackUtil.isValid(this.slots.getStackInSlot(1))){
if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
int extracted = 0;
boolean canTakeUp = false;
int maxExtract = this.storage.getMaxEnergyStored()-this.storage.getEnergyStored();
if(this.slots.get(0).hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage cap = this.slots.get(0).getCapability(CapabilityEnergy.ENERGY, null);
if(this.slots.getStackInSlot(0).hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage cap = this.slots.getStackInSlot(0).getCapability(CapabilityEnergy.ENERGY, null);
if(cap != null){
extracted = cap.extractEnergy(maxExtract, false);
canTakeUp = cap.getEnergyStored() <= 0;
}
}
else if(ActuallyAdditions.teslaLoaded){
if(this.slots.get(0).hasCapability(TeslaUtil.teslaProducer, null)){
ITeslaProducer cap = this.slots.get(0).getCapability(TeslaUtil.teslaProducer, null);
if(this.slots.getStackInSlot(0).hasCapability(TeslaUtil.teslaProducer, null)){
ITeslaProducer cap = this.slots.getStackInSlot(0).getCapability(TeslaUtil.teslaProducer, null);
if(cap != null){
extracted = (int)cap.takePower(maxExtract, false);
}
}
if(this.slots.get(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots.get(0).getCapability(TeslaUtil.teslaHolder, null);
if(this.slots.getStackInSlot(0).hasCapability(TeslaUtil.teslaHolder, null)){
ITeslaHolder cap = this.slots.getStackInSlot(0).getCapability(TeslaUtil.teslaHolder, null);
if(cap != null){
canTakeUp = cap.getStoredPower() <= 0;
}
@ -80,8 +80,8 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
}
if(canTakeUp){
this.slots.set(1, this.slots.get(0).copy());
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
this.slots.setStackInSlot(1, this.slots.getStackInSlot(0).copy());
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1));
}
}
}
@ -103,12 +103,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == 1;
}

View file

@ -121,16 +121,16 @@ public class TileEntityFarmer extends TileEntityInventoryBase{
}
boolean putSeeds = true;
if(!WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, false, true)){
if(!WorldUtil.addToInventory(this.slots, 0, 6, seeds, false)){
other.addAll(seeds);
putSeeds = false;
}
if(WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, false, true)){
WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, true, true);
if(WorldUtil.addToInventory(this.slots, 6, 12, other, false)){
WorldUtil.addToInventory(this.slots, 6, 12, other, true);
if(putSeeds){
WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, true, true);
WorldUtil.addToInventory(this.slots, 0, 6, seeds, true);
}
this.world.playEvent(2001, plant, Block.getStateId(plantState));
@ -185,13 +185,13 @@ public class TileEntityFarmer extends TileEntityInventoryBase{
private IBlockState getFirstPlantablePlantFromSlots(BlockPos pos){
for(int i = 0; i < 6; i++){
ItemStack stack = this.slots.get(i);
ItemStack stack = this.slots.getStackInSlot(i);
if(StackUtil.isValid(stack)){
IPlantable plantable = getPlantableFromStack(stack);
if(plantable != null){
IBlockState state = plantable.getPlant(this.world, pos);
if(state != null && state.getBlock() instanceof BlockCrops && state.getBlock().canPlaceBlockAt(this.world, pos)){
this.decrStackSize(i, 1);
this.slots.decrStackSize(i, 1);
return state;
}
}
@ -206,12 +206,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot >= 6;
}

View file

@ -74,13 +74,13 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
if(this.currentAnimalAmount < THRESHOLD){
if(this.currentTimer >= TIME){
this.currentTimer = 0;
if(StackUtil.isValid(this.slots.get(0))){
if(StackUtil.isValid(this.slots.getStackInSlot(0))){
EntityAnimal randomAnimal = animals.get(this.world.rand.nextInt(this.currentAnimalAmount));
if(!randomAnimal.isInLove() && randomAnimal.getGrowingAge() == 0 && (randomAnimal.isBreedingItem(this.slots.get(0)) || this.canHorseBeFed(randomAnimal))){
if(!randomAnimal.isInLove() && randomAnimal.getGrowingAge() == 0 && (randomAnimal.isBreedingItem(this.slots.getStackInSlot(0)) || this.canHorseBeFed(randomAnimal))){
this.feedAnimal(randomAnimal);
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), -1));
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1));
}
}
}
@ -112,7 +112,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
if(animal instanceof EntityHorse){
EntityHorse horse = (EntityHorse)animal;
if(horse.isTame()){
Item item = this.slots.get(0).getItem();
Item item = this.slots.getStackInSlot(0).getItem();
return item == Items.GOLDEN_APPLE || item == Items.GOLDEN_CARROT;
}
}
@ -135,12 +135,7 @@ public class TileEntityFeeder extends TileEntityInventoryBase{
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return false;
}
}

View file

@ -11,9 +11,11 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
@ -44,9 +46,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
super(4, "furnaceDouble");
}
public static void autoSplit(NonNullList<ItemStack> slots, int slot1, int slot2){
ItemStack first = slots.get(slot1);
ItemStack second = slots.get(slot2);
public static void autoSplit(ItemStackHandlerCustom slots, int slot1, int slot2){
ItemStack first = slots.getStackInSlot(slot1);
ItemStack second = slots.getStackInSlot(slot2);
if(StackUtil.isValid(first) || StackUtil.isValid(second)){
ItemStack toSplit = StackUtil.getNull();
@ -68,8 +70,8 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
if(StackUtil.isValid(toSplit)){
ItemStack splitFirst = toSplit.copy();
ItemStack secondSplit = splitFirst.splitStack(StackUtil.getStackSize(splitFirst)/2);
slots.set(slot1, StackUtil.validateCheck(splitFirst));
slots.set(slot2, StackUtil.validateCheck(secondSplit));
slots.setStackInSlot(slot1, StackUtil.validateCheck(splitFirst));
slots.setStackInSlot(slot2, StackUtil.validateCheck(secondSplit));
}
}
}
@ -152,10 +154,10 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
}
public boolean canSmeltOn(int theInput, int theOutput){
if(StackUtil.isValid(this.slots.get(theInput))){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
if(StackUtil.isValid(this.slots.getStackInSlot(theInput))){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.getStackInSlot(theInput));
if(StackUtil.isValid(output)){
if(!StackUtil.isValid(this.slots.get(theOutput)) || (this.slots.get(theOutput).isItemEqual(output) && StackUtil.getStackSize(this.slots.get(theOutput)) <= this.slots.get(theOutput).getMaxStackSize()-StackUtil.getStackSize(output))){
if(!StackUtil.isValid(this.slots.getStackInSlot(theOutput)) || (this.slots.getStackInSlot(theOutput).isItemEqual(output) && StackUtil.getStackSize(this.slots.getStackInSlot(theOutput)) <= this.slots.getStackInSlot(theOutput).getMaxStackSize()-StackUtil.getStackSize(output))){
return true;
}
}
@ -165,15 +167,15 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
}
public void finishBurning(int theInput, int theOutput){
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.get(theInput));
if(!StackUtil.isValid(this.slots.get(theOutput))){
this.slots.set(theOutput, output.copy());
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(this.slots.getStackInSlot(theInput));
if(!StackUtil.isValid(this.slots.getStackInSlot(theOutput))){
this.slots.setStackInSlot(theOutput, output.copy());
}
else if(this.slots.get(theOutput).getItem() == output.getItem()){
this.slots.set(theOutput, StackUtil.addStackSize(this.slots.get(theOutput), StackUtil.getStackSize(output)));
else if(this.slots.getStackInSlot(theOutput).getItem() == output.getItem()){
this.slots.setStackInSlot(theOutput, StackUtil.addStackSize(this.slots.getStackInSlot(theOutput), StackUtil.getStackSize(output)));
}
this.slots.set(theInput, StackUtil.addStackSize(this.slots.get(theInput), -1));
this.slots.setStackInSlot(theInput, StackUtil.addStackSize(this.slots.getStackInSlot(theInput), -1));
}
@SideOnly(Side.CLIENT)
@ -187,12 +189,7 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == SLOT_OUTPUT_1 || slot == SLOT_OUTPUT_2;
}

View file

@ -14,6 +14,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.AwfulUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -56,18 +57,13 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
}
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return true;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}
@ -104,7 +100,7 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
if(player != null){
builder.withLuck(player.getLuck());
}
table.fillInventory(this, new Random(), builder.build());
AwfulUtil.fillInventory(table, this.slots, new Random(), builder.build());
}
}
}

View file

@ -148,9 +148,9 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
}
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){
if(StackUtil.isValid(this.slots.get(theInput))){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.get(theInput));
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.get(theInput));
if(StackUtil.isValid(this.slots.getStackInSlot(theInput))){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.getStackInSlot(theInput));
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.getStackInSlot(theInput));
if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0);
@ -158,7 +158,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
if(StackUtil.isValid(outputTwo) && outputTwo.getItemDamage() == Util.WILDCARD){
outputTwo.setItemDamage(0);
}
if((!StackUtil.isValid(this.slots.get(theFirstOutput)) || (this.slots.get(theFirstOutput).isItemEqual(outputOne) && StackUtil.getStackSize(this.slots.get(theFirstOutput)) <= this.slots.get(theFirstOutput).getMaxStackSize()-StackUtil.getStackSize(outputOne))) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.slots.get(theSecondOutput)) || (this.slots.get(theSecondOutput).isItemEqual(outputTwo) && StackUtil.getStackSize(this.slots.get(theSecondOutput)) <= this.slots.get(theSecondOutput).getMaxStackSize()-StackUtil.getStackSize(outputTwo))))){
if((!StackUtil.isValid(this.slots.getStackInSlot(theFirstOutput)) || (this.slots.getStackInSlot(theFirstOutput).isItemEqual(outputOne) && StackUtil.getStackSize(this.slots.getStackInSlot(theFirstOutput)) <= this.slots.getStackInSlot(theFirstOutput).getMaxStackSize()-StackUtil.getStackSize(outputOne))) && (!StackUtil.isValid(outputTwo) || (!StackUtil.isValid(this.slots.getStackInSlot(theSecondOutput)) || (this.slots.getStackInSlot(theSecondOutput).isItemEqual(outputTwo) && StackUtil.getStackSize(this.slots.getStackInSlot(theSecondOutput)) <= this.slots.getStackInSlot(theSecondOutput).getMaxStackSize()-StackUtil.getStackSize(outputTwo))))){
return true;
}
}
@ -171,36 +171,36 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
}
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.get(theInput));
ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots.getStackInSlot(theInput));
if(StackUtil.isValid(outputOne)){
if(outputOne.getItemDamage() == Util.WILDCARD){
outputOne.setItemDamage(0);
}
if(!StackUtil.isValid(this.slots.get(theFirstOutput))){
this.slots.set(theFirstOutput, outputOne.copy());
if(!StackUtil.isValid(this.slots.getStackInSlot(theFirstOutput))){
this.slots.setStackInSlot(theFirstOutput, outputOne.copy());
}
else if(this.slots.get(theFirstOutput).getItem() == outputOne.getItem()){
this.slots.set(theFirstOutput, StackUtil.addStackSize(this.slots.get(theFirstOutput), StackUtil.getStackSize(outputOne)));
else if(this.slots.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()){
this.slots.setStackInSlot(theFirstOutput, StackUtil.addStackSize(this.slots.getStackInSlot(theFirstOutput), StackUtil.getStackSize(outputOne)));
}
}
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.get(theInput));
ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots.getStackInSlot(theInput));
if(StackUtil.isValid(outputTwo)){
if(outputTwo.getItemDamage() == Util.WILDCARD){
outputTwo.setItemDamage(0);
}
int rand = this.world.rand.nextInt(100)+1;
if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots.get(theInput))){
if(!StackUtil.isValid(this.slots.get(theSecondOutput))){
this.slots.set(theSecondOutput, outputTwo.copy());
if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots.getStackInSlot(theInput))){
if(!StackUtil.isValid(this.slots.getStackInSlot(theSecondOutput))){
this.slots.setStackInSlot(theSecondOutput, outputTwo.copy());
}
else if(this.slots.get(theSecondOutput).getItem() == outputTwo.getItem()){
this.slots.set(theSecondOutput, StackUtil.addStackSize(this.slots.get(theSecondOutput), StackUtil.getStackSize(outputTwo)));
else if(this.slots.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()){
this.slots.setStackInSlot(theSecondOutput, StackUtil.addStackSize(this.slots.getStackInSlot(theSecondOutput), StackUtil.getStackSize(outputTwo)));
}
}
}
this.slots.set(theInput, StackUtil.addStackSize(this.slots.get(theInput), -1));
this.slots.setStackInSlot(theInput, StackUtil.addStackSize(this.slots.getStackInSlot(theInput), -1));
}
@SideOnly(Side.CLIENT)
@ -219,12 +219,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IButto
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2;
}

View file

@ -16,7 +16,6 @@ import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
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;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -97,7 +96,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
private boolean newPutting(){
if(this.checkBothFilters(this.slots.get(0), true)){
if(this.checkBothFilters(this.slots.getStackInSlot(0), true)){
for(EnumFacing side : EnumFacing.values()){
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
@ -143,10 +142,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
this.placeToPull = this.world.getTileEntity(this.pos.offset(side));
if(this.slotToPullEnd <= 0 && this.placeToPull != null){
if(this.placeToPull instanceof IInventory){
this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
}
else{
if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
IItemHandler cap = this.placeToPull.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if(cap != null){
@ -155,17 +150,12 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
}
}
}
if(this.sideToPut != -1){
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
this.placeToPut = this.world.getTileEntity(this.pos.offset(side));
if(this.slotToPutEnd <= 0 && this.placeToPut != null){
if(this.placeToPut instanceof IInventory){
this.slotToPutEnd = ((IInventory)this.placeToPut).getSizeInventory();
}
else{
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if(cap != null){
@ -175,7 +165,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
}
}
}
@Override
public void onButtonPressed(int buttonID, EntityPlayer player){
@ -267,7 +256,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
if(this.sideToPull != -1 && this.placeToPull != null){
this.newPulling();
}
if(StackUtil.isValid(this.slots.get(0)) && this.sideToPut != -1 && this.placeToPut != null){
if(StackUtil.isValid(this.slots.getStackInSlot(0)) && this.sideToPut != -1 && this.placeToPut != null){
this.newPutting();
}
}
@ -293,12 +282,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == 0;
}
}

View file

@ -10,39 +10,52 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{
public abstract class TileEntityInventoryBase extends TileEntityBase{
private final SidedInvWrapper[] invWrappers = new SidedInvWrapper[6];
public NonNullList<ItemStack> slots;
public final ItemStackHandlerCustom slots;
public TileEntityInventoryBase(int slots, String name){
super(name);
this.slots = StackUtil.createSlots(slots);
if(this.hasInvWrapperCapabilities()){
this.getInvWrappers(this.invWrappers);
}
this.slots = new ItemStackHandlerCustom(slots){
@Override
public boolean canInsert(ItemStack stack, int slot){
return TileEntityInventoryBase.this.isItemValidForSlot(slot, stack);
}
public static void saveSlots(IInventory slots, NBTTagCompound compound){
if(slots != null && slots.getSizeInventory() > 0){
@Override
public boolean canExtract(ItemStack stack, int slot){
return TileEntityInventoryBase.this.canExtractItem(slot, stack);
}
@Override
protected int getStackLimit(int slot, ItemStack stack){
return TileEntityInventoryBase.this.getMaxStackSizePerSlot(slot, stack);
}
@Override
protected void onContentsChanged(int slot){
super.onContentsChanged(slot);
TileEntityInventoryBase.this.markDirty();
}
};
}
public static void saveSlots(IItemHandler slots, NBTTagCompound compound){
if(slots != null && slots.getSlots() > 0){
NBTTagList tagList = new NBTTagList();
for(int i = 0; i < slots.getSizeInventory(); i++){
for(int i = 0; i < slots.getSlots(); i++){
ItemStack slot = slots.getStackInSlot(i);
NBTTagCompound tagCompound = new NBTTagCompound();
if(StackUtil.isValid(slot)){
@ -54,177 +67,68 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
}
}
public static void loadSlots(IInventory slots, NBTTagCompound compound){
if(slots != null && slots.getSizeInventory() > 0){
public static void loadSlots(IItemHandlerModifiable slots, NBTTagCompound compound){
if(slots != null && slots.getSlots() > 0){
NBTTagList tagList = compound.getTagList("Items", 10);
for(int i = 0; i < slots.getSizeInventory(); i++){
for(int i = 0; i < slots.getSlots(); i++){
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
slots.setInventorySlotContents(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull());
slots.setStackInSlot(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull());
}
}
}
protected void getInvWrappers(SidedInvWrapper[] wrappers){
for(int i = 0; i < wrappers.length; i++){
wrappers[i] = new SidedInvWrapper(this, EnumFacing.values()[i]);
}
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){
saveSlots(this, compound);
saveSlots(this.slots, compound);
}
}
@Override
public IItemHandler getItemHandler(EnumFacing facing){
return this.slots;
}
public boolean isItemValidForSlot(int slot, ItemStack stack){
return true;
}
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}
public int getMaxStackSizePerSlot(int slot, ItemStack stack){
return stack.getMaxStackSize();
}
public boolean shouldSyncSlots(){
return false;
}
@Override
public int getComparatorStrength(){
return Container.calcRedstoneFromInventory(this);
int i = 0;
float f = 0;
for(int j = 0; j < this.slots.getSlots(); ++j){
ItemStack stack = this.slots.getStackInSlot(j);
if(StackUtil.isValid(stack)){
f += (float)StackUtil.getStackSize(stack)/(float)Math.min(this.getMaxStackSizePerSlot(j, stack), stack.getMaxStackSize());
i++;
}
}
f = f/(float)this.slots.getSlots();
return MathHelper.floor(f*14.0F)+(i > 0 ? 1 : 0);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){
loadSlots(this, compound);
loadSlots(this.slots, compound);
}
}
@Override
public int[] getSlotsForFace(EnumFacing side){
int invSize = this.getSizeInventory();
if(invSize > 0){
int[] theInt = new int[invSize];
for(int i = 0; i < theInt.length; i++){
theInt[i] = i;
}
return theInt;
}
else{
return new int[0];
}
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public boolean isUsableByPlayer(EntityPlayer player){
return this.canPlayerUse(player);
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public int getField(int id){
return 0;
}
@Override
public void setField(int id, int value){
}
@Override
public int getFieldCount(){
return 0;
}
@Override
public void clear(){
this.slots.clear();
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.slots.set(i, stack);
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.slots.size();
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.slots.get(i);
}
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.slots.get(i))){
ItemStack stackAt;
if(StackUtil.getStackSize(this.slots.get(i)) <= j){
stackAt = this.slots.get(i);
this.slots.set(i, StackUtil.getNull());
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.slots.get(i)) <= 0){
this.slots.set(i, StackUtil.getNull());
}
this.markDirty();
return stackAt;
}
}
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots.get(index);
this.slots.set(index, StackUtil.getNull());
return stack;
}
@Override
public String getName(){
return this.getDisplayedName();
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
if(this.hasInvWrapperCapabilities() && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
return (T)this.invWrappers[facing == null ? 0 : facing.ordinal()];
}
else{
return super.getCapability(capability, facing);
}
}
public boolean hasInvWrapperCapabilities(){
return true;
}
@Override
public boolean isEmpty(){
return StackUtil.isIInvEmpty(this.slots);
}
}

View file

@ -77,11 +77,11 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
public void updateEntity(){
super.updateEntity();
if(!this.world.isRemote){
ItemStack input = this.slots.get(SLOT_INPUT);
if(!StackUtil.isValid(this.slots.get(SLOT_OUTPUT)) && canBeRepaired(input)){
ItemStack input = this.slots.getStackInSlot(SLOT_INPUT);
if(!StackUtil.isValid(this.slots.getStackInSlot(SLOT_OUTPUT)) && canBeRepaired(input)){
if(input.getItemDamage() <= 0){
this.slots.set(SLOT_OUTPUT, input.copy());
this.slots.set(SLOT_INPUT, StackUtil.getNull());
this.slots.setStackInSlot(SLOT_OUTPUT, input.copy());
this.slots.setStackInSlot(SLOT_INPUT, StackUtil.getNull());
this.nextRepairTick = 0;
}
else{
@ -125,19 +125,14 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase{
@SideOnly(Side.CLIENT)
public int getItemDamageToScale(int i){
if(StackUtil.isValid(this.slots.get(SLOT_INPUT))){
return (this.slots.get(SLOT_INPUT).getMaxDamage()-this.slots.get(SLOT_INPUT).getItemDamage())*i/this.slots.get(SLOT_INPUT).getMaxDamage();
if(StackUtil.isValid(this.slots.getStackInSlot(SLOT_INPUT))){
return (this.slots.getStackInSlot(SLOT_INPUT).getMaxDamage()-this.slots.getStackInSlot(SLOT_INPUT).getItemDamage())*i/this.slots.getStackInSlot(SLOT_INPUT).getMaxDamage();
}
return 0;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return slot == SLOT_OUTPUT;
}

View file

@ -19,11 +19,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import javax.annotation.Nonnull;
import java.util.*;
public class TileEntityItemViewer extends TileEntityInventoryBase{
public class TileEntityItemViewer extends TileEntityBase{
private final List<GenericItemHandlerInfo> genericInfos = new ArrayList<GenericItemHandlerInfo>();
private final Map<Integer, SpecificItemHandlerInfo> specificInfos = new HashMap<Integer, SpecificItemHandlerInfo>();
@ -32,37 +32,54 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
private Network oldNetwork;
private int lastNetworkChangeAmount = -1;
private final IItemHandler itemHandler;
public TileEntityItemViewer(){
super(0, "itemViewer");
super("itemViewer");
this.itemHandler = new IItemHandler(){
@Override
public int getSlots(){
int size = 0;
List<GenericItemHandlerInfo> infos = TileEntityItemViewer.this.getItemHandlerInfos();
if(infos != null){
for(GenericItemHandlerInfo info : infos){
for(IItemHandler handler : info.handlers){
size += handler.getSlots();
}
}
}
return size;
}
@Override
protected void getInvWrappers(SidedInvWrapper[] wrappers){
for(int i = 0; i < wrappers.length; i++){
final EnumFacing direction = EnumFacing.values()[i];
wrappers[i] = new SidedInvWrapper(this, direction){
public ItemStack getStackInSlot(int slot){
SpecificItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(handler != null){
return handler.handler.getStackInSlot(handler.switchedIndex);
}
return StackUtil.getNull();
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
if(TileEntityItemViewer.this.canInsertItem(slot, stack, direction)){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null){
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){
ItemStack inserted = info.handler.insertItem(info.switchedIndex, stack, simulate);
if(!ItemStack.areItemStacksEqual(inserted, stack)){
TileEntityItemViewer.this.markDirty();
}
return inserted;
}
}
return super.insertItem(slot, stack, simulate);
return stack;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate){
ItemStack stackIn = TileEntityItemViewer.this.getStackInSlot(slot);
ItemStack stackIn = this.getStackInSlot(slot);
if(StackUtil.isValid(stackIn)){
if(TileEntityItemViewer.this.canExtractItem(slot, stackIn, direction)){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null){
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
if(extracted != null){
TileEntityItemViewer.this.markDirty();
@ -70,11 +87,14 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
return extracted;
}
}
}
return super.extractItem(slot, amount, simulate);
return StackUtil.getNull();
}
};
}
@Override
public IItemHandler getItemHandler(EnumFacing facing){
return this.itemHandler;
}
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
@ -159,25 +179,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
this.connectedRelay = tileFound;
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return this.isItemValidForSlot(index, stack);
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
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, StackUtil.getStackSize(stack), true);
return StackUtil.isValid(gaveBack);
}
}
}
return false;
}
private boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output){
boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output);
TileEntityLaserRelayItem connected = this.connectedRelay;
@ -189,96 +190,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
}
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){
if(this.isWhitelisted(handler, stack, false)){
ItemStack gaveBack = handler.handler.insertItem(handler.switchedIndex, stack, true);
return !ItemStack.areItemStacksEqual(gaveBack, stack);
}
}
return false;
}
@Override
public void clear(){
for(int i = 0; i < this.getSizeInventory(); i++){
this.removeStackFromSlot(i);
}
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
if(StackUtil.isValid(stack)){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){
ItemStack toInsert = stack.copy();
ItemStack inSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(StackUtil.isValid(inSlot)){
toInsert = StackUtil.addStackSize(toInsert, -StackUtil.getStackSize(inSlot));
}
handler.handler.insertItem(handler.switchedIndex, toInsert, false);
this.markDirty();
}
}
else{
this.removeStackFromSlot(i);
}
}
@Override
public int getSizeInventory(){
int size = 0;
List<GenericItemHandlerInfo> infos = this.getItemHandlerInfos();
if(infos != null){
for(GenericItemHandlerInfo info : infos){
for(IItemHandler handler : info.handlers){
size += handler.getSlots();
}
}
}
return size;
}
@Override
public ItemStack getStackInSlot(int i){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){
return handler.handler.getStackInSlot(handler.switchedIndex);
}
return null;
}
@Override
public ItemStack decrStackSize(int i, int j){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){
ItemStack extract = handler.handler.extractItem(handler.switchedIndex, j, false);
if(extract != null){
this.markDirty();
}
return extract;
}
return null;
}
@Override
public ItemStack removeStackFromSlot(int index){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){
ItemStack stackInSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(StackUtil.isValid(stackInSlot)){
ItemStack extracted = handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stackInSlot), false);
if(extracted != null){
this.markDirty();
}
return extracted;
}
}
return null;
}
private static class SpecificItemHandlerInfo{
public final IItemHandler handler;

View file

@ -124,7 +124,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
}
}
if(change){
if(change || old.size() != this.receiversAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
if(network != null){
network.changeAmount++;

View file

@ -89,7 +89,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
}
}
if(change){
if(change || old.size() != this.receiversAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
if(network != null){
network.changeAmount++;

View file

@ -79,7 +79,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
}
}
if(change){
if(change || old.size() != this.handlersAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
if(network != null){
network.changeAmount++;

View file

@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@ -21,6 +22,7 @@ import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
@ -79,17 +81,17 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
copy = StackUtil.setStackSize(copy, 1);
if(!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
for(int k = 0; k < usedSettings.filterInventory.getSizeInventory(); k++){
for(int k = 0; k < usedSettings.filterInventory.getSlots(); k++){
ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
if(StackUtil.isValid(slot)){
if(SlotFilter.isFilter(slot)){
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, slot);
boolean did = false;
for(int j = 0; j < inv.getSizeInventory(); j++){
for(int j = 0; j < inv.getSlots(); j++){
if(!StackUtil.isValid(inv.getStackInSlot(j))){
inv.setInventorySlotContents(j, copy);
inv.setStackInSlot(j, copy);
did = true;
break;
}
@ -102,7 +104,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
}
}
else{
usedSettings.filterInventory.setInventorySlotContents(k, copy);
usedSettings.filterInventory.setStackInSlot(k, copy);
break;
}
}

View file

@ -106,11 +106,11 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.world, pos, this.world.getBlockState(pos), 0, 1, false, null);
if(this.world.rand.nextFloat() <= chance){
if(WorldUtil.addToInventory(this, drops, false, true)){
if(WorldUtil.addToInventory(this.slots, drops, false)){
this.world.playEvent(2001, pos, Block.getStateId(this.world.getBlockState(pos)));
this.world.setBlockToAir(pos);
WorldUtil.addToInventory(this, drops, true, true);
WorldUtil.addToInventory(this.slots, drops, true);
this.markDirty();
this.storage.extractEnergyInternal(actualUse, false);
@ -184,12 +184,7 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -11,8 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -25,93 +23,14 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
this.type = BlockPhantom.Type.FACE;
}
@Override
public int[] getSlotsForFace(EnumFacing side){
if(this.isBoundThingInRange()){
if(this.getSided() != null){
return this.getSided().getSlotsForFace(side);
}
else{
int[] theInt = new int[this.getSizeInventory()];
for(int i = 0; i < theInt.length; i++){
theInt[i] = i;
}
return theInt;
}
}
return new int[0];
}
@Override
public int getInventoryStackLimit(){
return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0;
}
@Override
public void clear(){
if(this.isBoundThingInRange()){
this.getInventory().clear();
}
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
if(this.isBoundThingInRange()){
this.getInventory().setInventorySlotContents(i, stack);
}
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.isBoundThingInRange() ? this.getInventory().getSizeInventory() : 0;
}
@Override
public ItemStack getStackInSlot(int i){
return this.isBoundThingInRange() ? this.getInventory().getStackInSlot(i) : null;
}
@Override
public ItemStack decrStackSize(int i, int j){
return this.isBoundThingInRange() ? this.getInventory().decrStackSize(i, j) : null;
}
@Override
public ItemStack removeStackFromSlot(int index){
if(this.isBoundThingInRange()){
return this.getInventory().removeStackFromSlot(index);
}
return null;
}
public ISidedInventory getSided(){
return this.getInventory() instanceof ISidedInventory ? (ISidedInventory)this.getInventory() : null;
}
public IInventory getInventory(){
if(this.boundPosition != null){
TileEntity tile = this.world.getTileEntity(this.boundPosition);
if(tile instanceof IInventory){
return (IInventory)tile;
}
}
return null;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack);
return this.isBoundThingInRange();
}
@Override
public boolean isBoundThingInRange(){
if(super.isBoundThingInRange()){
if(this.getInventory() != null){
return true;
}
else{
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
if(tile != null){
for(EnumFacing facing : EnumFacing.values()){
@ -121,17 +40,11 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
}
}
}
}
return false;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canInsertItem(slot, stack, side));
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canExtractItem(slot, stack, side));
public boolean canExtractItem(int slot, ItemStack stack){
return this.isBoundThingInRange();
}
}

View file

@ -138,19 +138,19 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
drops.addAll(blockToBreak.getDrops(this.world, this.boundPosition, this.world.getBlockState(this.boundPosition), 0));
if(WorldUtil.addToInventory(this, drops, false, true)){
if(WorldUtil.addToInventory(this.slots, drops, false)){
this.world.playEvent(2001, this.boundPosition, Block.getStateId(this.world.getBlockState(this.boundPosition)));
this.world.setBlockToAir(this.boundPosition);
WorldUtil.addToInventory(this, drops, true, true);
WorldUtil.addToInventory(this.slots, drops, true);
this.markDirty();
}
}
}
else{
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, this.slots.get(theSlot)));
if(!StackUtil.isValid(this.slots.get(theSlot))){
this.slots.set(theSlot, StackUtil.getNull());
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, this.slots.getStackInSlot(theSlot)));
if(!StackUtil.isValid(this.slots.getStackInSlot(theSlot))){
this.slots.setStackInSlot(theSlot, StackUtil.getNull());
}
}
}
@ -206,12 +206,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return this.isBreaker;
}

View file

@ -121,11 +121,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
this.markDirty();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack){
return false;
}
@Override
public boolean hasBoundPosition(){
if(this.boundPosition != null){
@ -182,21 +177,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
return this.range;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return false;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return false;
}
@Override
public boolean hasInvWrapperCapabilities(){
return false;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
if(this.isBoundThingInRange()){

View file

@ -20,20 +20,24 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import java.util.UUID;
public class TileEntityPlayerInterface extends TileEntityInventoryBase implements IEnergyDisplay{
public class TileEntityPlayerInterface extends TileEntityBase implements IEnergyDisplay{
public static final int DEFAULT_RANGE = 32;
private final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 50, 0);
public UUID connectedPlayer;
private IItemHandler playerHandler;
private EntityPlayer oldPlayer;
public String playerName;
private int oldEnergy;
private int range;
public TileEntityPlayerInterface(){
super(0, "playerInterface");
super("playerInterface");
}
private EntityPlayer getPlayer(){
@ -48,6 +52,19 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement
return null;
}
@Override
public IItemHandler getItemHandler(EnumFacing facing){
EntityPlayer player = this.getPlayer();
if(this.oldPlayer != player){
this.oldPlayer = player;
this.playerHandler = player == null ? null : new PlayerInvWrapper(player.inventory);
}
return this.playerHandler;
}
@Override
public void updateEntity(){
super.updateEntity();
@ -121,96 +138,6 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement
}
}
@Override
public int[] getSlotsForFace(EnumFacing side){
if(this.getPlayer() != null){
int[] theInt = new int[this.getSizeInventory()];
for(int i = 0; i < theInt.length; i++){
theInt[i] = i;
}
return theInt;
}
return new int[0];
}
@Override
public int getInventoryStackLimit(){
EntityPlayer player = this.getPlayer();
return player != null ? player.inventory.getInventoryStackLimit() : 0;
}
@Override
public void clear(){
EntityPlayer player = this.getPlayer();
if(player != null){
player.inventory.clear();
}
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
EntityPlayer player = this.getPlayer();
if(player != null){
player.inventory.setInventorySlotContents(i, stack);
}
}
@Override
public int getSizeInventory(){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.getSizeInventory();
}
else{
return 0;
}
}
@Override
public ItemStack getStackInSlot(int i){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.getStackInSlot(i);
}
else{
return null;
}
}
@Override
public ItemStack decrStackSize(int i, int j){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.decrStackSize(i, j);
}
return null;
}
@Override
public ItemStack removeStackFromSlot(int index){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.removeStackFromSlot(index);
}
return null;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
EntityPlayer player = this.getPlayer();
return player != null && player.inventory.isItemValidForSlot(i, stack);
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return true;
}
@Override
public CustomEnergyStorage getEnergyStorage(){
return this.storage;

View file

@ -60,8 +60,8 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
if(this.filter.check(toAdd)){
ArrayList<ItemStack> checkList = new ArrayList<ItemStack>();
checkList.add(toAdd);
if(WorldUtil.addToInventory(this, checkList, EnumFacing.UP, false, true)){
WorldUtil.addToInventory(this, checkList, EnumFacing.UP, true, true);
if(WorldUtil.addToInventory(this.slots, checkList, false)){
WorldUtil.addToInventory(this.slots, checkList, true);
((WorldServer)this.world).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D);
@ -85,12 +85,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -123,16 +123,16 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
super.updateEntity();
if(!this.world.isRemote){
if(this.amount > 0){
if(!StackUtil.isValid(this.slots.get(0))){
if(!StackUtil.isValid(this.slots.getStackInSlot(0))){
int toSet = this.amount > 64 ? 64 : this.amount;
this.slots.set(0, new ItemStack(InitItems.itemSolidifiedExperience, toSet));
this.slots.setStackInSlot(0, new ItemStack(InitItems.itemSolidifiedExperience, toSet));
this.amount -= toSet;
this.markDirty();
}
else if(StackUtil.getStackSize(this.slots.get(0)) < 64){
int needed = 64-StackUtil.getStackSize(this.slots.get(0));
else if(StackUtil.getStackSize(this.slots.getStackInSlot(0)) < 64){
int needed = 64-StackUtil.getStackSize(this.slots.getStackInSlot(0));
int toAdd = this.amount > needed ? needed : this.amount;
this.slots.set(0, StackUtil.addStackSize(this.slots.get(0), toAdd));
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), toAdd));
this.amount -= toAdd;
this.markDirty();
}
@ -157,9 +157,9 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
}
}
if(StackUtil.isValid(this.slots.get(1)) && this.slots.get(1).getItem() instanceof ItemSolidifiedExperience){
this.amount += StackUtil.getStackSize(this.slots.get(1));
this.slots.set(1, StackUtil.getNull());
if(StackUtil.isValid(this.slots.getStackInSlot(1)) && this.slots.getStackInSlot(1).getItem() instanceof ItemSolidifiedExperience){
this.amount += StackUtil.getStackSize(this.slots.getStackInSlot(1));
this.slots.setStackInSlot(1, StackUtil.getNull());
this.markDirty();
}
@ -175,12 +175,7 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
public boolean canExtractItem(int slot, ItemStack stack){
return true;
}

View file

@ -0,0 +1,98 @@
/*
* This file ("AwfulUtil.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 com.google.common.collect.Lists;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
//This is stuff copied from somewhere in vanilla and changed so that it works properly
//It's unpolished and vanilla-y, so don't look at it! O_O
public final class AwfulUtil{
public static void fillInventory(LootTable table, IItemHandlerModifiable inventory, Random rand, LootContext context){
List<ItemStack> list = table.generateLootForPools(rand, context);
List<Integer> list1 = getEmptySlotsRandomized(inventory, rand);
shuffleItems(list, list1.size(), rand);
for(ItemStack itemstack : list){
if(itemstack.isEmpty()){
inventory.setStackInSlot(list1.remove(list1.size()-1), ItemStack.EMPTY);
}
else{
inventory.setStackInSlot(list1.remove(list1.size()-1), itemstack);
}
}
}
private static void shuffleItems(List<ItemStack> stacks, int someInt, Random rand){
List<ItemStack> list = Lists.newArrayList();
Iterator<ItemStack> iterator = stacks.iterator();
while(iterator.hasNext()){
ItemStack itemstack = iterator.next();
if(itemstack.isEmpty()){
iterator.remove();
}
else if(itemstack.getCount() > 1){
list.add(itemstack);
iterator.remove();
}
}
someInt = someInt-stacks.size();
while(someInt > 0 && ((List)list).size() > 0){
ItemStack itemstack2 = list.remove(MathHelper.getInt(rand, 0, list.size()-1));
int i = MathHelper.getInt(rand, 1, itemstack2.getCount()/2);
ItemStack itemstack1 = itemstack2.splitStack(i);
if(itemstack2.getCount() > 1 && rand.nextBoolean()){
list.add(itemstack2);
}
else{
stacks.add(itemstack2);
}
if(itemstack1.getCount() > 1 && rand.nextBoolean()){
list.add(itemstack1);
}
else{
stacks.add(itemstack1);
}
}
stacks.addAll(list);
Collections.shuffle(stacks, rand);
}
private static List<Integer> getEmptySlotsRandomized(IItemHandlerModifiable inventory, Random rand){
List<Integer> list = Lists.newArrayList();
for(int i = 0; i < inventory.getSlots(); ++i){
if(inventory.getStackInSlot(i).isEmpty()){
list.add(i);
}
}
Collections.shuffle(list, rand);
return list;
}
}

View file

@ -0,0 +1,72 @@
/*
* This file ("CheckingItemStackHandler.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;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.ItemStackHandler;
public class ItemStackHandlerCustom extends ItemStackHandler{
private boolean tempIgnoreConditions;
public ItemStackHandlerCustom(int slots){
super(slots);
}
public void decrStackSize(int slot, int amount){
this.setStackInSlot(slot, StackUtil.addStackSize(this.getStackInSlot(slot), -amount));
}
public NonNullList<ItemStack> getItems(){
return this.stacks;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
if(!this.tempIgnoreConditions && !this.canInsert(stack, slot)){
return stack;
}
return super.insertItem(slot, stack, simulate);
}
public ItemStack insertItemInternal(int slot, ItemStack stack, boolean simulate){
this.tempIgnoreConditions = true;
ItemStack result = this.insertItem(slot, stack, simulate);
this.tempIgnoreConditions = false;
return result;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate){
if(!this.tempIgnoreConditions && !this.canExtract(this.getStackInSlot(slot), slot)){
return StackUtil.getNull();
}
return super.extractItem(slot, amount, simulate);
}
public ItemStack extractItemInternal(int slot, int amount, boolean simulate){
this.tempIgnoreConditions = true;
ItemStack result = this.extractItem(slot, amount, simulate);
this.tempIgnoreConditions = false;
return result;
}
public boolean canInsert(ItemStack stack, int slot){
return true;
}
public boolean canExtract(ItemStack stack, int slot){
return true;
}
}

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -97,9 +98,6 @@ public final class ItemUtil{
return false;
}
/**
* Returns true if array contains stack or if both contain null
*/
public static boolean contains(ItemStack[] array, ItemStack stack, boolean checkWildcard){
return getPlaceAt(array, stack, checkWildcard) != -1;
}
@ -108,9 +106,6 @@ public final class ItemUtil{
return getPlaceAt(Arrays.asList(array), stack, checkWildcard);
}
/**
* Returns the place of stack in array, -1 if not present
*/
public static int getPlaceAt(List<ItemStack> list, ItemStack stack, boolean checkWildcard){
if(list != null && list.size() > 0){
for(int i = 0; i < list.size(); i++){

View file

@ -23,15 +23,12 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
@ -216,30 +213,15 @@ public final class WorldUtil{
return blocks;
}
public static boolean addToInventory(IInventory inventory, List<ItemStack> stacks, boolean actuallyDo, boolean shouldAlwaysWork){
return addToInventory(inventory, stacks, EnumFacing.UP, actuallyDo, shouldAlwaysWork);
public static boolean addToInventory(ItemStackHandlerCustom inventory, List<ItemStack> stacks, boolean actuallyDo){
return addToInventory(inventory, 0, inventory.getSlots(), stacks, actuallyDo);
}
public static boolean addToInventory(IInventory inventory, List<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
return addToInventory(inventory, 0, inventory.getSizeInventory(), stacks, side, actuallyDo, shouldAlwaysWork);
}
//TODO This is disgusting and has to be updated to the capability system
/**
* Add an ArrayList of ItemStacks to an Array of slots
*
* @param inventory The inventory to try to put the items into
* @param stacks The stacks to be put into the slots (Items don't actually get removed from there!)
* @param side The side to input from
* @param actuallyDo Do it or just test if it works?
* @return Does it work?
*/
public static boolean addToInventory(IInventory inventory, int start, int end, List<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
public static boolean addToInventory(ItemStackHandlerCustom inventory, int start, int end, List<ItemStack> stacks, boolean actuallyDo){
//Copy the slots if just testing to later load them again
ItemStack[] backupSlots = null;
if(!actuallyDo){
backupSlots = new ItemStack[inventory.getSizeInventory()];
backupSlots = new ItemStack[inventory.getSlots()];
for(int i = 0; i < backupSlots.length; i++){
ItemStack stack = inventory.getStackInSlot(i);
backupSlots[i] = StackUtil.validateCopy(stack);
@ -247,38 +229,30 @@ public final class WorldUtil{
}
int working = 0;
for(ItemStack stackToPutIn : stacks){
for(ItemStack stack : stacks){
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(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{
inventory.setInventorySlotContents(i, StackUtil.addStackSize(stackInQuestion, StackUtil.getStackSize(stackToPutIn)));
}
working++;
stack = inventory.insertItemInternal(i, stack, false);
if(!StackUtil.isValid(stack)){
working++;
break;
}
}
}
}
//Load the slots again
if(!actuallyDo){
for(int i = 0; i < backupSlots.length; i++){
inventory.setInventorySlotContents(i, backupSlots[i]);
inventory.setStackInSlot(i, backupSlots[i]);
}
}
return working >= stacks.size();
}
public static int findFirstFilledSlot(NonNullList<ItemStack> slots){
for(int i = 0; i < slots.size(); i++){
if(StackUtil.isValid(slots.get(i))){
public static int findFirstFilledSlot(ItemStackHandlerCustom slots){
for(int i = 0; i < slots.getSlots(); i++){
if(StackUtil.isValid(slots.getStackInSlot(i))){
return i;
}
}

View file

@ -836,7 +836,7 @@ booklet.actuallyadditions.chapter.feeder.name=Feeder
booklet.actuallyadditions.chapter.feeder.text.1=The <item>Feeder<r> is a good alternative to a manual animal farm. Place it in the middle of an animal pen and supply it with some wheat, seeds or carrots, depending on the animal you want to feed, and just wait. It will <imp>automatically feed the animals<r> and if there is enough animals near it, it will <imp>shut off on its own<r> to prevent lag or animal overflow. <n><n><i>Greenpeace approves
booklet.actuallyadditions.chapter.compost.name=Compost and Fertilizer
booklet.actuallyadditions.chapter.compost.text.1=The <item>Compost<r> is used to make <item>Fertilizer<r> from <item>Bio-Mash<r>. <item>Fertilizer<r> acts just like Bone Meal, but can be crafted in a much simpler manner just by crafting <item>Bio-Mash<r> and then putting 10 of those inside of a <item>Compost<r> and waiting for a bit. When the mash is composted, just take it out by right-clicking again. <n><n>This, however, also works for some other items, which will be explained when needed.
booklet.actuallyadditions.chapter.compost.text.1=The <item>Compost<r> is used to make <item>Fertilizer<r> from <item>Bio-Mash<r>. <item>Fertilizer<r> acts just like Bone Meal, but can be crafted in a much simpler manner just by crafting <item>Bio-Mash<r> and then putting those inside of a <item>Compost<r> and waiting for a bit. When the mash is composted, just take it out by right-clicking again. <n><n>This, however, also works for some other items, which will be explained when needed.
booklet.actuallyadditions.chapter.compost.text.3=<item>Bio-Mash<r> can be crafted from <imp>any type of food or plantable item<r>.
booklet.actuallyadditions.chapter.crate.name=Storage Crates