MFF

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

    Problème de hammer

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    3 Messages 2 Publieurs 182 Vues 2 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.
    • Ck_LukyC Hors-ligne
      Ck_Luky
      dernière édition par

      Bonjour a tous,
      J’ai récemment créer un hammer qui mine en 3x3x1 sur mon mod,
      mais lorsque je l’utilise il mine tous les blocs, même la bedrock alors que je voudrai qu’il ne puisse miner que la stone.
      J’ai longuement recherché dans la classe de mon hammer sans rien trouver…
      Pourriez vous m’aider ?
      Voici la “fonction” de mon hammer qui lui permet de miner en 3x3x1 ( le reste c’est l’init de l’item et la fonction qui permet de le réparer avec une enclume).

           public RayTraceResult rayTrace(double blockReachDistance, float partialTicks, World w, EntityLivingBase e)
          {
              Vec3d vec3d = e.getPositionEyes(partialTicks);
              Vec3d vec3d1 = e.getLook(partialTicks);
              Vec3d vec3d2 = vec3d.addVector(vec3d1.x * blockReachDistance, vec3d1.y * blockReachDistance, vec3d1.z * blockReachDistance);
              return w.rayTraceBlocks(vec3d, vec3d2, true, false, true);
          }
          @Override
          public boolean onBlockDestroyed(ItemStack breaker, World w, IBlockState state, BlockPos pos, EntityLivingBase e)
          {
              if (e instanceof EntityPlayer && !w.isRemote)
              {
                  EntityPlayer p = (EntityPlayer) e;
                  RayTraceResult r = this.rayTrace(5.0D, 0.0F, w, e);
                  if (r.typeOfHit == RayTraceResult.Type.BLOCK)
                  {
                      int x = pos.getX();
                      int y = pos.getY();
                      int z = pos.getZ();
                      EnumFacing side = r.sideHit;
                      // Y
                      // UP - DOWN
                      if (side == EnumFacing.DOWN || side == EnumFacing.UP)
                      {
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y, z - 1);
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y, z);
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y, z + 1);
                          this.destroyAndDropBlock(w, p, breaker, x, y, z - 1);
                          // Middle block
                          this.destroyAndDropBlock(w, p, breaker, x, y, z + 1);
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y, z - 1);
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y, z);
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y, z + 1);
                      }
                      // Z
                      // NORTH - SOUTH
                      else if (side == EnumFacing.NORTH || side == EnumFacing.SOUTH)
                      {
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y + 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x, y + 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y + 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y, z);
                          // Middle block
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y, z);
                          this.destroyAndDropBlock(w, p, breaker, x + 1, y - 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x, y - 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x - 1, y - 1, z);
                      }
                      // X
                      // EAST - WEST
                      else if (side == EnumFacing.EAST || side == EnumFacing.WEST)
                      {
                          this.destroyAndDropBlock(w, p, breaker, x, y + 1, z + 1);
                          this.destroyAndDropBlock(w, p, breaker, x, y + 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x, y + 1, z - 1);
                          this.destroyAndDropBlock(w, p, breaker, x, y, z + 1);
                          // Middle block
                          this.destroyAndDropBlock(w, p, breaker, x, y, z - 1);
                          this.destroyAndDropBlock(w, p, breaker, x, y - 1, z + 1);
                          this.destroyAndDropBlock(w, p, breaker, x, y - 1, z);
                          this.destroyAndDropBlock(w, p, breaker, x, y - 1, z - 1);
                      }
                      return true;
                  }
              }
              return super.onBlockDestroyed(breaker, w, state, pos, e);
          }
          private void destroyAndDropBlock(World w, EntityPlayer p, ItemStack breaker, int x, int y, int z)
          {
              BlockPos pos = new BlockPos(x, y, z);
              w.getBlockState(pos).getBlock().harvestBlock(w, p, pos, w.getBlockState(pos), w.getTileEntity(pos), breaker);
              w.setBlockToAir(pos);
          }
      

      Merci d’avance, Luky.

      Je travail actuellement sur le Feurimod, un mod à l'origine pour un serveur entre potes en 1.12.2, mais le projet de serveur aillant été abandonné, je le termine pour mon propre plaisir.
      Je suis un membre apprécié et joueur, j'ai déjà obtenu 3 points de réputation.

      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

        Bonjour,
        Dans ta fonction destroyAndDropBlock ajoute une condition vérifiant que `w.getBlockState(pos).getBlockHardness(w, pos) est supérieur à 0.
        Les blocs indestructibles comme la bedrock ont une valeur néfative.

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

          Merci beaucoup @robin4002 ça marche super bien 👍😁

          Voici le code pour ceux qui veulent :

          public RayTraceResult rayTrace(double blockReachDistance, float partialTicks, World w, EntityLivingBase e)
              {
                  Vec3d vec3d = e.getPositionEyes(partialTicks);
                  Vec3d vec3d1 = e.getLook(partialTicks);
                  Vec3d vec3d2 = vec3d.addVector(vec3d1.x * blockReachDistance, vec3d1.y * blockReachDistance, vec3d1.z * blockReachDistance);
                  return w.rayTraceBlocks(vec3d, vec3d2, true, false, true);
              }
              @Override
              public boolean onBlockDestroyed(ItemStack breaker, World w, IBlockState state, BlockPos pos, EntityLivingBase e)
              {
                  if (e instanceof EntityPlayer && !w.isRemote)
                  {
                      EntityPlayer p = (EntityPlayer) e;
                      RayTraceResult r = this.rayTrace(5.0D, 0.0F, w, e);
                      if (r.typeOfHit == RayTraceResult.Type.BLOCK)
                      {
                          int x = pos.getX();
                          int y = pos.getY();
                          int z = pos.getZ();
                          EnumFacing side = r.sideHit;
                          // Y
                          // UP - DOWN
                          if (side == EnumFacing.DOWN || side == EnumFacing.UP)
                          {
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y, z - 1);
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y, z);
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y, z + 1);
                              this.destroyAndDropBlock(w, p, breaker, x, y, z - 1);
                              // Middle block
                              this.destroyAndDropBlock(w, p, breaker, x, y, z + 1);
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y, z - 1);
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y, z);
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y, z + 1);
                          }
                          // Z
                          // NORTH - SOUTH
                          else if (side == EnumFacing.NORTH || side == EnumFacing.SOUTH)
                          {
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y + 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x, y + 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y + 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y, z);
                              // Middle block
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y, z);
                              this.destroyAndDropBlock(w, p, breaker, x + 1, y - 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x, y - 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x - 1, y - 1, z);
                          }
                          // X
                          // EAST - WEST
                          else if (side == EnumFacing.EAST || side == EnumFacing.WEST)
                          {
                              this.destroyAndDropBlock(w, p, breaker, x, y + 1, z + 1);
                              this.destroyAndDropBlock(w, p, breaker, x, y + 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x, y + 1, z - 1);
                              this.destroyAndDropBlock(w, p, breaker, x, y, z + 1);
                              // Middle block
                              this.destroyAndDropBlock(w, p, breaker, x, y, z - 1);
                              this.destroyAndDropBlock(w, p, breaker, x, y - 1, z + 1);
                              this.destroyAndDropBlock(w, p, breaker, x, y - 1, z);
                              this.destroyAndDropBlock(w, p, breaker, x, y - 1, z - 1);
                          }
                          return true;
                      }
                  }
                  return super.onBlockDestroyed(breaker, w, state, pos, e);
              }
              private void destroyAndDropBlock(World w, EntityPlayer p, ItemStack breaker, int x, int y, int z) {
                  BlockPos pos = new BlockPos(x, y, z);
          
                  if (w.getBlockState(pos).getBlockHardness(w, pos) > 0){
                      w.getBlockState(pos).getBlock().harvestBlock(w, p, pos, w.getBlockState(pos), w.getTileEntity(pos), breaker);
                      w.setBlockToAir(pos);
                  }
              }
          

          Je travail actuellement sur le Feurimod, un mod à l'origine pour un serveur entre potes en 1.12.2, mais le projet de serveur aillant été abandonné, je le termine pour mon propre plaisir.
          Je suis un membre apprécié et joueur, j'ai déjà obtenu 3 points de réputation.

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

          MINECRAFT FORGE FRANCE © 2024

          Powered by NodeBB