Started by
Ahmet Enes TAŞÇI
on
Topic category: Help with Minecraft modding (Java Edition)
Hello, this wither head ignition is one of the most frequently asked questions but I have a more complex plan. I am using Mccreator 2023.4. I made a wither model (Geckolib) and I want it to identify multiple attack targets at the same time and fire wither heads at them. While all this is happening, you know that wither has two more heads (right and left) besides the main head in the middle, I want him to look at the attack targets in these heads. This is a very complicated job and I will be both surprised and happy if there is someone brave enough to help me. You can also let me know if there is a tutorial that shows exactly this. Can all this be done procedurally?
Getting the heads to look at multiple targets is borderline impossible, at least without quite a bit of custom code. You'd essentially have to make a new animation system from the ground up; minecraft's built in animation system just supports the one movable head segment. It's possible there's a plugin for it, but I wouldn't know where to find it.
Attacking multiple targets isn't too tricky though. You can use an entity iterator to locate all entities within a certain radius of the wither, and then fire a projectile at their positions. (You will probably also want to have some built in limit for how many entities the wither can target at once, and will want to specify what types of entities can be targeted, so it doesn't start attacking dropped items or something. Also probably want to use some sort of NBT tag as a cooldown.) There's a little bit of trig involved- if I remember correctly you can only summon projectiles with x/y/z velocity, so you need to calculate a vector from the wither to its target, and then sin/cos to get the individual x/y/z components, and then multiply each of these components by a decimal number to determine the projectile's speed.
A simpler method could be to just make the entity look at its target using the 'make entity look at x/y/z' function, and then set the projectile's x/y/z velocity to the x/y/z look angle vectors of the entity, multiplied by your desired speed. This might cause some visual jankiness though.
How will I do all this? It's obviously not something that can be explained. Could you post an example procedure photo? Also, can you give me the source code of wither, as I want to make a more efficient mob in terms of behavior? Or tell me where I can find the source code of wither.
Luckily enough, MCreator comes with a built in library of Minecraft's source code. (It's just kinda hard to locate.) You want to go into the file explorer on the left-hand side of the workspace, and navigate to external libraries/gradle forge 1.20.1/net/minecraft, most of the actual entity and gameplay code is kept in the 'world' folder. (You can also just use the search bar.) Keep in mind though, the wither doesn't really attack multiple targets at once, it just spins around really quick to shoot a bunch of separate projectiles.
As for the trig stuff... yeah, it's not the easiest to explain. The basic idea is that wither skulls are a projectile without gravity, (it's WAY more complicated with gravity involved), so if you give them an x/y/z velocity, they'll travel in a straight line. To calculate a line to the target, you need to make a right triangle between the position of the attacker, and the position of the target; and then calculate the x/y/z components of the hypotenuse- this will yield the x/y/z velocities required to shoot a projectile along said line, which you can then multiply by whole numbers or decimals to make the projectile to faster or slower.
The look-angle vectors essentially do the same thing- you make the entity look at the target, get the individual x/y/z components of that line, (in this case, decimals from -1 to 1), then multiply by your desired speed. (This involves unit circles, and is even more of a headache, but at least has some built in functions to work with.)
If you're really determined, I recommend some Khan academy videos on trig/velocity basics. Here's a (sort of unrelated) but similar thing I did some code for.
I did something like this that works exactly. Frankly, advanced mathematics will be my goal going forward. All I want now is the source code for wither. Where exactly can I find it (WitherEntity.java and WitherRenderer.java)?
There's a tab you can pull out on the left side of the workspace. You can search for the wither code there.
Ok. I found all the code files of wither as you said. My friend, I cannot make a deal with you for money, but I want you to know that I will be very happy if you help me fully. I made a geckolib animated entity. Could you please explain in detail how I can transfer all the codes of Wither to it in the code editor? It can be video or image. I can change parameters such as health points and xp rewards myself. I just want to transfer the wither codes to the geckolib entity I made and create the remaining features from the visual interface. Or “There's no way you can do that.” If such a situation occurs, show me how I can proceed instead. As for the skull firing issue, I figured it out. Yesterday, with a flash in my head, I thought why I don't "copy-paste" wither's codes.
Anyway, I talked too much.
Thanks in advance... :)
Happy to help! I'm not sure if copying the wither's code is the best idea, there's a good chance it'll have unforseen consequences, and you'd have to manually change every file reference to your own assets and whatnot; whereas if you do your own code, using the visual interface you can more easily edit and debug it. Most of the wither's behavior should be pretty straightforward to replicate, here's a sort of general overview:
...If you've got the projectiles figured out, that's pretty much it. I could send some pictures of procedures if that would help?
Yes, I would love to. It's nice to see helpful people like you ;D