Navigation

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    SOLVED Caisse avec key random

    1.7.x
    1.7.10
    2
    6
    1057
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • darkvince37
      darkvince37 last edited by

      Bonjour,

      J’ai créer une caise qui s’ouvre avec une key sauf que je voudrai faire que certain objet soit plus dure a avoir avec un taux de pourcentage

      package fr.darkvince.ultrav2.cassefauchon;
      
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      import fr.darkvince.ultrav2.Main;
      
      import java.util.Random;
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.enchantment.Enchantment;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.init.Items;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemStack;
      import net.minecraft.world.World;
      
      public class CasseFauchon
        extends Block
      {
        private Item[] Tableau;
      
        public CasseFauchon(Material p_i45394_1_)
        {
          super(p_i45394_1_);
        }
      
        public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
        {
          if ((p_149727_5_.getHeldItem() != null) && (p_149727_5_.getHeldItem().getItem() == Main.KeyFauchon))
          {
            Random rand = new Random();
            p_149727_5_.inventory.decrStackSize(p_149727_5_.inventory.currentItem, 1).copy();
            ItemStack[] prices = { new ItemStack(Main.bootsLinarite, 0), new ItemStack(Items.coal, 64), new ItemStack(Main.GemMineraiLinarite, 2), new ItemStack(Main.GemMineraiPyrite, 3), new ItemStack(Main.helmetPyrite, 1), new ItemStack(Main.GemMineraiLinarite, 12), new ItemStack(Main.helmetIridium, 1), new ItemStack(Items.book, 1), new ItemStack(Main.GemMineraiPyrite, 16), new ItemStack(Main.swordIridium, 1)  };
      
           /* prices[0].addEnchantment(Enchantment.protection, 4);
            prices[0].addEnchantment(Enchantment.unbreaking, 3);
            prices[1].addEnchantment(Enchantment.protection, 4);
            prices[1].addEnchantment(Enchantment.unbreaking, 3);
            prices[2].addEnchantment(Enchantment.protection, 2);
            prices[2].addEnchantment(Enchantment.unbreaking, 1);
            prices[3].addEnchantment(Enchantment.protection, 4);
            prices[3].addEnchantment(Enchantment.unbreaking, 2);
            prices[5].addEnchantment(Enchantment.power, 4);
            prices[5].addEnchantment(Enchantment.infinity, 1);
            prices[6].addEnchantment(Enchantment.sharpness, 4);
            prices[6].addEnchantment(Enchantment.fireAspect, 1);*/
            prices[7].addEnchantment(Enchantment.protection, 4);
           /* prices[10].addEnchantment(Enchantment.sharpness, 4);
            prices[10].addEnchantment(Enchantment.knockback, 2);
            prices[12].addEnchantment(Enchantment.sharpness, 5);
            */
            ItemStack price = prices[rand.nextInt(prices.length)];
            p_149727_5_.inventory.addItemStackToInventory(price.copy());
          }
          return true;
        }
      
        @SideOnly(Side.CLIENT)
        public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
        {
          for (int l = 0; l < 5; l++)
          {
            double d6 = p_149734_2_ + p_149734_5_.nextFloat();
            double d1 = p_149734_3_ + p_149734_5_.nextFloat();
            d6 = p_149734_4_ + p_149734_5_.nextFloat();
            double d3 = 0.0D;
            double d4 = 0.0D;
            double d5 = 0.0D;
            int i1 = p_149734_5_.nextInt(2) * 2 - 1;
            int j1 = p_149734_5_.nextInt(2) * 2 - 1;
            d3 = (p_149734_5_.nextFloat() - 0.5D) * 0.2D;
            d4 = (p_149734_5_.nextFloat() - 0.5D) * 0.2D;
            d5 = (p_149734_5_.nextFloat() - 0.5D) * 0.2D;
            double d2 = p_149734_4_ + 0.5D + 0.25D * j1;
            d5 = p_149734_5_.nextFloat() * 1.0F * j1;
            double d0 = p_149734_2_ + 0.5D + 0.25D * i1;
            d3 = p_149734_5_.nextFloat() * 1.0F * i1;
            p_149734_1_.spawnParticle("portal", d0, d1, d2, d3, d4, d5);
          }
        }
      }
      
      
      1 Reply Last reply Reply Quote 0
      • robin4002
        robin4002 Administrateurs Rédacteurs Moddeurs confirmés last edited by

        Salut,
        Une question similaire a déjà été posé dans le passé.
        Il faut appliquer un poids à chaque item stack, minecraft a déjà ce qu’il faut avec net.minecraft.util.WeightedRandom

        1 Reply Last reply Reply Quote 0
        • darkvince37
          darkvince37 last edited by

          @‘robin4002’:

          Salut,
          Une question similaire a déjà été posé dans le passé.
          Il faut appliquer un poids à chaque item stack, minecraft a déjà ce qu’il faut avec net.minecraft.util.WeightedRandom

          Ok merci, je suis tombé sur sa https://www.minecraftforgefrance.fr/showthread.php?tid=3016&highlight=pourcentage se qui est se que je voudrai mais mettre plusieurs fois la même chose on c’est pas exactement le top sauf si j’en mais 100 se qui est long.

          “Il faut appliquer un poids à chaque item stack”

          Je veut bien essayé je voie pas j’ai était voir dans la classe j’ai trouvé sa en rapport avec le poids.

            public static WeightedRandom.Item getRandomItem(Random p_76273_0_, Collection p_76273_1_, int p_76273_2_)
              {
                  if (p_76273_2_ <= 0)
                  {
                      throw new IllegalArgumentException();
                  }
                  return getItem(p_76273_1_, p_76273_0_.nextInt(p_76273_2_));
              }
          
              //Forge: Added to allow custom random implementations, Modder is responsible for making sure the 
              //'weight' is under the totalWeight of the items.
              public static WeightedRandom.Item getItem(Collection par1Collection, int weight)
              {
                  {
                      int j = weight;
                      Iterator iterator = par1Collection.iterator();
                      WeightedRandom.Item item;
          
                      do
                      {
                          if (!iterator.hasNext())
                          {
                              return null;
                          }
          
                          item = (WeightedRandom.Item)iterator.next();
                          j -= item.itemWeight;
                      }
                      while (j >= 0);
          
                      return item;
                  }
              }
          

          Mais comment l’adapté au code

          1 Reply Last reply Reply Quote 0
          • robin4002
            robin4002 Administrateurs Rédacteurs Moddeurs confirmés last edited by

            WeightedRandomChestContent[] items = new WeightedRandomChestContent[]{new WeightedRandomChestContent(ItemStack, min, max, poids), etc …};
            WeightedRandomChestContent item = (WeightedRandomChestContent)WeightedRandom.getRandomItem(rand, items);

            Et tu peux récupérer l’itemstack avec item.theItemId, le min avec item.theMinimumChanceToGenerateItem et le max avec item.theMaximumChanceToGenerateItem

            Tu peux utiliser WeightedRandomFishable au lieu de WeightedRandomChestContent si tu ne veux pas mettre de min / max

            1 Reply Last reply Reply Quote 0
            • darkvince37
              darkvince37 last edited by

              Merci beaucoup sa marche

                public boolean onBlockActivated(World world, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
                {
                  if ((p_149727_5_.getHeldItem() != null) && (p_149727_5_.getHeldItem().getItem() == Main.KeyFauchon))
                  {
                    Random rand = new Random();
                    p_149727_5_.inventory.decrStackSize(p_149727_5_.inventory.currentItem, 1).copy();
                /*    ItemStack[] gris = { new ItemStack(Main.bootsLinarite, 1), new ItemStack(Items.coal, 64), new ItemStack(Main.GemMineraiLinarite, 2) };
                    ItemStack[] bleu = { new ItemStack(Main.GemMineraiPyrite, 3), new ItemStack(Main.helmetPyrite, 1), new ItemStack(Main.GemMineraiLinarite, 12)};
                    ItemStack[] rouge = { new ItemStack(Main.helmetIridium, 1), new ItemStack(Items.book, 1), new ItemStack(Main.GemMineraiPyrite, 16)  };
                    ItemStack[] jaune = { new ItemStack(Main.swordIridium, 1)  };*/
                    WeightedRandomChestContent[] items = new WeightedRandomChestContent[]{new WeightedRandomChestContent(new ItemStack (Main.bootsLinarite), 1, 1, 10), new WeightedRandomChestContent(new ItemStack (Items.coal), 32, 64, 90)};
                    WeightedRandomChestContent item = (WeightedRandomChestContent)WeightedRandom.getRandomItem(rand, items);
              
                   // rouge[1].addEnchantment(Enchantment.protection, 4);
              
                       WeightedRandomChestContent price = items[rand.nextInt(items.length)];
                        p_149727_5_.inventory.addItemStackToInventory(item.theItemId, item.theMinimumChanceToGenerateItem, item.theMaximumChanceToGenerateItem);
              
                  }
                  return true;
                }
              

              sauf ici y une erreur ```java
                   p_149727_5_.inventory.addItemStackToInventory(item.theItemId, item.theMinimumChanceToGenerateItem, item.theMaximumChanceToGenerateItem);

              1 Reply Last reply Reply Quote 0
              • robin4002
                robin4002 Administrateurs Rédacteurs Moddeurs confirmés last edited by

                int count = item.theMinimumChanceToGenerateItem+ (rand.nextInt(item.theMaximumChanceToGenerateItem - item.theMinimumChanceToGenerateItem + 1));
                p_149727_5_.inventory.addItemStackToInventory(new ItemStack(item.theItemId.getItem(), count);

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Design by Woryk
                Contact / Mentions Légales / Faire un don

                MINECRAFT FORGE FRANCE © 2018

                Powered by NodeBB