Jump to content

[Solved]How to get players hand during break speed event?


jredfox

Recommended Posts

Edit: for break event the hand will always be your main hand and the itemstack you can get off of that don't know why they just didn't throw the enum hand in there in case a mod wants to change something up

 

I must be noob but, there is no hand argument in break speed event and get active hand randomly returns null and crashes the game
 

    @SubscribeEvent
    public void breakFix(PlayerEvent.BreakSpeed e)
    {
    	EntityPlayer p = e.getEntityPlayer();
    	String blockclazz = e.getState().getBlock().getHarvestTool(e.getState());
    	String itemclazz = ItemUtil.getToolClass(EntityUtil.getActiveItemStack(p,p.getActiveHand() ) );//error on this line null point exception
    	if(!blockclazz.equals(itemclazz) )
    		e.setNewSpeed(1.0F);
    	System.out.println(e.getNewSpeed());
    }
	

 

 

older version you literally just called player.getActiveItemStack() and it never returned null during events unless the player had no item in that slot here it randomly returns air when it's always pickaxe help.

Edited by jredfox
Link to comment
Share on other sites

 

51 minutes ago, jredfox said:

String blockclazz = e.getState().getBlock().getHarvestTool(e.getState()); String itemclazz = ItemUtil.getToolClass(EntityUtil.getActiveItemStack(p,p.getActiveHand() ) );//error on this line null point exception if(!blockclazz.equals(itemclazz) )

what are you trying to do???

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

whats wrong with 

Spoiler

player.getHeldItem(player.getActiveHand()).getItem()

 

Try it before saying it doesn't work

 

You also didn't post your EntityUtil.getActiveItemStack method

Edited by Cadiboo

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

6 minutes ago, Cadiboo said:

whats wrong with 

  Reveal hidden contents

player.getHeldItem(player.getActiveHand()).getItem()

 

Try it before saying it doesn't work

 

You also didn't post your EntityUtil.getActiveItemStack method

just returns p.getHeldItem(hand);

I know it doesn't work always because I changed the toolclasses of diamond ore to axe and set the material to wood then next thing I know the speed is default for pickaxe when it should be 1.0F. 

It's due to vanilla hard coding a list of blocks rather then comparing block material mods shouldn't have this issue.

I mean I could just always get the main hand but, since break speed can only be done with main hand stupid but, for other events I would like to know this.

Edited by jredfox
Link to comment
Share on other sites

5 hours ago, jredfox said:

other events I would like to know this

Other events usually have a getHand() method

6 hours ago, Cadiboo said:

You also didn't post your EntityUtil.getActiveItemStack method

 

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

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.