9 nov. 2016, 21:43

Dsl j’ai du faire n’importe quoi comme d’hab avec le zip 😕
pour le code j’ai suivis le tuto de SCAREX sur les backpack + du code foireux 1.7.10 à la SpyMan d’un de mes mods

package net.spyman.utils.common.inventory;

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;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.spyman.utils.common.items.ItemPortableFurnace;

import javax.annotation.Nullable;

public class InventoryPortableFurnace implements IInventory
{
   private ItemStack[] inventorySlots = new ItemStack[3];
   public int workingTime = 0;
   public int workingTimeNeeded = 200;
   public int workingTimeNeededDefault = 200;
   public int burnTime = 0;
   public int burnTimeTotal = 0;
   public int inventorySize = inventorySlots.length;
   public int fuelSlot = 1;
   public int outputSlot = 2;
   public int inputSlot = 0;

   public InventoryPortableFurnace(ItemStack itemStack)
   {
       if (!itemStack.hasTagCompound())
       {
           itemStack.setTagCompound(new NBTTagCompound());
       }

       this.readFromNBT(itemStack.getTagCompound());
   }

   public void readFromNBT(NBTTagCompound compound)
   {
       NBTTagList nbttaglist = compound.getTagList("items", 10);
       this.inventorySlots = new ItemStack[this.getSizeInventory()];

       for(int i = 0; i < nbttaglist.tagCount(); ++i)
       {
           NBTTagCompound nbtTagCompound1 = nbttaglist.getCompoundTagAt(i);
           int j = nbtTagCompound1.getByte("Slot") & 255;

           if(j >= 0 && j < this.inventorySlots.length)
           {
               this.inventorySlots[j] = ItemStack.loadItemStackFromNBT(nbtTagCompound1);
           }
       }
       this.workingTime = compound.getShort("workingTime");
       this.burnTime = compound.getShort("burnTime");
       this.burnTimeTotal = compound.getShort("burnTimeTotal");
   }

   public void writeToNBT(NBTTagCompound compound)
   {
       NBTTagList nbttaglist = new NBTTagList();
       for(int i = 0; i < this.inventorySlots.length; ++i)
       {
           if(this.inventorySlots* != null)
           {
               NBTTagCompound nbtTagCompound1 = new NBTTagCompound();
               nbtTagCompound1.setByte("Slot", (byte)i);
               this.inventorySlots*.writeToNBT(nbtTagCompound1);
               nbttaglist.appendTag(nbtTagCompound1);

           }
       }
       compound.setTag("items", nbttaglist);
       compound.setShort("workingTime", (short)this.workingTime);
       compound.setShort("burnTime", (short)this.burnTime);
       compound.setShort("burnTimeTotal", (short)this.burnTimeTotal);
   }

   @Override
   public int getSizeInventory()
   {
       return this.inventorySize;
   }

   @Nullable
   @Override
   public ItemStack getStackInSlot(int index)
   {
       return this.inventorySlots[index];
   }

   @Nullable
   @Override
   public ItemStack decrStackSize(int index, int amount)
   {
       if(this.inventorySlots[index] != null)
       {
           ItemStack itemstack;

           if(this.inventorySlots[index].stackSize <= amount)
           {
               itemstack = this.inventorySlots[index];
               this.inventorySlots[index] = null;
               this.markDirty();
               return itemstack;
           }
           else
           {
               itemstack = this.inventorySlots[index].splitStack(amount);

               if(this.inventorySlots[index].stackSize == 0)
               {
                   this.inventorySlots[index] = null;
               }
               this.markDirty();
               return itemstack;
           }
       }
       else
       {
           return null;
       }
   }

   @Nullable
   @Override
   public ItemStack removeStackFromSlot(int index)
   {
       return null;
   }

   @Override
   public void setInventorySlotContents(int index, @Nullable ItemStack stack)
   {
       this.inventorySlots[index] = stack;
   }

   @Override
   public int getInventoryStackLimit()
   {
       return 64;
   }

   @Override
   public void markDirty()
   {

   }

   @Override
   public boolean isUseableByPlayer(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 !(stack.getItem() instanceof ItemPortableFurnace);
   }

   public boolean isBurning()
   {
       return this.workingTime > 0;
   }

   protected boolean canSmelt()
   {
       if(this.inventorySlots[this.inputSlot] == null)
       {
           return false;
       }
       else
       {
           ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(inventorySlots[this.inputSlot]);

           if(itemstack == null)
           {
               return false;
           }
           if(this.inventorySlots[this.outputSlot] == null)
           {
               return true;
           }
           if(!this.inventorySlots[this.outputSlot].isItemEqual(itemstack))
           {
               return false;
           }

           int result = inventorySlots[this.outputSlot].stackSize + itemstack.stackSize;
           return result <= getInventoryStackLimit() && result <= this.inventorySlots[2].getMaxStackSize();
       }
   }

