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

    Résolu Affichage du GUI incorrect ..

    1.12.x
    1.12.x
    2
    4
    1065
    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.
    • Flow
      Flow dernière édition par

      Bonjour,

      J’ai un petit problème, j’ajoute des joueurs à une liste stockée dans le tile entity par un guiSettings. 
      Le problème c’est que après avoir markDirty(markBlockForUpdate) mon tile entity, ce gui agit bizarrement, voici une vidéo car c’est compliqué à expliquer et à visualiser avec du texte/:

      https://youtu.be/CF25hry9B4g

      Donc en gros normalement en faisant enter, ca ajoute un player a la liste (5 maximum), donc il y a bien 5 players ajouter a la list mais on dirait que dans le drawScreen et dans le initGui ca en affiche plus que ca devrait … 
      J’ai vraiment tout essayer et il semblerait que ca ai un rapport avec les markDirty… quand j’active mon block je fais te.markDirty(); mais je ne vois pas pourquoi ca cause se problème 😕
      Surtout quand les enlevant ca ne le fais plus … Voici mes codes :

      GuiSettings

      package fr.fifou.economy.gui;
      
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.List;
      import java.util.UUID;
      
      import org.lwjgl.input.Keyboard;
      
      import fr.fifou.economy.ModEconomy;
      import fr.fifou.economy.blocks.tileentity.TileEntityBlockSeller;
      import fr.fifou.economy.blocks.tileentity.TileEntityBlockVault;
      import fr.fifou.economy.packets.PacketCardChange;
      import fr.fifou.economy.packets.PacketListNBT;
      import net.minecraft.client.Minecraft;
      import net.minecraft.client.gui.GuiButton;
      import net.minecraft.client.gui.GuiScreen;
      import net.minecraft.client.gui.GuiTextField;
      import net.minecraft.client.renderer.GlStateManager;
      import net.minecraft.client.renderer.OpenGlHelper;
      import net.minecraft.client.renderer.RenderHelper;
      import net.minecraft.client.renderer.entity.RenderManager;
      import net.minecraft.client.resources.I18n;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.item.ItemStack;
      import net.minecraft.util.ResourceLocation;
      import net.minecraft.util.text.TextFormatting;
      import net.minecraft.world.World;
      import net.minecraftforge.fml.client.config.GuiButtonExt;
      
      public class GuiVaultSettings extends GuiScreen
      {
      private static final ResourceLocation background = new ResourceLocation(ModEconomy.MODID ,"textures/gui/screen/gui_item.png");
      protected int xSize = 256;
      protected int ySize = 124;
      protected int guiLeft;
      protected int guiTop;
      private GuiTextField addPlayersToList;
      private TileEntityBlockVault tile;
      
      public GuiVaultSettings(TileEntityBlockVault tile) 
      {
      this.tile = tile;
      }
      
      @Override
      public void initGui()
      {
              int k = (this.width - this.xSize) / 2;
              int j = (this.height - this.ySize) / 2;
              Keyboard.enableRepeatEvents(true);
              this.addPlayersToList = new GuiTextField(0, this.fontRenderer, k + 50, j + 110, 155, 12);
              this.addPlayersToList.setMaxStringLength(35);
              this.addPlayersToList.setEnabled(false);
              this.addPlayersToList.setText("Add other players.");
              for(int i = 0; i < tile.getOthers().size(); i++)
              {
              this.buttonList.add(new GuiButtonExt(i, (width / 2) + 35, ((height /2) - 55) + i * 20, 40, 13, TextFormatting.BOLD.toString() + TextFormatting.DARK_RED + "✖"));
              }
      
      }
      
      @Override
      public void updateScreen() 
      {
      if(tile.getMax() == 5)
      {
      this.addPlayersToList.setEnabled(false);
      this.addPlayersToList.setText("Max players allowed reached");
      } 
      }
      
      @Override
      public void drawScreen(int mouseX, int mouseY, float partialTicks) 
      {
      this.drawDefaultBackground();
      // added
              this.mc.getTextureManager().bindTexture(background);
              int k = (this.width - this.xSize) / 2;
              int j = (this.height - this.ySize) / 2;
              this.drawTexturedModalRect(k, j, 0, 0, this.xSize, this.ySize);
              for(int i = 0; i < tile.getOthers().size(); i++)
              {
              this.fontRenderer.drawString(TextFormatting.BOLD + (String) tile.getOthers().get(i), (width / 2) - 75, ((height /2) - 52) + i * 20, 0x000);         
              }
          super.drawScreen(mouseX, mouseY, partialTicks);
          GlStateManager.disableLighting();
          GlStateManager.disableBlend();
          if(!Minecraft.getMinecraft().isSingleplayer())
          {
          if(tile.getOwnerS().equals(Minecraft.getMinecraft().player.getUniqueID().toString()))
          {
          this.addPlayersToList.drawTextBox();
          }
          }
      }
      
      @Override
      public void onGuiClosed() 
      {
      super.onGuiClosed();
      Keyboard.enableRepeatEvents(false);
      }
      
      @Override
      protected void keyTyped(char typedChar, int keyCode) throws IOException
          {
      if(keyCode == 1)
              {
                  super.keyTyped(typedChar, keyCode);
              }
              else if(keyCode == 28 || keyCode == 156)
              {
              if(tile.getMax() < 5)
              {
              this.addPlayerToTileEntity();
              this.addPlayersToList.setText("");
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
              }
              else
              {
              this.addPlayersToList.setText("Max players allowed reached ");
              }
              }
              else
              {
                  this.addPlayersToList.textboxKeyTyped(typedChar, keyCode);
              }
          }
      
          private void addPlayerToTileEntity()
          {
              String s = this.addPlayersToList.getText();
              EntityPlayer playerAdd = Minecraft.getMinecraft().world.getPlayerEntityByName(s);
              if(playerAdd != null)
              {
              String playerAddUUID = playerAdd.getName();
              ModEconomy.network.sendToServer(new PacketListNBT(playerAddUUID, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "add", 0));
              }
              else
              {
          this.addPlayersToList.setText("No player with this name ");
              }
          }
      
      @Override
      protected void actionPerformed(GuiButton button) throws IOException 
      {
      
      switch (button.id) {
      case 0:
              ModEconomy.network.sendToServer(new PacketListNBT("", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "remove", 0));
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
      break;
      case 1:
              ModEconomy.network.sendToServer(new PacketListNBT("", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "remove", 1));
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
      
              break;
      case 2:
              ModEconomy.network.sendToServer(new PacketListNBT("", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "remove", 2));
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
      
              break;
      case 3:
              ModEconomy.network.sendToServer(new PacketListNBT("", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "remove", 3));
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
      
              break;
      case 4:
              ModEconomy.network.sendToServer(new PacketListNBT("", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), false, "remove", 4));
              Minecraft.getMinecraft().player.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_SETTINGS, mc.world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
              break;
      }
      }
      
      @Override
        protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
          {
              super.mouseClicked(mouseX, mouseY, mouseButton);
              if(this.addPlayersToList.mouseClicked(mouseX, mouseY, mouseButton))
              {
              this.addPlayersToList.setText("");
              this.addPlayersToList.setEnabled(true);
              }        
          }
      
      @Override
        public boolean doesGuiPauseGame()
          {
              return false;
          }
      
      }
      

      Le Packet envoyé

      package fr.fifou.economy.packets;
      
      import fr.fifou.economy.ModEconomy;
      import fr.fifou.economy.blocks.tileentity.TileEntityBlockVault;
      import fr.fifou.economy.blocks.tileentity.TileEntityBlockVault2by2;
      import fr.fifou.economy.capability.CapabilityLoading;
      import fr.fifou.economy.capability.IMoney;
      import fr.fifou.economy.items.ItemCreditcard;
      import io.netty.buffer.ByteBuf;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.item.ItemStack;
      import net.minecraft.util.math.BlockPos;
      import net.minecraft.world.World;
      import net.minecraftforge.fml.common.network.ByteBufUtils;
      import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
      import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
      import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
      
      public class PacketListNBT implements IMessage {
      
      private static String names;
      private static double x;
      private static double y;
      private static double z;
      private static boolean isBlock2x2;
      private static String addrem;
      private static int index;
      
      public PacketListNBT() 
      {
      
      }
      
      public PacketListNBT(String names, double x, double y, double z, boolean isBlock2x2, String addrem, int index)
      {
      this.names = names;
      this.x = x;
      this.y = y;
      this.z = z;
      this.isBlock2x2 = isBlock2x2;
      this.addrem = addrem;
      this.index = index;
      }
      
      public void fromBytes(ByteBuf buf) 
      {
      this.names = ByteBufUtils.readUTF8String(buf);
      this.x = buf.readDouble();
      this.y = buf.readDouble();
      this.z = buf.readDouble();
      this.isBlock2x2 = buf.readBoolean();
      this.addrem = ByteBufUtils.readUTF8String(buf);
      this.index = buf.readInt();
      }
      
      public void toBytes(ByteBuf buf) 
      {
      ByteBufUtils.writeUTF8String(buf, this.names);
      buf.writeDouble(this.x);
      buf.writeDouble(this.y);
      buf.writeDouble(this.z);
      buf.writeBoolean(this.isBlock2x2);
      ByteBufUtils.writeUTF8String(buf, this.addrem);
      buf.writeInt(this.index);
      }
      
      public static class Handler implements IMessageHandler <packetlistnbt, imessage="">{
      
      public IMessage onMessage(PacketListNBT message, MessageContext ctx) 
      {
      EntityPlayer player = ctx.getServerHandler().player; // GET PLAYER
      World worldIn = player.world; // GET WORLD
      if(message.addrem.equals("add"))
      {
      if(message.isBlock2x2)
      {
      TileEntityBlockVault2by2 te = (TileEntityBlockVault2by2)worldIn.getTileEntity(new BlockPos(message.x, message.y, message.z));
      if(te != null)
      {
      te.setOthers(message.names);
      te.addToMax();
      te.markDirty();
      }
      }
      else
      {
      TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(new BlockPos(message.x, message.y, message.z));
      if(te != null)
      {
      te.setOthers(message.names);
      te.addToMax();
      te.markDirty();
      
      }
      }
      }
      else if(message.addrem.equals("remove"))
      {
      if(message.isBlock2x2)
      {
      TileEntityBlockVault2by2 te = (TileEntityBlockVault2by2)worldIn.getTileEntity(new BlockPos(message.x, message.y, message.z));
      if(te != null)
      {
      te.getOthers().remove(message.index);
      te.removeToMax();
      te.markDirty();
      
      }
      }
      else
      {
      TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(new BlockPos(message.x, message.y, message.z));
      if(te != null)
      {
      te.getOthers().remove(message.index);
      te.removeToMax();
      te.markDirty();
      
      }
      }
      }
      return null;
      }
      }
      }
      
      

      le onBlockActivated avec les tile.markDirty(); qui sont ceux qui crée ce bug/problème…

      @Override
      public boolean onBlockActivated(World worldIn, BlockPos pos,IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
      {
      if(!worldIn.isRemote)
      {
      TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
      if(te != null)
      {
      
      if(te.getOwnerS() != null)
      {
      String checkONBT = te.getOwnerS();
      String checkOBA = playerIn.getUniqueID().toString();
      
      if(checkONBT.equals(checkOBA))
      {
      playerIn.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_NEW, worldIn, pos.getX(), pos.getY(), pos.getZ());
      te.addNumbUse();
      **te.markDirty();**
      }
      else
      {
      for(int i = 0; i < te.getOthers().size(); i++)
      {
      String checkList = te.getOthers().get(i).toString();
      if(playerIn.getName().equals(checkList))
      {
      playerIn.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_NEW, worldIn, pos.getX(), pos.getY(), pos.getZ());
      te.addNumbUse();
      **te.markDirty();**
      }
      }
      }
      
      }
      
      }
      }
               return true;
           }
      

      Merci à ceux qui m’aideront :)</packetlistnbt,>

      Oui ce gif est drôle.

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

        À chaque makeDirty la fonction getUpdatePacket est appelé.
        Celle-ci génère un paquet qui va être envoyé à tous les joueurs proches. Dans ce paquet, tu as un nbt que tu remplis avec la fonction writeToNBT donc avec la liste des joueurs.
        Quand le client reçoit le paquet, il appelle la fonction onDataPacket dans laquelle tu appelles la fonction readFromNBT. Et dans cette dernière tu ajoutes à la liste le contenu que le serveur à écrit.

        Et voila le problème. La liste contenait avant déjà le joueur et cela vient s’ajouter une fois de plus.
        Avec de simple variable ou un tableau il n’y a pas ce problème comme la valeur précédent est écrasé. La ce n’est pas le cas comme tu ajoutes à que fois à la suite.

        Je te laisse réfléchir à comment faire.
        :::

        Pour régler cela tu peux simplement clear le contenu de la liste dans la fonction onDataPacket, avant d’appeler readFromNBT.

        :::

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

          Salut,
          Tu peux envoyer le code du tile entity ?

          1 réponse Dernière réponse Répondre Citer 0
          • Flow
            Flow dernière édition par

            Oui bien sur 🙂 !

            package fr.fifou.economy.blocks.tileentity;
            
            import java.util.ArrayList;
            import java.util.List;
            import java.util.UUID;
            
            import javax.annotation.Nonnull;
            import javax.annotation.Nullable;
            
            import fr.fifou.economy.blocks.BlocksRegistery;
            import fr.fifou.economy.blocks.BlockVault;
            
            import net.minecraft.block.Block;
            import net.minecraft.block.BlockChest;
            import net.minecraft.block.ITileEntityProvider;
            import net.minecraft.block.state.IBlockState;
            import net.minecraft.client.Minecraft;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.entity.player.InventoryPlayer;
            import net.minecraft.init.Blocks;
            import net.minecraft.init.SoundEvents;
            import net.minecraft.inventory.Container;
            import net.minecraft.inventory.ContainerChest;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.inventory.ISidedInventory;
            import net.minecraft.inventory.InventoryLargeChest;
            import net.minecraft.inventory.ItemStackHelper;
            import net.minecraft.item.Item;
            import net.minecraft.item.ItemStack;
            import net.minecraft.nbt.NBTTagCompound;
            import net.minecraft.nbt.NBTTagList;
            import net.minecraft.nbt.NBTTagString;
            import net.minecraft.network.NetworkManager;
            import net.minecraft.network.Packet;
            import net.minecraft.network.play.server.SPacketUpdateTileEntity;
            import net.minecraft.server.MinecraftServer;
            import net.minecraft.tileentity.IHopper;
            import net.minecraft.tileentity.TileEntity;
            import net.minecraft.tileentity.TileEntityChest;
            import net.minecraft.util.EnumFacing;
            import net.minecraft.util.ITickable;
            import net.minecraft.util.NonNullList;
            import net.minecraft.util.SoundCategory;
            import net.minecraft.util.datafix.DataFixer;
            import net.minecraft.util.datafix.FixTypes;
            import net.minecraft.util.datafix.walkers.ItemStackDataLists;
            import net.minecraft.util.math.AxisAlignedBB;
            import net.minecraft.util.math.BlockPos;
            import net.minecraft.world.World;
            import net.minecraftforge.common.capabilities.Capability;
            import net.minecraftforge.common.util.Constants;
            import net.minecraftforge.common.util.Constants.NBT;
            import net.minecraftforge.items.CapabilityItemHandler;
            import net.minecraftforge.items.IItemHandler;
            import net.minecraftforge.items.ItemStackHandler;
            
            public class TileEntityBlockVault extends TileEntity
            {
            ItemStackHandler inventory = new ItemStackHandler(27);
            public String ownerS = "";
            private byte direction;
            private List <string>allowedPlayers = new ArrayList<string>();
            private int maxAllowedPlayers = 0;
            public int numbUse;
            
            public TileEntityBlockVault()
            {
            }
            
            public ItemStackHandler getHandler()
            {
            return inventory;
            }
            
            public TileEntityBlockVault(String ownerData, int numbUse)
            {
            this.ownerS = ownerData;
            this.numbUse = numbUse;
            }
            
            public SPacketUpdateTileEntity getUpdatePacket()
            {
            return new SPacketUpdateTileEntity(this.pos, 1, this.getUpdateTag());
            }
            
            public NBTTagCompound getUpdateTag()
            {
            return this.writeToNBT(new NBTTagCompound());
            }
            
            @Override
            public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
            {
            readFromNBT(pkt.getNbtCompound());
            }
            
            public int getNumbUse()
            {
            return this.numbUse;
            }
            
            public void removeNumbUse()
            {
            this.numbUse = this.numbUse - 1;
            }
            
            public void addNumbUse()
            {
            this.numbUse = this.numbUse + 1;
            }
            
            public void setOwner(String string)
            {
            this.ownerS = string;
            }
            
            public String getOwnerS()
            {
            return this.ownerS;
            }
            
            public Boolean hasItems()
            {
            for(int i = 0; i < 27; i++)
            {
            if(inventory.getStackInSlot(i) != ItemStack.EMPTY)
            {
            return true;
            }
            }
            return false;
            }
            
            public void setOthers(String allowed)
            {
            this.allowedPlayers.add(allowed);
            }
            
            public List getOthers()
            {
            return this.allowedPlayers;
            }
            
            public int getMax()
            {
            return this.maxAllowedPlayers;
            }
            
            public void addToMax()
            {
            this.maxAllowedPlayers = this.maxAllowedPlayers + 1;
            }
            
            public void removeToMax()
            {
            this.maxAllowedPlayers = this.maxAllowedPlayers - 1;
            }
            
            public byte getDirection()
            {
            return this.direction;
            }
            
            public void setDirection(byte direction)
            {
            this.direction = direction;
            }
            
            @Override
            public NBTTagCompound writeToNBT(NBTTagCompound compound)
            {
            compound.setTag("inventory", inventory.serializeNBT());
            compound.setString("ownerS", this.ownerS);
            compound.setByte("direction", this.direction);
            compound.setInteger("maxallowed", this.maxAllowedPlayers);
            compound.setInteger("numbUse", this.numbUse);
            NBTTagList tagList = new NBTTagList();
            for(int i = 0; i < this.allowedPlayers.size(); i++)
            {
            String s = allowedPlayers.get(i);
            if(s != null)
            {
            tagList.appendTag(new NBTTagString(s));
            }
            }
            compound.setTag("allowedList", tagList);
            return super.writeToNBT(compound);
            }
            
            @Override
            public void readFromNBT(NBTTagCompound compound)
            {
            super.readFromNBT(compound);
            inventory.deserializeNBT(compound.getCompoundTag("inventory"));
            this.ownerS = compound.getString("ownerS");
            this.direction = compound.getByte("direction");
            this.maxAllowedPlayers = compound.getInteger("maxallowed");
            this.numbUse = compound.getInteger("numbUse");
            NBTTagList tagList = compound.getTagList("allowedList", NBT.TAG_STRING);
            for(int i = 0; i < tagList.tagCount(); i++)
            {
            this.allowedPlayers.add(i, tagList.getStringTagAt(i));
            }
            }
            
            @Override
            public void markDirty()
            {
            IBlockState state = this.world.getBlockState(getPos());
            this.world.notifyBlockUpdate(getPos(), state, state, 3);
            }
            
            }
            
            ```</string></string>

            Oui ce gif est drôle.

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

              À chaque makeDirty la fonction getUpdatePacket est appelé.
              Celle-ci génère un paquet qui va être envoyé à tous les joueurs proches. Dans ce paquet, tu as un nbt que tu remplis avec la fonction writeToNBT donc avec la liste des joueurs.
              Quand le client reçoit le paquet, il appelle la fonction onDataPacket dans laquelle tu appelles la fonction readFromNBT. Et dans cette dernière tu ajoutes à la liste le contenu que le serveur à écrit.

              Et voila le problème. La liste contenait avant déjà le joueur et cela vient s’ajouter une fois de plus.
              Avec de simple variable ou un tableau il n’y a pas ce problème comme la valeur précédent est écrasé. La ce n’est pas le cas comme tu ajoutes à que fois à la suite.

              Je te laisse réfléchir à comment faire.
              :::

              Pour régler cela tu peux simplement clear le contenu de la liste dans la fonction onDataPacket, avant d’appeler readFromNBT.

              :::

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

              MINECRAFT FORGE FRANCE © 2018

              Powered by NodeBB