Started by
Argus Obsidian
on
Topic category: Help with Minecraft modding (Java Edition)
I am working on adding guns to my mod, and the best solution I came up with for making them would be to raycast once the gun item is right clicked, and check what mob or block is hit. I prefer not to use a ranged item, as that makes certain parts of my mod impossible to do. Does anyone know how I could achieve this effect?
I have solved this through doing a LOT of coding! If anyone else wants to know how to do this, just reply to this post and I will try to explain.
I'd love to know how you did this!
Same!
How did you do it?
Sorry for replying late, but the way I solved this was using a lot of code, not procedures. Simply, every time the player right clicked with a gun, I would run a loop that moved a collision box through space until it collided with something. To make sure the game wouldn't crash, I made it have a maximum shooting distance, but it seems to work very well now.
TLDR: I shot a mob out of the gun. :p
.......
A bit more detailed explanation here:
1. I made a gun item that would trigger a procedure when it was right clicked.
2. I edited the code of the procedure, with the built in code editor in MCreator
3. I made it so when triggered, the code would create a bounding box, and using a loop, move it in the direction the player was looking.
4. If the bounding box hit a mob, block, or went too far, it would trigger an action, such as damaging the hit mob or spawning impact particles on the block it struck.
I basically made a lazar gun, because the gun shoots in a perfectly straight line.
Can you do a tutorial on this?
You've already created a tutorial on custom animated mobs and that was pretty helpful