Jump to content

How to modify vanilla block drops in 1.12.2?


Jiro7

Recommended Posts

I've been searching about this but all the answers seem to be outdated. I want to change the drops of vanilla blocks. For example, I want Iron Ores to drop a custom item I made instead of the block itself. I also want to change the amount of lapis dropped.

 

I tried handling the BlockEvent.HarvestDropsEvent event, however it doesn't seem to have any method to change the drops nor drop amounts, just to change the drop chances. Any help?

Link to comment
Share on other sites

6 minutes ago, Jiro7 said:

it doesn't seem to have any method to change the drops nor drop amounts

This is not true. BlockEvent.HarvestDropsEvent has a List<ItemStack> that contains all drops. You can access the list with HarvestDropsEvent#getDrops. You can then modify the list's contents as you want.

Link to comment
Share on other sites

13 minutes ago, V0idWa1k3r said:

This is not true. BlockEvent.HarvestDropsEvent has a List<ItemStack> that contains all drops. You can access the list with HarvestDropsEvent#getDrops. You can then modify the list's contents as you want.

Thanks, I managed to make it drop an item. However, there is only one value for drop chances, how can I give each drop on the list its own probability?

So for example I want it to drop between 1-3 iron nuggets and a 10% chance to drop an iron ingot. Is it possible?

Link to comment
Share on other sites

8 minutes ago, Jiro7 said:

I want it to drop between 1-3 iron nuggets and a 10% chance to drop an iron ingot. Is it possible?

Have your random chance happen in the event. Add a new ItemStack to the list that is your nuggets with a count of 1 - 3 based on random number, then check against a random value and if it is within the range you want add an Iron ingot.

drops.add(new ItemStack(Items.IRON_NUGGET, 1 + rand.nextInt(2), 0));
if (rand.nextFloat() <= 0.1F)
{
	drops.add(new ItemStack(Items.IRON_INGOT, 1, 0));
}

 

Link to comment
Share on other sites

24 minutes ago, V0idWa1k3r said:

Have your random chance happen in the event. Add a new ItemStack to the list that is your nuggets with a count of 1 - 3 based on random number, then check against a random value and if it is within the range you want add an Iron ingot.


drops.add(new ItemStack(Items.IRON_NUGGET, 1 + rand.nextInt(2), 0));
if (rand.nextFloat() <= 0.1F)
{
	drops.add(new ItemStack(Items.IRON_INGOT, 1, 0));
}

 

Oh, that was simpler than I thought, thank you.

Link to comment
Share on other sites

  • 7 months later...
On 10/23/2018 at 11:13 PM, V0idWa1k3r said:

Have your random chance happen in the event. Add a new ItemStack to the list that is your nuggets with a count of 1 - 3 based on random number, then check against a random value and if it is within the range you want add an Iron ingot.


drops.add(new ItemStack(Items.IRON_NUGGET, 1 + rand.nextInt(2), 0));
if (rand.nextFloat() <= 0.1F)
{
	drops.add(new ItemStack(Items.IRON_INGOT, 1, 0));
}

 

Where in mod main class should be this function?

Link to comment
Share on other sites

  • 6 months later...
  • Guest locked this topic
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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