MFF

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

    Xp drop et faire drop en plus avec fortune

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    11 Messages 4 Publieurs 3.0k 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.
    • MursaatM Hors-ligne
      Mursaat
      dernière édition par

      Si tu es en version 1.8 le code de BlockOre c’est ça :

      package net.minecraft.block;
      
      import java.util.Random;
      import net.minecraft.block.material.Material;
      import net.minecraft.block.state.IBlockState;
      import net.minecraft.creativetab.CreativeTabs;
      import net.minecraft.init.Blocks;
      import net.minecraft.init.Items;
      import net.minecraft.item.EnumDyeColor;
      import net.minecraft.item.Item;
      import net.minecraft.util.BlockPos;
      import net.minecraft.util.MathHelper;
      import net.minecraft.world.IBlockAccess;
      import net.minecraft.world.World;
      
      public class BlockOre extends Block
      {
         private static final String __OBFID = "CL_00000282";
      
         public BlockOre()
         {
             super(Material.rock);
             this.setCreativeTab(CreativeTabs.tabBlock);
         }
      
         /**
          * Get the Item that this Block should drop when harvested.
          *  
          * @param fortune the level of the Fortune enchantment on the player's tool
          */
         public Item getItemDropped(IBlockState state, Random rand, int fortune)
         {
             return this == Blocks.coal_ore ? Items.coal : (this == Blocks.diamond_ore ? Items.diamond : (this == Blocks.lapis_ore ? Items.dye : (this == Blocks.emerald_ore ? Items.emerald : (this == Blocks.quartz_ore ? Items.quartz : Item.getItemFromBlock(this)))));
         }
      
         /**
          * Returns the quantity of items to drop on block destruction.
          */
         public int quantityDropped(Random random)
         {
             return this == Blocks.lapis_ore ? 4 + random.nextInt(5) : 1;
         }
      
         /**
          * Get the quantity dropped based on the given fortune level
          */
         public int quantityDroppedWithBonus(int fortune, Random random)
         {
             if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState)this.getBlockState().getValidStates().iterator().next(), random, fortune))
             {
                 int j = random.nextInt(fortune + 2) - 1;
      
                 if (j < 0)
                 {
                     j = 0;
                 }
      
                 return this.quantityDropped(random) * (j + 1);
             }
             else
             {
                 return this.quantityDropped(random);
             }
         }
      
         /**
          * Spawns this Block's drops into the World as EntityItems.
          *  
          * @param chance The chance that each Item is actually spawned (1.0 = always, 0.0 = never)
          * @param fortune The player's fortune level
          */
         public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
         {
             super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
         }
         @Override
         public int getExpDrop(IBlockAccess world, BlockPos pos, int fortune)
         {
             IBlockState state = world.getBlockState(pos);
             Random rand = world instanceof World ? ((World)world).rand : new Random();
             if (this.getItemDropped(state, rand, fortune) != Item.getItemFromBlock(this))
             {
                 int j = 0;
      
                 if (this == Blocks.coal_ore)
                 {
                     j = MathHelper.getRandomIntegerInRange(rand, 0, 2);
                 }
                 else if (this == Blocks.diamond_ore)
                 {
                     j = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                 }
                 else if (this == Blocks.emerald_ore)
                 {
                     j = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                 }
                 else if (this == Blocks.lapis_ore)
                 {
                     j = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                 }
                 else if (this == Blocks.quartz_ore)
                 {
                     j = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                 }
      
                 return j;
             }
             return 0;
         }
      
         public int getDamageValue(World worldIn, BlockPos pos)
         {
             return 0;
         }
      
         /**
          * Get the damage value that this Block should drop
          */
         public int damageDropped(IBlockState state)
         {
             return this == Blocks.lapis_ore ? EnumDyeColor.BLUE.getDyeDamage() : 0;
         }
      }
      

      Et plus précisement ce que tu cherche ça doit être les fonctions

      public int getExpDrop(IBlockAccess world, BlockPos pos, int fortune)
      ``` Pour l'xp
      ```java
      public int quantityDroppedWithBonus(int fortune, Random random)
      ``` Pour le drop
      1 réponse Dernière réponse Répondre Citer 0
      • T Hors-ligne
        Teko
        dernière édition par

        OK merci j’ai oublier préciser ma version 1.7

        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

          C’est pour ça que les balises de versions existes et que le règlement de la section dit qu’il faut les utiliser …
          En 1.7 c’est presque la même chose, va voir la classe BlockOres.

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

            @Override
            public int getExpDrop(IBlockAccess world, BlockPos pos, int fortune)
            {
            if (this.getItemDropped(state, rand, fortune) != Item.getItemFromBlock(this))
            {
            int j1 = 0;
            
            if (this == Blocks.coal_ore)
            {
            j1 = MathHelper.getRandomIntegerInRange(rand, 0, 2);
            }
            else if (this == Blocks.diamond_ore)
            {
            j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
            }
            else if (this == Blocks.emerald_ore)
            {
            j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
            }
            else if (this == Blocks.lapis_ore)
            {
            j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
            }
            else if (this == Blocks.quartz_ore)
            {
            j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
            }
            
            return j1;
            }
            return 0;
            }
            

            C’est comme sa que je dois le coder ? car sa me met des erreurs. x)

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

              Tu utilise une variable rand qui n’existe pas dans ton code.
              D’ailleurs si ta classe te sert juste pour un bloc tu peux virer tout les “if (this == Blocks.xxx)” et juste faire un return MathHelper.getRandomIntegerInRange(rand, a, b);

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

                actuellement j’ai des erreurs sur le BlockPos pos, et state.

                private Random rand = new Random();
                @Override
                public int getExpDrop(IBlockAccess world, BlockPos pos, int fortune)
                {
                
                if (this.getItemDropped(state, rand, fortune) != Item.getItemFromBlock(this))
                {
                int j1 = 0;
                
                if (this == Blocks.coal_ore)
                {
                j1 = MathHelper.getRandomIntegerInRange(rand, 0, 2);
                }
                else if (this == Blocks.diamond_ore)
                {
                j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                }
                else if (this == Blocks.emerald_ore)
                {
                j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                }
                else if (this == Blocks.lapis_ore)
                {
                j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                }
                else if (this == Blocks.quartz_ore)
                {
                j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                }
                
                return j1;
                }
                return 0;
                }
                

                J’ai beau chercher, recopier le code blockOre impossible d’enlever ce rouge u_U x)

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

                  Normal, les BlockPos sont utilisés en 1.8, il faut utiliser des type primitifs : int x, int y, int z.

                  Petit conseil : fait Alt + shift + s puis “override or implement methods” et choisis getExpDrop, ça te permettra d’éviter les erreurs de ré-écriture de fonctions.

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

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

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

                    @‘robin4002’:

                    En 1.7 c’est presque la même chose, va voir la classe BlockOres.

                    Allons voir cette classe. Je la copie/colle et je te commente tout :

                    package net.minecraft.block;
                    
                    import java.util.Random;
                    import net.minecraft.block.material.Material;
                    import net.minecraft.creativetab.CreativeTabs;
                    import net.minecraft.init.Blocks;
                    import net.minecraft.init.Items;
                    import net.minecraft.item.Item;
                    import net.minecraft.util.MathHelper;
                    import net.minecraft.world.IBlockAccess;
                    import net.minecraft.world.World;
                    
                    public class BlockOre extends Block // déclaration de la classe
                    {
                    private static final String __OBFID = "CL_00000282"; // identificateur pour Forge Gradle, ce code ne sert que à la compilation pour Forge gradle, ça ne sert à rien de le copier
                    
                    public BlockOre()
                    {
                    super(Material.rock);
                    this.setCreativeTab(CreativeTabs.tabBlock);
                    }
                    
                    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) // la fonction qui défini quel item il faut dropper
                    {
                    return this == Blocks.coal_ore ? Items.coal : (this == Blocks.diamond_ore ? Items.diamond : (this == Blocks.lapis_ore ? Items.dye : (this == Blocks.emerald_ore ? Items.emerald : (this == Blocks.quartz_ore ? Items.quartz : Item.getItemFromBlock(this)))));
                    }
                    
                    /**
                    * Returns the quantity of items to drop on block destruction.
                    */
                    public int quantityDropped(Random p_149745_1_) // la quantité à dropper
                    {
                    return this == Blocks.lapis_ore ? 4 + p_149745_1_.nextInt(5) : 1;
                    }
                    
                    /**
                    * Returns the usual quantity dropped by the block plus a bonus of 1 to 'i' (inclusive).
                    */
                    public int quantityDroppedWithBonus(int p_149679_1_, Random p_149679_2_) // la quantité à dropper avec fortune
                    {
                    if (p_149679_1_ > 0 && Item.getItemFromBlock(this) != this.getItemDropped(0, p_149679_2_, p_149679_1_)) // on n'applique pas fortune si l'item droppé est le bloc lui même (fer, or)
                    {
                    int j = p_149679_2_.nextInt(p_149679_1_ + 2) - 1;
                    
                    if (j < 0)
                    {
                    j = 0;
                    }
                    
                    return this.quantityDropped(p_149679_2_) * (j + 1);
                    }
                    else
                    {
                    return this.quantityDropped(p_149679_2_);
                    }
                    }
                    
                    /**
                    * Drops the block items with a specified chance of dropping the specified items
                    */
                    public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
                    {
                    super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, p_149690_7_);
                    }
                    
                    private Random rand = new Random();
                    @Override
                    public int getExpDrop(IBlockAccess p_149690_1_, int p_149690_5_, int p_149690_7_) // la quantité d'xp à dropper
                    {
                    if (this.getItemDropped(p_149690_5_, rand, p_149690_7_) != Item.getItemFromBlock(this)) // on ne drop pas d'xp si l'item droppé est le bloc lui même (fer, or)
                    {
                    int j1 = 0;
                    
                    if (this == Blocks.coal_ore)
                    {
                    j1 = MathHelper.getRandomIntegerInRange(rand, 0, 2);
                    }
                    else if (this == Blocks.diamond_ore)
                    {
                    j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                    }
                    else if (this == Blocks.emerald_ore)
                    {
                    j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
                    }
                    else if (this == Blocks.lapis_ore)
                    {
                    j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                    }
                    else if (this == Blocks.quartz_ore)
                    {
                    j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
                    }
                    
                    return j1;
                    }
                    return 0;
                    }
                    
                    /**
                    * Determines the damage on the item the block drops. Used in cloth and wood.
                    */
                    public int damageDropped(int p_149692_1_) // metadata de l'item droppé
                    {
                    return this == Blocks.lapis_ore ? 4 : 0;
                    }
                    }
                    

                    Donc pour toi les fonctions à reprendre sont :

                    private Random rand = new Random();
                    @Override
                    public int getExpDrop(IBlockAccess world, int metadata, int fortune)
                    {
                    return MathHelper.getRandomIntegerInRange(rand, minimum, maximum);
                    }
                    
                    public int quantityDroppedWithBonus(int fortune, Random rand)
                    {
                    if (fortune > 0)
                    {
                    int j = rand.nextInt(fortune + 2) - 1;
                    
                    if (j < 0)
                    {
                    j = 0;
                    }
                    
                    return this.quantityDropped(rand) * (j + 1);
                    }
                    else
                    {
                    return this.quantityDropped(rand);
                    }
                    }
                    
                    public Item getItemDropped(int metadata, Random rand, int fortune)
                    {
                    return TaClassePrincipale.l'itemÀdropper;
                    }
                    
                    1 réponse Dernière réponse Répondre Citer 0
                    • T Hors-ligne
                      Teko
                      dernière édition par

                      Ok bah je vous merci à tous car ça a marcher et merci pour le ALT+Shift+S vraiment utile o !

                      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

                        Si c’est résolu n’oublies pas de mettre la balise résolu.

                        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