   public void smeltItem()
   {
       if (this.canSmelt())
       {
           ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(inventorySlots[this.inputSlot]);
           if (this.inventorySlots[this.outputSlot] == null)
           {
               this.inventorySlots[this.outputSlot] = itemstack.copy();
           }
           else if (this.inventorySlots[this.outputSlot].getItem() == itemstack.getItem())
           {
               this.inventorySlots[this.outputSlot].stackSize += itemstack.stackSize;
           }
           this.decrStackSize(0, 1);
       }
   }

   @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()
   {

   }

   @Override
   public String getName()
   {
       return "item.container.portable_furnace.gui";
   }

   @Override
   public boolean hasCustomName()
   {
       return false;
   }

   @Override
   public ITextComponent getDisplayName()
   {
       return null;
   }

   @SideOnly(Side.CLIENT)
   public int getSmeltProcess()
   {
       return this.workingTime * 24 / this.workingTimeNeeded;
   }

   @SideOnly(Side.CLIENT)
   public int getBurnTime()
   {
       return this.burnTime * 14 / this.burnTimeTotal;
   }
}

package net.spyman.utils.common.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.spyman.utils.common.container.slot.SlotPortableFurnace;
import net.spyman.utils.common.inventory.InventoryPortableFurnace;

import javax.annotation.Nullable;

public class ContainerPortableFurnace extends Container
{
   InventoryPortableFurnace inventory;
   private int workingTime;
   private int workingTimeNeeded;

   public ContainerPortableFurnace(InventoryPlayer playerInv, InventoryPortableFurnace inv)
   {
       this.inventory = inv;
       int j;
       int k;

       this.addSlotToContainer(new Slot(this.inventory, 0, 56, 17));                   // input
       this.addSlotToContainer(new Slot(this.inventory, 1, 56, 53));                   // coal
       this.addSlotToContainer(new SlotPortableFurnace(this.inventory, 2, 116, 35));   // output

       this.bindPlayerInventory(playerInv);
   }

   @Override
   public boolean canInteractWith(EntityPlayer playerIn)
   {
       return true;
   }

   private void bindPlayerInventory(InventoryPlayer inventory)
   {
       int i;
       for (i = 0; i < 3; ++i)
       {
           for (int j = 0; j < 9; ++j)
           {
               this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
           }
       }

       for (i = 0; i < 9; ++i)
       {
           this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
       }
   }

   @Override
   public ItemStack transferStackInSlot(EntityPlayer player, int quantity)
   {
       ItemStack itemstack = null;
       Slot slot = (Slot)this.inventorySlots.get(quantity);

       if (slot != null && slot.getHasStack())
       {
           ItemStack itemStack1 = slot.getStack();
           itemstack = itemStack1.copy();

           if (quantity < this.inventory.getSizeInventory())
           {
               if (!this.mergeItemStack(itemStack1, this.inventory.getSizeInventory(), this.inventorySlots.size(), true))
               {
                   return null;
               }
           }
           else if (!this.mergeItemStack(itemStack1, 0, this.inventory.getSizeInventory(), false))
           {
               return null;
           }

           if (itemStack1.stackSize == 0)
           {
               slot.putStack((ItemStack)null);
           }
           else
           {
               slot.onSlotChanged();
           }
       }
       return itemstack;
   }

   @Override
   public void onContainerClosed(EntityPlayer player)
   {
       super.onContainerClosed(player);
       this.inventory.closeInventory(player);
   }

   @SideOnly(Side.CLIENT)
   public void updateProgressBar(int id, int value)
   {
       if(id == 0)
       {
           this.inventory.workingTime = value;
       }

       if(id == 1)
       {
           this.inventory.workingTimeNeeded = value;
       }
   }
}

package net.spyman.utils.common.container.slot;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class SlotPortableFurnace extends Slot
{
   public SlotPortableFurnace(IInventory inventoryIn, int index, int xPosition, int yPosition)
   {
       super(inventoryIn, index, xPosition, yPosition);
   }

   @Override
   public boolean isItemValid(ItemStack stack)
   {
       return false;
   }

   public ItemStack decrStackSize(int amount)
   {
       return super.decrStackSize(amount);
   }

   public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
   {
       super.onCrafting(stack);
       super.onPickupFromSlot(player, stack);
   }
}

EDIT : Si j’utilise la fonction onUpdate() de mon item elle est bien appelé a chaque tick ?