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

      Bonjour,
      Avant tout merci pour ce Tuto encore très bien Rédige !
      Après l’avoir suivi à la lettre, tout fonctionne parfaitement !!

      J’ai modifié à ma guise à savoir : 
      Le conteneur a été réduit à 2 slot.

      Et que à l’activation rédstone du block, il l lance une boucle pour remplacer l’air sur 5 block au dessus de lui par de la stone. 
      Jusque là tout marche impeccable !!

      Mais j’aurais aimé que le setblock soit fait avec le block présent dans le stack(0) de mon conteneur…

      Je me doute que ça soit suffisamment bête pour que je ne le trouve pas… Mais je bute…
      J’ai bataille tout la mâtiné pour arriver à ça… Sans succès…
      Donc ma ptite question est :

      Est-il possible d’aller chercher le contenu du stack(0)
      Pour s’en servir dans ma fonction de génération ?
      Si oui je veux bien un ptit coup de pouce,
      J’ai essayé diverses choses ce matin trop longue a toute écrire, 
      getstackinslot[0] etc etc.
      Mais je coince a chaque fois (sûrement car je sais pas trop comment importer ca dans ma classe du block…)

      Si il faut ce soir j’ouvrirai un autre sujet.
      Dans la section support.
      Bonne journée.

      https://www.youtube.com/channel/UC74HKvv67kvm8and7xkQfbg

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

        il suffit de tester que getStackInSlot(0) != null et que Block.getBlockFromItem(getStackInSlot(0)) != null.
        Ensuite tu utilises Block.getBlockFromItem(getStackInSlot(0)) pour ton setBlock

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

          @‘robin4002’:

          il suffit de tester que getStackInSlot(0) != null et que Block.getBlockFromItem(getStackInSlot(0)) != null.
          Ensuite tu utilises Block.getBlockFromItem(getStackInSlot(0)) pour ton setBlock

          salut,
          je te remercie je vais tester ça.

          a +

          https://www.youtube.com/channel/UC74HKvv67kvm8and7xkQfbg

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

            Super tutoriel !
            Une simple question : à quoi sert la fonction “world.func_147453_f(x, y, z, block)” dans le onBreak() du Block ?

            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

              elle sert à signalé que le bloc a changé.

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

                Merci ! Et une autre remarque , dans le onBlockActivated() , tu ouvres le gui quand isRemote vaut false , ce n’est pas le contraire ?

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

                  Non c’est bien si il est false, car le serveur va ouvrir le Container du gui puis enverra un packet au client pour lui dire d’ouvrir le gui.

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

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

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

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

                    Euh… J’aimerais savoir comment on fait pour créer une sorte de nouvelle table de craft ? Pour m’aider, j’ai un peu observé le pré-code qu’ils utilisent sur MCreator mais bon…

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

                      https://www.minecraftforgefrance.fr/showthread.php?tid=3556
                      Un peu de recherche ne fait pas de mal.

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

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

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

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

                        O.K, merci, je suis désolé de demander comme ça, hein mais je ne trouvais pas dans le sommaire et j’oublie tt le temps de chercher un article particulier sur le site

                        EDIT : J’ai lu l’article et les commentaires mais j’avoue que ça m’intéresserait plus en 1.7.10 comme tuto complet si tu en as un

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

                          N’empêche que c’est vrai que ça serait bien de l’ajouter au sommaire ^^ mais c’est pas moi qui le gère.

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

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

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

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

                            Faut regarder du côté des TileEntities 🙂

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

                              O.k merci mais ou précisément ?

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

                                Salut,
                                J’ai une petite erreur au niveau de la TileEntity
                                http://prntscr.com/d6eakw

                                Cordialement, FanatikForce

                                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

                                  Cette fonction doit être mise dans la classe du bloc et non dans le tile entity.

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

                                    J’ai un problème quant je mes un hopper au dessus de mon block, le contenue du hopper disparaît bien mais il apparaît pas tous dans mon block et quant mon block est full il disparaisse comme même du hopper.

                                    PS le block a un seul emplacement qui peut contenir qu’un item.

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

                                      Pourrais-tu montrer la classe de ton TileEntity ?

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

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

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

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

                                        Merci pour le tuto !!

                                        J’ai un petit soucis,

                                        Si je passe le getInventoryStackLimit() à 1 pour avoir un seul item, quand on utilise le shift + click sur un stack de plusieurs items, ils disparaissent (à l’exception de celui qui rentre dans le slot)

                                        La fonction transferStackInSlot n’est pas commenté, du coup je suis un peu perdu 😕

                                        Les sources :
                                        https://github.com/mandonnaud/houbmod/blob/master/src/main/java/fr/adslhouba/houbmod/common/ContainerCupboard.java
                                        https://github.com/mandonnaud/houbmod/blob/master/src/main/java/fr/adslhouba/houbmod/common/block/cc/TileEntityEnclumeCPO.java

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

                                          Bonjour.

                                          J’ai suivi ce tutoriel à la lettre et j’ai voulu tester si ça marcher bien et quand je clique sur mon block… BOOM… MineCraft Crash !!! et je sais pas pourquoi…

                                          Voici mes code :

                                          Classe Principale :

                                          package mod.plantsandfoodpack.common;
                                          
                                          import net.minecraft.block.Block;
                                          import net.minecraft.block.Block.SoundType;
                                          import net.minecraft.block.material.Material;
                                          import net.minecraft.creativetab.CreativeTabs;
                                          import net.minecraft.init.Blocks;
                                          import net.minecraft.init.Items;
                                          import net.minecraft.item.Item;
                                          import net.minecraft.item.ItemFood;
                                          import net.minecraft.item.ItemSeeds;
                                          import net.minecraft.item.ItemStack;
                                          import mod.plantsandfoodpack.proxy.CommonProxy;
                                          import cpw.mods.fml.common.Mod;
                                          import cpw.mods.fml.common.Mod.EventHandler;
                                          import cpw.mods.fml.common.Mod.Instance;
                                          import cpw.mods.fml.common.SidedProxy;
                                          import cpw.mods.fml.common.event.FMLInitializationEvent;
                                          import cpw.mods.fml.common.event.FMLPostInitializationEvent;
                                          import cpw.mods.fml.common.event.FMLPreInitializationEvent;
                                          import cpw.mods.fml.common.network.NetworkRegistry;
                                          import cpw.mods.fml.common.registry.GameRegistry;
                                          
                                          @Mod(modid= "plantsandfoodpack", name="Plants & Food Pack Mod", version ="1.0.0")
                                          
                                          public class ModPlantsandFoodPack{
                                          
                                          public static final String MODID = "plantsandfoodpack";
                                          
                                          @Instance(MODID)
                                          public static ModPlantsandFoodPack instance;
                                          
                                          @SidedProxy(clientSide = "mod.plantsandfoodpack.proxy.ClientProxy", serverSide ="mod.plantsandfoodpack.proxy.CommonProxy")
                                          public static CommonProxy proxy;
                                          
                                          public static Item flour, itemTomato, itemTomatoSeeds, itemLettuceSeeds, itemLettuceLeaf;
                                          public static Block blockSugar, blockTomatoCrop, blockLettuceCrop, blockKitchenCupboard;
                                          
                                          @EventHandler
                                          public void preInit(FMLPreInitializationEvent event){
                                          
                                          blockSugar = new BlockSugar(Material.sand).setBlockName("sugarBlock").setBlockTextureName(MODID + ":sugar_block").setCreativeTab(CreativeTabs.tabBlock).setStepSound(Block.soundTypeSand);
                                          blockTomatoCrop = new BlockTomatoCrop().setBlockName("tomatoCrop").setBlockTextureName(MODID + ":tomato_crop");
                                          blockLettuceCrop = new BlockLettuceCrop().setBlockName("lettuceCrop").setBlockTextureName(MODID + ":lettuce_crop");
                                          blockKitchenCupboard = new BlockKitchenCupboard(Material.wood).setBlockName("kitchenCupboard");
                                          
                                          flour = new ItemFlour().setUnlocalizedName("flour").setTextureName(MODID + ":flour").setCreativeTab(CreativeTabs.tabMaterials);
                                          itemTomato = new ItemTomato(3, 2.5F, false).setUnlocalizedName("tomato").setTextureName(MODID + ":tomato").setCreativeTab(CreativeTabs.tabFood);
                                          itemTomatoSeeds = new ItemSeeds(this.blockTomatoCrop, Blocks.farmland).setUnlocalizedName("tomatoSeed").setTextureName(MODID + ":tomato_seeds").setCreativeTab(CreativeTabs.tabMaterials);
                                          itemLettuceLeaf = new ItemFood(2, 1.5F, false).setUnlocalizedName("lettuceLeaf").setTextureName(MODID + ":lettuce_leaf").setCreativeTab(CreativeTabs.tabFood);
                                          itemLettuceSeeds = new ItemSeeds(this.blockLettuceCrop, Blocks.farmland).setUnlocalizedName("lettuceSeeds").setTextureName(MODID + ":lettuce_seeds").setCreativeTab(CreativeTabs.tabMaterials);
                                          
                                          GameRegistry.registerBlock(blockSugar, "sugar_block");
                                          GameRegistry.registerBlock(blockTomatoCrop, "tomatoCrop");
                                          GameRegistry.registerBlock(blockLettuceCrop, "lettuceCrop");
                                          GameRegistry.registerBlock(blockKitchenCupboard, "kitchenCupboard");
                                          
                                          GameRegistry.registerItem(flour, "flour");
                                          GameRegistry.registerItem(itemTomato, "tomato");
                                          GameRegistry.registerItem(itemTomatoSeeds, "tomato_seeds");
                                          GameRegistry.registerItem(itemLettuceLeaf, "lettuce_leaf");
                                          GameRegistry.registerItem(itemLettuceSeeds, "lettuce_seeds");
                                          
                                          }
                                          
                                          @EventHandler
                                          public void Init(FMLInitializationEvent event){
                                          
                                          GameRegistry.addRecipe(new ItemStack(flour, 1), new Object[] {"*", '*', Items.wheat});
                                          GameRegistry.addRecipe(new ItemStack(blockSugar, 1), new Object[] {"###", "###", "###", '#', Items.sugar});
                                          GameRegistry.addRecipe(new ItemStack(blockKitchenCupboard, 1), new Object[] {"WWW", "W W", "WWW", 'W', Blocks.log});
                                          
                                          GameRegistry.registerTileEntity(TileEntityKitchenCupboard.class, MODID + ":kitchenCupboard");
                                          proxy.registerRender();
                                          
                                          NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandlerPlantsAndFoodPack());
                                          }
                                          
                                          @EventHandler
                                          public void postInit(FMLPostInitializationEvent event){
                                          
                                          }
                                          }
                                          
                                          

                                          Classe du Block :

                                          package mod.plantsandfoodpack.common;
                                          
                                          import mod.plantsandfoodpack.proxy.ClientProxy;
                                          import net.minecraft.block.Block;
                                          import net.minecraft.block.material.Material;
                                          import net.minecraft.entity.EntityLivingBase;
                                          import net.minecraft.entity.item.EntityItem;
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.inventory.IInventory;
                                          import net.minecraft.item.ItemStack;
                                          import net.minecraft.nbt.NBTTagCompound;
                                          import net.minecraft.tileentity.TileEntity;
                                          import net.minecraft.tileentity.TileEntityChest;
                                          import net.minecraft.util.MathHelper;
                                          import net.minecraft.world.World;
                                          import net.minecraftforge.common.util.ForgeDirection;
                                          
                                          public class BlockKitchenCupboard extends Block{
                                          
                                          protected BlockKitchenCupboard(Material p_i45394_1_) {
                                          super(p_i45394_1_);
                                          }
                                          
                                          @Override
                                          public boolean hasTileEntity(int metadata) {
                                          
                                          return true;
                                          }
                                          
                                          @Override
                                          public TileEntity createTileEntity(World world, int metadata) {
                                          
                                          return new TileEntityKitchenCupboard ();
                                          }
                                          
                                          public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
                                             {
                                                 TileEntity tileentity = world.getTileEntity(x, y, z);
                                          
                                                 if (tileentity instanceof IInventory)
                                                 {
                                                  IInventory inv = (IInventory)tileentity;
                                                     for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
                                                     {
                                                         ItemStack itemstack = inv.getStackInSlot(i1);
                                          
                                                         if (itemstack != null)
                                                         {
                                                             float f = world.rand.nextFloat() * 0.8F + 0.1F;
                                                             float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                                                             EntityItem entityitem;
                                          
                                                             for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                                                             {
                                                                 int j1 = world.rand.nextInt(21) + 10;
                                          
                                                                 if (j1 > itemstack.stackSize)
                                                                 {
                                                                     j1 = itemstack.stackSize;
                                                                 }
                                          
                                                                 itemstack.stackSize -= j1;
                                                                 entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                                                                 float f3 = 0.05F;
                                                                 entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                                                                 entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                                                                 entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
                                          
                                                                 if (itemstack.hasTagCompound())
                                                                 {
                                                                     entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                                                                 }
                                                             }
                                                         }
                                                     }
                                          
                                                     world.func_147453_f(x, y, z, block);
                                                 }
                                          
                                                 super.breakBlock(world, x, y, z, block, metadata);
                                             }
                                          
                                          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
                                             {
                                          if(world.isRemote)
                                                {
                                                    return true;
                                                }
                                                else
                                                {
                                                    player.openGui(ModPlantsandFoodPack.instance, 0, world, x, y, z);
                                                    return true;
                                                }
                                             }
                                          
                                          public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack){
                                          if(stack.getItemDamage() == 0)
                                          {
                                          TileEntity tile = world.getTileEntity(x, y, z);
                                          if(tile instanceof TileEntityKitchenCupboard)
                                          {
                                          int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
                                          ((TileEntityKitchenCupboard)tile).setDirection((byte)direction);
                                          if(stack.hasDisplayName())
                                          {
                                          ((TileEntityKitchenCupboard)tile).setCustomName(stack.getDisplayName());
                                          }
                                          }
                                          }
                                          }
                                          
                                          @Override
                                          public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
                                          {
                                          if((axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) && !world.isRemote && world.getBlockMetadata(x, y, z) == 0)
                                          {
                                          TileEntity tile = world.getTileEntity(x, y, z);
                                          if(tile instanceof TileEntityKitchenCupboard)
                                          {
                                          TileEntityKitchenCupboard tileKitchenCupboard = (TileEntityKitchenCupboard)tile;
                                          byte direction = tileKitchenCupboard.getDirection();
                                          direction++;
                                          if(direction > 3)
                                          {
                                          direction = 0;
                                          }
                                          tileKitchenCupboard.setDirection(direction);
                                          return true;
                                          }
                                          }
                                          return false;
                                          }
                                          
                                          public ForgeDirection[] getValidRotation(World world, int x, int y, int z)
                                          {
                                          return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] {ForgeDirection.UP, ForgeDirection.DOWN,} : ForgeDirection.VALID_DIRECTIONS;
                                          }
                                          
                                          public boolean isOpaqueCube(){
                                          return false;
                                          }
                                          
                                          public boolean renderAsNormalBlock(){
                                          return false;
                                          }
                                          
                                          public int getRenderType(){
                                          return ClientProxy.tesrRenderId;
                                          }
                                          
                                          }
                                          
                                          

                                          Classe du Tile Entity :

                                          package mod.plantsandfoodpack.common;
                                          
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.inventory.IInventory;
                                          import net.minecraft.item.ItemStack;
                                          import net.minecraft.nbt.NBTTagCompound;
                                          import net.minecraft.nbt.NBTTagList;
                                          import net.minecraft.network.NetworkManager;
                                          import net.minecraft.network.Packet;
                                          import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
                                          import net.minecraft.tileentity.TileEntity;
                                          import net.minecraftforge.common.util.Constants;
                                          
                                          public class TileEntityKitchenCupboard extends TileEntity implements IInventory {
                                          
                                          private byte direction;
                                          private ItemStack[] contents = new ItemStack[18];
                                          private String customName;
                                          
                                          @Override
                                          public void readFromNBT(NBTTagCompound compound)
                                          {
                                          super.readFromNBT(compound);
                                          this.direction = compound.getByte("Direction");
                                          
                                                 if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
                                                 {
                                                     this.customName = compound.getString("CustomName");
                                                 }
                                          
                                                 NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
                                                 this.contents = new ItemStack[this.getSizeInventory()];
                                          
                                                 for (int i = 0; i < nbttaglist.tagCount(); ++i)
                                                 {
                                                     NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                                                     int j = nbttagcompound1.getByte("Slot") & 255;
                                          
                                                     if (j >= 0 && j < this.contents.length)
                                                     {
                                                         this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                                                     }
                                                 }
                                          }
                                          
                                          public void writeToNBT(NBTTagCompound compound)
                                          {
                                          super.writeToNBT(compound);
                                          compound.setByte("Direction", this.direction);
                                          if (this.hasCustomInventoryName())
                                                 {
                                                     compound.setString("CustomName", this.customName);
                                                 }
                                          
                                          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);
                                          
                                          }
                                          
                                          public byte getDirection()
                                          {
                                          return direction;
                                          }
                                          
                                          public void setDirection(byte direction)
                                          {
                                          this.direction = direction;
                                          this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
                                          }
                                          
                                          public Packet getDescriptionPacket()
                                          {
                                          NBTTagCompound nbttagcompound = new NBTTagCompound();
                                          this.writeToNBT(nbttagcompound);
                                          return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
                                          }
                                          
                                          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
                                          {
                                          this.readFromNBT(pkt.func_148857_g());
                                          this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
                                          }
                                          
                                          @Override
                                          public int getSizeInventory() {
                                          return this.contents.length;
                                          }
                                          
                                             @Override
                                            public ItemStack getStackInSlot(int slotIndex)
                                            {
                                                return this.contents[slotIndex];
                                            }
                                          
                                          @Override
                                          public ItemStack decrStackSize(int slotIndex, int amount)
                                             {
                                                 if (this.contents[slotIndex] != null)
                                                 {
                                                     ItemStack itemstack;
                                          
                                                     if (this.contents[slotIndex].stackSize <= amount)
                                                     {
                                                         itemstack = this.contents[slotIndex];
                                                         this.contents[slotIndex] = null;
                                                         this.markDirty();
                                                         return itemstack;
                                                     }
                                                     else
                                                     {
                                                         itemstack = this.contents[slotIndex].splitStack(amount);
                                          
                                                         if (this.contents[slotIndex].stackSize == 0)
                                                         {
                                                             this.contents[slotIndex] = null;
                                                         }
                                          
                                                         this.markDirty();
                                                         return itemstack;
                                                     }
                                                 }
                                                 else
                                                 {
                                                     return null;
                                                 }
                                             }
                                          
                                          @Override
                                          public ItemStack getStackInSlotOnClosing(int slotIndex)
                                             {
                                                 if (this.contents[slotIndex] != null)
                                                 {
                                                     ItemStack itemstack = this.contents[slotIndex];
                                                     this.contents[slotIndex] = null;
                                                     return itemstack;
                                                 }
                                                 else
                                                 {
                                                     return null;
                                                 }
                                             }
                                          
                                          @Override
                                          public void setInventorySlotContents(int slotIndex, ItemStack stack) {
                                          this.contents[slotIndex] = stack;
                                          
                                                 if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                                                 {
                                                     stack.stackSize = this.getInventoryStackLimit();
                                                 }
                                          
                                                 this.markDirty();
                                          }
                                          
                                          @Override
                                          public String getInventoryName() {
                                          return this.hasCustomInventoryName() ? this.customName : "tile.kitchenCupboard";
                                          }
                                          
                                          @Override
                                          public boolean hasCustomInventoryName() {
                                          return this.customName != null && !this.customName.isEmpty();
                                          }
                                          
                                          public void setCustomName(String customName) {
                                          this.customName = customName;
                                          }
                                          
                                          @Override
                                          public int getInventoryStackLimit() {
                                          return 64;
                                          }
                                          
                                          @Override
                                          public boolean isUseableByPlayer(EntityPlayer player) {
                                          return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
                                          }
                                          
                                          @Override
                                          public void openInventory() {
                                          
                                          }
                                          
                                          @Override
                                          public void closeInventory() {
                                          
                                          }
                                          
                                          @Override
                                          public boolean isItemValidForSlot(int slotIndex, ItemStack stack) {
                                          return true;
                                          }
                                          
                                          }
                                          
                                          

                                          Classe du GuiHandler :

                                          package mod.plantsandfoodpack.common;
                                          
                                          import mod.plantsandfoodpack.client.GuiKitchenCupboard;
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.tileentity.TileEntity;
                                          import net.minecraft.world.World;
                                          import cpw.mods.fml.common.network.IGuiHandler;
                                          
                                          public class GuiHandlerPlantsAndFoodPack 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 TileEntityKitchenCupboard)
                                          {
                                          return new ContainerKitchenCupboard((TileEntityKitchenCupboard)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 TileEntityKitchenCupboard)
                                          {
                                          return new GuiKitchenCupboard((TileEntityKitchenCupboard)tile, player.inventory);
                                          }
                                          return null;
                                          }
                                          
                                          }
                                          
                                          

                                          Classe du Container :

                                          package mod.plantsandfoodpack.common;
                                          
                                          import net.minecraft.entity.player.EntityPlayer;
                                          import net.minecraft.entity.player.InventoryPlayer;
                                          import net.minecraft.init.Blocks;
                                          import net.minecraft.inventory.Container;
                                          import net.minecraft.inventory.Slot;
                                          import net.minecraft.item.Item;
                                          import net.minecraft.item.ItemStack;
                                          
                                          public class ContainerKitchenCupboard extends Container
                                          {
                                          private final TileEntityKitchenCupboard tileKitchenCupboard;
                                          
                                          public ContainerKitchenCupboard(TileEntityKitchenCupboard tile, InventoryPlayer inventory)
                                          {
                                          this.tileKitchenCupboard = tile;
                                          tile.openInventory();
                                          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, 85 + i * 18 -18));
                                                     }
                                                 }
                                          
                                                 for (i = 0; i < 9; ++i)
                                                 {
                                                     this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 143));
                                                 }
                                          }
                                          
                                          public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, 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.tileKitchenCupboard.getSizeInventory())
                                                     {
                                                         if (!this.mergeItemStack(itemstack1, this.tileKitchenCupboard.getSizeInventory(), this.inventorySlots.size(), true))
                                                         {
                                                             return null;
                                                         }
                                                     }
                                                     else if (!this.mergeItemStack(itemstack1, 0, this.tileKitchenCupboard.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.tileKitchenCupboard.isUseableByPlayer(player);
                                          }
                                          
                                          public void onContainerClosed(EntityPlayer player)
                                             {
                                                 super.onContainerClosed(player);
                                                 this.tileKitchenCupboard.closeInventory();
                                             }
                                          
                                          }
                                          
                                          

                                          Classe du Gui :

                                          package mod.plantsandfoodpack.client;
                                          
                                          import java.awt.Container;
                                          
                                          import mod.plantsandfoodpack.common.ContainerKitchenCupboard;
                                          import mod.plantsandfoodpack.common.TileEntityKitchenCupboard;
                                          import net.minecraft.client.gui.inventory.GuiContainer;
                                          import net.minecraft.entity.player.InventoryPlayer;
                                          
                                          public class GuiKitchenCupboard extends GuiContainer {
                                          
                                          public GuiKitchenCupboard(TileEntityKitchenCupboard tile, InventoryPlayer inventory) {
                                          super(new ContainerKitchenCupboard(tile, inventory));
                                          }
                                          
                                          @Override
                                          protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
                                          
                                          }
                                          
                                          }
                                          
                                          

                                          Au passage, j’aimera savoir comment je pourrais faire pour que sur mon Gui, il y est 3 rangées de 6 slots ?

                                          Merci d’avance !

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

                                            Il manque l’essentiel : le rapport de crash.

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB