Jump to content

Random drops from block


Razor

Recommended Posts

Heyyy, i try to make a block that drops the most of all the items in my mod (~100), but whats the easiest way to do this?

 

Thats my current way, but to much work for all my items..  Anyone an idea?:

 

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        switch(rand.nextInt(6)){
        case 1:
            return Item1;
        case 2:
            return Item2;
        case 3:
            return Item3;
        case 4:
            return Item4;
        case 5:
            return Item5;
        default:
            return Item6;
        }
    }

Link to comment
Share on other sites

You can create a public list in your item registry and add all of your items (at least those you want to be dropped from that item) ot that list while registering them. You can then select a random item from that list. I think it's propably the fastest way.

Link to comment
Share on other sites

11 hours ago, fcelon said:

You can create a public list in your item registry and add all of your items (at least those you want to be dropped from that item) ot that list while registering them. You can then select a random item from that list. I think it's propably the fastest way.

but how i make this without write all the items in

Link to comment
Share on other sites

1 hour ago, Razor said:

but how i make this without write all the items in

You can't. 

At some point, somewhere, you have to specify what you want dropped. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

If you're lazy you can use this to obtain all Items added by your mod. But don't do this every time, do it once and store it in a field

 


List<Item> myItems = ForgeRegistries.ITEMS.getValues().stream()
  .filter(it -> it.getRegistryName().getResourceDomain().equals("yourmod"))
  .collect(Collectors.toList());

Yes, thats what i mean :D         And how can i get a single item for the drop out of this list ?   Sorry i´m new     ^^  

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Ahem.

 

Yes, i tried this:

 

     int index = rand.nextInt(myItems.size());
            Item item = myItems.get(index);
            return item;

 

but the console says:

 

java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: bound must be positive

Link to comment
Share on other sites

  • 2 weeks later...
7 minutes ago, diesieben07 said:

I don't know why. You wrote the code and you have not posted it.

 

public class BlockBox extends Block {
    List<Item> myItems = ForgeRegistries.ITEMS.getValues().stream().filter(it -> it.getRegistryName().getResourceDomain().equals("ageofweapons")).collect(Collectors.toList());

 

    public BlockWeaponBox() {
        super(Material.WOOD);
        this.setCreativeTab(ModTabs.generalTab);
        this.setHardness(0.5F);
        this.setResistance(1.0F);
        this.setSoundType(SoundType.WOOD);       

    }

    
   
    
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
         int index = rand.nextInt(myItems.size());
            Item item = myItems.get(index);
            return item;
        
    }
    
    
   

Link to comment
Share on other sites

You can't put it there, that's why. No items exist when that list is created.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.