MFF

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

    Créer un bloc type four (machine)

    Planifier Épinglé Verrouillé Déplacé Les interfaces (GUI) et les container
    1.7.10
    236 Messages 39 Publieurs 69.0k Vues 15 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.
    • BrokenSwingB Hors-ligne
      BrokenSwing Moddeurs confirmés Rédacteurs
      dernière édition par

      Normal qu’il n’y est plus d’images, j’avais fait l’erreur de mettre les images du tuto sur noelshack mais elles sont supprimées au bout d’un moment. Il te suffit de suivre les tutoriels donnés en pré-requis, car c’est dans ces pré-requis que tu apprendra à faire un GuiHandler. Pour ce qui est du four qui ne s’ouvre pas, il me faut ta fonction onBlockActived

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

        Je ne trouve pas les moments dans les prérequis où ça montre la texture du GUI et pour la barre de progression

        Mon onBlockActivated :

          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz)
           {
        FMLNetworkHandler.openGui(player, CompleatCraft.instance, 0, world, x, y, z);
               if (world.isRemote)
               {
                   return true;
               }
               else
               {
                player.openGui(CompleatCraft.instance, 0, world, x, y, z);
                   return true;
               }
           }
        
        1 réponse Dernière réponse Répondre Citer 0
        • A Hors-ligne
          aypristyle
          dernière édition par

          Voici un GuiHandler type tu n’aura plus qu’a remplacer

          public class GuiHandler implements IGuiHandler {
          
          @Override
          public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
          TileEntity te = world.getTileEntity(new BlockPos(x, y, z);
          if(te instanceof TaClasseTileEntity) {
          return new TaClasseContainer(player.inventory, (TaClasseTileEntity)te);
          }
          return null;
          }
          
          @Override
          public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
          
          TileEntity te = world.getTileEntity(new BlockPos(x, y, z);
          if(te instanceof TaClasseTileEntity) {
          return new TaClasseGui(player.inventory, (TaClasseTileEntity)te);
          }
          return null;
          }
          
          }
          

          je te conseille d’implementer d’abord les méthodes pour ensuite compléter avec ce que je t’ai marquer  😉

          **Je suis un membre apprécié et joueur, j'ai déjà obtenu 1[ point de réputation./…

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

            @‘BrokenSwing’:

            Normal qu’il n’y est plus d’images, j’avais fait l’erreur de mettre les images du tuto sur noelshack mais elles sont supprimées au bout d’un moment. Il te suffit de suivre les tutoriels donnés en pré-requis, car c’est dans ces pré-requis que tu apprendra à faire un GuiHandler. Pour ce qui est du four qui ne s’ouvre pas, il me faut ta fonction onBlockActived

            euh ça ne marche toujours pas 😢 !
            La moitié de la texture s’affiche de haut en bas -_-
             Voici mes codes :
            tileEntity :

            package mod.plantsandfoodpack.common;
            
            import cpw.mods.fml.relauncher.Side;
            import cpw.mods.fml.relauncher.SideOnly;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.item.ItemStack;
            import net.minecraft.nbt.NBTTagCompound;
            import net.minecraft.nbt.NBTTagList;
            import net.minecraft.tileentity.TileEntity;
            
            public class TileEntityFermentator extends TileEntity implements IInventory {
            
            private ItemStack[] contents = new ItemStack[2];
            private int workingTime = 0;
            private int workingTimeNeeded = 500;
            
            @Override 
                public void writeToNBT(NBTTagCompound compound)
                {
                    super.writeToNBT(compound);
                    NBTTagList nbttaglist = new NBTTagList();
            
                    for (int i = 0; i < this.contents.length; ++i) //pour les slots
                    {
                        if (this.contents* != null)
                        {
                            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                            nbttagcompound1.setByte("Slot", (byte)i);
                            this.contents*.writeToNBT(nbttagcompound1);
                            nbttaglist.appendTag(nbttagcompound1);
                        }
                    }
            
                    compound.setTag("Items", nbttaglist);
                    compound.setShort("workingTime",(short)this.workingTime); //On les enregistrent en short
                    compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                }
            
            @Override
                public void readFromNBT(NBTTagCompound compound)
                {
                    super.readFromNBT(compound);
            
                    NBTTagList nbttaglist = compound.getTagList("Items", 10);
                    this.contents = new ItemStack[this.getSizeInventory()];
            
                    for (int i = 0; i < nbttaglist.tagCount(); ++i) //Encore une fois pour les slots
                    {
                        NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                        int j = nbttagcompound1.getByte("Slot") & 255;
            
                        if (j >= 0 && j < this.contents.length)
                        {
                            this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                        }
                    }
            
                    this.workingTime = compound.getShort("workingTime"); //On lit nos valeurs
                    this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                }
            
            @Override
            public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
            return this.contents.length;
            }
            
            @Override
            public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
            return this.contents[slotIndex];
            }
            
            @Override //Comme dit plus haut, c'est expliqué dans le tutoriel de robin
            public ItemStack decrStackSize(int slotIndex, int amount) {
            if (this.contents[slotIndex] != null)
                   {
                       ItemStack itemstack;
            
                       if (this.contents[slotIndex].stackSize <= amount)
                       {
                           itemstack = this.contents[slotIndex];
                           this.contents[slotIndex] = null;
                           this.markDirty();
                           return itemstack;
                       }
                       else
                       {
                           itemstack = this.contents[slotIndex].splitStack(amount);
            
                           if (this.contents[slotIndex].stackSize == 0)
                           {
                               this.contents[slotIndex] = null;
                           }
            
                           this.markDirty();
                           return itemstack;
                       }
                   }
                   else
                   {
                       return null;
                   }
            }
            
            @Override
            public ItemStack getStackInSlotOnClosing(int slotIndex) {
            if (this.contents[slotIndex] != null)
                    {
                        ItemStack itemstack = this.contents[slotIndex];
                        this.contents[slotIndex] = null;
                        return itemstack;
                    }
                    else
                    {
                        return null;
                    }
            }
            
            @Override
            public void setInventorySlotContents(int slotIndex, ItemStack stack) {
            this.contents[slotIndex] = stack;
            
                    if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                    {
                        stack.stackSize = this.getInventoryStackLimit();
                    }
            
                    this.markDirty();
            }
            
            @Override
            public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
            return "tile.Fermentator";
            }
            
            @Override
            public boolean hasCustomInventoryName() {
            return false;
            }
            
            @Override
            public int getInventoryStackLimit() {
            return 64;
            }
            
            @Override
            public boolean isUseableByPlayer(EntityPlayer player) {
            return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
            }
            
            @Override
            public void openInventory() {
            
            }
            
            @Override
            public void closeInventory() {
            
            }
            
            @Override
            public boolean isItemValidForSlot(int slot, ItemStack stack) {
            return slot == 3 ? false : true;
            }
            
            public boolean isBurning()
                {
                    return this.workingTime > 0;
                }
            
            private boolean canSmelt()
                {
                    if (this.contents[0] == null) //Si les trois premiers slots sont vides
                    {
                        return false; //On ne peut pas lancer le processus
                    }
                    else
                    {
                        ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                        if (itemstack == null) return false; //rapport avec les recettes
                        if (this.contents[1] == null) return true; //vérifications du slot d'output
                        if (!this.contents[1].isItemEqual(itemstack)) return false; //ici aussi
                        int result = contents[1].stackSize + itemstack.stackSize;
                        return result <= getInventoryStackLimit() && result <= this.contents[1].getMaxStackSize(); //Et là aussi décidément
                    }
                }
            
            public void updateEntity() //Méthode exécutée à chaque tick
                {
                if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
                {
                ++this.workingTime; //incrémentation
                }
                if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
                {
                this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
                }
                if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
                {
                this.smeltItem(); //on "cuit" les items
                this.workingTime = 0; //et on réinitialise le temps de cuisson
                }
                    if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
                    {
                           this.workingTime= 0; //le temps de cuisson est de 0
                    }
                }
            
            public void smeltItem()
                {
                    if (this.canSmelt())
                    {
                        ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0]}); //On récupère l'output de la recette
                         if (this.contents[1] == null) //Si il y a rien dans le slot d'output
                         {
                              this.contents[1] = itemstack.copy(); //On met directement l'ItemStack
                         }
                         else if (this.contents[1].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                         {
                              this.contents[1].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                         }
            
                         –this.contents[0].stackSize; //On décrémente les slots d'input
            
                         if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                         {
                             this.contents[0] = null;
                         }
                    }
                }
            
            @SideOnly(Side.CLIENT)
            public int getCookProgress()
            {
            return this.workingTime * 22 / this.workingTimeNeeded;
            }
            
            }
            

            gui :

            package mod.plantsandfoodpack.client;
            
            import org.lwjgl.opengl.GL11;
            
            import mod.plantsandfoodpack.common.ContainerFermentator;
            import mod.plantsandfoodpack.common.ModPlantsandFoodPack;
            import mod.plantsandfoodpack.common.TileEntityFermentator;
            import net.minecraft.client.gui.inventory.GuiContainer;
            import net.minecraft.client.resources.I18n;
            import net.minecraft.entity.player.InventoryPlayer;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.util.ResourceLocation;
            
            public class GuiFermentator extends GuiContainer {
            
            private static final ResourceLocation texture = new ResourceLocation(ModPlantsandFoodPack.MODID,"textures/gui/container/guiFermentator.png");
            private TileEntityFermentator tileFermentator;
                private IInventory playerInv;
            
            public GuiFermentator(TileEntityFermentator tile, InventoryPlayer inventory) 
            {
            super(new ContainerFermentator(tile, inventory));
                    this.tileFermentator = tile;
                    this.playerInv = inventory;
                    this.allowUserInput = false;
                    this.ySize = 168;
            }
            
            @Override
            protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) 
            {
            
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                    this.mc.getTextureManager().bindTexture(texture);
                    int k = (this.width - this.xSize) / 2;
                    int l = (this.height - this.ySize) / 2;
                    this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
            
                    if(this.tileFermentator.isBurning())
                    {
                    int i = this.tileFermentator.getCookProgress(); //Nous créerons cette fonction après
                    this.drawTexturedModalRect(k + 80, l + 37, 176, 0, 12, i);
                    }
            
            }
            
            protected void drawGuiContainerForegroundLayer(int x, int y)
                {
                    this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 8, this.ySize - 96 + 2, 4210752);
                }
            
            }
            

            Ma texture :

            la texture de la barre de progression mesure 22px de large et 12px de haut

            Merci pour votre aide

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

              @‘BrokenSwing’:

              @__Freezer__ Ton TileEntity implémente-t-il l’interface IInventory ? C’est sûrement la solution à beaucoup de tes problèmes.

              @themoney158 Oui, il suffit pour cela de changer la largeur de la texture affiché suivant la progression de “la recette”

              Petit probleme…

              ça ne marche toujours pas :‘( :’( 😢

              Seul la moitié de la texture s’affiche et de haut en bas -_-

              Si ça peut vous aider a m’aider

              Voici mes codes :

              Gui :

              package mod.plantsandfoodpack.client;
              
              import org.lwjgl.opengl.GL11;
              
              import mod.plantsandfoodpack.common.ContainerFermentator;
              import mod.plantsandfoodpack.common.ModPlantsandFoodPack;
              import mod.plantsandfoodpack.common.TileEntityFermentator;
              import net.minecraft.client.gui.inventory.GuiContainer;
              import net.minecraft.client.resources.I18n;
              import net.minecraft.entity.player.InventoryPlayer;
              import net.minecraft.inventory.IInventory;
              import net.minecraft.util.ResourceLocation;
              
              public class GuiFermentator extends GuiContainer {
              
              private static final ResourceLocation texture = new ResourceLocation(ModPlantsandFoodPack.MODID,"textures/gui/container/guiFermentator.png");
              private TileEntityFermentator tileFermentator;
                  private IInventory playerInv;
              
              public GuiFermentator(TileEntityFermentator tile, InventoryPlayer inventory) 
              {
              super(new ContainerFermentator(tile, inventory));
                      this.tileFermentator = tile;
                      this.playerInv = inventory;
                      this.allowUserInput = false;
                      this.ySize = 168;
              }
              
              @Override
              protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) 
              {
              
              GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                      this.mc.getTextureManager().bindTexture(texture);
                      int k = (this.width - this.xSize) / 2;
                      int l = (this.height - this.ySize) / 2;
                      this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
              
                      if(this.tileFermentator.isBurning())
                      {
                      int i = this.tileFermentator.getCookProgress(); //Nous créerons cette fonction après
                      this.drawTexturedModalRect(k + 80, l + 37, 176, 0, 12, i);
                      }
              
              }
              
              protected void drawGuiContainerForegroundLayer(int x, int y)
                  {
                      this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 8, this.ySize - 96 + 2, 4210752);
                  }
              
              }
              

              TileEntity :

              package mod.plantsandfoodpack.common;
              
              import cpw.mods.fml.relauncher.Side;
              import cpw.mods.fml.relauncher.SideOnly;
              import net.minecraft.entity.player.EntityPlayer;
              import net.minecraft.inventory.IInventory;
              import net.minecraft.item.ItemStack;
              import net.minecraft.nbt.NBTTagCompound;
              import net.minecraft.nbt.NBTTagList;
              import net.minecraft.tileentity.TileEntity;
              
              public class TileEntityFermentator extends TileEntity implements IInventory {
              
              private ItemStack[] contents = new ItemStack[2];
              private int workingTime = 0;
              private int workingTimeNeeded = 500;
              
              @Override 
                  public void writeToNBT(NBTTagCompound compound)
                  {
                      super.writeToNBT(compound);
                      NBTTagList nbttaglist = new NBTTagList();
              
                      for (int i = 0; i < this.contents.length; ++i) //pour les slots
                      {
                          if (this.contents* != null)
                          {
                              NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                              nbttagcompound1.setByte("Slot", (byte)i);
                              this.contents*.writeToNBT(nbttagcompound1);
                              nbttaglist.appendTag(nbttagcompound1);
                          }
                      }
              
                      compound.setTag("Items", nbttaglist);
                      compound.setShort("workingTime",(short)this.workingTime); //On les enregistrent en short
                      compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                  }
              
              @Override
                  public void readFromNBT(NBTTagCompound compound)
                  {
                      super.readFromNBT(compound);
              
                      NBTTagList nbttaglist = compound.getTagList("Items", 10);
                      this.contents = new ItemStack[this.getSizeInventory()];
              
                      for (int i = 0; i < nbttaglist.tagCount(); ++i) //Encore une fois pour les slots
                      {
                          NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                          int j = nbttagcompound1.getByte("Slot") & 255;
              
                          if (j >= 0 && j < this.contents.length)
                          {
                              this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                          }
                      }
              
                      this.workingTime = compound.getShort("workingTime"); //On lit nos valeurs
                      this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                  }
              
              @Override
              public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
              return this.contents.length;
              }
              
              @Override
              public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
              return this.contents[slotIndex];
              }
              
              @Override //Comme dit plus haut, c'est expliqué dans le tutoriel de robin
              public ItemStack decrStackSize(int slotIndex, int amount) {
              if (this.contents[slotIndex] != null)
                     {
                         ItemStack itemstack;
              
                         if (this.contents[slotIndex].stackSize <= amount)
                         {
                             itemstack = this.contents[slotIndex];
                             this.contents[slotIndex] = null;
                             this.markDirty();
                             return itemstack;
                         }
                         else
                         {
                             itemstack = this.contents[slotIndex].splitStack(amount);
              
                             if (this.contents[slotIndex].stackSize == 0)
                             {
                                 this.contents[slotIndex] = null;
                             }
              
                             this.markDirty();
                             return itemstack;
                         }
                     }
                     else
                     {
                         return null;
                     }
              }
              
              @Override
              public ItemStack getStackInSlotOnClosing(int slotIndex) {
              if (this.contents[slotIndex] != null)
                      {
                          ItemStack itemstack = this.contents[slotIndex];
                          this.contents[slotIndex] = null;
                          return itemstack;
                      }
                      else
                      {
                          return null;
                      }
              }
              
              @Override
              public void setInventorySlotContents(int slotIndex, ItemStack stack) {
              this.contents[slotIndex] = stack;
              
                      if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                      {
                          stack.stackSize = this.getInventoryStackLimit();
                      }
              
                      this.markDirty();
              }
              
              @Override
              public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
              return "tile.Fermentator";
              }
              
              @Override
              public boolean hasCustomInventoryName() {
              return false;
              }
              
              @Override
              public int getInventoryStackLimit() {
              return 64;
              }
              
              @Override
              public boolean isUseableByPlayer(EntityPlayer player) {
              return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
              }
              
              @Override
              public void openInventory() {
              
              }
              
              @Override
              public void closeInventory() {
              
              }
              
              @Override
              public boolean isItemValidForSlot(int slot, ItemStack stack) {
              return slot == 3 ? false : true;
              }
              
              public boolean isBurning()
                  {
                      return this.workingTime > 0;
                  }
              
              private boolean canSmelt()
                  {
                      if (this.contents[0] == null) //Si les trois premiers slots sont vides
                      {
                          return false; //On ne peut pas lancer le processus
                      }
                      else
                      {
                          ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                          if (itemstack == null) return false; //rapport avec les recettes
                          if (this.contents[1] == null) return true; //vérifications du slot d'output
                          if (!this.contents[1].isItemEqual(itemstack)) return false; //ici aussi
                          int result = contents[1].stackSize + itemstack.stackSize;
                          return result <= getInventoryStackLimit() && result <= this.contents[1].getMaxStackSize(); //Et là aussi décidément
                      }
                  }
              
              public void updateEntity() //Méthode exécutée à chaque tick
                  {
                  if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
                  {
                  ++this.workingTime; //incrémentation
                  }
                  if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
                  {
                  this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
                  }
                  if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
                  {
                  this.smeltItem(); //on "cuit" les items
                  this.workingTime = 0; //et on réinitialise le temps de cuisson
                  }
                      if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
                      {
                             this.workingTime= 0; //le temps de cuisson est de 0
                      }
                  }
              
              public void smeltItem()
                  {
                      if (this.canSmelt())
                      {
                          ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0]}); //On récupère l'output de la recette
                           if (this.contents[1] == null) //Si il y a rien dans le slot d'output
                           {
                                this.contents[1] = itemstack.copy(); //On met directement l'ItemStack
                           }
                           else if (this.contents[1].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                           {
                                this.contents[1].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                           }
              
                           –this.contents[0].stackSize; //On décrémente les slots d'input
              
                           if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                           {
                               this.contents[0] = null;
                           }
                      }
                  }
              
              @SideOnly(Side.CLIENT)
              public int getCookProgress()
              {
              return this.workingTime * 22 / this.workingTimeNeeded;
              }
              
              }
              

              ma texture :

              la texture de la barre de progression mesure 22 px de large et 12 px de haut

              Merci pour votre aide !

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

                @‘themoney158’:

                @‘BrokenSwing’:

                @__Freezer__ Ton TileEntity implémente-t-il l’interface IInventory ? C’est sûrement la solution à beaucoup de tes problèmes.

                @themoney158 Oui, il suffit pour cela de changer la largeur de la texture affiché suivant la progression de “la recette”

                Petit probleme…

                ça ne marche toujours pas :‘( :’( 😢

                Seul la moitié de la texture s’affiche et de haut en bas -_-

                Si ça peut vous aider a m’aider

                Voici mes codes :

                Gui :

                package mod.plantsandfoodpack.client;
                
                import org.lwjgl.opengl.GL11;
                
                import mod.plantsandfoodpack.common.ContainerFermentator;
                import mod.plantsandfoodpack.common.ModPlantsandFoodPack;
                import mod.plantsandfoodpack.common.TileEntityFermentator;
                import net.minecraft.client.gui.inventory.GuiContainer;
                import net.minecraft.client.resources.I18n;
                import net.minecraft.entity.player.InventoryPlayer;
                import net.minecraft.inventory.IInventory;
                import net.minecraft.util.ResourceLocation;
                
                public class GuiFermentator extends GuiContainer {
                
                private static final ResourceLocation texture = new ResourceLocation(ModPlantsandFoodPack.MODID,"textures/gui/container/guiFermentator.png");
                private TileEntityFermentator tileFermentator;
                    private IInventory playerInv;
                
                public GuiFermentator(TileEntityFermentator tile, InventoryPlayer inventory) 
                {
                super(new ContainerFermentator(tile, inventory));
                        this.tileFermentator = tile;
                        this.playerInv = inventory;
                        this.allowUserInput = false;
                        this.ySize = 168;
                }
                
                @Override
                protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) 
                {
                
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                        this.mc.getTextureManager().bindTexture(texture);
                        int k = (this.width - this.xSize) / 2;
                        int l = (this.height - this.ySize) / 2;
                        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
                        
                        if(this.tileFermentator.isBurning())
                        {
                        int i = this.tileFermentator.getCookProgress(); //Nous créerons cette fonction après
                        this.drawTexturedModalRect(k + 80, l + 37, 176, 0, 12, i);
                        }
                
                }
                
                protected void drawGuiContainerForegroundLayer(int x, int y)
                    {
                        this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 8, this.ySize - 96 + 2, 4210752);
                    }
                
                }
                

                TileEntity :

                package mod.plantsandfoodpack.common;
                
                import cpw.mods.fml.relauncher.Side;
                import cpw.mods.fml.relauncher.SideOnly;
                import net.minecraft.entity.player.EntityPlayer;
                import net.minecraft.inventory.IInventory;
                import net.minecraft.item.ItemStack;
                import net.minecraft.nbt.NBTTagCompound;
                import net.minecraft.nbt.NBTTagList;
                import net.minecraft.tileentity.TileEntity;
                
                public class TileEntityFermentator extends TileEntity implements IInventory {
                
                private ItemStack[] contents = new ItemStack[2];
                private int workingTime = 0;
                private int workingTimeNeeded = 500;
                
                @Override 
                    public void writeToNBT(NBTTagCompound compound)
                    {
                        super.writeToNBT(compound);
                        NBTTagList nbttaglist = new NBTTagList();
                
                        for (int i = 0; i < this.contents.length; ++i) //pour les slots
                        {
                            if (this.contents* != null)
                            {
                                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                                nbttagcompound1.setByte("Slot", (byte)i);
                                this.contents*.writeToNBT(nbttagcompound1);
                                nbttaglist.appendTag(nbttagcompound1);
                            }
                        }
                
                        compound.setTag("Items", nbttaglist);
                        compound.setShort("workingTime",(short)this.workingTime); //On les enregistrent en short
                        compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                    }
                
                @Override
                    public void readFromNBT(NBTTagCompound compound)
                    {
                        super.readFromNBT(compound);
                        
                        NBTTagList nbttaglist = compound.getTagList("Items", 10);
                        this.contents = new ItemStack[this.getSizeInventory()];
                
                        for (int i = 0; i < nbttaglist.tagCount(); ++i) //Encore une fois pour les slots
                        {
                            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                            int j = nbttagcompound1.getByte("Slot") & 255;
                
                            if (j >= 0 && j < this.contents.length)
                            {
                                this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                            }
                        }
                        
                        this.workingTime = compound.getShort("workingTime"); //On lit nos valeurs
                        this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                    }
                
                @Override
                public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
                return this.contents.length;
                }
                
                @Override
                public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
                return this.contents[slotIndex];
                }
                
                @Override //Comme dit plus haut, c'est expliqué dans le tutoriel de robin
                public ItemStack decrStackSize(int slotIndex, int amount) {
                if (this.contents[slotIndex] != null)
                       {
                           ItemStack itemstack;
                
                           if (this.contents[slotIndex].stackSize <= amount)
                           {
                               itemstack = this.contents[slotIndex];
                               this.contents[slotIndex] = null;
                               this.markDirty();
                               return itemstack;
                           }
                           else
                           {
                               itemstack = this.contents[slotIndex].splitStack(amount);
                
                               if (this.contents[slotIndex].stackSize == 0)
                               {
                                   this.contents[slotIndex] = null;
                               }
                
                               this.markDirty();
                               return itemstack;
                           }
                       }
                       else
                       {
                           return null;
                       }
                }
                
                @Override
                public ItemStack getStackInSlotOnClosing(int slotIndex) {
                if (this.contents[slotIndex] != null)
                        {
                            ItemStack itemstack = this.contents[slotIndex];
                            this.contents[slotIndex] = null;
                            return itemstack;
                        }
                        else
                        {
                            return null;
                        }
                }
                
                @Override
                public void setInventorySlotContents(int slotIndex, ItemStack stack) {
                this.contents[slotIndex] = stack;
                
                        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                        {
                            stack.stackSize = this.getInventoryStackLimit();
                        }
                
                        this.markDirty();
                }
                
                @Override
                public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
                return "tile.Fermentator";
                }
                
                @Override
                public boolean hasCustomInventoryName() {
                return false;
                }
                
                @Override
                public int getInventoryStackLimit() {
                return 64;
                }
                
                @Override
                public boolean isUseableByPlayer(EntityPlayer player) {
                return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
                }
                
                @Override
                public void openInventory() {
                
                }
                
                @Override
                public void closeInventory() {
                
                }
                
                @Override
                public boolean isItemValidForSlot(int slot, ItemStack stack) {
                return slot == 3 ? false : true;
                }
                
                public boolean isBurning()
                    {
                        return this.workingTime > 0;
                    }
                
                private boolean canSmelt()
                    {
                        if (this.contents[0] == null) //Si les trois premiers slots sont vides
                        {
                            return false; //On ne peut pas lancer le processus
                        }
                        else
                        {
                            ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                            if (itemstack == null) return false; //rapport avec les recettes
                            if (this.contents[1] == null) return true; //vérifications du slot d'output
                            if (!this.contents[1].isItemEqual(itemstack)) return false; //ici aussi
                            int result = contents[1].stackSize + itemstack.stackSize;
                            return result <= getInventoryStackLimit() && result <= this.contents[1].getMaxStackSize(); //Et là aussi décidément
                        }
                    }
                
                public void updateEntity() //Méthode exécutée à chaque tick
                    {
                    if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
                    {
                    ++this.workingTime; //incrémentation
                    }
                    if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
                    {
                    this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
                    }
                    if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
                    {
                    this.smeltItem(); //on "cuit" les items
                    this.workingTime = 0; //et on réinitialise le temps de cuisson
                    }
                        if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
                        {
                               this.workingTime= 0; //le temps de cuisson est de 0
                        }
                    }
                
                public void smeltItem()
                    {
                        if (this.canSmelt())
                        {
                            ItemStack itemstack = FermentatorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0]}); //On récupère l'output de la recette
                             if (this.contents[1] == null) //Si il y a rien dans le slot d'output
                             {
                                  this.contents[1] = itemstack.copy(); //On met directement l'ItemStack
                             }
                             else if (this.contents[1].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                             {
                                  this.contents[1].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                             }
                
                             –this.contents[0].stackSize; //On décrémente les slots d'input
                
                             if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                             {
                                 this.contents[0] = null;
                             }
                        }
                    }
                
                @SideOnly(Side.CLIENT)
                public int getCookProgress()
                {
                return this.workingTime * 22 / this.workingTimeNeeded;
                }
                
                }
                

                ma texture :

                la texture de la barre de progression mesure 22 px de large et 12 px de haut

                Merci pour votre aide !

                En fait non c’est bon j’ai trouvé

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

                  Bonjour j’ai un souci, mon gui s’affiche 1 tick et se referme, auriez-vous une idée d’où celà pourrait venir ??
                  :::

                  public class BlockTethMachine extends Block {
                  
                  public BlockTethMachine(Material p_i45394_1_) {
                  super(p_i45394_1_);
                  // TODO Auto-generated constructor stub
                  }
                  
                  @Override
                  public TileEntity createTileEntity(World world, int metadata)
                  {
                     return new TileEntityTethMachine();
                  }
                  
                  @Override
                  public boolean hasTileEntity(int metadata)
                  {
                     return true;
                  }  
                  
                  public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
                    {
                        TileEntity tileentity = world.getTileEntity(x, y, z);
                  
                        if (tileentity instanceof IInventory)
                        {
                         IInventory inv = (IInventory)tileentity;
                            for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
                            {
                                ItemStack itemstack = inv.getStackInSlot(i1);
                  
                                if (itemstack != null)
                                {
                                    float f = world.rand.nextFloat() * 0.8F + 0.1F;
                                    float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                                    EntityItem entityitem;
                  
                                    for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                                    {
                                        int j1 = world.rand.nextInt(21) + 10;
                  
                                        if (j1 > itemstack.stackSize)
                                        {
                                            j1 = itemstack.stackSize;
                                        }
                  
                                        itemstack.stackSize -= j1;
                                        entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                                        float f3 = 0.05F;
                                        entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                                        entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                                        entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
                  
                                        if (itemstack.hasTagCompound())
                                        {
                                            entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                                        }
                                    }
                                }
                            }
                  
                            world.func_147453_f(x, y, z, block);
                        }
                  
                        super.breakBlock(world, x, y, z, block, metadata);
                    }
                  
                  public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
                  {
                  
                             player.openGui(CiolMod.instance, 10, world, x, y, z);
                             return true;
                  
                  }
                  
                  }
                  
                  

                  :::

                  :::

                  package com.mod.ciolmod.blocks.tileentities;
                  
                  import com.mod.ciolmod.gui.GuiMachineTeth;
                  
                  import cpw.mods.fml.common.network.IGuiHandler;
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.tileentity.TileEntity;
                  import net.minecraft.world.World;
                  
                  public class GuiTethMachineHandler implements IGuiHandler {
                  
                  @Override
                     public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                     {
                         switch (ID)
                         {
                             case 10:
                                 return new ContainerMachineTeth(world.getTileEntity(x, y, z), player.inventory);//backpack
                         }
                         return null;
                  
                     }
                  
                     @Override
                     public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                     {
                         switch (ID)
                         {
                             case 10:
                                 return new GuiMachineTeth((TileEntityTethMachine)world.getTileEntity(x, y, z), player.inventory);//Le block en question
                         }
                         return null;
                     }
                  
                  }
                  
                  

                  :::

                  Mon Init :
                  :::

                  @EventHandler
                  public void Init(FMLInitializationEvent event)
                  {
                  proxy.registerRenders();
                  
                  proxy.registerRenderers();
                  proxy.registerEntities();
                  
                  EntityRegistry.registerGlobalEntityID(EntityTethanium.class, "mobBlackKoala", EntityRegistry.findGlobalUniqueEntityId(), new Color(255, 255, 255).getRGB(), new Color(0, 0, 165).getRGB());
                  EntityRegistry.registerModEntity(EntityTethanium.class, "mobBlackKoala", EntityRegistry.findGlobalUniqueEntityId(), this.instance, 40, 1, true);
                  EntityRegistry.registerGlobalEntityID(EntityKoala.class, "mobKoala", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(165, 0, 0).getRGB());
                  EntityRegistry.registerModEntity(EntityKoala.class, "mobKoala", EntityRegistry.findGlobalUniqueEntityId(), this.instance, 40, 1, true);
                  
                  //EntityRegistry.addSpawn("mobTethanium", 99, 5 ,10, EnumCreatureType.monster, BiomeGenBase.beach, BiomeGenBase.plains);
                  
                  GameRegistry.registerTileEntity(TileEntityBlockFDC.class, Reference.MOD_ID + ":teBlockFDC");
                  GameRegistry.registerTileEntity(TileEntityXPParticuler.class, Reference.MOD_ID + ":teXPPARTICULER");
                  
                     EntityRegistry.registerModEntity(EntityDynamite.class, "dynamite", 451, CiolMod.instance, 32, 20, true);
                  
                     GameRegistry.registerTileEntity(TileEntityTethaniumISpawner.class, Reference.MOD_ID + ":tileentityispawner");
                  
                     GameRegistry.registerTileEntity(TileEntityTethMachine.class, Reference.MOD_ID + ":TethMachineTE");
                  
                     NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiTethMachineHandler());
                  
                  //   MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
                  
                  }
                  

                  :::

                  :::

                  package com.mod.ciolmod.blocks.tileentities;
                  
                  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.tileentity.TileEntity;
                  
                  public class ContainerMachineTeth extends Container{
                  
                  private TileEntityTethMachine tileMachineTuto;
                  
                  @Override
                  public boolean canInteractWith(EntityPlayer p_75145_1_) {
                  // TODO Auto-generated method stub
                  return false;
                  }
                  
                  public ContainerMachineTeth(TileEntityTethMachine tile, InventoryPlayer inventory)
                  {
                        this.tileMachineTuto = tile;
                        this.addSlotToContainer(new Slot(tile, 0, 49, 75)); //Lancez votre jeu en debug pour calibrer vos slots
                        this.addSlotToContainer(new Slot(tile, 1, 89, 75));
                        this.addSlotToContainer(new Slot(tile, 2, 129, 75));
                        this.addSlotToContainer(new SlotResult(tile, 3, 89, 135)); //Ici c'est un slot que j'ai créer, on le fera après
                        this.bindPlayerInventory(inventory); //Les containers ont été vus dans un tutoriel de robin, merci de d'y référer
                  }
                  
                  public ContainerMachineTeth(TileEntity tileEntity, InventoryPlayer inventory) {
                  // TODO Auto-generated constructor stub
                  }
                  
                  private void bindPlayerInventory(InventoryPlayer inventory) {
                  // TODO Auto-generated method stub
                  
                  }
                  
                  }
                  

                  :::

                  :::

                  package com.mod.ciolmod.blocks.tileentities;
                  
                  import net.minecraft.entity.player.EntityPlayer;
                  import net.minecraft.inventory.IInventory;
                  import net.minecraft.item.ItemStack;
                  import net.minecraft.nbt.NBTTagCompound;
                  import net.minecraft.nbt.NBTTagList;
                  import net.minecraft.tileentity.TileEntity;
                  
                  public class TileEntityTethMachine extends TileEntity implements IInventory {
                  
                  private ItemStack[] contents = new ItemStack[4];
                  
                  private int workingTime = 0; //Temps de cuisson actuel
                  private int workingTimeNeeded = 60; //Temps de cuisson nécessaire
                  
                  @Override
                    public void writeToNBT(NBTTagCompound compound)
                    {
                        super.writeToNBT(compound);
                        NBTTagList nbttaglist = new NBTTagList();
                  
                        for (int i = 0; i < this.contents.length; ++i) //pour les slots
                        {
                            if (this.contents* != null)
                            {
                                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                                nbttagcompound1.setByte("Slot", (byte)i);
                                this.contents*.writeToNBT(nbttagcompound1);
                                nbttaglist.appendTag(nbttagcompound1);
                            }
                        }
                  
                        compound.setTag("Items", nbttaglist);
                        compound.setShort("workingTime",(short)this.workingTime); //On les enregistrent en short
                        compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                    }
                  
                  @Override
                    public void readFromNBT(NBTTagCompound compound)
                    {
                        super.readFromNBT(compound);
                  
                        NBTTagList nbttaglist = compound.getTagList("Items", 10);
                        this.contents = new ItemStack[this.getSizeInventory()];
                  
                        for (int i = 0; i < nbttaglist.tagCount(); ++i) //Encore une fois pour les slots
                        {
                            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                            int j = nbttagcompound1.getByte("Slot") & 255;
                  
                            if (j >= 0 && j < this.contents.length)
                            {
                                this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                            }
                        }
                  
                        this.workingTime = compound.getShort("workingTime"); //On lit nos valeurs
                        this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                    }
                  
                  public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
                  return this.contents.length;
                  }
                  
                  public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
                  return this.contents[slotIndex];
                  }
                  
                  public ItemStack decrStackSize(int slotIndex, int amount) {
                  if (this.contents[slotIndex] != null)
                        {
                            ItemStack itemstack;
                  
                            if (this.contents[slotIndex].stackSize <= amount)
                            {
                                itemstack = this.contents[slotIndex];
                                this.contents[slotIndex] = null;
                                this.markDirty();
                                return itemstack;
                            }
                            else
                            {
                                itemstack = this.contents[slotIndex].splitStack(amount);
                  
                                if (this.contents[slotIndex].stackSize == 0)
                                {
                                    this.contents[slotIndex] = null;
                                }
                  
                                this.markDirty();
                                return itemstack;
                            }
                        }
                        else
                        {
                            return null;
                        }
                  }
                  
                  public ItemStack getStackInSlotOnClosing(int slotIndex) {
                  if (this.contents[slotIndex] != null)
                        {
                            ItemStack itemstack = this.contents[slotIndex];
                            this.contents[slotIndex] = null;
                            return itemstack;
                        }
                        else
                        {
                            return null;
                        }
                  }
                  
                  public void setInventorySlotContents(int slotIndex, ItemStack stack) {
                  this.contents[slotIndex] = stack;
                  
                        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                        {
                            stack.stackSize = this.getInventoryStackLimit();
                        }
                  
                        this.markDirty();
                  }
                  
                  public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
                  return "ttt";
                  }
                  
                  public boolean hasCustomInventoryName() {
                  return false;
                  }
                  
                  public int getInventoryStackLimit() {
                  return 64;
                  }
                  
                  public boolean isUseableByPlayer(EntityPlayer player) {
                  return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
                  }
                  
                  public void openInventory() {
                  
                  }
                  
                  public void closeInventory() {
                  
                  }
                  
                  public boolean isItemValidForSlot(int slot, ItemStack stack) {
                  return slot == 3 ? false : true;
                  }
                  
                  public boolean isBurning()
                    {
                        return this.workingTime > 0;
                    }
                  
                  private boolean canSmelt()
                    {
                        if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null) //Si les trois premiers slots sont vides
                        {
                            return false; //On ne peut pas lancer le processus
                        }
                        else
                        {
                            ItemStack itemstack = MachineTethRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                            if (itemstack == null) return false; //rapport avec les recettes
                            if (this.contents[3] == null) return true; //vérifications du slot d'output
                            if (!this.contents[3].isItemEqual(itemstack)) return false; //ici aussi
                            int result = contents[3].stackSize + itemstack.stackSize;
                            return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); //Et là aussi décidément
                        }
                    }
                  public void updateEntity() //Méthode exécutée à chaque tick
                    {
                     if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
                     {
                     ++this.workingTime; //incrémentation
                     }
                     if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
                     {
                     this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
                     }
                     if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
                     {
                     this.smeltItem(); //on "cuit" les items
                     this.workingTime = 0; //et on réinitialise le temps de cuisson
                     }
                        if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
                        {
                               this.workingTime= 0; //le temps de cuisson est de 0
                        }
                    }
                  
                  public void smeltItem()
                    {
                        if (this.canSmelt())
                        {
                            ItemStack itemstack = MachineTethRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //On récupère l'output de la recette
                             if (this.contents[3] == null) //Si il y a rien dans le slot d'output
                             {
                                  this.contents[3] = itemstack.copy(); //On met directement l'ItemStack
                             }
                             else if (this.contents[3].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                             {
                                  this.contents[3].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                             }
                  
                             –this.contents[0].stackSize; //On décrémente les slots d'input
                             –this.contents[1].stackSize;
                             –this.contents[2].stackSize;
                  
                             if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                             {
                                 this.contents[0] = null;
                             }
                             if (this.contents[1].stackSize <= 0)
                             {
                                 this.contents[1] = null;
                             }
                             if (this.contents[2].stackSize <= 0)
                             {
                                 this.contents[2] = null;
                             }
                        }
                    }
                  
                  }
                  
                  

                  :::

                  :::

                  package com.mod.ciolmod.gui;
                  
                  import org.lwjgl.opengl.GL11;
                  
                  import com.mod.ciolmod.Reference;
                  import com.mod.ciolmod.blocks.tileentities.ContainerMachineTeth;
                  import com.mod.ciolmod.blocks.tileentities.TileEntityTethMachine;
                  
                  import net.minecraft.client.gui.inventory.GuiContainer;
                  import net.minecraft.client.resources.I18n;
                  import net.minecraft.entity.player.InventoryPlayer;
                  import net.minecraft.inventory.IInventory;
                  import net.minecraft.util.ResourceLocation;
                  
                  public class GuiMachineTeth extends GuiContainer {
                  
                  private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID ,"textures/gui/guitethmachine.png");
                    private TileEntityTethMachine tileMachineTuto;
                    private IInventory playerInv;
                  
                  public GuiMachineTeth(TileEntityTethMachine tile, InventoryPlayer inventory)
                  {
                  super(new ContainerMachineTeth(tile, inventory));
                        this.tileMachineTuto = tile;
                        this.playerInv = inventory;
                        this.allowUserInput = false;
                        this.ySize = 256;
                        this.xSize = 256;
                  }
                  
                  @Override
                  protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
                  {
                  
                  GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                        this.mc.getTextureManager().bindTexture(texture);
                        int k = (this.width - this.xSize) / 2;
                        int l = (this.height - this.ySize) / 2;
                        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
                        this.drawTexturedModalRect(0, 0, 176, 14, 100 + 1, 16);
                  
                  }
                  
                  protected void drawGuiContainerForegroundLayer(int x, int y)
                    {
                     this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752);
                    }
                  }
                  
                  

                  :::

                  Merci de votre réponse : 🙂 et bonne soirée

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

                    😕

                    
                    @Override
                    public boolean canInteractWith(EntityPlayer p_75145_1_) {
                       // TODO Auto-generated method stub
                       return false;
                    }
                    
                    

                    Si le joueur ne peux pas interagire, bah il peut pas ouvrir le gui.

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

                      @‘LeBossMax2’:

                      😕

                      
                      @Override
                      public boolean canInteractWith(EntityPlayer p_75145_1_) {
                         // TODO Auto-generated method stub
                         return false;
                      }
                      
                      

                      Si le joueur ne peux pas interagire, bah il peut pas ouvrir le gui.

                      Merci beaucoup beaucoup !!

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

                        Il y a des problème avec les images qui sont inaccessible.
                        J’ai aussi des problème dans le code (je dev en 1.12.2) a ItemStack.stackSize il dit

                        The field ItemStack.stackSize is not visible
                        

                        aussi a ItemStack.loadItemStackFromNBT

                        The method loadItemStackFromNBT(NBTTagCompound) is undefined for the type ItemStack
                        
                        1 réponse Dernière réponse Répondre Citer 0
                        • Phenix246P Hors-ligne
                          Phenix246 Rédacteurs
                          dernière édition par

                          Pour ce qui concerne les images, le problème vient de l’hébergeur utilisé…

                          En 1.12.2 les ItemStacks ont été refait, il passe par des méthodes au lieu d’exposer les propriétés,

                          stackSize a été remplacé par “count()” et un ensemble d’autres méthodes, je t’invite à regarder plus en détails la classe ItemStack.

                          pour loadItemStackFromNBT je t’invite à regarder si la méthode n’a pas été renommer.

                          1 réponse Dernière réponse Répondre Citer 1
                          • AymericRedA Hors-ligne
                            AymericRed
                            dernière édition par

                            Pour loadItemStackFromNBT ça n’a pas été renommé mais ça passe directement par le constructeur (il faut faire ```java
                            new ItemStack(letagnbt);

                            Si je vous ai aidé, n'oubliez pas d’être heureux, j'aiderai encore +

                            AymericRed, moddeur expérimenté qui aide sur ce forum et qui peut accepter de faire un mod Forge rémunéré de temps en temps.

                            Mes tutos : Table de craft, plugin NEI, plugin JEI, modifier l'overlay
                            Je suis un membre apprécié et joueur, j'ai déjà obtenu 6 points de réputation.

                            1 réponse Dernière réponse Répondre Citer 1
                            • Z Hors-ligne
                              Zacharie
                              dernière édition par

                              Merci beaucoup 🙂
                              Mais il me reste des erreurs.

                              Dans GuiMachine a la ligne

                              this.fontRenderer.drawString(this.playerInv.hasCustomName() ? this.playerInv.getInventoryName()
                              : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752);
                              

                              il dit

                              The method getInventoryName() is undefined for the type IInventory
                              

                              dans SlotResult

                              super.onPickupFromSlot(player, stack);
                              

                              il dit

                              The method onPickupFromSlot(EntityPlayer, ItemStack) is undefined for the type Slot
                              

                              et enfin dans TileEntityMachine

                              public void writeToNBT(NBTTagCompound compound) {
                              

                              il dit

                              The return type is incompatible with TileEntity.writeToNBT(NBTTagCompound)
                              
                              1 réponse Dernière réponse Répondre Citer 0
                              • Superloup10S Hors-ligne
                                Superloup10 Modérateurs
                                dernière édition par

                                C’est difficile d’aller regarder les classes vanilla pour savoir quoi mettre ?

                                Si vous souhaitez me faire un don, il vous suffit de cliquer sur le bouton situé en dessous.

                                Je suis un membre apprécié et joueur, j'ai déjà obtenu 17 points de réputation.

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

                                  Étant donné que rien n’est dans les classes vanilla ça risque d’être un peu compliquer

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • Superloup10S Hors-ligne
                                    Superloup10 Modérateurs
                                    dernière édition par

                                    Bah si, tu as tout dans les classes vanilla.

                                    Si vous souhaitez me faire un don, il vous suffit de cliquer sur le bouton situé en dessous.

                                    Je suis un membre apprécié et joueur, j'ai déjà obtenu 17 points de réputation.

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

                                      Quand je clique sur le bloc en question sa fait bien l’annimation avec la main comme quoi je l’ai ouvert mais la gui ne s’affiche pas !!

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

                                        j’ai un souci ici ca me donne cette erreur:

                                        Cannot invoke writeToNBT(NBTTagCompound) on the array type ItemStack[]
                                        

                                        dans la ligne:

                                        this.contents.writeToNBT(nbttagcompound1);
                                        

                                        dans la classe:

                                        package fr.askipie.funfight;
                                        
                                        import net.minecraft.entity.player.EntityPlayer;
                                        import net.minecraft.inventory.IInventory;
                                        import net.minecraft.item.ItemStack;
                                        import net.minecraft.nbt.NBTTagCompound;
                                        import net.minecraft.nbt.NBTTagList;
                                        import net.minecraft.tileentity.TileEntity;
                                        import net.minecraftforge.common.util.Constants;
                                        
                                        public class TileEntityFungieMachine extends TileEntity implements IInventory
                                        {
                                            
                                            private ItemStack[] contents = new ItemStack[4]; //0, 1 et 2 sont les inputs et 3 est l'output
                                            
                                            private int workingTime = 0; //Temps de cuisson actuel
                                            private int workingTimeNeeded = 200; //Temps de cuisson nécessaire
                                        
                                            
                                          
                                        
                                            @Override
                                            public void writeToNBT(NBTTagCompound compound)
                                            {
                                                super.writeToNBT(compound);
                                                NBTTagList nbttaglist = new NBTTagList();
                                         
                                                for (int i = 0; i < this.contents.length; ++i) //pour les slots
                                                {
                                                    if (this.contents != null)
                                                    {
                                                        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                                                        nbttagcompound1.setByte("Slot", (byte)i);
                                                        this.contents.writeToNBT(nbttagcompound1);
                                                        nbttaglist.appendTag(nbttagcompound1);
                                                    }
                                                }
                                         
                                                compound.setTag("Items", nbttaglist);
                                                compound.setShort("workingTime",(short)this.workingTime); //On les enregistrent en short
                                                compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                                            }
                                            
                                            @Override
                                            public void readFromNBT(NBTTagCompound compound)
                                            {
                                                super.readFromNBT(compound);
                                         
                                                NBTTagList nbttaglist = compound.getTagList("Items", 10);
                                                this.contents = new ItemStack[this.getSizeInventory()];
                                         
                                                for (int i = 0; i < nbttaglist.tagCount(); ++i) //Encore une fois pour les slots
                                                {
                                                    NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                                                    int j = nbttagcompound1.getByte("Slot") & 255;
                                         
                                                    if (j >= 0 && j < this.contents.length)
                                                    {
                                                        this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                                                    }
                                                }
                                         
                                                this.workingTime = compound.getShort("workingTime"); //On lit nos valeurs
                                                this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                                            }
                                            
                                        
                                        
                                            @Override
                                            public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
                                                return this.contents.length;
                                            }
                                        
                                            @Override
                                            public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
                                                return this.contents[slotIndex];
                                            }
                                        
                                            @Override //Comme dit plus haut, c'est expliqué dans le tutoriel de robin
                                            public ItemStack decrStackSize(int slotIndex, int amount) {
                                                    if (this.contents[slotIndex] != null)
                                                    {
                                                        ItemStack itemstack;
                                         
                                                        if (this.contents[slotIndex].stackSize <= amount)
                                                        {
                                                            itemstack = this.contents[slotIndex];
                                                            this.contents[slotIndex] = null;
                                                            this.markDirty();
                                                            return itemstack;
                                                        }
                                                        else
                                                        {
                                                            itemstack = this.contents[slotIndex].splitStack(amount);
                                         
                                                            if (this.contents[slotIndex].stackSize == 0)
                                                            {
                                                                this.contents[slotIndex] = null;
                                                            }
                                         
                                                            this.markDirty();
                                                            return itemstack;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return null;
                                                    }
                                            }
                                         
                                            @Override
                                            public ItemStack getStackInSlotOnClosing(int slotIndex) {
                                                if (this.contents[slotIndex] != null)
                                                {
                                                    ItemStack itemstack = this.contents[slotIndex];
                                                    this.contents[slotIndex] = null;
                                                    return itemstack;
                                                }
                                                else
                                                {
                                                    return null;
                                                }
                                            }
                                         
                                            @Override
                                            public void setInventorySlotContents(int slotIndex, ItemStack stack) {
                                                this.contents[slotIndex] = stack;
                                         
                                                if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                                                {
                                                    stack.stackSize = this.getInventoryStackLimit();
                                                }
                                         
                                                this.markDirty();
                                            }
                                         
                                            @Override
                                            public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
                                                return "tile.machineTuto";
                                            }
                                         
                                            @Override
                                            public boolean hasCustomInventoryName() {
                                                return false;
                                            }
                                         
                                            @Override
                                            public int getInventoryStackLimit() {
                                                return 64;
                                            }
                                         
                                            @Override
                                            public boolean isUseableByPlayer(EntityPlayer player) {
                                                return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
                                            }
                                         
                                            @Override
                                            public void openInventory() {
                                         
                                            }
                                         
                                            @Override
                                            public void closeInventory() {
                                         
                                            }
                                         
                                            @Override
                                            public boolean isItemValidForSlot(int slot, ItemStack stack) {
                                                return slot == 3 ? false : true;
                                            }
                                        
                                            public boolean isBurning()
                                            {
                                                return this.workingTime > 0;
                                            }
                                            
                                            private boolean canSmelt()
                                            {
                                                if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null) //Si les trois premiers slots sont vides
                                                {
                                                    return false; //On ne peut pas lancer le processus
                                                }
                                                else
                                                {
                                                    ItemStack itemstack = FungieMachineRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                                                    if (itemstack == null) return false; //rapport avec les recettes
                                                    if (this.contents[3] == null) return true; //vérifications du slot d'output
                                                    if (!this.contents[3].isItemEqual(itemstack)) return false; //ici aussi
                                                    int result = contents[3].stackSize + itemstack.stackSize;
                                                    return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); //Et là aussi décidément
                                                }
                                            }
                                            
                                            public void updateEntity() //Méthode exécutée à chaque tick
                                            {
                                                if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
                                                {
                                                    ++this.workingTime; //incrémentation
                                                }
                                                if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
                                                {
                                                    this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
                                                }
                                                if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
                                                {
                                                    this.smeltItem(); //on "cuit" les items
                                                    this.workingTime = 0; //et on réinitialise le temps de cuisson
                                                }
                                                if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
                                                {
                                                        this.workingTime= 0; //le temps de cuisson est de 0
                                                }
                                            }
                                            
                                            public void smeltItem()
                                            {
                                                if (this.canSmelt())
                                                {
                                                    ItemStack itemstack = FungieMachineRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //On récupère l'output de la recette
                                                    if (this.contents[3] == null) //Si il y a rien dans le slot d'output
                                                    {
                                                        this.contents[3] = itemstack.copy(); //On met directement l'ItemStack
                                                    }
                                                    else if (this.contents[3].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                                                    {
                                                        this.contents[3].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                                                    }
                                         
                                                    --this.contents[0].stackSize; //On décrémente les slots d'input
                                                    --this.contents[1].stackSize;
                                                    --this.contents[2].stackSize;
                                         
                                                    if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                                                    {
                                                        this.contents[0] = null;
                                                    }
                                                    if (this.contents[1].stackSize <= 0)
                                                    {
                                                        this.contents[1] = null;
                                                    }
                                                    if (this.contents[2].stackSize <= 0)
                                                    {
                                                        this.contents[2] = null;
                                                    }
                                                }
                                            }
                                        }
                                        
                                        1 réponse Dernière réponse Répondre Citer 0
                                        • ZunF1xZ Hors-ligne
                                          ZunF1x @Superloup10
                                          dernière édition par

                                          @Superloup10 j’ai un problème stp repond

                                          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

                                            Cela devrait être this.contents[i].writeToNBT(nbttagcompound1);

                                            Par contre, tu n’as visiblement toujours pas compris ce qu’on t’as dit : ça ne sert à rien de venir demander de l’aide sur d’autres discussions, de poster plusieurs messages à la suite, ou encore de mentionner n’importe qui.
                                            La prochaine fois que tu reprends ce genre de comportement insupportable, ça sera un ban. C’est le dernier avertissement.

                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 7
                                            • 8
                                            • 11
                                            • 12
                                            • 6 / 12
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB