Jump to content

[1.10] Get drops when a BlockBreakHandler is used


dakamojo

Recommended Posts

My machine harvests the drop from a block without breaking it.  I'm using Block#getDrops to figure out what drops from each block.  However, some blocks implement a BlockBreakHandler (TechReborn for oreRuby is an example).  The drops from this are not getting return in getDrops.  How should I be getting the drops from a block as if it were broken?

Link to comment
Share on other sites

BlockBreakHandler is not a Forge or vanilla class.

 

We need details.

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

My bad.  I guess the correct thing to say is a class that is registered for the HarvestDropsEvent event.

 

MinecraftForge.EVENT_BUS.register(new BlockBreakHandler());

 

public class BlockBreakHandler {


	@SubscribeEvent
	public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) {
		if (!event.isSilkTouching() && OreDictUtils.isOre(event.getState(), "oreRuby")) {
			event.getDrops().add(ItemGems.getGemByName("red_garnet").copy());
		}
	}
}

 

Link to comment
Share on other sites

Events are fired across each mod in succession meaning that if you handle the event after another mod then you will have access to any changes it made to the drops for that event. A lot of people don't realize that you can change the priority of your subscribe so that it processes after or before other mods -- or at least has a better chance to (if other mod also sets the priority then it is a matter of which mod loads first I think so you would have to control the order the mods actually load).

 

So in your case you want it to load after. Plus you need to handle the case where the previous mod tries to cancel the event (which would normally prevent you from getting it) using the receive cancelled option.

 

Simply create an event handler annotated with @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

 

In that you can grab the event.getDrops() and do something with it.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Event event = new BlockEvent.HarvestDropsEvent(...);
MinecraftForge.EVENT_BUS.fire(event);
event.getDrops()

 

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:

A less accurate way is to call Block::getDrops and then fire the event manually, but I don't recommend that.

Whiiiich is what I suggested...

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

uh.png

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

I was pointing out how to fire the event, not providing the entire solution

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

5 hours ago, diesieben07 said:

What are you doing...

 

If you truly want to capture a block's drops, you will need to use internal mechanics. 

You will need to call Block::dropBlockAsItemWithChance. That however spawns entities directly into the world, so you need to use the captureDrops method in Block, which is protected, but can be accessed with some tricks.

 

I don't think you read the OP's problem carefully. He's not worried about vanilla blocks, he's handled that. He's worried about other mods that manipulate drops in the harvest event.

 

So I think you need to process the event further (as the methods you mentioned aren't relevant) after the other mod's manipulation.

 

I would basically find all the other mods' blocks in the registry and do a sort of test where I take a location in the world and during one tick successively place each block then break them and handle the harvest event with the low priority and receive canceled annotation I suggested.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.