Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Mobs AI and Attributes


American2050
 Share

Recommended Posts

Hello forum.

 

So I'm coding a Mob and I'm having some problems with the attributes and AI for it.

 

For example, the first problem I'm having is that I need the mob to follow players to attack from a distance about, lets say 128 blocks.

 

So I have all this, but still seems not taking effect. Is there something I'm missing here?

Also, I made it "Giant" like a Giant Zombie, is there anything I should consider when coding a Mob like this? I added some code from the GiantZombie in Minecraft, not really sure what it does and if its really necessary.

Thanks for the help

 

The complete code is:

 

package com.mramericanmike.mymod.entity;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIMoveTowardsTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

import com.mramericanmike.mymod.Log;
import com.mramericanmike.mymod.init.ModItems;

public class EntityMyMob extends EntityMob implements IBossDisplayData, IMob
{

public EntityMyMob(World world) {
	super(world);


	this.experienceValue = 150;
	this.captureDrops = true;
	this.setCanPickUpLoot(true);
	this.isImmuneToFire = true;
	this.getNavigator().setCanSwim(true);

	this.setHealth(this.getMaxHealth());
//        this.width = 3F;
//        this.height = 8F;
        this.addPotionEffect(new PotionEffect(Potion.resistance.id, 24000, 0));
        
        
        this.yOffset *= 4.0F;
        this.setSize(this.width * 4.5F, this.height * 5.5F);
        
        
        
        //AI
        
        
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 128.0F));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, 1.75D, true));
        this.tasks.addTask(3, new EntityAIMoveTowardsTarget(this, 1.75D, 128.0F));
        
        this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector));
        


}

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(128.0D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(100.0D);
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(1000.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.75D);
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D);
        
    }
    
    
    
    
    public float getBlockPathWeight(int p_70783_1_, int p_70783_2_, int p_70783_3_)
    {
        return this.worldObj.getLightBrightness(p_70783_1_, p_70783_2_, p_70783_3_) - 0.5F;
    }
    
    
    

    @Override
    protected boolean canDespawn()
    {
        return false;
    }
    
    @Override
    protected String getHurtSound()
    {
//        return "game.hostile.hurt";
    	Log.Debug("MyMob Hurt");
    	return null;
    }

    @Override
    protected String getDeathSound()
    {
//        return "game.hostile.hurt";
    	Log.Debug("MyMob Death");
    	return null;
    }
    
    @Override
    protected Item getDropItem()
    {
    	Log.Debug("MyMob Drops");
    	return ModItems.apple;
    	
    }
}

 

PS: If I'm trying to make a Boss, what attributes and AI do you recommend me to use?

 

Link to comment
Share on other sites

ok dude, u need to realize that all this stuff is in vanilla mob classes. so you failed to the upmost extent.

 

you need to enable the ai..  which every other mob class in minecraft has (well pretty much).

	}

public boolean isAIEnabled() {

	return true;
}

 

and for getting ur boss bar?? look at wither or enderdragon code, seriously.

vanilla has everything you need.

 

so for the boss bar you have to make an onlivingupdate method, like this..

public void onLivingUpdate() {
	super.onLivingUpdate();

 

and to get the boss bar all you need is this line of code, which set the boss bar, believe it or not.

BossStatus.setBossStatus(this, true);

 

basically for the future. look at vanilla code first, and look for tutorials.

It will help you out ALLOT.

Im serious don't look at it!!

Link to comment
Share on other sites

 

Also, I made it "Giant" like a Giant Zombie, is there anything I should consider when coding a Mob like this? I added some code from the GiantZombie in Minecraft, not really sure what it does and if its really necessary.

 

 

the witdth and the height sets the size of the hit box, a better way to do that might be this.setSize(3F, 8F)

Im serious don't look at it!!

Link to comment
Share on other sites

For AI, I have some tutorials: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-custom-entity-ai.html

 

For attacking attributes, I have this tutorial: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-apply.html

 

For giant mobs, one of the main difficulties is the hit box, I think there are some limits to the size, at least in the height. This is due, I think, to the pathfinding -- it is hard for Minecraft to figure out how large hitboxes can move through terrain. In the giant entity I made, I think the maximum size I found that worked was setSize(1.0F, 4.5F).

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

Link to comment
Share on other sites

BoonieQuafter-CrAfTeR Thanks a lot, yes I finally noticed I was missing that isAIEnabled()

Thanks also on the tips about the Boss Bar, that was coming after I figured the AI so thanks a lot on the tips for that aswell ;)

 

Jabelar, thanks a lot, I'm going to take a look at yours tutorials.

Also thanks with the tips on how big the Hitbox should be, I think I made mine too big as for now, so I should probably start with the same dimensions the GiantZombie has and test from there

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

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.