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.
    • 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
                                  • SpyManS Hors-ligne
                                    SpyMan
                                    dernière édition par robin4002

                                    class.zip

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

                                      Dans le container tu as oublié le write

                                      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

                                        Où sa ?

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

                                          Dans la classe du container

                                          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

                                            pourtant elle est bien appelé car dans la fonction oncontainerClosed j’appelle la fonction closeInventoty qui elle appelle la fonction writeToNBT

                                            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 NBTTagCompound 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);
                                                   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;
                                               }
                                            }
                                            
                                            import net.minecraft.entity.player.EntityPlayer;
                                            import net.minecraft.entity.player.InventoryPlayer;
                                            import net.minecraft.inventory.Container;
                                            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.InventoryItemPortableFurnace;
                                            import net.spyman.utils.common.items.ItemPortableFurnace;
                                            
                                            public class ContainerPortableFurnace extends Container
                                            {
                                               InventoryItemPortableFurnace inventory;
                                               private int workingTime;
                                               private int workingTimeNeeded;
                                            
                                               public ContainerPortableFurnace(InventoryPlayer playerInv, InventoryItemPortableFurnace 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;
                                                   }
                                               }
                                            }
                                            
                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB