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.
    • InfiniteI Hors-ligne
      Infinite
      dernière édition par

      Merci , je sais pas comment mais j’ai réglé le problème.
      Sinon , j’ai une question : y a t’il moyen de dire 
      “2 pommes dans le premier slot , 3 fers dans le 2ème slot et 1 charbon dans le 3ème” ?

      Mes Sites(Mes Sites)
      |
      |    Site général : Game & play
      |   Site de projets (en dev !) :Infinite's Ressources
      J'ai et je suis content d'avoir 16,75 points d'ICRating

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

        Oui, c’est possible (en fait rien n’est vraiment impossible), mais dans ce cas là il va bien falloir que tu comprenne comment fonctionne le code parce qu’il faut que tu changes le système de recette que je donne dans le tutoriel.

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

          Ok , tu as une idée de comment faire ?
          Je pense qu’il faut juste adapter les publics voids addRecipe de façon a qu’on puisse entrer un chiffre pour la quantité non ?

          Mes Sites(Mes Sites)
          |
          |    Site général : Game & play
          |   Site de projets (en dev !) :Infinite's Ressources
          J'ai et je suis content d'avoir 16,75 points d'ICRating

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

            Oui bien sûr mais comme je te dit le mieux serai que tu comprenne comment fonctionne le système de recette que tu viens de créer dans le tutoriel pour pouvoir le modifier et arriver au résultat que tu veux. Si tu veux avoir des explications du code j’ai fait plusieurs versions de ce tutoriel (plusieurs versions de Minecraft) et tu en trouvera peut-être un où tu comprendra mieux (peut-être) :
            1.11
            1.8

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

              Merci  😄

              Mes Sites(Mes Sites)
              |
              |    Site général : Game & play
              |   Site de projets (en dev !) :Infinite's Ressources
              J'ai et je suis content d'avoir 16,75 points d'ICRating

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

                Salut ! 
                Ce tuto est super et il m’a permis de créer une machine a 3 slots d’input et 1 slots d’output.

                Mais j’aimerais pouvoir créer une machine à 2 slots d’input et 1 slot d’output. J’ai chercher pendant une apres midi entière et j’ ai réussi a mettre 2 slots mais les recettes ne marchent pas.

                MachineUpRecipes :

                package nolann.juet.multiore.common.machineUp;
                
                import java.util.HashMap;
                import java.util.Iterator;
                import java.util.Map;
                import java.util.Map.Entry;
                
                import net.minecraft.block.Block;
                import net.minecraft.init.Blocks;
                import net.minecraft.init.Items;
                import net.minecraft.item.Item;
                import net.minecraft.item.ItemStack;
                import nolann.juet.multiore.common.MultiOre;
                
                public class MachineUpRecipes {
                
                private static final MachineUpRecipes smeltingBase = new MachineUpRecipes(); //Permet d'instancier votre classe car vous le l'instancierez nul part ailleur
                private Map smeltingList = new HashMap(); //Ceci permet de mettre vos recettes
                
                public MachineUpRecipes()
                {
                this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
                
                }
                
                public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack) //Cette fonction de comprend que des ItemStack, c'est celle qui ajoute les recettes à la HashMap
                {
                ItemStack[] stackList = new ItemStack[]{stack1, stack2};
                this.smeltingList.put(stackList, stack);
                }
                
                        public void addRecipe(Item item1, Item item2, ItemStack stack) //1er cas
                {
                this.addRecipe(new ItemStack(item1), new ItemStack(item2), stack);
                
                this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
                
                }
                
                public void addRecipe(Block block1, Item item2, ItemStack stack) //2nd cas
                {
                this.addRecipe(Item.getItemFromBlock(block1), item2, stack);
                }
                
                public void addRecipe(Block block1, Block block2, ItemStack stack) //3ème cas
                {
                this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), stack);
                }
                
                public ItemStack getSmeltingResult(ItemStack[] stack) //En argument : un tableau avec le contenu des trois slots d'input
                {
                    Iterator iterator = this.smeltingList.entrySet().iterator();
                    Entry entry;
                
                    do
                    {
                        if (!iterator.hasNext()) // Si il n'y a plus de recettes dans la liste
                        {
                            return null; //Il n'y a pas de recette correspondante
                        }
                           entry = (Entry)iterator.next(); //prend la recette suivante
                       }
                       while (!this.isSameKey(stack, (ItemStack[])entry.getKey())); //Check si le tableau passé en argument correspond à celui de la recette, vous avez une erreur ici, on crée la fonction tout de suite.
                
                       return (ItemStack)entry.getValue(); //retourne l'itemstack : resultat de la recette
                 }
                
                private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2)
                {
                boolean isSame = false; //Au début ce n'est pas la même
                for(int i=0; i<=2; i++) // Pour les 3 items
                {
                if(stackList*.getItem() == stackList2*.getItem()) //On vérifie si ce sont les même
                {
                isSame = true; // Si c'est le cas alors isSame vaut true
                }
                else
                {
                return false; //Si un seul n'est pas bon, on cherche pas, c'est pas la bonne recette
                }
                }
                return isSame;
                }
                
                public Map getSmeltingList()
                {
                       return this.smeltingList;
                    }
                
                public static MachineUpRecipes smelting()
                {
                return smeltingBase;
                }
                }
                

                SlotResultUp :

                package nolann.juet.multiore.common.machineUp;
                
                import net.minecraft.entity.player.EntityPlayer;
                import net.minecraft.inventory.IInventory;
                import net.minecraft.inventory.Slot;
                import net.minecraft.item.ItemStack;
                
                public class SlotResultUp extends Slot {
                
                    public SlotResultUp(IInventory inventory, int id, int x, int y) 
                    {
                        super(inventory, id, x, y);
                    }
                
                    @Override
                    public boolean isItemValid(ItemStack stack) //Interdit la pose d'items dans le slot
                   {
                       return false;
                   }
                
                    public ItemStack decrStackSize(int amount)
                   {
                       return super.decrStackSize(amount);
                   }
                
                    public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
                   {
                       super.onCrafting(stack);
                       super.onPickupFromSlot(player, stack);
                   }
                
                }
                
                TileEntityMachineUp : 
                
                package nolann.juet.multiore.common.machineUp;
                
                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 TileEntityMachineUp 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");
                    }
                
                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 "tile.machineTuto";
                }
                
                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 = MachineUpRecipes.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 = MachineUpRecipes.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;
                             }
                        }
                    }
                
                 @SideOnly(Side.CLIENT)
                 public int getCookProgress()
                 {
                   return this.workingTime * 100 / this.workingTimeNeeded;
                 }
                
                }
                

                Merci à ce qui m’aideront !!

                Mon Mod :

                :::

                Dragonite

                :::

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

                  Quand je clic sur mon bloc le jeu crash voici mon crash report :

                  
                  –-- Minecraft Crash Report ----
                  // Why is it breaking :(
                  
                  Time: 08/07/17 13:46
                  Description: Ticking memory connection
                  
                  java.lang.ClassCastException: com.mod.metallica.entity.TileEntityForge cannot be cast to net.minecraft.inventory.IInventory
                  at com.mod.metallica.entity.ContainerForge.<init>(ContainerForge.java:16)
                  at com.mod.metallica.gui.GuiHandler.getServerGuiElement(GuiHandler.java:20)
                  at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:243)
                  at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75)
                  at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
                  at com.mod.metallica.blocks.ForgeBlock.onBlockActivated(ForgeBlock.java:92)
                  at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
                  at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
                  at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
                  at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
                  at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
                  at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
                  at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
                  at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
                  at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
                  at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
                  at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
                  
                  A detailed walkthrough of the error, its code path and all known details is as follows:
                  ---------------------------------------------------------------------------------------
                  
                  -- Head --
                  Stacktrace:
                  at com.mod.metallica.entity.ContainerForge.<init>(ContainerForge.java:16)
                  at com.mod.metallica.gui.GuiHandler.getServerGuiElement(GuiHandler.java:20)
                  at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:243)
                  at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75)
                  at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
                  at com.mod.metallica.blocks.ForgeBlock.onBlockActivated(ForgeBlock.java:92)
                  at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
                  at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
                  at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
                  at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
                  at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
                  
                  -- Ticking connection --
                  Details:
                  Connection: net.minecraft.network.NetworkManager@a010313
                  Stacktrace:
                  at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
                  at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
                  at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
                  at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
                  at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
                  at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
                  
                  -- System Details --
                  Details:
                  Minecraft Version: 1.7.10
                  Operating System: Windows 10 (amd64) version 10.0
                  Java Version: 1.8.0_131, Oracle Corporation
                  Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
                  Memory: 755641032 bytes (720 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
                  JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
                  AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
                  IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
                  FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 4 mods loaded, 4 mods active
                  States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
                  UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)
                  UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
                  UCHIJAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
                  UCHIJAAAA metallica{1.1.0} [Mod Metallica] (bin)
                  GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
                  Profiler Position: N/A (disabled)
                  Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
                  Player Count: 1 / 8; [EntityPlayerMP['Player361'/96, l='New World', x=-99902,72, y=71,00, z=-8,88]]
                  Type: Integrated Server (map_client.txt)
                  Is Modded: Definitely; Client brand changed to 'fml,forge'
                  ```</init></init>
                  1 réponse Dernière réponse Répondre Citer 0
                  • BrokenSwingB Hors-ligne
                    BrokenSwing Moddeurs confirmés Rédacteurs
                    dernière édition par

                    Tu n’as pas implémenter IInventory dans ton TileEntity

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

                      Ah ok merci maintenant sa fonctionne .

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

                        Ce message a été supprimé !
                        1 réponse Dernière réponse Répondre Citer 0
                        • _ Hors-ligne
                          ___Freezer___
                          dernière édition par

                          Moi j’ai que des erreurs 😕

                          http://www.noelshack.com/2017-28-3-1499811822-capture.png
                          http://www.noelshack.com/2017-28-3-1499811828-1.png
                          http://www.noelshack.com/2017-28-3-1499811836-2.png
                          http://www.noelshack.com/2017-28-3-1499811838-3.png
                          http://www.noelshack.com/2017-28-3-1499811841-4.png
                          http://www.noelshack.com/2017-28-3-1499811843-5.png
                          http://www.noelshack.com/2017-28-3-1499811848-6.png

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

                            J’ai l’impression que tu n’as pas implémenté IInventory dans la classe de ton TileEntity, est ce que ton Container hérite bien de la class Container ? Et quelle est l’erreur affichée pour le GUI ?

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

                              Oui mon Container est en extends vers la classe Container.
                              Pour le GUI, il n’y a plus d’erreur juste un triangle jaune :

                              http://www.noelshack.com/2017-28-3-1499860230-capture1.png

                              Il me dit "Unnecessary @SupressWarnings(“unused”)

                              Il ne reste des erreurs que dans le Container le SlotResult et le TilEntity (et se mystérieux triangle jaune^^)
                              J’ai aussi modifié un peu mon Container pour n’avoir plus qu’une seule erreur :

                              http://www.noelshack.com/2017-28-3-1499860865-capture2.png

                              Pour le SlotResult et le TyleEntity ça me dit d’enlever l’annotation “@Override”
                              Et il y certaines méthodes que le SlotResult ne connais pas et me dit de créer (comme .addSlotToContainer, .mergeItemStack, .onContainerClosed) mais aussi le .inventorySlots où là, il me propose de créer le field ou la constante.

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

                                Bien le bonjour !

                                Grâce à se tuto, j’ai pu créer un “fermentateur” qui transforme des fruits en boissons alcoolisées.

                                Par contre, je me demande si on peut mettre le déroulement de la barre de progression à l’horizontal comme dans le four.

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

                                  @__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”

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

                                    @BrokenSwing Oui merci 🙂 reste plus que comme erreurs le GUI, j’ai régler le reste, il y avait une erreur dans le SlotResult.
                                    Je ne vois aucunes images et je n’ai pas de guihandler, pourrais-tu m’aider ?

                                    http://www.noelshack.com/2017-28-3-1499884852-7.png

                                    http://www.noelshack.com/2017-28-3-1499884917-8.png

                                    Et dernière chose, mon Four ne s’ouvre pas.

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • 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
                                            • 1
                                            • 2
                                            • 6
                                            • 7
                                            • 8
                                            • 9
                                            • 10
                                            • 11
                                            • 12
                                            • 8 / 12
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB