Jump to content

[1.14.4] Applying Fortune enchantment to BreakEvent


norquisd

Recommended Posts

Hi, so I am making a mod that functions as a hammer, such that when 1 block is mined all blocks in a square around it also break (3X3X1). I'd like if the enchantment on the tool I use effects how many, say, diamonds drop when a diamond block is broken. Right now, with the following code (similar in y and z directions) in my Hammer class:

	         Vec3d facing = entityLiving.getLookVec();
	         double faceX= facing.getX();
	         double faceY= facing.getY();
	         double faceZ= facing.getZ();
	         int posX=pos.getX();
	         int posY=pos.getY();
	         int posZ=pos.getZ();
	         PlayerEntity player = (PlayerEntity) entityLiving;
	         if((Math.abs(faceX))>=(Math.abs(faceY))&&(Math.abs(faceX))>=(Math.abs(faceZ))){
	        	 for(int i=-1; i<=1; i++) {
	        		 for(int j=-1; j<=1;j++) {
	        			 BlockPos newPos= new BlockPos(posX, posY+i, posZ+j);
	        			 BreakEvent b = new BreakEvent(worldIn, newPos, state, player);
	        			 player.giveExperiencePoints(b.getExpToDrop());
	        			 MinecraftForge.EVENT_BUS.register(b);
	        			 BlockState blS = worldIn.getBlockState(newPos);
	        			 Block bl = blS.getBlock();
	        			 if (bl!=Blocks.BEDROCK) {
		        			 worldIn.destroyBlock(newPos, true);
	        				}	        	
	        			 }
	        		 }
	        	 }

I have it so it does break said blocks, and will give the player the right amount of exp. However, If fortune 3 is applied to the hammer, I'd like for all the blocks in the mined area to function as though they were mined with a fortune 3 pickaxe. I looked at the HarvestBlockEvent subclass, but there were no methods with which I can spawn any entities. How should I go about this? (Also, if I could spawn the exp as the orbs that you would get when breaking a block in vanilla, rather than directly adding exp, that would be a nice addon). Thanks!

Link to comment
Share on other sites

4 hours ago, norquisd said:

MinecraftForge.EVENT_BUS.register(b);

This doesn't do what you're trying to make it do.

 

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 minutes ago, norquisd said:

I don't really know what I am trying to make that do to be honest, I just figured it was good practice to register your events.

Yes, but you aren't passing in an event handler class, you're passing in an event.

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

3 minutes ago, norquisd said:

How do I pass an event then?

MinecraftForge.EVENT_BUS.post

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, norquisd said:

how this helps me

It doesn't help you. It's meant to help you be compatible with other mods.

 

The best way to do what you are trying to do I think would be to cast the player to ServerPlayerEntity then get the PlayerInteractionManager field(interactionManager) and call PlayerInteractionManager#tryHarvestBlock(BlockPos)

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

You shouldn't be making your item work from inside an event. You don't need an event, you can just override the method in the 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

12 minutes ago, Draco18s said:

You don't need an event, you can just override the method in the class....

That's what he is doing.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Are we sure about that? Because he's never posted the full class. Or even the method signature of where his code is located.

And there's NO way he could get an infinite loop unless he was firing a BreakEvent from within a BreakEvent.

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

6 hours ago, Draco18s said:

And there's NO way he could get an infinite loop unless he was firing a BreakEvent from within a BreakEvent.

Yes there is.

 

19 hours ago, Animefan8888 said:

PlayerInteractionManager#tryHarvestBlock(BlockPos)

Calls Item#onBlockDestroyed so by calling it from Item#onBlockDestroyed it loops recursively. 

 

6 hours ago, Draco18s said:

Are we sure about that? 

I am at least 95% sure because this is the same guy whom you and I helped a few days ago. Where you told him to use Item#onBlockDestroyed and I stepped him through ray tracing to get the side of the block the player was looking at.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

6 minutes ago, Animefan8888 said:

I am at least 95% sure because this is the same guy whom you and I helped a few days ago.

Agreed, but I never saw the method there either.

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

9 minutes ago, Draco18s said:

Agreed, but I never saw the method there either.

It's right here.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.