Jump to content

[STILL UNSOLVED] A mob question.


MagnumMike55

Recommended Posts

Hello everyone. I know i've been asking this for a while now, but still even without asking for help, I still cant get my fish mob working the way I want it to. My fish mob will float like regular mobs would. So can anyone help me? How can I make a water mob? Should I make my own AI for it or something? I really need help guys becuase I have no clue what to do. Any help is appretiated like always  :).

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Link to comment
Share on other sites

It floats like regular mobs would? Do you mean like EntityGhast or like entities which can swim or what?

Show the part of your code that doesn't work. It really depends your needs if you should create AI task for it. If your entity should not be very smart with moving (like pathfinding around the obstacles) you can do basic moving without AI tasks.

Link to comment
Share on other sites

If you want AI behavior like vanilla, look at vanilla mobs. Probably what you want is EntityAISwimming, which is what pretty much every swimming mob using, e.g. zombies and skeletons.

If you want similar but not exact behavior, it is easy concept, the way Minecraft handles swimming is by entity's jump, if entity is under water and it jumps, it goes up. This way all you have to do is to use entity.getJumpHelper().setJumping() and it will go up on water and when it hits the surface, it will start going up and back to water just like how skeletons and zombies do.

Link to comment
Share on other sites

What I mean is my water mob is jumping in the water like regular mobs do. Here is my code and yes I did extend the entitywatermob class. If things look like they shoudn't be there, it's becuase im trying to write my own AI since the entitysquid class isn't helping.

 

My entityfishmob class:

package com.MagZAquaticLifeExperience.common.entity;

import com.MagZAquaticLifeExperience.common.MagzAquaticLifeExperience;

import net.minecraft.block.material.Material;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.EntityWaterMob;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityFishMob extends EntityWaterMob {

 private float randomMotionSpeed;
 private float randomMotionVecX;
 private float randomMotionVecY;
 private float randomMotionVecZ;

public EntityFishMob(World par1World) {
	super(par1World);
	 this.setSize(1.0F, 0.5F);
}


protected void applyEntityAttributes() {
	super.applyEntityAttributes();
    this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(4.0D);
}

public boolean canBreatheUnderwater()
    {
        return true;
    }

 public void moveEntityWithHeading(float par1, float par2) {

	 this.moveEntity(this.motionX, this.motionY, this.motionZ);
    
 }


@Override
public boolean isInWater() {
	return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(1.0D, 0.0D, 0.0D), Material.water, this);
}

@Override
public void onLivingUpdate() {

	super.onLivingUpdate();

	if(this.isInWater()) {

		this.randomMotionSpeed = 2.0F;
	}

	if(!this.isInWater()) {

		this.randomMotionSpeed = 0.0F;
	}
}

protected String getLivingSound() {
	return "";
}

protected String getDeathSound() {
	return "";
}

}


  

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Link to comment
Share on other sites

I think if you want it to swim like a fish (under the water instead of on the water surface, and smoothly instead of jerky like a squid) you will need custom AI and maybe custom pathfinding.  You can use the "new" AI where you create a list of tasks that have priority and mutual exclusivity or you can use the "old" UI which basically just processes all possible movement actions in one method.

 

I suspect that there are some open source code for other fish mods that may implement proper swimming.

 

If you end up coding your own I think to be fish like you'd basically choose some underwater point that you know you can get to and swim towards that and then occasionally (and bit randomly) decide to choose other target location.  Like a school of fish moving along and then switching direction.  In terms of moving up and down in the water, you'd probably have to check how much water is above and below and decide if it needs to move up or down based on how "deep" (maybe including some randomness) you want it to swim.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thanks for the reply! But yeah I can't find any open source code for fish mobs :(. Could you possibly help me work things out? Like how to make it pathfind and such. I'm a little new to how mob AI's work for minecraft. I was mainly focused on gui's, tile entities and such. So could anyone help me out? Please don't post code, just tell me how to work things out. Thanks  :)

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Link to comment
Share on other sites

Thanks for the reply! But yeah I can't find any open source code for fish mobs :(. Could you possibly help me work things out? Like how to make it pathfind and such. I'm a little new to how mob AI's work for minecraft. I was mainly focused on gui's, tile entities and such. So could anyone help me out? Please don't post code, just tell me how to work things out. Thanks  :)

Look at the vanilla AI classes - some of those have path-finding algorithms in them; or look at EntitySquid to see how they are caused to move somewhat randomly, or EntityBat, which also has an interesting path-finding algorithm which may be more suitable for a fish than the squid's motion.

 

Then, either create a custom AI class and add it as a task for your fish (preferable), or add the movement code directly into the update tick like bats and squid (not as preferable, but still works).

Link to comment
Share on other sites

Quick question coolAlias. When you said "create a custom AI class and add it as a task for your fish" does that mean make the custom ai class and in my entityfishmob class, extend it?

 

Ex: public class EntityFishMob extends CustomAI() {

 

}

 

I think i'm just confused on what you're saying, even if it is obvious. Anyway thanks for the help!  :D

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Link to comment
Share on other sites

Have you ever looked at any of the vanilla mob classes? Most of them have an EntityAITasks field named 'tasks', and you will see in the class constructor all of the tasks that get added such as 'tasks.addTask(0, new EntityAISwimming(this));', where the number is the priority of execution (low number is high priority) and the second argument is an instance of the AI task that you want.

 

Spend some time looking through vanilla code and you will find the answers, and if you don't understand it, then spend some more time reading the code and look up as much Java as you need to figure out what's going on.

Link to comment
Share on other sites

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.