MFF

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

    Petit probleme GUI

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    10 Messages 4 Publieurs 1.9k Vues 1 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.
    • XeNeX Hors-ligne
      XeNe
      dernière édition par

      Hello,
      Je continue sur mon generator, qui est presque fini mais, j’ai un petit probleme…
      Ma barre BurnTime sur mon Gui ne s’affiche pas, Meme quand je met un if pour check si BurnTime est au dessus de 0 il me return false donc j’y comprends rien xD

      Mon TE:```java
      package tileEntity;

      import scala.reflect.internal.Trees.This;
      import block.ElectricFurnace;
      import block.Generator;
      import block.GeneratorRecipe;
      import main.TAqmod2;
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.init.Blocks;
      import net.minecraft.init.Items;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.inventory.ISidedInventory;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemBlock;
      import net.minecraft.item.ItemHoe;
      import net.minecraft.item.ItemStack;
      import net.minecraft.item.ItemSword;
      import net.minecraft.item.ItemTool;
      import net.minecraft.item.crafting.FurnaceRecipes;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.nbt.NBTTagList;
      import net.minecraft.tileentity.TileEntity;
      import cpw.mods.fml.common.registry.GameRegistry;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;

      public class TileEntityGenerator extends TileEntity implements ISidedInventory
      {
         public TileEntityGenerator()
         {

      }

      private static final int[] slots_fuel = new int[] {0};
         private static final int[] slots_result = new int[] {1};

      /**
          * The ItemStacks that hold the items currently being used in the furnace
          */
         private ItemStack[] slots = new ItemStack[2];

      /**
          * MaxBurnTime
          /
         public int maxBurnTime = 2000;
         public int processTime = 2048;
         /
      * power /
         public int power = 0;
         /
      * Max Power */
         public int maxPower = 1000;

      /** The number of ticks that the current item has been cooking for */
         public int cookTime;
         public int burnTime;

      private String GeneratorName;

      public void GeneratorName(String string)
         {
             this.GeneratorName = string;
         }

      @Override
         public int getSizeInventory()
         {
             return this.slots.length;
         }

      @Override
         public ItemStack getStackInSlot(int par1)
         {
             return this.slots[par1];
         }

      @Override
         public ItemStack decrStackSize(int par1, int par2)
         {
             if(this.slots[par1] != null)
             {
                 ItemStack itemstack;

      if(this.slots[par1].stackSize <= par2)
                 {
                     itemstack = this.slots[par1];
                     this.slots[par1] = null;
                     return itemstack;
                 }
                 else
                 {
                     itemstack = this.slots[par1].splitStack(par2);

      if(this.slots[par1].stackSize == 0)
                     {
                         this.slots[par1] = null;
                     }

      return itemstack;
                 }
             }
             else
             {
                 return null;
             }

      }

      public boolean hasPower()
         {
             return this.power > 0;
         }

      @Override
         public ItemStack getStackInSlotOnClosing(int par1)
         {

      if(this.slots[par1] != null)
             {
                 ItemStack itemstack = this.slots[par1];
                 this.slots[par1] = null;
                 return itemstack;
             }
             else
             {
                 return null;
             }
         }

      @Override
         public void setInventorySlotContents(int par1, ItemStack itemStack)
         {
             this.slots[par1] = itemStack;

      if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
             {
                 itemStack.stackSize = this.getInventoryStackLimit();
             }
         }

      @Override
         public String getInventoryName()
         {
             return this.hasCustomInventoryName() ? this.GeneratorName : “container.generator”;
         }

      @Override
         public boolean hasCustomInventoryName()
         {
             return this.GeneratorName != null && this.GeneratorName.length() > 0;
         }

      @Override
         public int getInventoryStackLimit()
         {
             return 64;
         }

      @Override
         public boolean isUseableByPlayer(EntityPlayer par1)
         {
             return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1.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 par1, ItemStack par2)
         {
             return par1 == 1 ? false : true;
         }

      @Override
         public int[] getAccessibleSlotsFromSide(int par1)
         {
             return par1 == 0 ? slots_fuel : slots_result;
         }

      @Override
         public boolean canInsertItem(int par1, ItemStack par2, int par3)
         {
             return this.isItemValidForSlot(par1, par2);
         }

      @Override
         public boolean canExtractItem(int par1, ItemStack par2, int par3)
         {
             return par3 != 0 || par1 != 1 || par2.getItem() == Items.bucket;
         }

      @Override
         public void readFromNBT(NBTTagCompound par1)
         {
             super.readFromNBT(par1);

      if(par1.hasKey(“power”))
             {
                 this.power = par1.getInteger(“power”);
             }

      NBTTagList nbttaglist = par1.getTagList(“Items”, 10);
             this.slots = new ItemStack[this.getSizeInventory()];

      for(int i = 0; i < nbttaglist.tagCount(); ++i)
             {
                 NBTTagCompound nbttacompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i);
                 byte b0 = nbttacompound1.getByte(“Slot”);

      if(b0 >= 0 && b0 < this.slots.length)
                 {
                     this.slots[b0] = ItemStack.loadItemStackFromNBT(nbttacompound1);
                 }
             }
             this.cookTime = par1.getShort(“CookTime”);
             if(par1.hasKey(“container.generator”))
             {
                 this.GeneratorName = par1.getString(“container.generator”);
             }
         }

      @Override
         public void writeToNBT(NBTTagCompound par1)
         {
             super.writeToNBT(par1);

      par1.setInteger(“power”, this.power);
             par1.setShort(“CookTime”, (short)this.cookTime);
             NBTTagList taglist = new NBTTagList();

      for(int i = 0; i < this.slots.length; i++)
             {
                 if(this.slots* != null)
                 {
                     NBTTagCompound tagcompound1 = new NBTTagCompound();
                 }
             }
             par1.setTag(“Items”, taglist);
             if(this.hasCustomInventoryName())
             {
                 par1.setString(“container.generator”, this.GeneratorName);
             }
         }

      public boolean isCharging()
         {
             return this.cookTime > 0;
         }

      /*
          * @SideOnly(Side.CLIENT)
          * public int getCookProgressScaled(int par1)
          * {
          * return this.cookTime * par1 / this.processTime;
          * }
          */

      @SideOnly(Side.CLIENT)
         public int getPowerRemainingScaled(int par1)
         {
             return this.power * par1 / this.maxPower;
         }

      @SideOnly(Side.CLIENT)
         public int getBurnTimeRemainingScaled(int par1)
         {
             return this.burnTime / this.maxBurnTime;
         }

      @Override
         public void updateEntity()
         {
             boolean flag = this.burnTime > 0;
             boolean flag1 = false;

      if(hasPower() && isCharging())
             {
                 this.power–;
             }
             if(!this.worldObj.isRemote)
             {

      if(this.power < this.maxPower)// && this.getItemPower(this.slots[0]) > 0)
                 {

      /*
                      * flag1 = true;
                      * if(this.burnTime > 0)
                      * {
                      * }else{
                      */
                     if(this.burnTime > 0)
                     {
                         this.powerUp();

      }
                     else
                     {
                         this.burnTime += getItemPower(this.slots[0]);

      if(this.slots[0] != null && this.getItemPower(this.slots[0]) > 0)
                         {
                             –this.slots[0].stackSize;

      }

      if(slots[0] != null && slots[0].stackSize <= 0)
                         {
                             this.slots[0] = null;
                         }
                     }
                 }

      /**
                  * Slots Chargement de Battery
                  */
                 if(this.power <= this.maxPower)
                 {
                     if(this.slots[1] != null)
                     {
                         if(this.slots[1].getItemDamage() <= this.slots[1].getMaxDamage() && hasPower())
                         {
                             if(this.slots[1].getItemDamage() == this.slots[1].getMaxItemUseDuration())
                             {

      }
                             else
                             {
                                 this.power–;
                                 this.slots[1] = new ItemStack(this.slots[1].getItem(), this.slots[1].stackSize, this.slots[1].getItemDamage() - 1);
                             }
                         }
                     }
                 }

      if(this.canSmelt() && this.hasPower())
                 {
                     this.cookTime = this.getItemPower(this.slots[0]);
                     if(this.cookTime == this.processTime)
                     {
                         this.cookTime = 0;
                         flag1 = true;
                     }
                 }
                 else
                 {
                     this.cookTime = 0;
                 }

      if(flag != burnTime > 0)
                 {
                     flag1 = true;
                     Generator.updateBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
                 }
             }

      if(flag1)
             {
                 this.markDirty();
             }

      }

      private boolean canSmelt()
         {

      if(this.power > 0)
             {

      if(this.power == maxPower)
                 {
                     return false;
                 }

      }
             return tileEntityInvalid;
         }

      protected static int getItemPower(ItemStack itemstack)
         {
             {
                 if(itemstack == null)
                 {
                     return 0;
                 }
                 else
                 {
                     Item item = itemstack.getItem();

      if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
                     {
                         Block block = Block.getBlockFromItem(item);

      if(block == Blocks.wooden_slab)
                         {
                             return 10;
                         }

      if(block.getMaterial() == Material.wood)
                         {
                             return 10;
                         }

      if(block == Blocks.coal_block)
                         {
                             return 1000;
                         }
                     }

      if(item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals(“WOOD”))
                         return 20;
                     if(item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals(“WOOD”))
                         return 20;
                     if(item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals(“WOOD”))
                         return 20;
                     if(item == Items.stick)
                         return 10;
                     if(item == Items.coal)
                         return 100;
                     if(item == Item.getItemFromBlock(Blocks.sapling))
                         return 10;
                     if(item == Items.blaze_rod)
                         return 160;
                     return GameRegistry.getFuelValue(itemstack);
                 }
             }
         }

      public static boolean isItemFuel(ItemStack itemstack)
         {
             return getItemPower(itemstack) > 0;
         }

      public boolean isPowering()
         {
             return this.burnTime > 0;
         }

      public void powerUp()
         {
             if(this.burnTime > 0)
             {
                 this.power++;
                 this.burnTime–;
             }

      }

      }

      Pourtant quand je regarde dans mon TE rien ne retourne burntime à 0...
      
      Mon GUI: ```java
      package gui;
      
      import org.lwjgl.opengl.GL11;
      
      import container.ContainerElectricFurnace;
      import container.ContainerGenerator;
      import tileEntity.TileEntityElectricFurnace;
      import tileEntity.TileEntityGenerator;
      import main.TAqmod2;
      import net.minecraft.client.Minecraft;
      import net.minecraft.client.gui.inventory.GuiContainer;
      import net.minecraft.client.resources.I18n;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.util.ResourceLocation;
      
      public class GuiGenerator extends GuiContainer
      {
      
         public static final ResourceLocation texture = new ResourceLocation(TAqmod2.MODID + ":textures/gui/container/generator.png");
         public TileEntityGenerator Generator;
      
         public GuiGenerator(InventoryPlayer player, TileEntityGenerator tileEntity)
         {
             super(new ContainerGenerator(player, tileEntity));
             this.Generator = tileEntity;
             this.xSize = 176;
             this.ySize = 165;
         }
      
         public void drawGuiContainerForegroundLayer(int par1, int par2)
         {
             String s = this.Generator.hasCustomInventoryName() ? this.Generator.getInventoryName() : I18n.format(this.Generator.getInventoryName());
             this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
             this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
         }
      
         @Override
         protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
         {
             GL11.glColor4f(1F, 1F, 1F, 1F);
             Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
             drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
             int i1;
      
             if(this.Generator.hasPower())
             {
                 i1 = this.Generator.getPowerRemainingScaled(47);
                 this.drawTexturedModalRect(guiLeft + 84, guiTop + 64 - i1, 176, 64 - i1, 16, i1);
             }
         //   if(this.Generator.isPowering())
         //  {
         //        System.out.println("Drawing");
                 i1 = this.Generator.getBurnTimeRemainingScaled(14);
                 this.drawTexturedModalRect(guiLeft + 57, guiTop + 64 - i1, 192, 31 - i1, i1, i1);
         //    }
                 System.out.println(this.Generator.isPowering()? "true" : "false");
      
         }
      
      }
      
      

      Aller voir l’état de mon mod sur trello! https://trello.com/b/p0JMg4ki/taqmod2

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

        Ta tileEntity doit être correctement synchronisée, tu demandes au client de trouver une variable qui existe uniquement côté serveur

        Site web contenant mes scripts : http://SCAREXgaming.github.io

        Pas de demandes de support par MP ni par skype SVP.
        Je n'accepte sur skype que l…

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

          Il me semble qu’il faut rajouter ça non ?

          
          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);
          }
          
          
          1 réponse Dernière réponse Répondre Citer 0
          • XeNeX Hors-ligne
            XeNe
            dernière édition par

            @Scarex: euh wat, pourtant dans le furnace ils ont fait pareil non? Mais du coup si je déclare une fonction elle est client et serveur non? si non j’en apprend des choses lol

            @BrokenSwing: euh non pas à ma connaisance et aussi tu l’as pas mis dans ton tuto 1.7 du machine(type furnace) sauf si j’ai mal regardé 😛

            Aller voir l’état de mon mod sur trello! https://trello.com/b/p0JMg4ki/taqmod2

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

              Bah apparemment je ne l’ai pas mis dans mon tutoriel mais est-ce que tu a essayé de le mettre ?
              EDIT : Essai mais en fait je sais pas trop où est ce que j’ai vu ces fonctions que je met dans tout mes TE xD

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

                nope ça change rien 😛 effectivement je sais pas d’où tu les sors tes 2 fonctions… xD

                Aller voir l’état de mon mod sur trello! https://trello.com/b/p0JMg4ki/taqmod2

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

                  Pourquoi cette condition dans le TE ?

                  if(!this.worldObj.isRemote)
                  

                  (Ton code est pas super propre, ne met pas de majuscule aux variables et tu fait des double condition du style if(burnTime > 0) { powerUp() } et dans powerUp tu revérifie si burnTime > 0)

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

                    C’est bizarre en effet.
                    Et les deux fonctions, je crois qu’elle viennent du four, ça permet au serveur d’envoyer les tags nbt au client pour la synchro.

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

                      Et pour les tests enlève la condition pour le markDirty()
                      Fait qu’à chaque fois que la méthode update() est appelée tu fait un this.markDirty()

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

                        Du coup la classe de ton TE ressemble à quoi ?

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

                        MINECRAFT FORGE FRANCE © 2024

                        Powered by NodeBB