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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.