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

    Résolu NBTTag propre a mon bloc

    1.7.x
    1.7.10
    3
    13
    1775
    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.
    • P
      PlagueZ dernière édition par

      Bonjour,

      j’ai créé un bloc avec des metadata le problème avec ce bloc c’est que les metadata se sauvegarde pour tout les bloc posé et j’aimerai que les metadata de ce bloc soit propre au bloc posé

      Mon code(c’est pas propre c’est en test)

      package virusz.block;
      
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.Entity;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.util.ChatComponentTranslation;
      import net.minecraft.util.EnumChatFormatting;
      import net.minecraft.world.World;
      
      import org.lwjgl.input.Keyboard;
      
      import virusz.core.VirusZCore;
      
      public class BlockSafeZone extends Block
      {
      public static double RADIUS;
      public static String way;
      public static int state;
      public BlockSafeZone(Material par2Material)
      {
      super(par2Material);
      this.setBlockUnbreakable();
      this.setCreativeTab(VirusZCore.Blocks);
      }
      
      @Override
         public boolean isOpaqueCube()
         {
             return true;
         }
      
         @Override
         public boolean renderAsNormalBlock()
         {
             return true;
         }  
         @Override
         public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
         {
      System.out.println(state);
      
         if (!par1World.isRemote)
          {    
          if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
          state++;
      
          switch(state){
          case 1:
          this.way = "left";
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "the way set to: " + way));
          break;
          case 2:
          this.way = "up";
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "the way set to: " + way));
          break;
          case 3:
          this.way = "down";
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "the way set to: " + way));
          break;
          case 4:
          this.way = "right";
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "the way set to: " + way));
          break;
          case 5:
          this.way = "nothing";
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "the way set to: " + way));
          this.state = state-5;
          break;
          }
          System.out.println(state);
          System.out.println(way);
          }
          else if(par5EntityPlayer.capabilities.isCreativeMode){
          if(RADIUS > 50){
          this.RADIUS = RADIUS-50;
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "radius set to: " + RADIUS + " block"));
          }
          else{
          this.RADIUS = RADIUS+5;
          par5EntityPlayer.addChatMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "radius set to: " + RADIUS + " block"));
          }
          }
          }
      
      return true;
      }
         @Override
         public void onEntityWalking(World world, int x, int y, int z, Entity entity){
                 EntityPlayer player = (EntityPlayer)entity;
      
          double X = entity.posX;
          double Y = entity.posY;
          double Z = entity.posZ;
      
          if(way == "right"){
          player.setPosition(X+RADIUS, Y, Z);
          }
          if(way == "left"){
          player.setPosition(X-RADIUS, Y, Z);
          }
          if(way == "up"){
          player.setPosition(X, Y, Z-RADIUS);
          }
          if(way == "down"){
          player.setPosition(X, Y, Z+RADIUS);
          }
         }
         public void writeToNBT(NBTTagCompound nbt)
         {
          nbt.setDouble("radius", RADIUS);
          nbt.setInteger("state", state);
          nbt.setString("way", way);
         }
         public void readFromNBT(NBTTagCompound nbt)
         {
          this.RADIUS = nbt.getDouble("radius");
          this.state = nbt.getInteger("state");
          this.way = nbt.getString("way");
         }
      }
      
      

      Merci d’avance

      “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

        http://www.minecraftforgefrance.fr/showthread.php?tid=1113

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

          On est obliger d’utiliser un TileEntity pour ça je savait pas 😕

          “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

            j’ai un autre probleme j’augmente ma valeur via un void mais dans le guetteur elle ne s actualise pas du coup la partie ou je téléporte mon joueur ne fonctionne plus ou alors elle reste a la valeur de base

            “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

              Code ?

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

                petit édit c’est seulement dans la fonction OnWalking que mon getteur ne fonctionne pas

                c’est toujours aussi sale désolé
                Le TileEntity

                package virusz.tileEntity;
                
                import net.minecraft.nbt.NBTTagCompound;
                import net.minecraft.tileentity.TileEntity;
                
                public class TileEntitySafeZone extends TileEntity {
                
                private double radius = 5;
                private int state;
                
                   public void IncreaseState(){
                    if(state > 3){
                    state = state-4;
                    }else{
                    state++;
                    }
                    System.out.println(state);
                   }
                   public int GetState(){
                    return state;
                   }
                   public void IncreaseRadius(){
                    if(radius > 60){
                    radius = radius-55;
                    }else{
                    radius = radius+5;
                    }
                
                   }
                   public Double GetRadius(){
                    return radius;
                   }
                   @Override
                   public void writeToNBT(NBTTagCompound compound)
                   {
                       super.writeToNBT(compound);
                       compound.setInteger("state", this.state);
                       compound.setDouble("radius", radius);
                   }
                   @Override
                   public void readFromNBT(NBTTagCompound compound)
                   {
                       super.readFromNBT(compound);
                       this.state = compound.getInteger("state");
                       this.radius = compound.getDouble("radius");
                   }
                }
                
                

                }```java
                package virusz.block;

                import net.minecraft.block.Block;
                import net.minecraft.block.material.Material;
                import net.minecraft.entity.Entity;
                import net.minecraft.entity.player.EntityPlayer;
                import net.minecraft.nbt.NBTTagCompound;
                import net.minecraft.tileentity.TileEntity;
                import net.minecraft.util.ChatComponentText;
                import net.minecraft.util.ChatComponentTranslation;
                import net.minecraft.util.EnumChatFormatting;
                import net.minecraft.world.World;

                import org.lwjgl.input.Keyboard;

                import virusz.core.VirusZCore;
                import virusz.tileEntity.TileEntitySafeZone;

                public class BlockSafeZone extends Block
                {
                private String State = “nothing”;
                public BlockSafeZone(Material par2Material)
                {
                super(par2Material);
                this.setBlockUnbreakable();
                this.setCreativeTab(VirusZCore.Blocks);
                }

                @Override
                   public boolean isOpaqueCube()
                   {
                       return true;
                   }

                @Override
                   public boolean renderAsNormalBlock()
                   {
                       return true;
                   }  
                   @Override
                   public TileEntity createTileEntity(World world, int metadata)
                   {
                       return new TileEntitySafeZone();
                   }

                @Override
                   public boolean hasTileEntity(int metadata)
                   {
                       return true;
                   }
                   @Override
                   public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
                   {
                           TileEntity tile = world.getTileEntity(x, y, z);
                           TileEntitySafeZone Tile = (TileEntitySafeZone)tile;
                   if (!world.isRemote){

                if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
                    Tile.IncreaseState();
                        if(Tile.GetState() == 0){
                        this.State = “left”;
                        }
                        if(Tile.GetState() == 1){
                        this.State = “up”;
                        }
                        if(Tile.GetState() == 2){
                        this.State = “Down”;
                        }
                        if(Tile.GetState() == 3){
                        this.State = “Right”;
                        }
                    player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "State set to: " + State + Tile.GetState()));
                    }else{
                    Tile.IncreaseRadius();
                    player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + “radius set to: " + Tile.GetRadius() + " block”));
                    }
                    }

                return true;
                }
                   @Override
                   public void onEntityWalking(World world, int x, int y, int z, Entity entity){
                           EntityPlayer player = (EntityPlayer)entity;
                           TileEntity tile = world.getTileEntity(x, y, z);
                           TileEntitySafeZone Tile = (TileEntitySafeZone)tile;

                double X = entity.posX;
                    double Y = entity.posY;
                    double Z = entity.posZ;
                    double RADIUS = Tile.GetRadius();
                    System.out.println(Tile.GetState());

                if(Tile.GetState() == 0){
                    player.setPosition(X-RADIUS, Y, Z);
                    }
                    if(Tile.GetState() == 1){
                    player.setPosition(X, Y, Z-RADIUS);
                    }
                    if(Tile.GetState() == 2){
                    player.setPosition(X, Y, Z+RADIUS);
                    }
                    if(Tile.GetState() == 3){
                    player.setPosition(X+RADIUS, Y, Z);
                    }

                }
                }

                “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

                  Rajoutes cette ligne à la fin de ta méthode increaseState()
                         this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

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

                    ça fonctionne pas =( la valeur passe a 1 pendant 1s et ensuite repasse a 0

                    le plus fou dans tout ça c est que dans le chat mon guetteur fonctionne c est la la méthode onWalking que tout casse 😕

                    il se passe ça exactement
                    http://puu.sh/jPG5v/19a2fbd7d6.png

                    “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

                      Problème de synchro client serveur sûrement.
                      Par contre ça :

                        if (!world.isRemote){
                         if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
                      

                      ne va jamais fonctionner sur un serveur.
                      Utilises plutôt player.isSneaking() pour la deuxième condition

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

                        je vois pas d’où ça peut venir le probleme de Synchro sachant que mes 2 variable radius et state ont le même probleme

                        “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

                          Et alors, ça n’empêche qu’elles peuvent avoir toutes les 2 un prob de synchro. Normalement ce que je t’ai filé devrait le régler. En tout cas chez moi c’est le cas ^^’

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

                            Il faut ajouter ça dans le tile entity d’abord :

                            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());
                            }
                            
                            1 réponse Dernière réponse Répondre Citer 0
                            • P
                              PlagueZ dernière édition par

                              je me disait bien que j avait oublier un truc merci de votre aide 😉

                              “Imagination is more important than knowledge. For knowledge is limited to all we now know and understand, while imagination embraces the entire wo…

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

                              MINECRAFT FORGE FRANCE © 2018

                              Powered by NodeBB