Started by
Mopru
on
Topic category: Help with Minecraft modding (Java Edition)
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.
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.
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
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!
One question related to mob coding. Is it possible to transfer the guardians attack to a custom mob
if so, how?
make your own forum, this one's for water walking mobs.
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.
..but he has more points than him?
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?
damn bro its not that deep
the dolphin grace seams not working anymore to make them faster...
we dont need more dolphin grace schnelligans, to change water mob speed : (change to 4.0+ for fast water mobs like dolphins)
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
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.
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