Posted August 20, 20178 yr 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; } }
August 20, 20178 yr 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.
August 21, 20178 yr Author 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
August 21, 20178 yr 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.
August 21, 20178 yr Author 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 And how can i get a single item for the drop out of this list ? Sorry i´m new ^^
August 21, 20178 yr Author 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
August 29, 20178 yr Author 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; }
August 29, 20178 yr You can't put it there, that's why. No items exist when that list is created. 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.
August 29, 20178 yr Author 10 minutes ago, Draco18s said: You can't put it there, that's why. No items exist when that list is created. omg it works! thanks guys
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.