• Récent
  • Mots-clés
  • Populaire
  • Utilisateurs
  • Groupes
  • S'inscrire
  • Se connecter
  • S'inscrire
  • Se connecter
  • Recherche
  • Récent
  • Mots-clés
  • Populaire
  • Utilisateurs
  • Groupes

Non résolu Afficher item dans un gui

Support pour les moddeurs
1.12.2
2
3
193
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.
  • C
    clement5188 dernière édition par 12 oct. 2021, 11:40

    Bonjour je suis entrain de créer un gui ou je voudrais afficher des items J’ai donc créer un boutton ou il y a 4 / 3 /2 item afficher avec ce code ça marche mais je voudrais savoir s’il y a un méthode plus simple pour aller chercher des textures d’items ?

    @SideOnly(Side.CLIENT)
    public class Button_craft_gui extends GuiButton{
    
    
        private final ResourceLocation resourceLocation;
        private final int xTexStart;
        private final int yTexStart;
        private final int yDiffText;
        private final ItemStack item_1;
        private final ItemStack item_2;
        private final ItemStack item_3;
        private final ItemStack item_craft;
    
    
        public Button_craft_gui(int p_i47392_1_, int x, int y, int p_i47392_4_, int p_i47392_5_, int p_i47392_6_, int p_i47392_7_, int p_i47392_8_, ResourceLocation p_i47392_9_, ItemStack item_1, ItemStack item_2, ItemStack item_3, ItemStack item_craft)
        {
            super(p_i47392_1_, x, y, p_i47392_4_, p_i47392_5_, "");
            this.height = p_i47392_5_;
            this.displayString = "";
            this.xTexStart = p_i47392_6_;
            this.yTexStart = p_i47392_7_;
            this.yDiffText = p_i47392_8_;
            this.resourceLocation = p_i47392_9_;
            this.item_1=item_1;
            this.item_2=item_2;
            this.item_3=item_3;
            this.item_craft=item_craft;
    
        }
        public Button_craft_gui(int p_i47392_1_, int p_i47392_2_, int p_i47392_3_, int p_i47392_4_, int p_i47392_5_, int p_i47392_6_, int p_i47392_7_, int p_i47392_8_, ResourceLocation p_i47392_9_, ItemStack item_1, ItemStack item_2, ItemStack item_craft)
        {
            super(p_i47392_1_, p_i47392_2_, p_i47392_3_, p_i47392_4_, p_i47392_5_, "");
            this.xTexStart = p_i47392_6_;
            this.yTexStart = p_i47392_7_;
            this.yDiffText = p_i47392_8_;
            this.resourceLocation = p_i47392_9_;
            this.item_1=item_1;
            this.item_2=item_2;
            this.item_3=null;
            this.item_craft=item_craft;
    
        }
        public Button_craft_gui(int p_i47392_1_, int p_i47392_2_, int p_i47392_3_, int p_i47392_4_, int p_i47392_5_, int p_i47392_6_, int p_i47392_7_, int p_i47392_8_, ResourceLocation p_i47392_9_, ItemStack item_1, ItemStack item_craft)
        {
            super(p_i47392_1_, p_i47392_2_, p_i47392_3_, p_i47392_4_, p_i47392_5_, "");
            this.xTexStart = p_i47392_6_;
            this.yTexStart = p_i47392_7_;
            this.yDiffText = p_i47392_8_;
            this.resourceLocation = p_i47392_9_;
            this.item_1=item_1;
            this.item_2=null;
            this.item_3=null;
            this.item_craft=item_craft;
    
        }
    
        public void setPosition(int p_191746_1_, int p_191746_2_)
        {
            this.x = p_191746_1_;
            this.y = p_191746_2_;
        }
    
        public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
        {
            if (this.visible)
            {
                if(item_3!=null) {
                    this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
                    mc.getTextureManager().bindTexture(new ResourceLocation(References.MODID, "textures/gui/craftgui3.png"));
                    GlStateManager.disableDepth();
                    int i = this.xTexStart;
                    int j = this.yTexStart;
    
                    if (this.hovered) {
                        j += this.yDiffText;
                    }
    
                    this.drawTexturedModalRect(this.x, this.y, i, j, this.width, this.height);
    
    
    
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_1.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_1.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 2, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_2.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_2.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 27, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_3.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_3.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 50, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_craft.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_craft.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 77, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
    
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_1.getCount()),this.x-i + 14, this.y-j + 12, 0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_2.getCount()),this.x-i + 39, this.y-j + 12,0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_3.getCount()),this.x-i + 62, this.y-j + 12,0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_craft.getCount()),this.x-i + 89, this.y-j + 12,0xFFFFFF);
                }
                else if(item_2!=null){
                    this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
                    mc.getTextureManager().bindTexture(new ResourceLocation(References.MODID, "textures/gui/craftgui3.png"));
                    GlStateManager.disableDepth();
                    int i = this.xTexStart;
                    int j = this.yTexStart;
    
                    if (this.hovered) {
    
                        j += this.yDiffText;
                    }
    
                    this.drawTexturedModalRect(this.x, this.y, i, j+21, this.width, this.height);
    
    
    
    System.out.println(new ItemStack(Item.REGISTRY.getObject(new ResourceLocation("harvestcraft","garlicitem")),1,146).getItem().getMetadata(new ItemStack(Item.REGISTRY.getObject(new ResourceLocation("harvestcraft","garlicitem")),1,146)));
                    //mc.getTextureManager().bindTexture(new ResourceLocation(item_1.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_1.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 23, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_2.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_2.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 50, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_craft.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_craft.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 77, this.y + 1, i, j, 16, 16, 16.0F, 16.0F);
    
    
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_1.getCount()),this.x-i + 35, this.y-j + 12, 0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_2.getCount()),this.x-i + 62, this.y-j + 12,0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_craft.getCount()),this.x-i + 89, this.y-j + 12,0xFFFFFF);
    
                }
                else if(item_1!=null) {
                    this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
                    mc.getTextureManager().bindTexture(new ResourceLocation(References.MODID, "textures/gui/craftgui3.png"));
                    GlStateManager.disableDepth();
                    int i = this.xTexStart;
                    int j = this.yTexStart;
    
                    if (this.hovered) {
    
    
                        j += this.yDiffText;
                    }
    
                    this.drawTexturedModalRect(this.x, this.y, i, j+42, this.width, this.height);
    
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_1.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_1.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 50, this.y + 2, i, j, 16, 16, 16.0F, 16.0F);
                    mc.getTextureManager().bindTexture(new ResourceLocation(item_craft.getItem().getRegistryName().getResourceDomain(), "textures/items/" + item_craft.getItem().getRegistryName().getResourcePath() + ".png"));
                    this.drawModalRectWithCustomSizedTexture(this.x + 77, this.y + 2, i, j, 16, 16, 16.0F, 16.0F);
    
    
    
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_1.getCount()),this.x-i + 62, this.y-j + 13, 0xFFFFFF);
                    this.drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(item_craft.getCount()),this.x-i + 89, this.y-j + 13,0xFFFFFF);
                }
            }
        }
    
    
        public ItemStack getItem_1() {
            return this.item_1;
        }
        public ItemStack getItem_2() {
            return this.item_2;
        }
    
        public ItemStack getItem_3() {
            return this.item_3;
        }
        public ItemStack getItem_craft(){return this.item_craft;}
    }
    
    
    Ama 1 réponse Dernière réponse 12 oct. 2021, 17:06 Répondre Citer 0
    • Ama
      Ama @clement5188 dernière édition par 12 oct. 2021, 17:06

      @clement5188
      Oui y’a plus simple (mais alors de tête parce-que c’est vieux la 1.12)
      Rends toi dans le GuiInventory ou le ContainerInventory quelque chose comme ça.
      Dans une des deux classes ou une autre (à toi de faire les recherches de ce côté).

      Dedans il doit y avoir l’affichage des items dans l’inventaire.
      Sans utiliser de textures, mais directement un item
      Par exemple: Items.APPLE ou TonMod.tonItemCustom
      De tête il me semble qu’il faudra passer par un ItemStack
      (ex: Items.APPLE.getItemStack()) quelque chose

      Recherches par là.

      Si je t'ai filé un coup de main n'oublie pas le + / -
      Par contre évite les demandes d'aides en MP, tu sera sympa'

      La JavaDoc c'est comme le PQ, ça sert à ce démerder tous seul. -Victor Hugo- 2017

      Une superbe API pour animer vos super modèles CraftStudio dans Minecraft !

      C 1 réponse Dernière réponse 12 oct. 2021, 18:06 Répondre Citer 0
      • C
        clement5188 @Ama dernière édition par 12 oct. 2021, 18:06

        @ama
        ok merci c’est je me doutais bien qu’il y avait un truc mais je trouvais qu’elle classe regarder
        j’ai trouver c’est une fonction dans ContainerGui c’est drawItemStack x)

        1 réponse Dernière réponse Répondre Citer 0
        • 1 / 1
        3 sur 3
        • Premier message
          3/3
          Dernier message
        Design by Woryk
        Contact / Mentions Légales

        MINECRAFT FORGE FRANCE © 2018

        Powered by NodeBB