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.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      Pas de problème ici, il faut le code du bloc, du tile entity, et du container.

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

        @‘robin4002’:

        Pas de problème ici, il faut le code du bloc, du tile entity, et du container.

        Voila voila et merci pour le coup de mains
        :::

        Block

        package be.hydroen.chimicraft.blocks;
        
        import be.hydroen.chimicraft.common.ModChimiCraft;
        import be.hydroen.chimicraft.tileentity.TileEntityComposer;
        import be.hydroen.chimicraft.tileentity.TileEntityDecomposer;
        import net.minecraft.block.Block;
        import net.minecraft.block.BlockContainer;
        import net.minecraft.block.material.Material;
        import net.minecraft.entity.EntityLivingBase;
        import net.minecraft.entity.item.EntityItem;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.inventory.IInventory;
        import net.minecraft.item.ItemStack;
        import net.minecraft.nbt.NBTTagCompound;
        import net.minecraft.tileentity.TileEntity;
        import net.minecraft.world.World;
        
        public class BlockDecomposer extends BlockContainer
        {
        
        public BlockDecomposer(Material material)
        {
        super(Material.rock);
        this.setResistance(8.0F);
        this.setHarvestLevel("pickaxe", 1);
        this.setBlockTextureName(ModChimiCraft.MODID + ":decomposer");
        this.setCreativeTab(ModChimiCraft.creativeTabsChimiCraft);
        }
        
        @Override
        public TileEntity createNewTileEntity(World world, int metadata)
        {
        if(metadata == 1)
        {
        return new TileEntityDecomposer();
        }
        
        return null;
        }
        
        @Override
        public boolean hasTileEntity(int metadata)
        {
        return true;
        }
        
        public boolean onBlockActived(World world, int x, int y, int z, EntityPlayer player, int side, float hitx,  float hity, float hitz)
        {
        if(world.isRemote)
        {
        return true;
        }
        else
        {
        player.openGui(ModChimiCraft.instance, 1,  world, x, y, z);
        return true;
        }
        }
        
        public void breakBlock(World world, int x, int y, int z, Block block, int metadata) //Loot les objets du bloc sur le sol
           {
               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  void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
        {
        TileEntity tile = world.getTileEntity(x, y, z);
        if(tile instanceof TileEntityComposer)
        {
        if(stack.hasDisplayName())
        {
        ((TileEntityComposer)tile).setCustomName(stack.getDisplayName());
        }
        }
        }
        }
        
        

        TileEntity

        package be.hydroen.chimicraft.tileentity;
        
        import be.hydroen.chimicraft.recipes.DecomposerRecipes;
        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 TileEntityDecomposer extends TileEntity implements IInventory
        {
        private ItemStack[] contents = new ItemStack[4];
        
        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 enregistre 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)
        {
        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");
        this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
        }
        
        @Override
        public int getSizeInventory()
        {
        return this.contents.length;
        }
        
        @Override
        public ItemStack getStackInSlot(int slotIndex)
        {
        return this.contents[slotIndex];
        }
        
        @Override
        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()
        {
        return "tile.decomposer";
        }
        
        @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 = DecomposerRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
                   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
               }
           }
        
        @Override
        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 = DecomposerRecipes.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;
                    }
               }
           }
        }
        

        Container

        package be.hydroen.chimicraft.container;
        
        import be.hydroen.chimicraft.tileentity.TileEntityDecomposer;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.entity.player.InventoryPlayer;
        import net.minecraft.inventory.Container;
        import net.minecraft.inventory.Slot;
        import net.minecraft.item.ItemStack;
        
        public class ContainerDecomposer extends Container
        {
        private TileEntityDecomposer tileDecomposer;
        
        public ContainerDecomposer(TileEntityDecomposer tile, InventoryPlayer inventory)
        {
        this.tileDecomposer = 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)); // Slot créé
        this.bindPlayerInventory(inventory);
        }
        
        private void bindPlayerInventory(InventoryPlayer inventory)
        {
        int i;
        
        for (i = 0; i < 3; ++i)
               {
                   for (int j = 0; j < 9; ++j)
                   {
                       this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 17 + j * 18, 171 + i * 18));
                   }
               }
        
               for (i = 0; i < 9; ++i)
               {
                   this.addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 229));
               }
        }
        
        public ItemStack transferStackInSlot(EntityPlayer player, int quantity)
           {
               ItemStack itemstack = null;
               Slot slot = (Slot)this.inventorySlots.get(quantity);
        
               if (slot != null && slot.getHasStack())
               {
                   ItemStack itemstack1 = slot.getStack();
                   itemstack = itemstack1.copy();
        
                   if (quantity < this.tileDecomposer.getSizeInventory())
                   {
                       if (!this.mergeItemStack(itemstack1, this.tileDecomposer.getSizeInventory(), this.inventorySlots.size(), true))
                       {
                           return null;
                       }
                   }
                   else if (!this.mergeItemStack(itemstack1, 0, this.tileDecomposer.getSizeInventory(), false))
                   {
                       return null;
                   }
        
                   if (itemstack1.stackSize == 0)
                   {
                       slot.putStack((ItemStack)null);
                   }
                   else
                   {
                       slot.onSlotChanged();
                   }
               }
        
               return itemstack;
           }
        
        public void onContainerClosed(EntityPlayer player)
           {
               super.onContainerClosed(player);
               this.tileDecomposer.closeInventory();
           }
        
        @Override
        public boolean canInteractWith(EntityPlayer player)
        {
        return this.tileDecomposer.isUseableByPlayer(player);
        }
        }
        
        

        :::

        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

          if(metadata == 1)
          {
          return new TileEntityDecomposer();
          }
          

          Ton bloc n’a qu’un tile entity sur le metadata 1.
          La raison du problème est surement là.

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

            @‘robin4002’:

            if(metadata == 1)
            {
            return new TileEntityDecomposer();
            }
            

            Ton bloc n’a qu’un tile entity sur le metadata 1.
            La raison du problème est surement là.

                   @Override
                   public TileEntity createTileEntity(World world, int metadata)
            {
            if(metadata == 0)
            {
            return new TileEntityComposer();
            }
            
            return null;
            }
            

            Ceci c’est le code de mon autre bloc et lui j’arrive à ouvrir le gui en cliquant droit dessus …

            Voila tout mon code ça sera peut-être plus simple comme ça
            https://github.com/Hydroen/chimicraft

            je me suis surement mélangé les pinceaux à un endroit…

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

              C’est normal, vu que zéro est la metadata par défaut, mais pas 1…

              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
              • robin4002R Hors-ligne
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                dernière édition par

                Remplaces le 1 par 0.
                Tu as seulement besoin d’utiliser un metadata différent si tu mets plusieurs tile entité sur un même bloc.

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

                  Merci, j’ai du zappé ce détail 😉

                  mais j’ai toujours le souci du gui du block decomposer qui ne s’ouvre pas 😕

                  PS: j’ai comparé mes deux blocks, mais je ne vois pas de différences qui pourraient engendré ce problème …

                  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

                    Tu as reposé le bloc après avoir mis 0 ?

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

                      Oui, je viens de le refaire à l’instant pour en être certain, mais j’ai toujours le problème en ayant reposé le block le gui ne s’ouvre toujours pas

                      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

                        Dans la classe BlockDecomposer, la fonction devrait se nommer onBlockActivated et non onBlockActived.
                        Le problème est ici.

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

                          @‘robin4002’:

                          Dans la classe BlockDecomposer, la fonction devrait se nommer onBlockActivated et non onBlockActived.
                          Le problème est ici.

                          Et bien merci, j’avais déjà passé tout le code en revue, mais je n’avais pas vu l’erreur dans le nom de la fonction … (mais j’avais trouvé 2 - 3 autres erreurs ^^)

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

                            Je me demandais dans la classe RECIPES j’ai

                            public DecomposerRecipes()
                            {
                            this.addRecipe(Items.apple, Items.apple, Items.arrow, new ItemStack(Blocks.diamond_block));
                            this.addRecipe(GetItem("Hydrogene"), GetItem("Hydrogene"), GetItem("Hydrogene"), new ItemStack(Blocks.gold_block));
                            }
                            
                            private Item GetItem(String name)
                            {
                            return GameRegistry.findItem(ModChimiCraft.MODID, name);
                            }
                            

                            mais je n’arrive pas à utiliser un item que j’ai créé pour l’utiliser dans une recette comme input, ou je dois mal m’y prendre 😕

                            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

                              ClassePrincipale.nomDuChampDeLitem

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

                                @‘robin4002’:

                                ClassePrincipale.nomDuChampDeLitem

                                Merci 😉

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

                                  Salut j’ai aucune erreur sur le code des class mais quand j’arrive sur minecraft et que je fais un clics droit sa bug et sa n’ouvre rien

                                  Mon Mod :

                                  :::

                                  Dragonite

                                  :::

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

                                    Il nous faut le code de la fonction onBlockRightClicking, et le contenue de ton GuiHandler

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

                                      Après avoir suivi le tuto a la lettre , après avoir mis les deux pommes et la flèche dans ma machine , rien ne se passe …
                                      J’ajoute aussi que je peux toujours mettre un item en output avec un shift clic …

                                      voici mes classes :
                                      :::

                                      Classe du block :

                                      
                                      package com.iutils.infinite.blocks;
                                      
                                      import com.iutils.infinite.IUtils;
                                      import com.iutils.infinite.Reference;
                                      import com.iutils.infinite.init.TabMod;
                                      import com.iutils.infinite.tileentities.CompressorTE;
                                      
                                      import cpw.mods.fml.common.registry.GameRegistry;
                                      import cpw.mods.fml.relauncher.Side;
                                      import cpw.mods.fml.relauncher.SideOnly;
                                      import net.minecraft.block.Block;
                                      import net.minecraft.block.material.Material;
                                      import net.minecraft.client.renderer.texture.IIconRegister;
                                      import net.minecraft.creativetab.CreativeTabs;
                                      import net.minecraft.entity.EntityLivingBase;
                                      import net.minecraft.entity.item.EntityItem;
                                      import net.minecraft.entity.player.EntityPlayer;
                                      import net.minecraft.inventory.IInventory;
                                      import net.minecraft.item.ItemStack;
                                      import net.minecraft.nbt.NBTTagCompound;
                                      import net.minecraft.tileentity.TileEntity;
                                      import net.minecraft.tileentity.TileEntityChest;
                                      import net.minecraft.util.IIcon;
                                      import net.minecraft.util.MathHelper;
                                      import net.minecraft.world.World;
                                      
                                      public class Compressor extends Block
                                      {
                                          private IIcon[] icons = new IIcon[6];
                                      
                                          public Compressor()
                                          {
                                              super(Material.iron);
                                              this.setCreativeTab(TabMod.iutilstab);
                                              this.setBlockName("compressor");
                                              this.setResistance(8.0F);
                                              this.setHarvestLevel("pickaxe", 1);
                                          }
                                      
                                          @Override
                                          public void registerBlockIcons(IIconRegister reg)
                                          {
                                              for (int i = 0; i < 6; i++)
                                              {
                                                  icons* = reg.registerIcon(Reference.MOD_ID + ":" + "compressor" + "_" + (i + 1));
                                              }
                                          }
                                      
                                          @Override
                                          public IIcon getIcon(int side, int meta)
                                          {
                                          return icons[side];
                                          }
                                          @Override
                                          public TileEntity createTileEntity(World world, int metadata)
                                          {
                                              if(metadata == 0)
                                              {
                                              return new CompressorTE();
                                              }
                                              else if(metadata == 1)
                                              {
                                                  return new CompressorTE();
                                              }
                                              else if(metadata == 2)
                                              {
                                                  return new CompressorTE();
                                              }
                                              return null;
                                          }
                                      
                                          @Override
                                          public boolean hasTileEntity(int metadata)
                                          {
                                              if(metadata >= 0 && metadata <= 2)
                                                  return true;
                                              return false;
                                          }
                                      
                                          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 void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
                                          {
                                              if(stack.getItemDamage() == 0)
                                              {
                                                  TileEntity tile = world.getTileEntity(x, y, z);
                                                  if(tile instanceof CompressorTE)
                                                  {
                                                      if(stack.hasDisplayName())
                                                      {
                                                          ((CompressorTE)tile).setCustomName(stack.getDisplayName());
                                                      }
                                                  }
                                              }
                                          }
                                      
                                          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
                                          {
                                              if (world.isRemote)
                                              {
                                                  return true;
                                              }
                                              else
                                              {
                                                      player.openGui(IUtils.instance, 0, world, x, y, z);
                                                  return true;
                                              }
                                          }
                                      }
                                      
                                      

                                      Classe TileEntity:

                                      
                                      package com.iutils.infinite.tileentities;
                                      
                                      import com.iutils.infinite.recipes.CompressorRecipes;
                                      
                                      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.network.NetworkManager;
                                      import net.minecraft.network.Packet;
                                      import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
                                      import net.minecraft.tileentity.TileEntity;
                                      import net.minecraftforge.common.util.Constants;
                                      
                                      public class CompressorTE extends TileEntity implements IInventory
                                      {
                                          private ItemStack[] contents = new ItemStack[4];
                                          private String customName;
                                          private int workingTime = 0;
                                          private int workingTimeNeeded = 200;
                                      
                                          @Override
                                          public void readFromNBT(NBTTagCompound compound)
                                          {
                                              super.readFromNBT(compound);
                                      
                                              if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
                                              {
                                                  this.customName = compound.getString("CustomName");
                                              }
                                      
                                              NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
                                              this.contents = new ItemStack[this.getSizeInventory()];
                                      
                                              for (int i = 0; i < nbttaglist.tagCount(); ++i)
                                              {
                                                  NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                                                  int j = nbttagcompound1.getByte("Slot") & 255;
                                      
                                                  if (j >= 0 && j < this.contents.length)
                                                  {
                                                      this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                                                  }
                                              }
                                              this.workingTime = compound.getShort("workingTime");
                                              this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
                                          }
                                      
                                          @Override
                                          public void writeToNBT(NBTTagCompound compound)
                                          {
                                              super.writeToNBT(compound);
                                              NBTTagList nbttaglist = new NBTTagList();
                                      
                                              if (this.hasCustomInventoryName())
                                              {
                                                  compound.setString("CustomName", this.customName);
                                              }
                                      
                                              for (int i = 0; i < this.contents.length; ++i)
                                              {
                                                  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);
                                              compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
                                          }
                                      
                                          public Packet getDescriptionPacket()
                                          {
                                              NBTTagCompound nbttagcompound = new NBTTagCompound();
                                              this.writeToNBT(nbttagcompound);
                                              return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
                                          }
                                      
                                          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
                                          {
                                              this.readFromNBT(pkt.func_148857_g());
                                          }
                                      
                                          @Override
                                          public int getSizeInventory()
                                          {
                                              return this.contents.length;
                                          }
                                      
                                          @Override
                                          public ItemStack getStackInSlot(int slotIndex)
                                          {
                                              return this.contents[slotIndex];
                                          }
                                      
                                          @Override
                                          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()
                                          {
                                              return this.hasCustomInventoryName() ? this.customName : "tile.compressor.name";
                                          }
                                      
                                          @Override
                                          public boolean hasCustomInventoryName()
                                          {
                                              return this.customName != null && !this.customName.isEmpty();
                                          }
                                      
                                          public void setCustomName(String customName)
                                          {
                                              this.customName = customName;
                                          }
                                      
                                          @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 slotIndex, ItemStack stack)
                                          {
                                              return true;
                                          }
                                      
                                          public boolean isBurning()
                                          {
                                              return this.workingTime > 0;
                                          }
                                          private boolean canSmelt()
                                          {
                                              if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null)
                                              {
                                                  return false;
                                              }
                                              else
                                              {
                                                  ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
                                                  if (itemstack == null) return false;
                                                  if (this.contents[3] == null) return true;
                                                  if (!this.contents[3].isItemEqual(itemstack)) return false;
                                                  int result = contents[3].stackSize + itemstack.stackSize;
                                                  return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize();
                                              }
                                          }
                                      
                                          public void updateEntity()
                                          {
                                              if(this.isBurning() && this.canSmelt())
                                              {
                                                  ++this.workingTime;
                                              }
                                              if(this.canSmelt() && !this.isBurning())
                                              {
                                                  this.workingTime = 1;
                                              }
                                              if(this.canSmelt() && this.workingTime == this.workingTimeNeeded)
                                              {
                                                  this.smeltItem();
                                                  this.workingTime = 0;
                                              }
                                              if(!this.canSmelt())
                                              {
                                                     this.workingTime= 0;
                                              }
                                          }
                                      
                                          public void smeltItem()
                                          {
                                              if (this.canSmelt())
                                              {
                                                  ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
                                                   if (this.contents[3] == null)
                                                   {
                                                        this.contents[3] = itemstack.copy();
                                                   }
                                                   else if (this.contents[3].getItem() == itemstack.getItem())
                                                   {
                                                        this.contents[3].stackSize += itemstack.stackSize;
                                                   }
                                      
                                                   –this.contents[0].stackSize;
                                                   –this.contents[1].stackSize;
                                                   –this.contents[2].stackSize;
                                      
                                                   if (this.contents[0].stackSize <= 0)
                                                   {
                                                       this.contents[0] = null;
                                                   }
                                                   if (this.contents[1].stackSize <= 0)
                                                   {
                                                       this.contents[1] = null;
                                                   }
                                                   if (this.contents[2].stackSize <= 0)
                                                   {
                                                       this.contents[2] = null;
                                                   }
                                              }
                                          }
                                      }
                                      
                                      

                                      Class du Gui Handler :

                                      
                                      package com.iutils.infinite;
                                      
                                      import com.iutils.infinite.containers.ContainerCompressor;
                                      import com.iutils.infinite.gui.GuiCompressor;
                                      import com.iutils.infinite.tileentities.CompressorTE;
                                      
                                      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 GuiHandlerIUtils implements IGuiHandler
                                      {
                                      
                                          @Override
                                          public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                                          {
                                              TileEntity tile = world.getTileEntity(x, y, z);
                                              if(tile instanceof CompressorTE)
                                              {
                                                  return new ContainerCompressor((CompressorTE)tile, player.inventory);
                                              }
                                              return null;
                                          }
                                      
                                          @Override
                                          public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                                          {
                                              TileEntity tile = world.getTileEntity(x, y, z);
                                              if(tile instanceof CompressorTE)
                                              {
                                                  return new GuiCompressor((CompressorTE)tile, player.inventory);
                                              }
                                              return null;
                                          }
                                      
                                      }
                                      
                                      

                                      Class du Container :

                                      
                                      package com.iutils.infinite.containers;
                                      
                                      import com.iutils.infinite.tileentities.CompressorTE;
                                      
                                      import cpw.mods.fml.client.FMLClientHandler;
                                      import net.minecraft.client.Minecraft;
                                      import net.minecraft.entity.player.EntityPlayer;
                                      import net.minecraft.entity.player.InventoryPlayer;
                                      import net.minecraft.init.Blocks;
                                      import net.minecraft.inventory.Container;
                                      import net.minecraft.inventory.Slot;
                                      import net.minecraft.inventory.SlotFurnace;
                                      import net.minecraft.item.Item;
                                      import net.minecraft.item.ItemStack;
                                      
                                      public class ContainerCompressor extends Container
                                      {
                                          private final CompressorTE tilecompressor;
                                      
                                          public ContainerCompressor(CompressorTE tile, InventoryPlayer inventory)
                                          {
                                              this.tilecompressor = tile;
                                              tile.openInventory();
                                              this.addSlotToContainer(new Slot(tile, 0, 9, 24));
                                              this.addSlotToContainer(new Slot(tile, 1, 30, 24));
                                              this.addSlotToContainer(new Slot(tile, 2, 80, 51));
                                              this.addSlotToContainer(new SlotResult(tile, 3, 136, 34));
                                              this.bindPlayerInventory(inventory);
                                          }
                                      
                                          private void bindPlayerInventory(InventoryPlayer inventory)
                                          {
                                              int i;
                                              for (i = 0; i < 3; ++i)
                                              {
                                                  for (int j = 0; j < 9; ++j)
                                                  {
                                                      this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
                                                  }
                                              }
                                      
                                              for (i = 0; i < 9; ++i)
                                              {
                                                  this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
                                              }
                                          }
                                      
                                          @Override
                                          public boolean canInteractWith(EntityPlayer player)
                                          {
                                              return this.tilecompressor.isUseableByPlayer(player);
                                          }
                                      
                                          public void onContainerClosed(EntityPlayer player)
                                          {
                                              super.onContainerClosed(player);
                                              this.tilecompressor.closeInventory();
                                          }
                                      
                                          public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
                                          {
                                              ItemStack itemstack = null;
                                              Slot slot = (Slot)this.inventorySlots.get(slotIndex);
                                      
                                              if (slot != null && slot.getHasStack())
                                              {
                                                  ItemStack itemstack1 = slot.getStack();
                                                  itemstack = itemstack1.copy();
                                      
                                                  if (slotIndex < this.tilecompressor.getSizeInventory())
                                                  {
                                                      if (!this.mergeItemStack(itemstack1, this.tilecompressor.getSizeInventory(), this.inventorySlots.size(), true))
                                                      {
                                                          return null;
                                                      }
                                                  }
                                                  else if (!this.mergeItemStack(itemstack1, 0, this.tilecompressor.getSizeInventory(), false))
                                                  {
                                                      return null;
                                                  }
                                      
                                                  if (itemstack1.stackSize == 0)
                                                  {
                                                      slot.putStack((ItemStack)null);
                                                  }
                                                  else
                                                  {
                                                      slot.onSlotChanged();
                                                  }
                                              }
                                              return itemstack;
                                          }
                                      }
                                      
                                      

                                      Class des Recipes :

                                      
                                      package com.iutils.infinite.recipes;
                                      
                                      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;
                                      
                                      public class CompressorRecipes
                                      {
                                          private static final CompressorRecipes smeltingBase = new CompressorRecipes();
                                          private Map smeltingList = new HashMap();
                                      
                                          public CompressorRecipes()
                                          {
                                              this.addRecipe(Items.apple, Items.apple, Items.arrow, new ItemStack(Blocks.diamond_block));
                                          }
                                      
                                          public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3, ItemStack stack4)
                                          {
                                              ItemStack[] stackList = new ItemStack[]{stack1, stack2, stack3};
                                              this.smeltingList.put(stackList, stack4);
                                          }
                                      
                                              public void addRecipe(Item item1, Item item2, Item item3, ItemStack stack)
                                          {
                                              this.addRecipe(new ItemStack(item1), new ItemStack(item2), new ItemStack(item3), stack);
                                          }
                                      
                                          public void addRecipe(Block block1, Item item2, Item item3, ItemStack stack)
                                          {
                                              this.addRecipe(Item.getItemFromBlock(block1), item2, item3, stack);
                                          }
                                      
                                          public void addRecipe(Block block1, Block block2, Item item3, ItemStack stack)
                                          {
                                              this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), item3, stack);
                                          }
                                      
                                          public void addRecipe(Block block1, Block block2, Block block3, ItemStack stack)
                                          {
                                              this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), Item.getItemFromBlock(block3), stack);
                                          }
                                      
                                          public ItemStack getSmeltingResult(ItemStack[] stack)
                                          {
                                              Iterator iterator = this.smeltingList.entrySet().iterator();
                                              Entry entry;
                                      
                                              do
                                              {
                                                  if (!iterator.hasNext())
                                                  {
                                                      return null;
                                                  }
                                                 entry = (Entry)iterator.next();
                                             }
                                             while (!this.isSameKey(stack, (ItemStack[])entry.getKey()));
                                      
                                             return (ItemStack)entry.getValue();
                                           }
                                      
                                          private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2)
                                          {
                                              boolean isSame = false;
                                              for(int i=0; i<=2; i++)
                                              {
                                                  if(stackList*.getItem() == stackList2*.getItem())
                                                  {
                                                      isSame = true;
                                                  }
                                                  else
                                                  {
                                                      return false;
                                                  }
                                              }
                                              return isSame;
                                          }
                                      
                                          public Map getSmeltingList()
                                          {
                                             return this.smeltingList;
                                          }
                                      
                                      public static CompressorRecipes smelting()
                                         {
                                             return smeltingBase;
                                         }
                                      }
                                      
                                      

                                      Voila , je vais essayer de faire le barre de progression même si ça marche pas 😕
                                      En espérant que quelqu’un trouve une solution
                                      Je précise également que c’était un très bon tuto mais avec quelques fautes d’orthographe  😄
                                      Par contre c’est dommage que les images ne fonctionnent pas …

                                      :::

                                      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

                                        Bonjour,
                                        Ceci n’est pas un super tutoriel, c’était un de mes premiers, il y a beaucoup de classes et on peut y trouver beaucoup d’erreurs. Je n’ai toujours pas la solution à ton problème cependant j’ai la solution pour le shift-click, remplace dans la fonction Container#transfertStackInSlot :

                                        
                                        else if (!this.mergeItemStack(itemstack1, 0, this.tilecompressor.getSizeInventory(), false))
                                        {
                                        return null;
                                        }
                                        
                                        

                                        Par : ```java

                                        else if (!this.mergeItemStack(itemstack1, 0, this.tilecompressor.getSizeInventory() - 1, false))
                                        {
                                        return null;
                                        }

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

                                          Merci , par contre c’est triste que tu est pas trouvé le gros problème …
                                          EDIT : Comme par magie , j’ai réglé le problème XD

                                          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

                                            Il faudrait que tu fournisse des informations qui nous guident vers le problème, de cette façon on a pas à lire chaque ligne de chaque classe. La fonction TileEntity#updateEntity est-elle appelée ? Si oui quel est l’évolution des variables de ta classe ?

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB