MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Gui/Container/Update Item Tick

    Planifier Épinglé Verrouillé Déplacé Résolu 1.9.x et 1.10.x
    1.10.x
    32 Messages 5 Publieurs 5.2k Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • SCAREXS Hors-ligne
      SCAREX
      dernière édition par

      Ouai surtout que là je suis au Mexique sur un ordi d’école donc je peux pas installer winrar ou 7zip

      Site web contenant mes scripts : http://SCAREXgaming.github.io

      Pas de demandes de support par MP ni par skype SVP.
      Je n'accepte sur skype que l…

      1 réponse Dernière réponse Répondre Citer 0
      • SpyManS Hors-ligne
        SpyMan
        dernière édition par

        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 ?

        1 réponse Dernière réponse Répondre Citer 0
        • SpyManS Hors-ligne
          SpyMan
          dernière édition par

          Personne aurait l’amabilité de me donner rien qu’une toute petite solution ? 😢
          car ce bug de no save des items commence a me rendre complètement ding
          et après 3 jours de recherche intense je vais finir par court circuiter mon petit cerveau

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002R Hors-ligne
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs
            dernière édition par

            Oui tu peux utiliser la fonction onUpdate de ton item pour gérer la cuisson.
            Pour l’enregistrement, j’ai l’impression que ta fonction writeToNBT n’est jamais appelé. Ce qui expliquera le problème.

            1 réponse Dernière réponse Répondre Citer 0
            • SpyManS Hors-ligne
              SpyMan
              dernière édition par

              ok merci je vois et pour le writeToNBT en gros quand j’ouvre le gui je peut y déposer les items il y reste, mais des que je le ferme  il 'y sont plus

              J’ai modif ma class IInventory

              
              import net.minecraft.entity.Entity;
              import net.minecraft.entity.player.EntityPlayer;
              import net.minecraft.inventory.IInventory;
              import net.minecraft.item.Item;
              import net.minecraft.item.ItemStack;
              import net.minecraft.item.crafting.FurnaceRecipes;
              import net.minecraft.nbt.NBTTagCompound;
              import net.minecraft.nbt.NBTTagList;
              import net.minecraft.tileentity.TileEntityFurnace;
              import net.minecraft.util.ActionResult;
              import net.minecraft.util.EnumActionResult;
              import net.minecraft.util.EnumHand;
              import net.minecraft.util.text.ITextComponent;
              import net.minecraft.world.World;
              import net.minecraftforge.fml.relauncher.Side;
              import net.minecraftforge.fml.relauncher.SideOnly;
              import net.spyman.utils.SpyUtil;
              
              import javax.annotation.Nullable;
              
              public class ItemPortableFurnace extends Item 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 ItemPortableFurnace()
                 {
                     this.setMaxStackSize(1);
                 }
              
                 @Override
                 public ActionResult <itemstack>onItemRightClick(ItemStack itemStack, World world, EntityPlayer player, EnumHand hand)
                 {
                     player.openGui(SpyUtil.INSTANCE, 1, world, (int) player.posX, (int) player.posY, (int) player.posZ);
                     return new ActionResult(EnumActionResult.PASS, itemStack);
                 }
              
                 public void readFromNBT(NBTTagCompound compound)
                 {
                     NBTTagList nbttaglist = compound.getTagList("SpyUtilsItems", 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("SpyUtilsItems", 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;
                     }
                 }
              
                 @Override
                 public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
                 {
                     if(this.burnTime > 0)
                     {
                         burnTime–;
                     }
                     if(this.canSmelt())
                     {
                         if(this.burnTime <= 0)
                         {
                             int time = TileEntityFurnace.getItemBurnTime(inventorySlots[1]);
              
                             if (time > 0)
                             {
                                 this.decrStackSize(1, 1);
                                 this.burnTimeTotal = time;
                                 this.burnTime = time;
                             }
                         }
                         if(burnTime > 0)
                         {
                             workingTime++;
                         }
                     }
                     if (this.workingTime >= this.workingTimeNeeded)
                     {
                         this.smeltItem();
                         this.workingTime = 0;
                     }
                     if (!this.canSmelt() || burnTime <= 0)
                     {
                         this.workingTime = 0;
                     }
                 }
              
                 @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;
                 }
              }
              ```</itemstack>
              1 réponse Dernière réponse Répondre Citer 0
              • LeBossMax2L Hors-ligne
                LeBossMax2
                dernière édition par

                Je viens de remarque mais c’est normal que ça fonctionne pas ! Tout ce qui est en rapport avec l’inventaire de l’item doit aller dans une autre class car ça dépend de l’ItemStack et non de l’Item. Il faut que tu fasse une class pour ton IInventory et que quand on ouvre le gui, ça créé une nouvelle instance de cet inventaire à partir des NBT de l’itemStack et quand tu ferme l’inventaire, ça sauvegarde tout dans les NBTTag. Ps : tout est dans le tuto pour créer un backPack.

                1 réponse Dernière réponse Répondre Citer 0
                • SpyManS Hors-ligne
                  SpyMan
                  dernière édition par

                  J’essayé les deux mais ça ne change pas grand chose

                  
                  import net.minecraft.entity.Entity;
                  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.tileentity.TileEntityFurnace;
                  import net.minecraft.util.text.ITextComponent;
                  import net.minecraft.world.World;
                  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 InventoryItemPortableFurnace 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 InventoryItemPortableFurnace(ItemStack itemStack)
                     {
                         if (!itemStack.hasTagCompound())
                         {
                             itemStack.setTagCompound(new NBTTagCompound());
                         }
                  
                         this.readFromNBT(itemStack.getTagCompound());
                     }
                  
                     public void readFromNBT(NBTTagCompound compound)
                     {
                         NBTTagList nbttaglist = compound.getTagList("SpyUtilsItems", 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)
                     {
                         System.out.println("WRITE TO NBT CALLED");
                  
                         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("SpyUtilsItems", 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;
                         }
                     }
                  
                     /**
                      * Used to update item.
                      * @param stack
                      * @param worldIn
                      * @param entityIn
                      * @param itemSlot
                      * @param isSelected
                      */
                     public void updateItem(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
                     {
                         if(this.burnTime > 0)
                         {
                             burnTime–;
                         }
                         if(this.canSmelt())
                         {
                             if(this.burnTime <= 0)
                             {
                                 int time = TileEntityFurnace.getItemBurnTime(inventorySlots[1]);
                  
                                 if (time > 0)
                                 {
                                     this.decrStackSize(1, 1);
                                     this.burnTimeTotal = time;
                                     this.burnTime = time;
                                 }
                             }
                             if(burnTime > 0)
                             {
                                 workingTime++;
                             }
                         }
                         if (this.workingTime >= this.workingTimeNeeded)
                         {
                             this.smeltItem();
                             this.workingTime = 0;
                         }
                         if (!this.canSmelt() || burnTime <= 0)
                         {
                             this.workingTime = 0;
                         }
                     }
                  
                     @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;
                     }
                  }
                  
                  1 réponse Dernière réponse Répondre Citer 0
                  • SCAREXS Hors-ligne
                    SCAREX
                    dernière édition par

                    Est-ce que le read et le write sont appelés ?

                    Site web contenant mes scripts : http://SCAREXgaming.github.io

                    Pas de demandes de support par MP ni par skype SVP.
                    Je n'accepte sur skype que l…

                    1 réponse Dernière réponse Répondre Citer 0
                    • SpyManS Hors-ligne
                      SpyMan
                      dernière édition par

                      Le read oui mais pas le write
                      où faut-il l’appeler déjà ?
                      normalement si je mais IInventory dans la class de l’item ce ne pause pas probleme?

                      1 réponse Dernière réponse Répondre Citer 0
                      • BrokenSwingB Hors-ligne
                        BrokenSwing Moddeurs confirmés Rédacteurs
                        dernière édition par

                        En 1.10, il me semble que c’est :

                        
                        public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
                        
                        }
                        
                        

                        D’où l’utilité des annotations

                        1 réponse Dernière réponse Répondre Citer 0
                        • SpyManS Hors-ligne
                          SpyMan
                          dernière édition par

                          Raté 😄
                          Avec le override il ne la trouve pas non plus

                          1 réponse Dernière réponse Répondre Citer 0
                          • BrokenSwingB Hors-ligne
                            BrokenSwing Moddeurs confirmés Rédacteurs
                            dernière édition par

                            1 réponse Dernière réponse Répondre Citer 0
                            • robin4002R Hors-ligne
                              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                              dernière édition par

                              Il n’y a pas de méthode writeToNBT dans l’inverface IInventory.
                              Donc même avec un @Override tu ne vas rien trouver en effet.

                              C’est à toi d’appeler la méthode.

                              1 réponse Dernière réponse Répondre Citer 0
                              • BrokenSwingB Hors-ligne
                                BrokenSwing Moddeurs confirmés Rédacteurs
                                dernière édition par

                                Ah merde, j’aurai dû lire, excusez-moi, c’est pas de la classe TileEntity dont on parle

                                1 réponse Dernière réponse Répondre Citer 0
                                • SpyManS Hors-ligne
                                  SpyMan
                                  dernière édition par

                                  D’accord mais je l’appele ou dans closeInventory() ?

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • robin4002R Hors-ligne
                                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                    dernière édition par

                                    Oui.

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • SpyManS Hors-ligne
                                      SpyMan
                                      dernière édition par

                                      Marche pas 😕

                                      
                                      import net.minecraft.entity.Entity;
                                      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.tileentity.TileEntityFurnace;
                                      import net.minecraft.util.text.ITextComponent;
                                      import net.minecraft.world.World;
                                      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 InventoryItemPortableFurnace 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 InventoryItemPortableFurnace(ItemStack itemStack)
                                         {
                                             if (!itemStack.hasTagCompound())
                                             {
                                                 itemStack.setTagCompound(new NBTTagCompound());
                                             }
                                      
                                             this.readFromNBT(itemStack.getTagCompound());
                                         }
                                      
                                         public void readFromNBT(NBTTagCompound compound)
                                         {
                                             System.out.println("READ TO NBT");
                                             NBTTagList nbttaglist = compound.getTagList("SpyUtilsItems", 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 NBTTagCompound writeToNBT(NBTTagCompound compound)
                                         {
                                             System.out.println("WRITE TO NBT");
                                      
                                             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("SpyUtilsItems", nbttaglist);
                                             compound.setShort("workingTime", (short) this.workingTime);
                                             compound.setShort("burnTime", (short) this.burnTime);
                                             compound.setShort("burnTimeTotal", (short) this.burnTimeTotal);
                                             return null;
                                         }
                                      
                                         @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;
                                             }
                                         }
                                      
                                         /**
                                          * Used to update item.
                                          *
                                          * @param stack
                                          * @param worldIn
                                          * @param entityIn
                                          * @param itemSlot
                                          * @param isSelected
                                          */
                                         public void updateItem(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
                                         {
                                             if (this.burnTime > 0)
                                             {
                                                 burnTime–;
                                             }
                                             if (this.canSmelt())
                                             {
                                                 if (this.burnTime <= 0)
                                                 {
                                                     int time = TileEntityFurnace.getItemBurnTime(inventorySlots[1]);
                                      
                                                     if (time > 0)
                                                     {
                                                         this.decrStackSize(1, 1);
                                                         this.burnTimeTotal = time;
                                                         this.burnTime = time;
                                                     }
                                                 }
                                                 if (burnTime > 0)
                                                 {
                                                     workingTime++;
                                                 }
                                             }
                                             if (this.workingTime >= this.workingTimeNeeded)
                                             {
                                                 this.smeltItem();
                                                 this.workingTime = 0;
                                             }
                                             if (!this.canSmelt() || burnTime <= 0)
                                             {
                                                 this.workingTime = 0;
                                             }
                                         }
                                      
                                         @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)
                                         {
                                             this.writeToNBT(new NBTTagCompound());
                                         }
                                      
                                         @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;
                                         }
                                      }
                                      
                                      
                                      1 réponse Dernière réponse Répondre Citer 0
                                      • robin4002R Hors-ligne
                                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                        dernière édition par

                                        Ha en effet, ici ça ne risque pas de fonctionner comme closeInventory n’est jamais appelé.
                                        C’est dans le container qu’il faut le mettre.

                                        1 réponse Dernière réponse Répondre Citer 0
                                        • SpyManS Hors-ligne
                                          SpyMan
                                          dernière édition par

                                          c’est déjà fait

                                          1 réponse Dernière réponse Répondre Citer 0
                                          • SCAREXS Hors-ligne
                                            SCAREX
                                            dernière édition par

                                            Envoi toutes tes classes

                                            Site web contenant mes scripts : http://SCAREXgaming.github.io

                                            Pas de demandes de support par MP ni par skype SVP.
                                            Je n'accepte sur skype que l…

                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB