Started by
redreddyred
on
Topic category: Advanced modding
I created a gun item in 1.7.9. and it works great! However, I would like the projectile to fire in a straight line, and not arch how an egg or a snowball would. I've locked the code so I can edit the java under code view. I'm trying to find the line of code that will allow me to manipulate the physics of the projectile. What do I need to add or change in order to accomplish a straight forward firing projectile for my new item?
Thanks for the assistance!
Edited by redreddyred on Wed, 06/27/2018 - 01:20
Bump, anyone? I feel like this is something so easy to change but I can't figure out what to manipulate or add to accomplish this.
The only thing I can think of is making a procedure for the gun and making the gun when right clicked when spawn an entity. You could then apply some force to it when it is shot. For making it go in a straight line that's a little bit different. There is no block in the procedures for gravity but I have two ideas, one: (probably not ideal) apply an upwards force to the entity opposite to the gravity or Idea two: look in the code editor for the entity and find the line for gravity and set that to false or 0 (not sure what it is called though). Now you could just make it so once the bullet entity collides with another it'll apply some damage to the hit entity.
That's my ideas on how you could achieve this. you could probably do it another way. I doubt this is the best way but hope this helped you out some.
I did mess around with the current code. I made the force 0, which just drops the item complete when you shoot it. Then I tried -1 but that didn't do anything. I'll have to play around with the procedures. Maybe I can find something there that would offset the gravity.
I'm still hoping someone knows the line of code, and where to put it, to make this thing just fire without being affected by gravity. I feel like this should be something so easy to do. Hell the bedrock edition already has it in there (see below)
Obviously that's the the bedrock edition, but the gravity snippet you set to zero, and it works like a charm.
I tried looking the code for the ranged item but couldn't find anything like gravity that's obvious but I bet its there somewhere.
As far as I can tell, below is the chunk of code that manipulates the force/physics of the item shoot. It's actually the chunk of code labeled, par3EntityPlayer.getLookVec().z, f * 2.0F, 0);
But every time I mess with that 2.0F I can never get it to work correctly. It will either just drop to the ground as soon as I fire, or still arch like a snowball or an egg. There has to be a simple change or addition can make to get this working...
I got it. Someone over on Minecraft Forums helped me out. You add this line in, and it worked.
entityarrow.setNoGravity(true);
BINGO! Thanks for trying to help me out with this my dude.
even though this post is forever old, but thank you solved my problem completely
add to line 189 for those who are wondering
entityarrow.setNoGravity(true);
thank you!