MFF

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

    Créer un gui et un container sur un bloc (type coffre)

    Planifier Épinglé Verrouillé Déplacé Les interfaces (GUI) et les container
    1.6.x
    136 Messages 24 Publieurs 55.9k Vues 5 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.
    • sosohS Hors-ligne
      sosoh
      dernière édition par

      Ok donc je fais que quand je cliques sur le bouton ca envoies un paquet et quand le serveur recoit se paquet alors ca check tout ca et si c’est bon ca donne l’objet et supprime les autres et sinon ca fait rien … C’est ca?

      Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

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

        Ok donc je fais que quand je cliques sur le bouton ca envoies un paquet et quand le serveur recoit se paquet alors ca check tout ca et si c’est bon ca donne l’objet et supprime les autres et sinon ca fait rien … C’est ca?

        Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

        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

          Oui c’est ça.

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

            Est ce possible de faire une case la ou on peut rien mettre (le joueur) comme la sortie d’un item dans le four, et une endroit la ou peut mettre que un type d’objet comme le fuel mais la c’est pas du fuel (ici une fiole)?

            Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

            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

              Oui, regarde dans le tile entity du four, il y a la fonction isItemValidForSlot, c’est elle qui gère ça.

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

                J’ai fais ce code mais rien ne se passes:
                this.addSlotToContainer(new Slot(teChaudron, 20, 8, 90)).isItemValid(new ItemStack(ModHarryPotter.itemFiole));

                Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                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

                  Non, c’est dans le tile entity que tu dois mettre ça.

                  public boolean isItemValidForSlot(int slot, ItemStack stack)
                  {
                      if(slot == 1 && stack.getItem() == ModHarryPotter.itemFiole)
                      {
                          return true;
                      }
                      else if(slot == 0)
                      {
                          return true;
                       }
                       return false;
                  }
                  

                  Par exemple. (vérifie les arguments de la fonction, je ne suis pas sûr de ce que j’ai mit).

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

                    Il n’y a pas d’erreur de code mais, ca ne marche pas: je peux mettre tout les items dedans mon slot 1…

                    Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                    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

                      Regarde aussi du côté de la fonction
                      public ItemStack transferStackInSlot(EntityPlayer player, int slotId)
                      dans la classe de ton container :
                      https://github.com/FFMT/Privatizer/blob/master/privatizer_src/fr/mcnanotech/privatizer/common/ContainerPrivateFurnace.java#L126-L133
                      (code du four)

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

                        Je ne comprends a quoi ca me sert le transferstackinslot… C’est pour empecher de mettre d’autres items que ma fiole (ModHarryPotter.itemFiole)?

                        Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                        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

                          transferStackInSlot gère le shift + clic. Il faut donc que tu le bloque si l’item va dans un slot ou il ne devrait pas aller (c’est ce que fait les conditions que j’ai surligné).

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

                            Ah mais j’ai pas compris comment l’adapter à mon code 😕 (je sais je suis chiant, des fois j’ai besoin qu’on m’explique sinon je comprends rien ^^)

                            Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                            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

                              Bha par exemple tu remplace :
                              if(FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
                              par :
                              if(itemstack1 != null && (itemstack1.getItem() == ClassePrincipale.itemQuiPeutAllerDedans || itemstack1.getItem() == ClassePrincipale.autreItem))

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

                                Ah ok! Merci de ton aide Robin! Qu’est ce que je ferais sans toi ! 🙂

                                Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

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

                                  J’ai mis ca :

                                  
                                  else if(slotId == 21 && slotId != 0)
                                  
                                              {
                                  if(itemstack1 != null && (itemstack1.getItem() == ModHarryPotter.itemFiole)){
                                  
                                                      if(!this.mergeItemStack(itemstack1, 0, 1, false))
                                                      {
                                                          return null;
                                                      }
                                                  }
                                              }
                                  
                                  

                                  dans cette fonction:

                                  
                                  public ItemStack transferStackInSlot(EntityPlayer player, int slotId)
                                  
                                  {
                                  ItemStack itemstack = null;
                                  Slot slot = (Slot)this.inventorySlots.get(slotId);
                                  
                                  if(slot != null && slot.getHasStack())
                                  {
                                  ItemStack itemstack1 = slot.getStack();
                                  itemstack = itemstack1.copy();
                                  
                                  if(slotId < 9)
                                  {
                                  if(!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true))
                                  {
                                  return null;
                                  }
                                  }
                                  else if(!this.mergeItemStack(itemstack1, 0, 9, false))
                                  {
                                  return null;
                                  }
                                  else if(slotId == 21)
                                              {
                                  if(itemstack1 != null && (itemstack1.getItem() == ModHarryPotter.itemFiole)){
                                  
                                                      if(!this.mergeItemStack(itemstack1, 0, 1, false))
                                                      {
                                                          return null;
                                                      }
                                                  }
                                              }
                                  
                                  if(itemstack1.stackSize == 0)
                                  {
                                  slot.putStack((ItemStack)null);
                                  }
                                  else
                                  {
                                  slot.onSlotChanged();
                                  }
                                  }
                                  return itemstack;
                                  }
                                  
                                  

                                  Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

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

                                    J’ai fais tout ce que vous m’avez mais ça marche pas vous pouvez m’aider ?

                                    Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                                    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

                                      Envoie toute tes classes avec juste ça je ne peux rien faire. Je ne sais même pas à quoi ressemble ton tile entity, et comme le tileentity est lier avec container …

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

                                        Je t’envoies mon src en message privé.

                                        Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                                        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

                                          Envoie l’essentiel, j’ai pas le temps pour le moment.

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

                                            Voila:

                                            
                                            package com.harrypotter.sosoh.common.gui.container;
                                            
                                            import com.harrypotter.sosoh.common.ModHarryPotter;
                                            import com.harrypotter.sosoh.common.blocks.TileEntityChaudron;
                                            
                                            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.util.ResourceLocation;
                                            
                                            public class ContainerChaudron extends Container
                                            {
                                            private TileEntityChaudron tileEntity;
                                            
                                            public ContainerChaudron(InventoryPlayer playerInventory, TileEntityChaudron teChaudron)
                                            {
                                            this.tileEntity = teChaudron;
                                            
                                            int yP = 21;
                                            int yS = 39;
                                            
                                            this.addSlotToContainer(new Slot(teChaudron, 1, 26, yP));
                                            this.addSlotToContainer(new Slot(teChaudron, 2, 62, yP));
                                            this.addSlotToContainer(new Slot(teChaudron, 3, 98, yP));
                                            this.addSlotToContainer(new Slot(teChaudron, 4, 134, yP));
                                            
                                            this.addSlotToContainer(new Slot(teChaudron, 5, 44, yS));
                                            this.addSlotToContainer(new Slot(teChaudron, 6, 80, yS));
                                            this.addSlotToContainer(new Slot(teChaudron, 7, 116, yS));
                                            
                                            //Sceau et Fiole
                                            
                                            this.addSlotToContainer(new Slot(teChaudron, 8, 8, 90));
                                            this.addSlotToContainer(new Slot(teChaudron, 9, 26, 90));
                                            
                                            //Potions
                                            
                                            this.addSlotToContainer(new Slot(teChaudron, 10, 80, 90));
                                            
                                            this.bindPlayerInventory(playerInventory);
                                            }
                                            
                                            private void bindPlayerInventory(InventoryPlayer playerInventory)
                                            {
                                            int i;
                                            for(i = 0; i < 3; i++)
                                            {
                                            for(int j = 0; j < 9; j++)
                                            {
                                            this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 103 + i * 18 + 37));
                                            }
                                            }
                                            
                                            for(i = 0; i < 9; i++)
                                            {
                                            this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 161 + 37));
                                            }
                                            }
                                            
                                            @Override
                                            public boolean canInteractWith(EntityPlayer player)
                                            {
                                            return tileEntity.isUseableByPlayer(player);
                                            }
                                            
                                            public ItemStack transferStackInSlot(EntityPlayer player, int slotId){
                                            
                                            ItemStack itemstack = null;
                                            Slot slot = (Slot)this.inventorySlots.get(slotId);
                                            
                                            if(slot != null && slot.getHasStack())
                                            {
                                            ItemStack itemstack1 = slot.getStack();
                                            itemstack = itemstack1.copy();
                                            
                                            if(slotId < 9)
                                            {
                                            if(!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true))
                                            {
                                            return null;
                                            }
                                            }
                                            else if(!this.mergeItemStack(itemstack1, 0, 9, false))
                                            {
                                            return null;
                                            }
                                            else if(slotId == 10)
                                            {
                                            if(itemstack1 != null && (itemstack1.getItem() == ModHarryPotter.itemFiole)){
                                            
                                            if(!this.mergeItemStack(itemstack1, 0, 1, false))
                                            {
                                                                  return null;
                                            }
                                            }
                                            }
                                            
                                            if(itemstack1.stackSize == 0)
                                            {
                                            slot.putStack((ItemStack)null);
                                            }
                                            else
                                            {
                                            slot.onSlotChanged();
                                            }
                                            }
                                            return itemstack;
                                            }
                                            
                                            public TileEntityChaudron getTile()
                                            {
                                              return tileEntity;
                                            }
                                            }
                                            
                                            

                                            Et:

                                            
                                            package com.harrypotter.sosoh.common.blocks;
                                            
                                            import com.harrypotter.sosoh.common.ModHarryPotter;
                                            
                                            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;
                                            
                                            public class TileEntityChaudron extends TileEntity implements IInventory{
                                            
                                                private byte direction;
                                                private ItemStack[] inventory = new ItemStack[72];
                                            private String customName;
                                            
                                                @Override
                                                public void readFromNBT(NBTTagCompound nbttag)
                                                {
                                                super.readFromNBT(nbttag);
                                                    this.direction = nbttag.getByte("Direction");
                                                    NBTTagList nbttaglist = nbttag.getTagList("Items", blockMetadata);
                                                    this.inventory = new ItemStack[this.getSizeInventory()];
                                            
                                                    if (nbttag.hasKey("CustomName"))
                                                    {
                                                        this.customName = nbttag.getString("CustomName");
                                                    }
                                            
                                                    for (int i = 0; i < nbttaglist.tagCount(); i++)
                                                    {
                                                        NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i);
                                                        int j = nbttagcompound1.getByte("Slot");
                                            
                                                        if (j >= 0 && j < this.inventory.length)
                                                        {
                                                            this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                                                        }
                                                    }
                                                }
                                            
                                                public void writeToNBT(NBTTagCompound nbttag)
                                                {
                                                super.writeToNBT(nbttag);
                                                    nbttag.setByte("Direction", this.direction);
                                            
                                                    NBTTagList nbttaglist = new NBTTagList();
                                            
                                                    for (int i = 0; i < this.inventory.length; i++)
                                                    {
                                                        if (this.inventory* != null)
                                                        {
                                                            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                                                            nbttagcompound1.setByte("Slot", (byte)i);
                                                            this.inventory*.writeToNBT(nbttagcompound1);
                                                            nbttaglist.appendTag(nbttagcompound1);
                                                        }
                                                    }
                                            
                                                    nbttag.setTag("Items", nbttaglist);
                                            
                                                    if (this.hasCustomInventoryName())
                                                    {
                                                        nbttag.setString("CustomName", this.customName);
                                                    }
                                                }
                                            
                                                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 inventory.length;
                                            }
                                            
                                            @Override
                                            public ItemStack getStackInSlot(int slotId) {
                                            return inventory[slotId];
                                            }
                                            
                                            @Override
                                            public ItemStack decrStackSize(int slotId, int quantity)
                                                {
                                                    if (this.inventory[slotId] != null)
                                                    {
                                                        ItemStack itemstack;
                                            
                                                        if (this.inventory[slotId].stackSize <= quantity)
                                                        {
                                                            itemstack = this.inventory[slotId];
                                                            this.inventory[slotId] = null;
                                                            this.updateContainingBlockInfo();
                                                            return itemstack;
                                                        }
                                                        else
                                                        {
                                                            itemstack = this.inventory[slotId].splitStack(quantity);
                                            
                                                            if (this.inventory[slotId].stackSize == 0)
                                                            {
                                                                this.inventory[slotId] = null;
                                                            }
                                            
                                                            this.updateContainingBlockInfo();
                                                            return itemstack;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return null;
                                                    }
                                                }
                                            
                                            @Override
                                            public ItemStack getStackInSlotOnClosing(int slotId)
                                            {
                                                    if (this.inventory[slotId] != null)
                                                    {
                                                        ItemStack itemstack = this.inventory[slotId];
                                                        this.inventory[slotId] = null;
                                                        return itemstack;
                                                    }
                                                    else
                                                    {
                                                        return null;
                                                    }
                                            }
                                            
                                            @Override
                                            public void setInventorySlotContents(int slotId, ItemStack stack)
                                            {
                                                    this.inventory[slotId] = stack;
                                            
                                                    if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                                                    {
                                                        stack.stackSize = this.getInventoryStackLimit();
                                                    }
                                            
                                                    this.updateContainingBlockInfo();
                                            }
                                            
                                            @Override
                                            public String getInventoryName()
                                            {
                                            return this.hasCustomInventoryName() ? this.customName : "container.chaudron";
                                            }
                                            
                                            @Override
                                            public boolean hasCustomInventoryName() 
                                            {
                                            return this.customName != null && this.customName.length() > 0;
                                            }
                                            
                                            public void setCustomGuiName(String name)
                                            {
                                               this.customName = name;
                                                }
                                            
                                            @Override
                                            public int getInventoryStackLimit() {
                                            return 1;
                                            }
                                            
                                            @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 true;
                                            }
                                            
                                            }
                                            
                                            

                                            Developpeur d'Hogsmod, un mod implémentant le Monde d'Harry Potter dans Minecraft!

                                            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