Jump to content

Recommended Posts

Posted

Hello friends,

 

I'm trying to make a mod that draws hitboxes for arrows. Currently the hitboxes show for all arrows and I'm trying to only make it show for moving arrows.

 

But I can't seem to find a way to check this properly, which is sort of ridiculous. Here's what I've tried so far:

 

1. Onground() doesn't work because I think it tests whether the item has been dropped, versus arrow being stuck in a block.

2. Comparing motionx,y,z to 0 doesn't work because I think the fields don't get updated after the arrow stops moving.

3. IsCollided() and insideOfBlock(air) don't work either.

4. InGround was what I was hoping I could use as it is a custom arrow field but looking through source code the field actually seems to be PRIVATE and theres no inGround() check method.

5. IsAirborne doesn't work either. Not sure but it always evaluates to false.

 

Here's what my eventhandler method looks like, nothing special: https://gist.github.com/hjongh/933709502c29dba99135e054a00688b0

 

So if anyone can give me suggestions on how I can do this, or maybe can say that one of my ways I tried should work, it would be much appreciated.

 

Posted

Part of the problem you've been having is that many of these fields are not synced to and/or are unreliable on the client which is where you need them to draw hit boxes.

 

The easiest way is to use Reflection to set the private #inGround field to public and then use Reflection to fetch the value - #inGround should be correct on both sides as vanilla uses it to render the arrows in the ground.

Posted

Wow, thanks for such quick and knowledgeable reply.

 

So I had to go search what it was, just added it in and it seems to work perfectly.

 

One last thing, for the exception handling, I just added a "throws thisexception thatexception" to the method, do you think that should work fine? Or do I need to use try catch?

 

 

Posted

If the method is not directly invoked anywhere (i.e. an event) you can get away with a

throws

declaration (otherwise you'll be passing the throws up the chain of execution).  Be aware that if you have an unhandled

throws

and it does throw the exception, the game will hard-crash instantly.  Buuuut, try-catch is slower.

 

By the way, you'll want to get the field once and store it and only have the throws on the actual set call (getting and setaccessible-ing you'll do once-ever and wrap in a try-catch).

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.

Posted

Hey Draco,

 

I was actually thinking about how if I do the reflection process for each arrow each time I handle an event then it would probably be really inefficient.

 

Here is what my event handler class looks like right now:

https://gist.github.com/hjongh/4659b0cab7b377b6d5713560f1a1c174

 

So if I wanted to make the private variable accessible only once so that I wouldn't have to do it each event handle how would I do that? I was thinking make a constructor for the eventhandler and put it there, but then I'm not sure how the error handling is going to work and whether that would even work aside from the error handling.

Posted

Works great, thanks so much you guys.

 

Just to confirm, in my Main preInit method I've created and setAccessible a new inGround field of EntityArrow class.

 

Then in my eventHandler method I'll just use the Main.inGround field to use to access the private inGround field for each EntityArrow object I'm iterating through.

 

Main.java : https://gist.github.com/hjongh/cfdb983dedc6aeadf50d35ebfdc08d4a

Event handler class: https://gist.github.com/hjongh/fac887b399710994bcf81146fe5eac4f

 

also if anything weird with my code or any way to improve..it'd be great if you guys pointed out! I'm sort of a newbie programmer haha

Posted

That's because the fields have obfuscated names in the live environment - there should be some methods in ReflectionHelper that take both the deobfuscated and obfuscated names as arguments. You can look up the obfuscated name using MCPBot.

 

Another option is to not use named fields but to instead fetch it by index, e.g. 2. It's not as robust, but it does work.

Posted

Do the first method. Looking up the SRG name isn't that hard.

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.

Posted

Thanks for help so far.

 

I added the obfuscated/srg code name and now the mod is working fine.

 

However, it's slightly choppy, especially in comparison to vanilla f3+b debug mode. Could anyone suggest how to make it smoother? I was thinking of using different event, as RenderWorldLastEvent runs the hitbox code after everything else so that might be the cause of lag. But when I use RenderWorldEvent pre/post no hitboxes ever render.

 

Here's my code:

Main: https://gist.github.com/hjongh/425840713795356c20195ea18a8a8025

Eventhandler class: https://gist.github.com/hjongh/41ab05b48920297ff5fcf97bf7badc53

Tesselator drawing class: https://gist.github.com/hjongh/14b53dd65425069731caed7d42531abe

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.