MFF

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

    Ajouter un gui et un container à un bloc

    Planifier Épinglé Verrouillé Déplacé Les interfaces (GUI) et les container
    1.7.x
    129 Messages 21 Publieurs 31.6k Vues 8 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.
    • DeletedD Hors-ligne
      Deleted
      dernière édition par

      File ta classe entièrement, on gagnera en efficacité/compréhension.
      Tu devrais sûrement rajouter un null-check de stackList*, avant d’appeler dessus un .getItem()

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

        BlockFourRecipes :

        package Package1.common.FourTotal;
        
        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 BlockFourRecipes {
        
        private static final BlockFourRecipes smeltingBase = new BlockFourRecipes();
        private Map smeltingList = new HashMap();
        
        public BlockFourRecipes()
        {
        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) //1er cas
        {
        this.addRecipe(new ItemStack(item1), new ItemStack(item2), new ItemStack(item3), stack);
        }
        
        public void addRecipe(Block block1, Item item2, Item item3, ItemStack stack) //2nd cas
        {
        this.addRecipe(Item.getItemFromBlock(block1), item2, item3, stack);
        }
        
        public void addRecipe(Block block1, Block block2, Item item3, ItemStack stack) //3ème cas
        {
        this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), item3, stack);
        }
        
        public void addRecipe(Block block1, Block block2, Block block3, ItemStack stack) //4ème cas
        {
        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 BlockFourRecipes smelting()
        {
        return smeltingBase;
        }
        }
        
        

        TileEntityFour:

        package Package1.common.FourTotal;
        
        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 TileEntityFour extends TileEntity implements IInventory{
        
        private ItemStack[] contents = new ItemStack[4];
        private int workingTime = 0;
        private int workingTimeNeeded = 200;
        
        @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() {
        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.BlockFour";
        }
        
        @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)
               {
                   return true;
               }
               else
               {
                   ItemStack itemstack = BlockFourRecipes.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;
                   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 = BlockFourRecipes.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;
                    }
               }
           }
        @SideOnly(Side.CLIENT)
        public int getCookProgress()
        {
        return this.workingTime * 41 / this.workingTimeNeeded; //41 correspond à la hauteur de la barre de progression car notre barre de progression se déroule de haut en bas
        }
        }
        
        1 réponse Dernière réponse Répondre Citer 0
        • _ Hors-ligne
          ___Freezer___
          dernière édition par

          ???

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

            Salut juste j’ai un problème j’ai suivi ce tuto (mon mc est en 1.8) en éspérant pouvoir réussir mais j’ai rencontré des erreurs.
            J’ai réussi à régler la plupart mais… yen a une qui me bloque.
            au niveau de la classe du container j’ai une erreur. :@

            Voici mon container et merci de votre réponse.

            package com.mod.mod2bk.init;
            
            import java.util.List;
            
            import Blocks.TileEntityGeneticMachine;
            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.world.World;
            
            public class ContainerGeneticMachine extends Container
            {
            
               private final TileEntityGeneticMachine tileGM;
            
               public ContainerGeneticMachine(TileEntityGeneticMachine tile, InventoryPlayer inventory)
               {
                   this.tileGM = tile;
            
                   tile.openInventory(); // c'est à ce niveau là que ya l'erreur.
            
                  for(int i = 0; i < 3; ++i)
                  {
                      for(int j = 0; j < 9; ++j)
                      {
                          this.addSlotToContainer(new Slot(tile, j + i * 9, 8 + j * 18, 18 + i * 18));
            
                      }
                  }
                  this.bindPlayerInventory(inventory);
               }
            
               @Override
               public boolean canInteractWith(EntityPlayer playerIn)
               {
                   return false;
               }
            }
            
            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

              Salut,
              La fonction a été renommée, il devrait en avoir une autre avec un nom similaire.

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

                @‘robin4002’:

                Salut,
                La fonction a été renommée, il devrait en avoir une autre avec un nom similaire.

                La fonction est toujours existante mais il me demande de rajouter des paramètres entre parenthèses(EntityPlayer)
                J’ai essayé de faire un```java
                EntityPlayer player = new EntityPlayer();

                Et après ça tourne en boucle comme ça…
                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

                  Mets inventory.player

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

                    Mon jeu est en 1.8…
                    Et super, quand je clic droit sur le bloc, il se passe rien…
                    Ma classe du bloc (Le bloc est GeneticMachine et la classe est geneticGMachine)

                    package Blocks;
                    
                    import com.mod.mod2bk.mod2bkpri;
                    
                    import net.minecraft.block.Block;
                    import net.minecraft.block.BlockPistonBase;
                    import net.minecraft.block.material.Material;
                    import net.minecraft.block.state.IBlockState;
                    import net.minecraft.entity.EntityLivingBase;
                    import net.minecraft.entity.player.EntityPlayer;
                    import net.minecraft.inventory.IInventory;
                    import net.minecraft.inventory.InventoryHelper;
                    import net.minecraft.item.ItemStack;
                    import net.minecraft.tileentity.TileEntity;
                    import net.minecraft.tileentity.TileEntityDispenser;
                    import net.minecraft.util.BlockPos;
                    import net.minecraft.util.ChatComponentText;
                    import net.minecraft.util.EnumFacing;
                    import net.minecraft.world.World;
                    import net.minecraftforge.fml.common.network.internal.FMLNetworkHandler;
                    
                    public class geneticGMachine extends Block
                    {
                    
                        public geneticGMachine(Material materialIn)
                        {
                            super(materialIn);
                        }
                    
                        @Override
                        public boolean hasTileEntity(IBlockState state)
                        {
                            return true;
                        }
                    
                        @Override
                        public TileEntity createTileEntity(World world, IBlockState state)
                        {
                            return new TileEntityGeneticMachine();
                        }
                    
                        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(mod2bkpri.instance, 0, world, x, y, z);
                    
                               return true;
                           }
                    
                       }
                    
                        public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
                        {
                            TileEntity tileentity = worldIn.getTileEntity(pos);
                    
                            if (tileentity instanceof IInventory)
                            {
                                InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory)tileentity);
                                worldIn.updateComparatorOutputLevel(pos, this);
                            }
                    
                            super.breakBlock(worldIn, pos, state);
                        }
                    
                        public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
                        {
                    
                            if (stack.hasDisplayName())
                            {
                                TileEntity tileentity = worldIn.getTileEntity(pos);
                    
                                if (tileentity instanceof TileEntityGeneticMachine)
                                {
                                    ((TileEntityGeneticMachine)tileentity).setCustomName(stack.getDisplayName());
                                }
                            }
                        }
                    
                    }
                    

                    Ma classe du TileEntity (TileEntityGeneticMachine)

                    package Blocks;
                    
                    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.minecraft.util.IChatComponent;
                    
                    public class TileEntityGeneticMachine extends TileEntity implements IInventory
                    {
                    
                        private ItemStack[] contents = new ItemStack[27];
                        private String customName;    
                    
                        private int number;
                    
                        @Override
                        public void readFromNBT(NBTTagCompound compound)
                        {
                            super.readFromNBT(compound);
                            this.number = compound.getInteger("Number");
                        }
                    
                        @Override
                        public void writeToNBT(NBTTagCompound compound)
                        {
                            super.writeToNBT(compound);
                            compound.setInteger("Number", this.number);
                        }
                    
                        public int getNumber()
                        {
                            return number;
                        }
                    
                        public void setNumber(int number)
                        {
                            this.number = number;
                        }
                    
                        @Override
                        public Packet getDescriptionPacket() {
                    
                            NBTTagCompound nbttagcompound = new NBTTagCompound();
                    
                            this.writeToNBT(nbttagcompound);
                    
                            return new S35PacketUpdateTileEntity(this.pos, 0, nbttagcompound);
                    
                        }
                    
                        @Override
                        public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
                    
                            super.onDataPacket(net, pkt);
                    
                            this.readFromNBT(pkt.getNbtCompound());
                    
                        }
                    
                        public void readFromNBT1(NBTTagCompound compound)
                        {
                            super.readFromNBT(compound);
                            NBTTagList nbttaglist = compound.getTagList("Items", 10);
                            this.contents = new ItemStack[this.getSizeInventory()];
                    
                            if (compound.hasKey("CustomName", 8))
                            {
                                this.customName = compound.getString("CustomName");
                            }
                    
                            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);
                                }
                            }
                        }
                    
                        public void writeToNBT1(NBTTagCompound compound)
                        {
                            super.writeToNBT(compound);
                            NBTTagList nbttaglist = new NBTTagList();
                    
                            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);
                    
                            if (this.hasCustomName())
                            {
                                compound.setString("CustomName", this.customName);
                            }
                        }
                    
                        @Override
                        public String getName()
                        {
                            return this.hasCustomName() ? this.customName : "tile.geneticmachine";
                        }
                    
                        public void setCustomName(String customName)    
                       {
                           this.customName = customName;
                       }
                    
                        @Override
                        public boolean hasCustomName()
                        {
                            return false;
                        }
                    
                        @Override
                        public IChatComponent getDisplayName()
                        {
                            return null;
                        }
                    
                        @Override
                        public int getSizeInventory()
                        {
                            return this.contents.length;
                        }
                    
                        @Override
                        public ItemStack getStackInSlot(int index)
                        {
                            return this.contents[index];
                        }
                    
                        @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; // met l'item stack dans le tableau
                    
                           if(stack != null && stack.stackSize > this.getInventoryStackLimit()) // si la taille de l'item stack dépasse la limite maximum de l'inventaire
                    
                           {
                    
                               stack.stackSize = this.getInventoryStackLimit(); // on le remet sur la limite
                    
                           }
                    
                           this.markDirty(); // met à jour le tile entity
                    
                       }
                    
                        @Override
                        public int getInventoryStackLimit()
                        {
                            return 64;
                        }
                    
                        public boolean isUseableByPlayer(EntityPlayer player)
                        {
                            return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
                        }
                    
                        @Override
                        public void openInventory(EntityPlayer player)
                        {
                    
                        }
                    
                        @Override
                        public void closeInventory(EntityPlayer player)
                        {
                    
                        }
                    
                        @Override
                        public boolean isItemValidForSlot(int index, ItemStack stack)
                        {
                            return true;
                        }
                    
                        @Override
                        public int getField(int id)
                        {
                            return 0;
                        }
                    
                        @Override
                        public void setField(int id, int value)
                        {
                    
                        }
                    
                        @Override
                        public int getFieldCount()
                        {
                            return 0;
                        }
                    
                        @Override
                        public void clear()
                        {
                    
                        }
                    }
                    

                    Le GuiHandler :

                    package com.mod.mod2bk;
                    
                    import com.mod.mod2bk.init.ContainerGeneticMachine;
                    
                    import Blocks.TileEntityGeneticMachine;
                    import net.minecraft.entity.player.EntityPlayer;
                    import net.minecraft.tileentity.TileEntity;
                    import net.minecraft.util.BlockPos;
                    import net.minecraft.world.World;
                    import net.minecraftforge.fml.common.network.IGuiHandler;
                    import net.minecraft.*;
                    
                    public class GuiHandlerGeneticMaster implements IGuiHandler
                    {
                    
                        @Override
                        public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                        {
                            BlockPos pos = new BlockPos(x, y, z);
                            TileEntity tile = world.getTileEntity(pos);
                    
                           if(tile instanceof TileEntityGeneticMachine)
                    
                           {
                    
                               return new ContainerGeneticMachine((TileEntityGeneticMachine)tile, player.inventory);
                    
                           }
                    
                           return null;
                        }
                    
                        @Override
                        public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                        {
                            BlockPos pos = new BlockPos(x, y, z);
                            TileEntity tile = world.getTileEntity(pos);
                    
                           if(tile instanceof TileEntityGeneticMachine)
                           {
                               return new GuiGeneticMachine((TileEntityGeneticMachine)tile, player.inventory);
                           }
                           return null;
                        }
                    }
                    

                    La classe du container (ContainerGeneticMachine)

                    package com.mod.mod2bk.init;
                    
                    import java.util.List;
                    
                    import Blocks.TileEntityGeneticMachine;
                    import net.minecraft.entity.player.EntityPlayer;
                    import net.minecraft.entity.player.InventoryPlayer;
                    import net.minecraft.inventory.Container;
                    import net.minecraft.inventory.Slot;
                    import net.minecraft.item.ItemStack;
                    import net.minecraft.world.World;
                    
                    public class ContainerGeneticMachine extends Container
                    {
                    
                        private final TileEntityGeneticMachine tileGM;
                    
                        public ContainerGeneticMachine(TileEntityGeneticMachine tile, InventoryPlayer inventory)
                        {
                    
                            this.tileGM = tile;
                    
                            tile.openInventory(inventory.player);
                    
                           for(int i = 0; i < 3; ++i)
                           {
                               for(int j = 0; j < 9; ++j)
                               {
                                   this.addSlotToContainer(new Slot(tile, j + i * 9, 8 + j * 18, 18 + i * 18));
                               }
                           }
                    
                           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, 86 + i * 18));
                               }
                    
                           }
                    
                           for(i = 0; i < 9; ++i)
                           {
                               this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 144));
                           }
                    
                       }
                    
                        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.tileGM.getSizeInventory())
                               {
                    
                                   if(!this.mergeItemStack(itemstack1, this.tileGM.getSizeInventory(), this.inventorySlots.size(), true))
                                   {
                                       return null;
                                   }
                               }
                    
                               else if(!this.mergeItemStack(itemstack1, 0, this.tileGM.getSizeInventory(), false))
                               {
                                   return null;
                               }
                    
                               if(itemstack1.stackSize == 0)
                               {
                                   slot.putStack((ItemStack)null);
                               }
                               else
                               {
                                   slot.onSlotChanged();
                               }
                           }
                           return itemstack;
                       }
                        @Override
                        public boolean canInteractWith(EntityPlayer player)
                       {
                           return this.tileGM.isUseableByPlayer(player);
                       }
                    }
                    

                    Et le Gui(GuiGeneticMachine)

                    package com.mod.mod2bk;
                    
                    import org.lwjgl.opengl.GL11;
                    
                    import com.mod.mod2bk.init.ContainerGeneticMachine;
                    
                    import Blocks.TileEntityGeneticMachine;
                    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 GuiGeneticMachine extends GuiContainer
                    {
                    
                        private static final ResourceLocation textures = new ResourceLocation(Reference.MOD_ID, "textures/gui/container/geneticmachine.png");
                    
                        private TileEntityGeneticMachine tileGM;
                    
                        private IInventory playerInv;
                    
                        public GuiGeneticMachine(TileEntityGeneticMachine tile, InventoryPlayer inventory)
                        {
                            super(new ContainerGeneticMachine(tile, inventory));
                    
                            this.tileGM = tile;
                            this.playerInv = inventory;
                            this.allowUserInput = false;
                            this.ySize = 170;
                        }
                    
                        @Override
                       protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
                       {
                    
                           GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                    
                           this.mc.getTextureManager().bindTexture(textures);
                    
                           int k = (this.width - this.xSize) / 2;
                    
                           int l = (this.height - this.ySize) / 2;
                           this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
                       }
                    
                        protected void drawGuiContainerForegroundLayer(int x, int y)
                       {
                    
                           String tileName = this.tileGM.hasCustomName() ? this.tileGM.getName() : I18n.format(this.tileGM.getName());
                    
                           this.fontRendererObj.drawString(tileName, (this.xSize - this.fontRendererObj.getStringWidth(tileName)) / 2, 6, 0);
                    
                           String invName = this.playerInv.hasCustomName() ? this.playerInv.getName() : I18n.format(this.playerInv.getName());
                    
                           this.fontRendererObj.drawString(invName, (this.xSize - this.fontRendererObj.getStringWidth(invName)) / 2, this.ySize - 96, 0);
                       }
                    
                    }
                    

                    Voilà et merci de la réponse

                    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

                      Ton gui handler est bien enregistré ?

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

                        @‘robin4002’:

                        Ton gui handler est bien enregistré ?

                        Oui, dans la fonction init

                        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

                          Ajoutes tes System.out.println(“quelque chose”) ou des points d’arrêt dans ton gui handler pour vérifier que les fonctions getClientElement et getServerElement sont bien appelé.

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

                            @‘robin4002’:

                            Ajoutes tes System.out.println(“quelque chose”) ou des points d’arrêt dans ton gui handler pour vérifier que les fonctions getClientElement et getServerElement sont bien appelé.

                            Désolé mais je comprends pas bien…
                            je suis débutant en Java après tout…
                            J’ai mis un “breakpoint” au niveau du “return null;”
                            Là

                            @Override
                                public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
                                {
                                    BlockPos pos = new BlockPos(x, y, z);
                                    TileEntity tile = world.getTileEntity(pos);
                            
                                   if(tile instanceof TileEntityGeneticMachine)
                            
                                   {
                            
                                       return new ContainerGeneticMachine((TileEntityGeneticMachine)tile, player.inventory);
                            
                                   }
                            
                                   return null; // juste avant ça
                                }   
                            

                            Je sais pas si c’est ça que tu me dis de faire…

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

                              @‘robin4002’:

                              Ajoutes tes System.out.println(“quelque chose”) ou des points d’arrêt dans ton gui handler pour vérifier que les fonctions getClientElement et getServerElement sont bien appelé.

                              J’ai trouvé mais pas assez…
                              En gros, je sais que depuis la 1.8, on a pas besoin de x, y, z mais d’autres choses (que je ne connais pas)
                              Et moi j’avais une erreur car eclipse me disait qu’il ne connaissait pas getTileEntity avec 3 éléments derrière
                              Alors j’ai remédié à ça en faisant ça :

                              BlockPos pos = new BlockPos(x, y, z); // ça je l'ai ajouté
                              
                                      TileEntity tile = world.getTileEntity(pos); //  le pos vient de la ligne du haut.
                              
                              

                              Et je pense que c’est pas bon (le “BlockPos pos = new BlockPos(x, y, z)”) mais je pense qu’il faut mettre autre chose.

                              Voilà je t’ai donné une piste, à toi de jouer maintenant !
                              Même si je suis pas sûr…

                              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

                                Ahh je viens de voir le problème.
                                C’est n’est pas ça, ce que tu as fais est bon.
                                Le problème est avant, la fonction onBlockActivated de ton bloc n’est jamais appelé car tu n’as pas les bon argument de fonction.
                                Regardes dans la classe Block.java tu devrais trouver les bons arguments. De tête int x, int y, int z ont été remplacé par BlockPos pos.
                                Il faut ensuite dans la fonction player.openGui remplacer x, y, z par pos.getX(), pos.getY(), pos.getZ()

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

                                  @‘robin4002’:

                                  Ahh je viens de voir le problème.
                                  C’est n’est pas ça, ce que tu as fais est bon.
                                  Le problème est avant, la fonction onBlockActivated de ton bloc n’est jamais appelé car tu n’as pas les bon argument de fonction.
                                  Regardes dans la classe Block.java tu devrais trouver les bons arguments. De tête int x, int y, int z ont été remplacé par BlockPos pos.
                                  Il faut ensuite dans la fonction player.openGui remplacer x, y, z par pos.getX(), pos.getY(), pos.getZ()

                                  Le jeu crash à l’initialization  😢
                                  Le crash-report :

                                  –-- Minecraft Crash Report ----
                                  // There are four lights!
                                  
                                  Time: 16/12/17 18:25
                                  Description: Initializing game
                                  
                                  java.lang.NullPointerException: Initializing game
                                  at com.mod.mod2bk.init.BlockMod.init(BlockMod.java:24)
                                  at com.mod.mod2bk.mod2bkpri.preInit(mod2bkpri.java:32)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:553)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
                                  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
                                  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
                                  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
                                  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
                                  at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
                                  at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
                                  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
                                  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
                                  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
                                  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
                                  at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
                                  at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:550)
                                  at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)
                                  at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
                                  at net.minecraft.client.Minecraft.run(Minecraft.java:356)
                                  at net.minecraft.client.main.Main.main(Main.java:117)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
                                  at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
                                  at GradleStart.main(Unknown Source)
                                  
                                  A detailed walkthrough of the error, its code path and all known details is as follows:
                                  ---------------------------------------------------------------------------------------
                                  
                                  -- Head --
                                  Stacktrace:
                                  at com.mod.mod2bk.init.BlockMod.init(BlockMod.java:24)
                                  at com.mod.mod2bk.mod2bkpri.preInit(mod2bkpri.java:32)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:553)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
                                  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
                                  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
                                  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
                                  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
                                  at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
                                  at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
                                  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
                                  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
                                  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
                                  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
                                  at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
                                  at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:550)
                                  at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)
                                  at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
                                  
                                  -- Initialization --
                                  Details:
                                  Stacktrace:
                                  at net.minecraft.client.Minecraft.run(Minecraft.java:356)
                                  at net.minecraft.client.main.Main.main(Main.java:117)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
                                  at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                  at java.lang.reflect.Method.invoke(Method.java:498)
                                  at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
                                  at GradleStart.main(Unknown Source)
                                  
                                  -- System Details --
                                  Details:
                                  Minecraft Version: 1.8
                                  Operating System: Windows 10 (amd64) version 10.0
                                  Java Version: 1.8.0_151, Oracle Corporation
                                  Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
                                  Memory: 791675320 bytes (755 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
                                  JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
                                  IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
                                  FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.4.1577 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
                                  UCH mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)
                                  UCH FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.4.1577.jar)
                                  UCH Forge{11.14.4.1577} [Minecraft Forge] (forgeSrc-1.8-11.14.4.1577.jar)
                                  UCE geneticmaster{1.0.0} [Genetic Master] (bin)
                                  Loaded coremods (and transformers):
                                  GL info: ' Vendor: 'ATI Technologies Inc.' Version: '3.3.11672 Compatibility Profile Context' Renderer: 'ATI Radeon HD 4800 Series'
                                  Launched Version: 1.8
                                  LWJGL: 2.9.1
                                  OpenGL: ATI Radeon HD 4800 Series GL version 3.3.11672 Compatibility Profile Context, ATI Technologies Inc.
                                  GL Caps: Using GL 1.3 multitexturing.
                                  Using GL 1.3 texture combiners.
                                  Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
                                  Shaders are available because OpenGL 2.1 is supported.
                                  VBOs are available because OpenGL 1.5 is supported.
                                  
                                  Using VBOs: No
                                  Is Modded: Definitely; Client brand changed to 'fml,forge'
                                  Type: Client (map_client.txt)
                                  Resource Packs: []
                                  Current Language: Français (France)
                                  Profiler Position: N/A (disabled)
                                  
                                  1 réponse Dernière réponse Répondre Citer 0
                                  • G Hors-ligne
                                    Games2bk
                                    dernière édition par

                                    @‘robin4002’:

                                    Ahh je viens de voir le problème.
                                    C’est n’est pas ça, ce que tu as fais est bon.
                                    Le problème est avant, la fonction onBlockActivated de ton bloc n’est jamais appelé car tu n’as pas les bon argument de fonction.
                                    Regardes dans la classe Block.java tu devrais trouver les bons arguments. De tête int x, int y, int z ont été remplacé par BlockPos pos.
                                    Il faut ensuite dans la fonction player.openGui remplacer x, y, z par pos.getX(), pos.getY(), pos.getZ()

                                    Nouvelle piste.
                                    Déjà, ce que tu as dit est bon(enfin, je suis pas sûr mais tu vas vite savoir pourquoi)
                                    Je me suis dit “mais tiens, je vais aller voir la classe BlockChest !”
                                    Et j’ai vu plusieurs choses.
                                    De 1 : il a un extends BlockContaienr
                                    De 2 : il n’a pas CreateTileEntity mais CreateNewTileEntity
                                    De 3 : ça marche quand-même pas  😢 
                                    Maintenant, j’ai un bloc qui voit à travers les autres blocs (type Cave Block) et qui ouvre toujours rien au clic
                                    Merci de ton aide et d’une réponse

                                    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

                                      Pas besoin de BlockContainer avec forge.
                                      Laisses comme c’était avant au niveau des extends et des fonctions.

                                      Il faut juste adapter onBlockActivated

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

                                        J’ai fait tous les code comme prevu tout marche minecraft se lance mais plante pas jusqu’a que quand je clique sur le block en question ca fait l’animation comme quoi je l’ai ouvert avec la main mais la GUI ne s’affiche pas. J’aurai besoin d’aide pour regler se souci svp !

                                        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

                                          Salut,
                                          Peux-tu envoyer le code de ton gui handler et de ton bloc ?

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

                                            @robin4002 tien le GUI Hanlder:

                                            package fr.askipie.funfight;
                                            
                                            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 GuiHandlerFungie 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 TileEntityFungie)
                                                    {
                                                        return new GuiCupboard((TileEntityFungie)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 TileEntityFungie)
                                                    {
                                                        return new ContainerCupboard((TileEntityFungie)tile, player.inventory);
                                                    }
                                                    return null;
                                            
                                                }
                                            
                                            }
                                            

                                            la classe du bloc:

                                            package fr.askipie.funfight;
                                            
                                            import cpw.mods.fml.common.registry.GameRegistry;
                                            import net.minecraft.block.Block;
                                            import net.minecraft.block.material.Material;
                                            
                                            public class FFBlocks 
                                            {
                                            	public static Block fungieBlock;
                                            	public static Block telluriumBlock;
                                            	public static Block vitriolBlock;
                                            	public static Block crystaliteBlock;
                                                public static Block fungieOre;
                                                public static Block telluriumOre;
                                                public static Block vitriolOre;
                                                public static Block crystaliteOre;
                                                public static Block fungieSeedsOre;
                                                public static Block telluriumSeedsOre;
                                                public static Block vitriolSeedsOre;
                                                public static Block crystaliteSeedsOre;
                                                public static Block borderBlock;
                                                public static Block fungieMachine;
                                            	
                                            	public static void init()
                                            	{
                                            		fungieBlock = new BlocksBasics(Material.rock).setBlockName("fungieBlock").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":fungieBlock").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                            		telluriumBlock = new BlocksBasics(Material.rock).setBlockName("telluriumBlock").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":telluriumBlock").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                            		vitriolBlock = new BlocksBasics(Material.rock).setBlockName("vitriolBlock").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":vitriolBlock").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                            		crystaliteBlock = new BlocksBasics(Material.rock).setBlockName("crystaliteBlock").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":crystaliteBlock").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                            		fungieOre = new BlocksBasics(Material.rock).setBlockName("fungieOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":fungieOre").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                                    telluriumOre = new BlocksBasics(Material.rock).setBlockName("telluriumOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":telluriumOre").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                                    vitriolOre = new BlocksBasics(Material.rock).setBlockName("vitriolOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":vitriolOre").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                                    crystaliteOre = new BlocksBasics(Material.rock).setBlockName("crystaliteOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":crystaliteOre").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                                    fungieSeedsOre = new BlocksBasics(Material.ground).setBlockName("fungieSeedsOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":fungieSeedsOre").setHardness(0.2F).setResistance(10.0F).setStepSound(Block.soundTypeGrass);
                                                    telluriumSeedsOre = new BlocksBasics(Material.ground).setBlockName("telluriumSeedsOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":telluriumSeedsOre").setHardness(0.2F).setResistance(10.0F).setStepSound(Block.soundTypeGrass);
                                                    vitriolSeedsOre = new BlocksBasics(Material.ground).setBlockName("vitriolSeedsOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":vitriolSeedsOre").setHardness(0.2F).setResistance(10.0F).setStepSound(Block.soundTypeGrass);
                                                    crystaliteSeedsOre = new BlocksBasics(Material.ground).setBlockName("crystaliteSeedsOre").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":crystaliteSeedsOre").setHardness(0.2F).setResistance(10.0F).setStepSound(Block.soundTypeGrass);
                                                    borderBlock = new BlocksBasics(Material.glass).setBlockName("borderBlock").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":borderBlock").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeCloth);
                                                    fungieMachine = new GUITutoriel(Material.rock).setBlockName("fungieMachine").setCreativeTab(FunFight.funTab).setBlockTextureName(References.MODID + ":FungieMachine/machineOFF").setHardness(2.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
                                            	}
                                            	
                                            	public static void register()
                                            	{
                                                    GameRegistry.registerBlock(fungieBlock, fungieBlock.getUnlocalizedName().substring(5));
                                            	GameRegistry.registerBlock(telluriumBlock, telluriumBlock.getUnlocalizedName().substring(5));
                                            	GameRegistry.registerBlock(vitriolBlock, vitriolBlock.getUnlocalizedName().substring(5));
                                            	GameRegistry.registerBlock(crystaliteBlock, crystaliteBlock.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(fungieOre, fungieOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(telluriumOre, telluriumOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(vitriolOre, vitriolOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(crystaliteOre, crystaliteOre.getUnlocalizedName().substring(5));		
                                                    GameRegistry.registerBlock(fungieSeedsOre, fungieSeedsOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(telluriumSeedsOre, telluriumSeedsOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(vitriolSeedsOre, vitriolSeedsOre.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(crystaliteSeedsOre, crystaliteSeedsOre.getUnlocalizedName().substring(5));     
                                                    GameRegistry.registerBlock(borderBlock, borderBlock.getUnlocalizedName().substring(5));
                                                    GameRegistry.registerBlock(fungieMachine, fungieMachine.getUnlocalizedName().substring(5));
                                            	}
                                            
                                            }
                                            

                                            et le block tile entity:

                                            package fr.askipie.funfight;
                                            
                                            import cpw.mods.fml.common.Mod.Instance;
                                            import cpw.mods.fml.common.network.NetworkRegistry;
                                            import net.minecraft.entity.player.EntityPlayer;
                                            import net.minecraft.inventory.IInventory;
                                            import net.minecraft.item.ItemStack;
                                            import net.minecraft.nbt.NBTTagCompound;
                                            import net.minecraft.nbt.NBTTagList;
                                            import net.minecraft.tileentity.TileEntity;
                                            import net.minecraftforge.common.util.Constants;
                                            
                                            public class TileEntityFungie extends TileEntity implements IInventory
                                            
                                            {
                                                
                                                private ItemStack[] contents = new ItemStack[27];
                                                private String customName;
                                            
                                            
                                            
                                                @Override
                                                public boolean hasCustomInventoryName()
                                                {
                                                    return false;
                                                }
                                            
                                            
                                            
                                                @Override
                                                public void openInventory()
                                                {
                                                    
                                                }
                                            
                                                @Override
                                                public void closeInventory()
                                                {
                                                    
                                                }
                                            
                                                
                                                @Override
                                            public void readFromNBT(NBTTagCompound compound)
                                            {
                                                super.readFromNBT(compound); // exécute ce qui se trouve dans la fonction readFromNBT de la classe mère (lecture de la position du tile entity)
                                                if(compound.hasKey("fungieMachine", Constants.NBT.TAG_STRING)) // si un tag custom name de type string existe
                                                {
                                                    this.customName = compound.getString("fungieMachine"); // on le lit
                                                }
                                            
                                                NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); // on obtient la liste de tags nommée Items
                                                this.contents = new ItemStack[this.getSizeInventory()]; // on réinitialise le tableau
                                                for(int i = 0; i < nbttaglist.tagCount(); ++i) // i varie de 0 à la taille la liste
                                                {
                                                    NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); // on lit le tag nbt
                                                    int j = nbttagcompound1.getByte("Slot") & 255; // on lit à quel slot se trouve l'item stack
                                            
                                                    if(j >= 0 && j < this.contents.length)
                                                    {
                                                        this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); // on lit l'item stack qui se trouve dans le tag
                                                    }
                                                }
                                            }
                                            
                                            @Override
                                            public void writeToNBT(NBTTagCompound compound)
                                            {
                                                super.writeToNBT(compound); // exécute se qui se trouve dans la fonction writeToNBT de la classe mère (écriture de la position du tile entity)
                                                if(this.hasCustomInventoryName()) // s'il y a un nom custom
                                                {
                                                    compound.setString("fungieMachine", this.customName); // on le met dans le tag nbt
                                                }
                                            
                                                NBTTagList nbttaglist = new NBTTagList(); // on créé une nouvelle liste de tags
                                                for(int i = 0; i < this.contents.length; ++i) // i varie de 0 à la taille de notre tableau
                                                {
                                                    if(this.contents[ i] != null) // si l'item stack à l'emplacement i du tableau n'est pas null
                                                    {
                                                        NBTTagCompound nbttagcompound1 = new NBTTagCompound(); // on créé un tag nbt
                                                        nbttagcompound1.setByte("Slot", (byte)i); // on enregistre son emplacement dans le tableau
                                                        this.contents[ i].writeToNBT(nbttagcompound1); // on écrit l'item dans le tag
                                                        nbttaglist.appendTag(nbttagcompound1); // on ajoute le tab à la liste
                                                    }
                                                }
                                                compound.setTag("Items", nbttaglist); // on enregistre la liste dans le tag nbt
                                            
                                            }
                                            
                                            @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) // si le contenu dans l'emplacement n'est pas null
                                                {
                                                    ItemStack itemstack;
                                            
                                                    if(this.contents[slotIndex].stackSize <= amount) // si la quantité est inférieur où égale à ce qu'on souhaite retirer
                                                    {
                                                        itemstack = this.contents[slotIndex]; // la variable itemstack prends la valeur du contenu
                                                        this.contents[slotIndex] = null; // on retire ce qui est dans la variable contents
                                                        this.markDirty(); // met à jour le tile entity
                                                        return itemstack; // renvoie itemstack
                                                    }
                                                    else // sinon
                                                    {
                                                        itemstack = this.contents[slotIndex].splitStack(amount); // la fonction splitStack(quantité) retire dans this.contents[slotIndex] le contenu et le met dans itemstack
                                            
                                                        if(this.contents[slotIndex].stackSize == 0) // au cas où la quantité passe à 0 (ce qui ne devrait pas arriver en temps normal)
                                                        {
                                                            this.contents[slotIndex] = null; // on met sur null, ça évite de se retrouver avec des itemstack bugué qui contiennent 0
                                                        }
                                                        this.markDirty(); // met à jour le tile entity
                                                        return itemstack; // renvoie itemstack
                                                    }
                                                }
                                                else // sinon si le contenu dans cette emplacement est null
                                                {
                                                    return null; // renvoie null, puisqu'il n'y a rien dans cette emplacement
                                                }
                                            }
                                            
                                            @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; // met l'item stack dans le tableau
                                            
                                                if(stack != null && stack.stackSize > this.getInventoryStackLimit()) // si la taille de l'item stack dépasse la limite maximum de l'inventaire
                                                {
                                                    stack.stackSize = this.getInventoryStackLimit(); // on le remet sur la limite
                                                }
                                            
                                                this.markDirty(); // met à jour le tile entity
                                            }
                                            
                                            @Override
                                            public String getInventoryName()
                                            {
                                                return this.hasCustomInventoryName() ? this.customName : "tile.cupboard";
                                            }
                                            
                                            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 boolean isItemValidForSlot(int slotIndex, ItemStack stack)
                                            {
                                                return true;
                                            }
                                            
                                            @Instance("funfight") // attention il doit respecter les majuscules/minuscules
                                            public static FunFight instance;
                                            
                                            {
                                            
                                            NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandlerFungie());
                                            
                                            }
                                            
                                            }
                                            
                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 7
                                            • 1 / 7
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB