Jump to content

[1.12.2] Block Break Event Post [SOLVED]


Krevik

Recommended Posts

Hello! I want to affect entities (items) that are dropped after block breaking with certain tool. I found only BlockBreakEvent which is called just before block is breaked so I cannot affect dropped items. What can I do? Is there some other event?

Edited by Krevik
Link to comment
Share on other sites

I think there’s an onHarvest (or something similar) event. There might also be a getDrops event?

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

HarvestDropsEvent can be used to change the drops of a block.

Okay so I was trying, but the events doesn't seems to be working. Forge version: 2747. Method: 

Spoiler

	@SubscribeEvent
	public void blockBreakEvent(BlockEvent.HarvestDropsEvent event) {
		System.out.println("fired1");
		EntityPlayer breaker = event.getHarvester();
		List<ItemStack> items=event.getDrops();
		ItemStack heldStack = breaker.getHeldItemMainhand();
		Item heldItem = heldStack.getItem();
		System.out.println("fired2");
		if(!breaker.world.isRemote) {
    		System.out.println("!remote");
			if(heldItem.equals(KCore.Magnethium_Axe)) {
        		System.out.println("equals1");
				event.setDropChance(0);
				event.setCanceled(true);
        		System.out.println("equals2");
				for(int c=0;c<items.size();c++) {
					ItemStack itemStack=items.get(c);
					EntityItem currentItem=new 	EntityItem(breaker.world,event.getPos().getX()+0.5,event.getPos().getY()+0.5,event.getPos().getZ()+0.5,itemStack);
					breaker.world.spawnEntity(currentItem);
	        		currentItem.motionX=breaker.posX-currentItem.posX;
	        		currentItem.motionY=breaker.posY-currentItem.posY;
	        		currentItem.motionZ=breaker.posZ-currentItem.posZ;
	        		System.out.println("for");
				}
			}
		}
	}

 

No word is fired in console so it looks like the event isn't fired. Also I have another events in the same class and another are working

Link to comment
Share on other sites

How are you registering your event handler class?

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

2 minutes ago, Draco18s said:

How are you registering your event handler class?

      

     @Mod.EventHandler
    public void postInit(FMLPostInitializationEvent e) {
        MinecraftForge.EVENT_BUS.register(KathairisEventsHandler.class);
    }

in the post init method of main mod class, but I don't think that matters cause another events in the same class are working
 

Edited by Krevik
update
Link to comment
Share on other sites

The method isn't static and it needs to be if you are registering it like that.

  • Thanks 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

You need to remove the existing drops and add the new ones to the list.

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

You shouldn't be doing that anway.

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.