How to make a wither that fires wither heads at multiple attack targets simultaneously?

Started by Ahmet Enes TAŞÇI on

Topic category: Help with modding (Java Edition)

Last seen on 11:56, 29. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make a wither that fires wither heads at multiple attack targets simultaneously?

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?

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Getting the heads to look at…
Fri, 04/12/2024 - 11:09

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.

Last seen on 11:56, 29. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How will I do all this? It's…
Sat, 04/13/2024 - 14:15

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.

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Luckily enough, MCreator…
Sat, 04/13/2024 - 14:23

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.

Last seen on 11:56, 29. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did something like this…
Sat, 04/13/2024 - 14:41

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)?

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There's a tab you can pull…
Sat, 04/13/2024 - 14:43

There's a tab you can pull out on the left side of the workspace. You can search for the wither code there.

Last seen on 11:56, 29. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok. I found all the code…
Sun, 04/14/2024 - 06:42

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... :)

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Happy to help! I'm not sure…
Sun, 04/14/2024 - 16:21

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:

  • You should be able to turn on a boss bar in the entity properties tab.
  • For health regeneration, you can give the entity an NBT number tag, which, on update tick, subtracts one from its current value. When it reaches zero, reset the tag, and set the entity's health to its current health, +1. (If you set the timer to 20, it will heal half a heart every 20 ticks, or every 1 second. This is the rate for the vanilla wither.) 
  • The wither also heals 2.5 hearts every time it kills an entity. For this, you would make a procedure, with the 'entity dies' global trigger, check if the source entity was your custom entity, and, if it was, set the source entity's health to its current health +5.
  • You can use custom animations in Blockbench to indicate when the boss changes to its second stage, and use procedures to trigger these animations. (On the entity's update tick, you would want to run the new animation if its health is less than its maximum health divided by two.)
  • When the wither reaches half health, it switches to a melee attack. If you're using custom procedures to fire projectiles, (instead of using the built in ranged attack), you should be able to simply check if the boss's health is high enough before firing; then, in the entity's AI, add a melee attack, with a start/continue condition that the boss must be below half health. (You could use a similar condition to add an 'avoid player' function to the AI that only runs when it's above half health.)
  • ...And in the second stage, the wither deflects projectiles. This is weirdly kind of hard to do, since you don't want it to do this in the first stage. You could pretty simply just make a procedure with a 'before entity hurt' trigger that cancels the trigger if the target entity is the boss, and the immedieate source entity is an arrow, but this will just make the boss immune to arrows instead of actually deflecting them. (To deflect, you would need to detect when their velocity would cause them to hit the boss, and if so, reverse said velocity.)

...If you've got the projectiles figured out, that's pretty much it. I could send some pictures of procedures if that would help?

Last seen on 11:56, 29. Apr 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, I would love to. It's…
Mon, 04/15/2024 - 10:54

Yes, I would love to. It's nice to see helpful people like you ;D