MFF

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

    Une clef pour une porte .

    Planifier Épinglé Verrouillé Déplacé Résolu 1.8.x
    1.8
    46 Messages 7 Publieurs 9.6k 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.
    • GabsG Hors-ligne
      Gabs
      dernière édition par

      @‘BrokenSwing’:

      InteractEvent + onItemRightClick de ta clé

      D’acc par contre j’ai un soucis la:

      
      @SubscribeEvent
      public void onBlockInteract(PlayerInteractEvent event)
      {
      ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
      System.out.println("");
      
      if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack != null && stack.getItem() == Main.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door) 
      {
      System.out.println("Clic droit sur un bloc en fer avec une clef !");
      }
      }
      

      Normal que dans la console j’ai pas le second print ?

      Alors que je clic droit avec ma clef sur une porte en fer.

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

        @‘BrokenSwing’:

        InteractEvent + onItemRightClick de ta clé

        Ok,
        Donc une fois que j’ai ça:

        
        @SubscribeEvent
        public void onBlockInteract(PlayerInteractEvent event)
        {
        ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
        
        if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door) 
        {
        
        System.out.println("Clic droit sur un bloc en fer avec une clef !");
        }
        }
        

        et ça:

        
            public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
            {
            System.out.println("clic droit clef");
                return stack;
            }
        
        

        Je vois pas comment utiliser les UUID pour la clef je dois procédé comment ?

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

          N’utilise pas les UUID, en fait je me suis trompé, pas de onItemRightClick, ça sert à rien. Juste quand tu fais un clique sur la porte il faut que :

          • Tu vérifie si la clef possède un NBT, si elle n’en a pas tu lui en ajoute un
          • Si tu viens juste de rajouté le tag NBT tu inscrit dedans les coordonnées de la porte
          • Si elle avais déjà un NBT avec des coordonnées de porte tu regarde si elles correspondent avec la porte sur laquelle a cliqué le joueur, si c’est le cas tu ouvre la porte

          EDIT : Après il faudra que tu stock côté serveur les coordonnées des porte qui ont déjà un clé pour qu’on ne puisse pas faire plusieurs clés d’une même porte + enregistrer ses coordonnées dans les tags NBT du monde. Quand le joueur fera un clique droit sur la porte avec une nouvelle clé, il faudra que tu vérifie si la porte n’as pas déjà une clé.

          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

            Salut,
            Je pense qu’il faut que tu fasse une porte custom car tu n’as aucun moyen de stocker la clé dans le tile entité de la porte (à vérifier).

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

              @‘BrokenSwing’:

              N’utilise pas les UUID, en fait je me suis trompé, pas de onItemRightClick, ça sert à rien. Juste quand tu fais un clique sur la porte il faut que :

              • Tu vérifie si la clef possède un NBT, si elle n’en a pas tu lui en ajoute un
              • Si tu viens juste de rajouté le tag NBT tu inscrit dedans les coordonnées de la porte
              • Si elle avais déjà un NBT avec des coordonnées de porte tu regarde si elles correspondent avec la porte sur laquelle a cliqué le joueur, si c’est le cas tu ouvre la porte

              EDIT : Après il faudra que tu stock côté serveur les coordonnées des porte qui ont déjà un clé pour qu’on ne puisse pas faire plusieurs clés d’une même porte + enregistrer ses coordonnées dans les tags NBT du monde. Quand le joueur fera un clique droit sur la porte avec une nouvelle clé, il faudra que tu vérifie si la porte n’as pas déjà une clé.

              D’acc,

              Le truc c’est comment je fais pour récupéré les coords de la porte en fer ?

              
              @SubscribeEvent
              public void onBlockInteract(PlayerInteractEvent event)
              {
              ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
              
              if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door) 
              {
              if(!stack.hasTagCompound())
              {
              stack.setTagCompound(new NBTTagCompound());
              stack.getTagCompound().setLong("porte", "X: " + pos.getX() + " Y: " + pos.getY() + " Z: " + pos.getZ()); // ici les coords je fais comment ???
              
              }
              System.out.println(stack.getTagCompound().getLong("porte"));
              
              System.out.println("Clic droit sur un bloc en fer avec une clef !");
              }
              }
              

              @Robin Sur ? au pire pas grave j’en créer une je vais voir ^^ c’est compliqué a faire ??

              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

                En fait non, ce que BrokenSwing a proposé fonctionnera.
                Et dans je ne sais plus quelle version de forge ils ont ajoutés une fonction pour get un tag custom qui est enregistré dans le tile entity.
                Donc regardes si tu as une fonction du genre getCustomTag dans la classe tile entity, si c’est le cas ça va simplifier les choses car tu aura juste à stocker une clé dans le tile entity et une dans le tag de l’item.

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

                  @‘robin4002’:

                  En fait non, ce que BrokenSwing a proposé fonctionnera.
                  Et dans je ne sais plus quelle version de forge ils ont ajoutés une fonction pour get un tag custom qui est enregistré dans le tile entity.
                  Donc regardes si tu as une fonction du genre getCustomTag dans la classe tile entity, si c’est le cas ça va simplifier les choses car tu aura juste à stocker une clé dans le tile entity et une dans le tag de l’item.

                  Nan 😞

                  
                  package net.minecraft.tileentity;
                  
                  import com.google.common.collect.Maps;
                  import java.util.Map;
                  import java.util.concurrent.Callable;
                  import net.minecraft.block.Block;
                  import net.minecraft.block.BlockJukebox;
                  import net.minecraft.block.state.IBlockState;
                  import net.minecraft.crash.CrashReportCategory;
                  import net.minecraft.init.Blocks;
                  import net.minecraft.nbt.NBTTagCompound;
                  import net.minecraft.network.Packet;
                  import net.minecraft.util.BlockPos;
                  import net.minecraft.world.World;
                  import net.minecraftforge.fml.relauncher.Side;
                  import net.minecraftforge.fml.relauncher.SideOnly;
                  import org.apache.logging.log4j.LogManager;
                  import org.apache.logging.log4j.Logger;
                  
                  public abstract class TileEntity
                  {
                      private static final Logger logger = LogManager.getLogger();
                      /** A HashMap storing string names of classes mapping to the actual java.lang.Class type. */
                      private static Map nameToClassMap = Maps.newHashMap();
                      /** A HashMap storing the classes and mapping to the string names (reverse of nameToClassMap). */
                      private static Map classToNameMap = Maps.newHashMap();
                      /** the instance of the world the tile entity is in. */
                      protected World worldObj;
                      protected BlockPos pos;
                      protected boolean tileEntityInvalid;
                      private int blockMetadata;
                      /** the Block type that this TileEntity is contained within */
                      protected Block blockType;
                      private static final String __OBFID = "CL_00000340";
                  
                      public TileEntity()
                      {
                          this.pos = BlockPos.ORIGIN;
                          this.blockMetadata = -1;
                      }
                  
                      /**
                       * Adds a new two-way mapping between the class and its string name in both hashmaps.
                       */
                      public static void addMapping(Class cl, String id)
                      {
                          if (nameToClassMap.containsKey(id))
                          {
                              throw new IllegalArgumentException("Duplicate id: " + id);
                          }
                          else
                          {
                              nameToClassMap.put(id, cl);
                              classToNameMap.put(cl, id);
                          }
                      }
                  
                      /**
                       * Returns the worldObj for this tileEntity.
                       */
                      public World getWorld()
                      {
                          return this.worldObj;
                      }
                  
                      /**
                       * Sets the worldObj for this tileEntity.
                       */
                      public void setWorldObj(World worldIn)
                      {
                          this.worldObj = worldIn;
                      }
                  
                      /**
                       * Returns true if the worldObj isn't null.
                       */
                      public boolean hasWorldObj()
                      {
                          return this.worldObj != null;
                      }
                  
                      public void readFromNBT(NBTTagCompound compound)
                      {
                          this.pos = new BlockPos(compound.getInteger("x"), compound.getInteger("y"), compound.getInteger("z"));
                      }
                  
                      public void writeToNBT(NBTTagCompound compound)
                      {
                          String s = (String)classToNameMap.get(this.getClass());
                  
                          if (s == null)
                          {
                              throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!");
                          }
                          else
                          {
                              compound.setString("id", s);
                              compound.setInteger("x", this.pos.getX());
                              compound.setInteger("y", this.pos.getY());
                              compound.setInteger("z", this.pos.getZ());
                          }
                      }
                  
                      /**
                       * Creates a new entity and loads its data from the specified NBT.
                       */
                      public static TileEntity createAndLoadEntity(NBTTagCompound nbt)
                      {
                          TileEntity tileentity = null;
                  
                          Class oclass = null;
                          try
                          {
                              oclass = (Class)nameToClassMap.get(nbt.getString("id"));
                  
                              if (oclass != null)
                              {
                                  tileentity = (TileEntity)oclass.newInstance();
                              }
                          }
                          catch (Exception exception)
                          {
                              exception.printStackTrace();
                          }
                  
                          if (tileentity != null)
                          {
                              tileentity.readFromNBT(nbt);
                          }
                          else
                          {
                              try
                              {
                              logger.warn("Skipping BlockEntity with id " + nbt.getString("id"));
                              }
                              catch (Exception ex)
                              {
                                  net.minecraftforge.fml.common.FMLLog.log(org.apache.logging.log4j.Level.ERROR, ex,
                                          "A TileEntity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author",
                                          nbt.getString("id"), oclass.getName());
                                  tileentity = null;
                              }
                          }
                  
                          return tileentity;
                      }
                  
                      public int getBlockMetadata()
                      {
                          if (this.blockMetadata == -1)
                          {
                              IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
                              this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate);
                          }
                  
                          return this.blockMetadata;
                      }
                  
                      /**
                       * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
                       * hasn't changed and skip it.
                       */
                      public void markDirty()
                      {
                          if (this.worldObj != null)
                          {
                              IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
                              this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate);
                              this.worldObj.markChunkDirty(this.pos, this);
                  
                              if (this.getBlockType() != Blocks.air)
                              {
                                  this.worldObj.updateComparatorOutputLevel(this.pos, this.getBlockType());
                              }
                          }
                      }
                  
                      /**
                       * Returns the square of the distance between this entity and the passed in coordinates.
                       */
                      public double getDistanceSq(double x, double y, double z)
                      {
                          double d3 = (double)this.pos.getX() + 0.5D - x;
                          double d4 = (double)this.pos.getY() + 0.5D - y;
                          double d5 = (double)this.pos.getZ() + 0.5D - z;
                          return d3 * d3 + d4 * d4 + d5 * d5;
                      }
                  
                      @SideOnly(Side.CLIENT)
                      public double getMaxRenderDistanceSquared()
                      {
                          return 4096.0D;
                      }
                  
                      public BlockPos getPos()
                      {
                          return this.pos;
                      }
                  
                      /**
                       * Gets the block type at the location of this entity (client-only).
                       */
                      public Block getBlockType()
                      {
                          if (this.blockType == null)
                          {
                              this.blockType = this.worldObj.getBlockState(this.pos).getBlock();
                          }
                  
                          return this.blockType;
                      }
                  
                      /**
                       * Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
                       * server to the client easily. For example this is used by signs to synchronise the text to be displayed.
                       */
                      public Packet getDescriptionPacket()
                      {
                          return null;
                      }
                  
                      public boolean isInvalid()
                      {
                          return this.tileEntityInvalid;
                      }
                  
                      /**
                       * invalidates a tile entity
                       */
                      public void invalidate()
                      {
                          this.tileEntityInvalid = true;
                      }
                  
                      /**
                       * validates a tile entity
                       */
                      public void validate()
                      {
                          this.tileEntityInvalid = false;
                      }
                  
                      public boolean receiveClientEvent(int id, int type)
                      {
                          return false;
                      }
                  
                      public void updateContainingBlockInfo()
                      {
                          this.blockType = null;
                          this.blockMetadata = -1;
                      }
                  
                      public void addInfoToCrashReport(CrashReportCategory reportCategory)
                      {
                          reportCategory.addCrashSectionCallable("Name", new Callable()
                          {
                              private static final String __OBFID = "CL_00000341";
                              public String call()
                              {
                                  return (String)TileEntity.classToNameMap.get(TileEntity.this.getClass()) + " // " + TileEntity.this.getClass().getCanonicalName();
                              }
                          });
                  
                          if (this.worldObj != null)
                          {
                              CrashReportCategory.addBlockInfo(reportCategory, this.pos, this.getBlockType(), this.getBlockMetadata());
                              reportCategory.addCrashSectionCallable("Actual block type", new Callable()
                              {
                                  private static final String __OBFID = "CL_00000343";
                                  public String call()
                                  {
                                      int i = Block.getIdFromBlock(TileEntity.this.worldObj.getBlockState(TileEntity.this.pos).getBlock());
                  
                                      try
                                      {
                                          return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(i), Block.getBlockById(i).getUnlocalizedName(), Block.getBlockById(i).getClass().getCanonicalName()});
                                      }
                                      catch (Throwable throwable)
                                      {
                                          return "ID #" + i;
                                      }
                                  }
                              });
                              reportCategory.addCrashSectionCallable("Actual block data value", new Callable()
                              {
                                  private static final String __OBFID = "CL_00000344";
                                  public String call()
                                  {
                                      IBlockState iblockstate = TileEntity.this.worldObj.getBlockState(TileEntity.this.pos);
                                      int i = iblockstate.getBlock().getMetaFromState(iblockstate);
                  
                                      if (i < 0)
                                      {
                                          return "Unknown? (Got " + i + ")";
                                      }
                                      else
                                      {
                                          String s = String.format("%4s", new Object[] {Integer.toBinaryString(i)}).replace(" ", "0");
                                          return String.format("%1$d / 0x%1$X / 0b%2$s", new Object[] {Integer.valueOf(i), s});
                                      }
                                  }
                              });
                          }
                      }
                  
                      public void setPos(BlockPos posIn)
                      {
                          this.pos = posIn;
                      }
                  
                      static
                      {
                          addMapping(TileEntityFurnace.class, "Furnace");
                          addMapping(TileEntityChest.class, "Chest");
                          addMapping(TileEntityEnderChest.class, "EnderChest");
                          addMapping(BlockJukebox.TileEntityJukebox.class, "RecordPlayer");
                          addMapping(TileEntityDispenser.class, "Trap");
                          addMapping(TileEntityDropper.class, "Dropper");
                          addMapping(TileEntitySign.class, "Sign");
                          addMapping(TileEntityMobSpawner.class, "MobSpawner");
                          addMapping(TileEntityNote.class, "Music");
                          addMapping(TileEntityPiston.class, "Piston");
                          addMapping(TileEntityBrewingStand.class, "Cauldron");
                          addMapping(TileEntityEnchantmentTable.class, "EnchantTable");
                          addMapping(TileEntityEndPortal.class, "Airportal");
                          addMapping(TileEntityCommandBlock.class, "Control");
                          addMapping(TileEntityBeacon.class, "Beacon");
                          addMapping(TileEntitySkull.class, "Skull");
                          addMapping(TileEntityDaylightDetector.class, "DLDetector");
                          addMapping(TileEntityHopper.class, "Hopper");
                          addMapping(TileEntityComparator.class, "Comparator");
                          addMapping(TileEntityFlowerPot.class, "FlowerPot");
                          addMapping(TileEntityBanner.class, "Banner");
                      }
                  
                      // – BEGIN FORGE PATCHES --
                      /**
                       * Called when you receive a TileEntityData packet for the location this
                       * TileEntity is currently in. On the client, the NetworkManager will always
                       * be the remote server. On the server, it will be whomever is responsible for
                       * sending the packet.
                       *
                       * @param net The NetworkManager the packet originated from
                       * @param pkt The data packet
                       */
                      public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.S35PacketUpdateTileEntity pkt)
                      {
                      }
                  
                      /**
                       * Called when the chunk this TileEntity is on is Unloaded.
                       */
                      public void onChunkUnload()
                      {
                      }
                  
                      private boolean isVanilla = getClass().getName().startsWith("net.minecraft.");
                      /**
                       * Called from Chunk.setBlockIDWithMetadata, determines if this tile entity should be re-created when the ID, or Metadata changes.
                       * Use with caution as this will leave straggler TileEntities, or create conflicts with other TileEntities if not used properly.
                       *
                       * @param world Current world
                       * @param pos Tile's world position
                       * @param oldID The old ID of the block
                       * @param newID The new ID of the block (May be the same)
                       * @return True to remove the old tile entity, false to keep it in tact {and create a new one if the new values specify to}
                       */
                      public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
                      {
                          return !isVanilla || (oldState.getBlock() != newSate.getBlock());
                      }
                  
                      public boolean shouldRenderInPass(int pass)
                      {
                          return pass == 0;
                      }
                  
                      /**
                       * Sometimes default render bounding box: infinite in scope. Used to control rendering on {@link TileEntitySpecialRenderer}.
                       */
                      public static final net.minecraft.util.AxisAlignedBB INFINITE_EXTENT_AABB = new net.minecraft.util.AxisAlignedBB(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
                      /**
                       * Return an {@link AxisAlignedBB} that controls the visible scope of a {@link TileEntitySpecialRenderer} associated with this {@link TileEntity}
                       * Defaults to the collision bounding box {@link Block#getCollisionBoundingBoxFromPool(World, int, int, int)} associated with the block
                       * at this location.
                       *
                       * @return an appropriately size {@link AxisAlignedBB} for the {@link TileEntity}
                       */
                      @SideOnly(Side.CLIENT)
                      public net.minecraft.util.AxisAlignedBB getRenderBoundingBox()
                      {
                          net.minecraft.util.AxisAlignedBB bb = INFINITE_EXTENT_AABB;
                          Block type = getBlockType();
                          if (type == Blocks.enchanting_table)
                          {
                              bb = new net.minecraft.util.AxisAlignedBB(getPos(), getPos().add(1, 1, 1));
                          }
                          else if (type == Blocks.chest || type == Blocks.trapped_chest)
                          {
                              bb = new net.minecraft.util.AxisAlignedBB(getPos().add(-1, 0, -1), getPos().add(2, 2, 2));
                          }
                          else if (type != null && type != Blocks.beacon)
                          {
                              net.minecraft.util.AxisAlignedBB cbb = null;
                              try
                              {
                                  cbb = type.getCollisionBoundingBox(worldObj, getPos(), worldObj.getBlockState(getPos()));
                              }
                              catch (Exception e)
                              {
                                  // We have to capture any exceptions that may occur here because BUKKIT servers like to send
                                  // the tile entity data BEFORE the chunk data, you know, the OPPOSITE of what vanilla does!
                                  // So we can not GARENTEE that the world state is the real state for the block...
                                  // So, once again in the long line of US having to accommodate BUKKIT breaking things,
                                  // here it is, assume that the TE is only 1 cubic block. Problem with this is that it may
                                  // cause the TileEntity renderer to error further down the line! But alas, nothing we can do.
                                  cbb = new net.minecraft.util.AxisAlignedBB(getPos().add(-1, 0, -1), getPos().add(1, 1, 1));
                              }
                              if (cbb != null) bb = cbb;
                          }
                          return bb;
                      }
                  
                      /**
                       * Checks if this tile entity knows how to render its 'breaking' overlay effect.
                       * If this returns true, The TileEntitySpecialRenderer will be called again with break progress set.
                       * @return True to re-render tile with breaking effect.
                       */
                      public boolean canRenderBreaking()
                      {
                          Block block = this.getBlockType();
                          return (block instanceof net.minecraft.block.BlockChest ||
                                  block instanceof net.minecraft.block.BlockEnderChest ||
                                  block instanceof net.minecraft.block.BlockSign ||
                                  block instanceof net.minecraft.block.BlockSkull);
                      }
                  }
                  
                  1 réponse Dernière réponse Répondre Citer 0
                  • BrokenSwingB Hors-ligne
                    BrokenSwing Moddeurs confirmés Rédacteurs
                    dernière édition par

                    De toute façon la porte n’a pas de TE, non ?

                    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

                      Ah oui mince x)

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

                        @‘BrokenSwing’:

                        De toute façon la porte n’a pas de TE, non ?

                        Exact ^^ x)

                        Du coup pour get les coords de la porte en fer je fais comment ?

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

                          Tu dois avoir event.pos qui donne la position, et faut que tu crée les clés en te basant soit sur le morceau du bas, soit le morceau du haut

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

                            @‘BrokenSwing’:

                            Tu dois avoir event.pos qui donne la position, et faut que tu crée les clés en te basant soit sur le morceau du bas, soit le morceau du haut

                            J’ai fais ça:

                            
                            @SubscribeEvent
                            public void onBlockInteract(PlayerInteractEvent event)
                            {
                            ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                            
                            BlockPos pos = event.pos;
                            
                            if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door) 
                            {
                            if(!stack.hasTagCompound())
                            {
                            stack.setTagCompound(new NBTTagCompound());
                            stack.getTagCompound().setLong("porte", pos.getX() + pos.getY() + pos.getZ());
                            
                            }
                            System.out.println(stack.getTagCompound().getLong("porte"));
                            
                            System.out.println("Clic droit sur un bloc en fer avec une clef !");
                            }
                            }
                            

                            Le truc c’est que le print m’envoie 23 quelque soit la position de la porte.

                            et j’ai pas compris ça: et faut que tu crée les clés en te basant soit sur le morceau du bas, soit le morceau du haut

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

                              Non, met les coordonnées une à une dans les NBT, sinon de clés vont pouvoir marcher sur de certaines portes alors qu’elles devraient pas.

                              
                              nbt.setInt("x", pos.getX());
                              nbt.setInt("y", pos.getY());
                              nbt.setInt("z", pos.getZ());
                              
                              

                              Et après il faut que tu stock les coordonnées dans une liste.
                              En gros quand tu fais clique-droit sur la porte, si c’est la partie basse tu aura (par exemple) x=0;y=1;z=0 et si tu cliques sur la partie haute x=0;y=2;z=0 ce qui est différent, tu dois donc vérifier quelle partie de la porte est cliquée et en fonction de cela rajouter 1 à la coord y ou ne rien faire (si on choisi de prendre la partie basse comme référence)

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

                                @‘BrokenSwing’:

                                Non, met les coordonnées une à une dans les NBT, sinon de clés vont pouvoir marcher sur de certaines portes alors qu’elles devraient pas.

                                
                                nbt.setInt("x", pos.getX());
                                nbt.setInt("y", pos.getY());
                                nbt.setInt("z", pos.getZ());
                                
                                

                                Et après il faut que tu stock les coordonnées dans une liste.
                                En gros quand tu fais clique-droit sur la porte, si c’est la partie basse tu aura (par exemple) x=0;y=1;z=0 et si tu cliques sur la partie haute x=0;y=2;z=0 ce qui est différent, tu dois donc vérifier quelle partie de la porte est cliquée et en fonction de cela rajouter 1 à la coord y ou ne rien faire (si on choisi de prendre la partie basse comme référence)

                                Ah oui exact c’est un bloc de deux de hauteur je vais prendre le bas comme ça je me casse pas la tête a ajouter 1 a chaque fois je vais voir comment faut faire pour vérifier la partie haute ou basse.

                                J’ai fais ça:

                                
                                @SubscribeEvent
                                public void onBlockInteract(PlayerInteractEvent event)
                                {
                                ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                                
                                if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door) 
                                {
                                if(!stack.hasTagCompound())
                                {
                                stack.setTagCompound(new NBTTagCompound());
                                stack.getTagCompound().setInteger("x", event.pos.getX());
                                stack.getTagCompound().setInteger("y", event.pos.getY());
                                stack.getTagCompound().setInteger("z", event.pos.getZ());
                                
                                }
                                System.out.println(stack.getTagCompound().getLong("x"));
                                System.out.println(stack.getTagCompound().getLong("y"));
                                System.out.println(stack.getTagCompound().getLong("z"));
                                
                                System.out.println("Clic droit sur un bloc en fer avec une clef !");
                                }
                                }
                                

                                ça me return 0 0 0 en x y z c’est pas bon j’ai dus me tromper.

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

                                  “setInteger”, “getLong”, c’est pas le même type de tag (int != long) donc il te retourne 0, la valeur par défaut.
                                  Et je ne veux pas être méchant, mais des fois tu ne cherches pas assez toi-même la solution de tes problèmes.

                                  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
                                  • GabsG Hors-ligne
                                    Gabs
                                    dernière édition par

                                    @‘AymericRed’:

                                    “setInteger”, “getLong”, c’est pas le même type de tag (int != long) donc il te retourne 0, la valeur par défaut.
                                    Et je ne veux pas être méchant, mais des fois tu ne cherches pas assez toi-même la solution de tes problèmes.

                                    Tu as raison j’avais pas fais attention mais c’est pareil ça return 0 aussi
                                    edit:

                                    C’est bon ! x) pour les coords

                                    EDIT:

                                    Alors,

                                    J’ai fais ça:

                                    
                                    public ArrayList <integer>array = new ArrayList();
                                    
                                    @SubscribeEvent
                                    public void onBlockInteract(PlayerInteractEvent event)
                                    {
                                    ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                                    
                                    BlockPos pos = event.pos;
                                    if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door && event.pos.getY() == 66) 
                                    {
                                    if(!stack.hasTagCompound())
                                    {
                                    stack.setTagCompound(new NBTTagCompound());
                                    }
                                    
                                    stack.getTagCompound().setInteger("x", event.pos.getX());
                                    stack.getTagCompound().setInteger("y", event.pos.getY());
                                    stack.getTagCompound().setInteger("z", event.pos.getZ());
                                    
                                    System.out.println(stack.getTagCompound().getInteger("x"));
                                    System.out.println(stack.getTagCompound().getInteger("y"));
                                    System.out.println(stack.getTagCompound().getInteger("z"));
                                    
                                    array.add(stack.getTagCompound().getInteger("x"));
                                    array.add(stack.getTagCompound().getInteger("y"));
                                    array.add(stack.getTagCompound().getInteger("z"));
                                    
                                    if(stack.hasTagCompound() && stack.getTagCompound().getInteger("x") && …) // ici j'ai une érreur du coup
                                    {
                                    
                                    }
                                    
                                    System.out.println("Clic droit sur un bloc en fer avec une clef !");
                                    }
                                    }
                                    

                                    J’ai stocké les coords dans une array.

                                    @Broken quand tu me dis: [font=Ubuntu, sans-serifSi elle avais déjà un NBT avec des coordonnées de porte tu regarde si elles correspondent avec la porte sur laquelle a cliqué le joueur, si c’est le cas tu ouvre la porte.]

                                    [font=Ubuntu, sans-serifLe truc c’est que dans le if je peux pas mettre un boolean (en l’occurrence stack.hasTagCompound()) et un int (stack.getTagCompound().getInteger(“x”)) donc je fais comment ? :x]

                                    [font=Ubuntu, sans-serifmerci 🙂
                                    ]</integer>

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • Benjamin LoisonB Hors-ligne
                                      Benjamin Loison
                                      dernière édition par

                                      Si j’étais toi je ferai,

                                      if(nbt == null)
                                      {
                                      // Aucune donnée attribuée, on met les coordonnées
                                      nbt.setInteger(X);
                                      nbt.setInteger(Y);
                                      nbt.setInteger(Z);
                                      }
                                      else if(nbt.get(X) == event.posX && …)
                                      {
                                      // Tu ouvres la porte
                                      }
                                      else
                                      {
                                      // Tu n'as pas accès à cette porte !
                                      }
                                      

                                      En espérant que ça t’ai fais comprendre la structure de sa pensée, si je ne me suis pas troimpé.

                                      Ps 1: Le code est fictif hein ^^
                                      Ps 2: Je n’ai pas compris pourquoi tu as crée une ArrayList sachant que get directement le nbt est plus court et si tu veux tester avec l’autre bloc (du haut ou du bas ou les 2), tu enregistres juste le x dans un int et la même chose pour y, z 😉

                                      >! Développeur de Altis-Life (Arma III) sur Minecraft !
                                      >! Site web     : https://lemnoslife.com

                                      1 réponse Dernière réponse Répondre Citer 1
                                      • GabsG Hors-ligne
                                        Gabs
                                        dernière édition par

                                        @‘Benjamin Loison’:

                                        Si j’étais toi je ferai,

                                        if(nbt == null)
                                        {
                                           // Aucune donnée attribuée, on met les coordonnées
                                           nbt.setInteger(X);
                                           nbt.setInteger(Y);
                                           nbt.setInteger(Z);
                                        }
                                        else if(nbt.get(X) == event.posX && …)
                                        {
                                           // Tu ouvres la porte
                                        }
                                        else
                                        {
                                           // Tu n'as pas accès à cette porte !
                                        }
                                        

                                        En espérant que ça t’ai fais comprendre la structure de sa pensée, si je ne me suis pas troimpé.

                                        Ps 1: Le code est fictif hein ^^
                                        Ps 2: Je n’ai pas compris pourquoi tu as crée une ArrayList sachant que get directement le nbt est plus court et si tu veux tester avec l’autre bloc (du haut ou du bas ou les 2), tu enregistres juste le x dans un int et la même chose pour y, z 😉

                                        Ah je vois ok merci :),

                                        Juste pour ouvrir la porte je fais comment ? x)

                                        et j’ai créer un array car on me la demander enfin du moins se que j’ai compris: [font=Ubuntu, sans-serifAprès il faudra que tu stock côté serveur les coordonnées des porte qui ont déjà un clé pour qu’on ne puisse pas faire plusieurs clés d’une même porte + enregistrer ses coordonnées dans les tags NBT du monde. Quand le joueur fera un clique droit sur la porte avec une nouvelle clé, il faudra que tu vérifie si la porte n’as pas déjà une clé.]
                                        [font=Ubuntu, sans-serifVoilà pourquoi ^^ mais quand il dit:  enregistrer ses coordonnées dans les tags NBT du monde,]

                                        [font=Ubuntu, sans-serifC’est ou exactement ? ]

                                        [font=Ubuntu, sans-serifJ’ai fais ça du coup je pense que c’est mieux garce à toi benjamin :)]

                                        
                                        [font=Ubuntu, sans-serifpublic ArrayList <integer>array = new ArrayList();
                                        
                                        @SubscribeEvent
                                        public void onBlockInteract(PlayerInteractEvent event)
                                        {
                                        ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                                        NBTTagCompound nbt = stack.getTagCompound();
                                        
                                        BlockPos pos = event.pos;
                                        if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door && event.pos.getY() == 66) 
                                        {
                                        if(!stack.hasTagCompound())
                                        {
                                        stack.setTagCompound(new NBTTagCompound());
                                        }
                                        if(!event.world.isRemote && stack.hasTagCompound())
                                        {
                                        array.add(nbt.getInteger("x"));
                                        array.add(nbt.getInteger("y"));
                                        array.add(nbt.getInteger("z"));
                                        }
                                        
                                        if(nbt == null)
                                        {
                                        stack.getTagCompound().setInteger("x", event.pos.getX());
                                        stack.getTagCompound().setInteger("y", event.pos.getY());
                                        stack.getTagCompound().setInteger("z", event.pos.getZ());
                                        }
                                        else if(nbt.getInteger("x") == event.pos.getX() && nbt.getInteger("y") == event.pos.getY() && nbt.getInteger("z") == event.pos.getZ())
                                        {
                                        System.out.println("Ouverture de la porte");
                                        }
                                        else
                                        {
                                        System.out.println("Vous n'avez pas accès à cette porte!");
                                        }
                                        
                                        System.out.println(stack.getTagCompound().getInteger("x"));
                                        System.out.println(stack.getTagCompound().getInteger("y"));
                                        System.out.println(stack.getTagCompound().getInteger("z"));
                                        
                                        System.out.println("Clic droit sur un bloc en fer avec une clef !");
                                        }
                                        }]
                                        
                                        

                                        Le problème est que je peux toujours créer deux clés sur la même porte se qui est normal car il faut que j’enregistre les [font=Ubuntu, sans-serifenregistrer ses coordonnées dans les tags NBT du monde.]
                                        [font=Ubuntu, sans-serifEt aussi pour prendre le haut ou le bas de la porte je fais comment appart ça  event.pos.getY() == 66)  car bon si c’est pas un monde plat …]
                                        [font=Ubuntu, sans-serifMerci ! 😉
                                        ]</integer>

                                        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

                                          Mettre x, y, z comme ceci dans ton array n’est pas vraiment une bonne idée.
                                          Il faudrait plutôt créer un objet contenant l’id de la dimension, x, y et z puis mettre cette objet dans l’array. Ou faire un tableau de 4 int.

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

                                            @‘robin4002’:

                                            Mettre x, y, z comme ceci dans ton array n’est pas vraiment une bonne idée.
                                            Il faudrait plutôt créer un objet contenant l’id de la dimension, x, y et z puis mettre cette objet dans l’array. Ou faire un tableau de 4 int.

                                            Comme ça ?

                                            
                                            public static ArrayList <object>array = new ArrayList();
                                            
                                            @SubscribeEvent
                                            public void onBlockInteract(PlayerInteractEvent event)
                                            {
                                            ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                                            NBTTagCompound nbt = stack.getTagCompound();
                                            BlockPos pos = event.pos;
                                            if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && stack.getItem() == CSCItems.clef && event.world.getBlockState(event.pos).getBlock() == Blocks.iron_door && event.pos.getY() == 66) 
                                            {
                                            if(!stack.hasTagCompound())
                                            {
                                            stack.setTagCompound(new NBTTagCompound());
                                            }
                                            
                                            if(nbt == null)
                                            {
                                            stack.getTagCompound().setInteger("x", event.pos.getX());
                                            stack.getTagCompound().setInteger("y", event.pos.getY());
                                            stack.getTagCompound().setInteger("z", event.pos.getZ());
                                            }
                                            else if(nbt.getInteger("x") == event.pos.getX() && nbt.getInteger("y") == event.pos.getY() && nbt.getInteger("z") == event.pos.getZ())
                                            {
                                            System.out.println("Ouverture de la porte");
                                            }
                                            else
                                            {
                                            System.out.println("Vous n'avez pas accès à cette porte!");
                                            }
                                            Object obj = new Object[] {event.world.provider.getDimensionId(), nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z")};
                                            
                                            if(!event.world.isRemote && stack.hasTagCompound())
                                            {
                                            array.add(obj);
                                            }
                                            
                                            System.out.println(stack.getTagCompound().getInteger("x"));
                                            System.out.println(stack.getTagCompound().getInteger("y"));
                                            System.out.println(stack.getTagCompound().getInteger("z"));
                                            
                                            }
                                            }
                                            
                                            

                                            edit crash avec une nouvelle clés:

                                            
                                            [13:52:04] [Server thread/INFO]: Player48 vient d'obtenir le succès [Faire l'inventaire]
                                            [13:52:04] [Client thread/INFO]: [CHAT] Player48 vient d'obtenir le succès [Faire l'inventaire]
                                            [13:52:19] [Server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.player.PlayerInteractEvent@1260ee5:
                                            java.lang.NullPointerException
                                            at com.CSC.net.Events.Events.onBlockInteract(Events.java:72) ~[Events.class:?]
                                            at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_Events_onBlockInteract_PlayerInteractEvent.invoke(.dynamic) ~[?:?]
                                            at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) ~[ASMEventHandler.class:?]
                                            at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?]
                                            at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract(ForgeEventFactory.java:119) [ForgeEventFactory.class:?]
                                            at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:452) [ItemInWorldManager.class:?]
                                            at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:624) [NetHandlerPlayServer.class:?]
                                            at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:67) [C08PacketPlayerBlockPlacement.class:?]
                                            at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:114) [C08PacketPlayerBlockPlacement.class:?]
                                            at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) [PacketThreadUtil$1.class:?]
                                            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_45]
                                            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
                                            at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) [FMLCommonHandler.class:?]
                                            at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
                                            at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?]
                                            at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [IntegratedServer.class:?]
                                            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
                                            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
                                            [13:52:19] [Server thread/ERROR] [FML]: Index: 1 Listeners:
                                            [13:52:19] [Server thread/ERROR] [FML]: 0: NORMAL
                                            [13:52:19] [Server thread/ERROR] [FML]: 1: ASM: com.CSC.net.Events.Events@1a4c99c onBlockInteract(Lnet/minecraftforge/event/entity/player/PlayerInteractEvent;)V
                                            [13:52:19] [Server thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
                                            java.util.concurrent.ExecutionException: java.lang.NullPointerException
                                            at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_45]
                                            at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_45]
                                            at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:710) [FMLCommonHandler.class:?]
                                            at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
                                            at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?]
                                            at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [IntegratedServer.class:?]
                                            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
                                            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
                                            Caused by: java.lang.NullPointerException
                                            at com.CSC.net.Events.Events.onBlockInteract(Events.java:72) ~[Events.class:?]
                                            at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_Events_onBlockInteract_PlayerInteractEvent.invoke(.dynamic) ~[?:?]
                                            at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) ~[ASMEventHandler.class:?]
                                            at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]
                                            at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract(ForgeEventFactory.java:119) ~[ForgeEventFactory.class:?]
                                            at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:452) ~[ItemInWorldManager.class:?]
                                            at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:624) ~[NetHandlerPlayServer.class:?]
                                            at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:67) ~[C08PacketPlayerBlockPlacement.class:?]
                                            at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:114) ~[C08PacketPlayerBlockPlacement.class:?]
                                            at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?]
                                            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_45]
                                            at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_45]
                                            at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?]
                                            … 5 more
                                            
                                            ```</object>
                                            1 réponse Dernière réponse Répondre Citer 0
                                            • 1
                                            • 2
                                            • 3
                                            • 3 / 3
                                            • Premier message
                                              Dernier message
                                            Design by Woryk
                                            ContactMentions Légales

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB