How do I make a water walking mob?

Started by Mopru on

Topic category: Help with modding (Java Edition)

Last seen on 21:51, 28. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a water walking mob?

I'm just gonna put it straight: I'm making a dimension full of spiders and I want one to walk on water. I've tried a lot but no other tutorial has given me a straight answer. Either it isn't a code block or it just doesn't make sense to have as actual code (I don't know coding but it just doesn't look right). Please help I feel like I'm running in endless circles.

Last seen on 17:47, 5. May 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey, I came across your post…
Sun, 02/19/2023 - 06:10

Hey, I came across your post and it seemed similar enough to some things I've already done, so I decided to give it a shot.

I understand this thread is a little old now and hopefully you've found a solution by now, but if not- and for anyone else who may come across this- I'll go through the process in stages:

 

First off, when you go to create a mob, make sure to tick the box to make them a water entity. Regarding their AI, you don't want to set the entity base to a spider, just leave it as "(none)". I tried testing this out multiple ways, but using the base spider AI appears to conflict with water-walking.

I arranged my AI task/goals list as follows:
 


(I tested the mob's aggro and path finding with chickens)

 

Now, regarding triggers/procedures, you do want one for "On each tick update".
In order to get the entity to walk on top of water, you basically just want it to swim as close to the surface as it can - while minimizing how much it bobs up and down in the water.

Here I started by checking for water just barely above the entity's position. If you check for water at the same level, or below the entity, the entity will be too high out of the water and won't be able to move properly. It'd just get stuck in the air above the water.

Next, if the velocity of the entity is below zero - in other words, if they're trying to move downward - force them to move back up instead. This prevents them from diving down and also helps keep them from bobbing up and down too much.

If the entity isn't moving downward, then add some upward velocity to them instead. This keeps them at a certain height at the surface of the water.

In my testing, I encountered a problem where constantly forcing the entity upwards resulted in it sometimes dying of fall damage once it touched ground, so I added a block in there to constantly reset its fall distance as long as it's just above water.

Next, I added dolphin's grace to the entity to increase its speed on water, as well as to give its movement a little 'slipperiness' - kind of like if it were walking on ice. It makes it look like it's walking on water a bit more realistically by giving it some momentum.

The second part of the procedure I'll get back to in a bit...

 

Now, onto code modifications. I'll preface this by saying I don't actually know how to write code, myself.
I can still read it decently well and I can make some adjustments here and there, but I don't know how to write something from scratch. So don't worry about how involving the following code is. It's pretty easy to copy over onto your custom entity.

Now then, you'll want to open up your custom entity's code, Drowned code, and Spider code. For those who don't know how to open up vanilla code, go ahead and drag the left sidebar in MCreator over (on the far left side of the MCreator window there's a bar you can drag to the right). Search for "drowned" and open "Drowned.java", and then do the same for the spider.

You also want to change your entity's "SWIM_SPEED" while you're editing its code. For whatever reason, a movement speed value of 0.3 results in decently quick movement on land, but a swim speed of 0.3 is pretty slow in the water. If you decided to give your entity dolphin's grace, I recommend setting its swim speed to 2.5. If you did not give it dolphin's grace, I recommend setting its swim speed to 3.5 instead.

Starting with the drowned code, look for what I've labeled in the images above and copy/paste that code into your custom entity's code. There is also some code you want to disable or delete from your entity. I personally prefer using /* and */ to turn chunks of code into a "comment" - allowing you to keep it there without it bothering anything. (Even if it's unnecessary to keep, you may want to toggle some code on or off like this as you're testing different things. You won't have to look for- or rewrite- something you deleted if you simply turned it into a comment instead.)

After you copied the drowned code over, I suggest saving and locking your entity's code, and then attempting to run the client to make sure what you just did works. (If you do mess up somewhere, it's easier to debug if you don't make so many changes at once.) Afterwards, do the same thing you just did with the spider code. You'll also have to write one line to have your entity's code import the spider code- since one thing you copied requires it.

 

Now that that's out of the way, in theory your custom entity should be done. However, I couldn't seem to figure out how to get the entity to correctly path find and climb up to a target that's out of the water. I tried adding additional bits of code and tweaking things, but to no avail. So, open up that procedure you made and add the second half.

What this does, is it checks to see if your custom entity sees something it wants to attack. If it does, then it compares the location of itself and its target, and then gives your entity a constant, slight push towards its target. Since it can climb like a spider now, this push causes your entity to climb out of the water and onto land- including up walls- to go after the target it's trying to attack.

 

Lastly, I do also want to go over a few (potential) problems with this entity. Overall I'd say it functions pretty well; however, there were some kinks I couldn't seem to work out...

Firstly, when standing on water and simply idling, they sometimes just... spin... I presume it's due to them trying to path to a location below them that they cannot reach.

Secondly, if they are in water and their target is on land - they don't path to their target too well. They prefer to stick to the water - which could be a good thing or a bad thing depending on how you want them to behave. They won't go straight for a target on land; instead, they'll try and swim around to whatever water is closest to their target. The second part of the procedure helps but doesn't completely fix this issue. If it doesn't work sufficiently to your liking, I recommend slightly upping the velocity values. Try 0.005 for a start. As you increase these values, you may want to decrease the speed value associated with their MeleeAttackGoal so they don't become too fast.

And finally, there have been one or two cases in my testing where one of these entities will just start walking away from their target without stopping. I haven't been able to reproduce this bug, but thought it worth mentioning.

Last seen on 17:47, 5. May 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm not really familiar with…
Sun, 02/19/2023 - 06:11

I'm not really familiar with how embedding images works here, but since they haven't loaded properly in my first post, as the time of writing, here's a link to the imgur album for them: https://imgur.com/a/gBPq3Xp

Last seen on 21:51, 28. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
gahdamn I just got back to…
Fri, 04/21/2023 - 01:08

gahdamn I just got back to my account and saw all this, thanks man, I originally deleted the concept for the water walking mob, but if I make another one, this will be my go-to. thank you so much! 

Last seen on 01:05, 22. Apr 2024
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
One question related to mob…
Tue, 06/27/2023 - 23:21

One question related to mob coding. Is it possible to transfer the guardians attack to a custom mob

if so, how?

Last seen on 21:51, 28. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
make your own forum, this…
Wed, 06/28/2023 - 01:40

make your own forum, this one's for water walking mobs.

Last seen on 02:15, 25. May 2024
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Chill dude, he just saw an…
Sat, 07/22/2023 - 19:04

Chill dude, he just saw an experienced MCreator user and tried to get some help as well.
You can't find many experience people using MCreator these days.

Last seen on 21:51, 28. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
..but he has more points…
Wed, 07/26/2023 - 21:56

..but he has more points than him?

Last seen on 02:15, 25. May 2024
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So you're saying that one…
Thu, 07/27/2023 - 08:51

So you're saying that one person can ask simpler questions only because they have low points?
You clearly do not know what you're talking about. Points can be obtain from several ways, but just because you have more points doesn't make you any more experience at MCreator.
I have 351 and there's still a lot of stuff that I don't know about it as well.
How can you be so ignorant? How does that question even fit in your head?

Last seen on 21:51, 28. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
damn bro its not that deep
Thu, 07/27/2023 - 16:56

damn bro its not that deep

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
the dolphin grace seams not…
Sat, 11/18/2023 - 01:24

the dolphin grace seams not working anymore to make them faster...

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
we dont need more dolphin…
Sat, 11/18/2023 - 01:43

we dont need more dolphin grace schnelligans, to change water mob speed : (change to 4.0+ for  fast water mobs like dolphins)

 

public static AttributeSupplier.Builder createAttributes() {
		AttributeSupplier.Builder builder = Mob.createMobAttributes();
		builder = builder.add(Attributes.MOVEMENT_SPEED, 0.3);
		builder = builder.add(Attributes.MAX_HEALTH, 40);
		builder = builder.add(Attributes.ARMOR, 0);
		builder = builder.add(Attributes.ATTACK_DAMAGE, 3);
		builder = builder.add(Attributes.FOLLOW_RANGE, 16);
		builder = builder.add(ForgeMod.SWIM_SPEED.get(), 1);
// <--- change swim speed here
		return builder;
	}
Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
about the point things…
Sat, 11/18/2023 - 02:22

about the point things someone talk about it; my acount was totally lost idk why i had to do another, i had a LOT of points before just check the posts

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
about walking water mobs …
Sat, 11/18/2023 - 02:24

about walking water mobs (like starfishes) - make it NOT water entity, make it immune to drown, and make it spawn like a waterEntity? that might work, im checking my starfishes codes later (im updating my mod) to be sure i set them like that.

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
scratch that, if u dont make…
Tue, 11/21/2023 - 20:15

scratch that, if u dont make it Water Entity it wont spawn on ocean anymore... idk how to do my starfishes now (they use to be regular non-water entities that had WaterCreature on the spawn tab