Jump to content

Recommended Posts

Posted (edited)

Hi guys, I'm trying to implement a shark. I'm having a few issues, can anyone help me out?

As it stands, my "shark" is using the dolphin model without the texture.

 

I'm trying to make my shark attack nearby entities, and attack an entity if it is attacked.
First, I tried making a mob that extends MonsterEntity and gave it some attacking goals from the spider / zombie class. Didn't seem to do anything.

 

Now, my shark extends WaterMobEntity (similar to a dolphin) and swims kind of wonkily, but ok (it mostly sticks to the ground).

Just now I tried adding some "NearestAttackableTargetGoal" for Player and AbstractFishEntity, but it wasn't working, until it crashed just now.

Does anyone have any advice or help for coding aggressive mobs? I'm thinking it may have crashed because I targeted the abstract class, but I assumed it was target all children of it. Probably wrong of me.

I also changed my code from the abstract class to TropicalFishEntity, the game didn't crash, but it did not attack anything.

 

The stack trace: https://pastebin.com/Zcrm7WVF

 

Is it possible that it's because it doesn't have an attack animation? Or because I'm missing some base attack method?

Here's my repo: https://github.com/BadBichShaquonda/shark-mod/tree/dr_shtroumphi

Edited by BadBichShaquonda
Posted (edited)

Howdy

In my experience, the Minecraft AI is difficult.  You really need to invest the time to understand exactly what it's doing otherwise random stuff will just happen for no reason.  I've found it very helpful to add logging code (print to console) into the AI code (even copying the vanilla classes out) to let you study what's going on without disrupting it using breakpoints.  Likewise adding a switch in your code (eg triggered by pressing the control key) to 'freeze' the AI and stop it updating so you can breakpoint and inspect all the variables.  It's also very helpful to strip the AI right back to one task and then slowly add them back (or add new) one at a time.

 

I've also found it useful to add a spawn inhibitor which prevents all entities from spawning except your own entity, so there are no other AI tasks running except for your own (makes breakpoints much easier) eg like this

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/usefultools/debugging/DebugSpawnInhibitor.java

 

-TGG

Edited by TheGreyGhost
  • Like 1
Posted

Thanks! I'll try mining more into it :)
I was thinking of logging code a bit everywhere, but how can I possibly make the entity stop moving?

Like I'd need to verify at all times if I click ctrl / whatever key, and then what do i do?

Posted

Hi

I haven't done it in 1.15.2 yet; in previous versions the AI was called from the entity's tick code, so all I needed to do was check if the key was being held down (CAPS LOCK I think from memory) and if so, just skip over the call to the AI code.  You can stop the entity updating entirely by doing the same trick at the start of the entire tick() method

 

eg MobEntity::updateEntityActionState looks like it might be where AI is controlled from, with updateAITasks() doing most of the work

 

-TGG

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.