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

1.7.10 Entity Won't Move or Attack


Evil Looply
 Share

Recommended Posts

I'm trying to create a custom entity that follows you around until you go in water and then attacks you.

 

However, I can't seem to figure out how to move my entity and get it to attack in a task i made.  The entity will just stand there and not move or attack at all.

I know that the everything is reached because i debugged it with some System.out.print's but they still won't do anything.

 

Entity Registry (or whatever it's called) :

Spoiler

package com.example.mob;

import com.example.tutorial.Main;
import com.sun.xml.internal.stream.Entity;

import cpw.mods.fml.common.registry.EntityRegistry;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;

public class EntityWatcher {
    
    public static void mainRegistry(){
        registerEntity();
    }
    
    public static void registerEntity(){
        createEntity(EntityWatcherMob.class, "Watcher", 0x0004FF, 0xFF00E1);
    }

    public static void createEntity(Class entityClass, String entityName, int solidColor, int spotColor){
        int randId = EntityRegistry.findGlobalUniqueEntityId();
        EntityRegistry.registerGlobalEntityID(entityClass, entityName, randId);
        EntityRegistry.registerModEntity(entityClass, entityName, randId, Main.instance, 60, 1, true);
        EntityRegistry.addSpawn(entityClass, 2, 0, 1, EnumCreatureType.creature, BiomeGenBase.hell);
        
        createEgg(randId,solidColor,spotColor);
    }
    
    private static void createEgg(int rId, int sC, int spC){
    EntityList.entityEggs.put(Integer.valueOf(rId), new EntityList.EntityEggInfo(rId, sC, spC));
    }
    
}
 

 

My Mob Class:

Spoiler

package com.example.mob;

import javax.swing.text.html.parser.Entity;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class EntityWatcherMob extends EntityCreature{

    public EntityWatcherMob(World par1W) {
        super(par1W);
        this.setSize(0.4F, 0.7F);
        this.tasks.addTask(0, new EntityWatcherAI(this));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true));
        //this.tasks.addTask(1, new EntityAIWander(this,0.5));
        
    }
    
    @Override
    protected boolean isAIEnabled()
    {
       return true;
    }
    
    protected void applyEntityAttributes(){
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1);
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(64);
    }
    
}

 

My AI part:

Spoiler

package com.example.mob;

import com.mojang.realmsclient.dto.PlayerInfo;
import com.sun.media.jfxmedia.events.PlayerStateEvent.PlayerState;

import ibxm.Player;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;

public class EntityWatcherAI extends EntityAIBase{

    public EntityWatcherMob watcher;
    //EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    //EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 64.0D);
    
    public EntityWatcherAI(EntityWatcherMob d){
        watcher=d;
        setMutexBits(1);
    }
    
    @Override
    public boolean shouldExecute(){
        EntityPlayer vic = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(watcher.isEntityAlive()){
            return true;
        }
        return false;
    }
    
    @Override
    public void startExecuting()
    {
        EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(player!=null){
            if(!(player.isInWater())){
            watcher.getNavigator().tryMoveToEntityLiving(player, watcher.getAIMoveSpeed());
            }
            else{
            watcher.attackEntityAsMob(player);
            }
        }
    }
    
    @Override
    public boolean continueExecuting(){
        EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(player!=null){
            if(!(player.isInWater())){
            watcher.getNavigator().tryMoveToEntityLiving(player, watcher.getAIMoveSpeed());}
            else{
            watcher.attackEntityAsMob(player);}
            return true;
        }
        return false;
    }
    
}
 

 

 

I'm kinda new to modding, (besides some items), so if anyone could help me, that'd be great ! 

Link to comment
Share on other sites

3 hours ago, KeeganDeathman said:

*yelling from the back of the auditorium* update your mod to 1.10.2 at least! 1.7.10 is no longer supported by forge and 1.10.2 is where the majority of the fanbase resides!

1.10 is already 2 versions old, update to 1.12 !!!! And no, 1.7 got still at least as many players as 1.10.

 

 

Spoiler
4 hours ago, Evil Looply said:

I'm trying to create a custom entity that follows you around until you go in water and then attacks you.

 

However, I can't seem to figure out how to move my entity and get it to attack in a task i made.  The entity will just stand there and not move or attack at all.

I know that the everything is reached because i debugged it with some System.out.print's but they still won't do anything.

 

Entity Registry (or whatever it's called) :

  Hide contents

package com.example.mob;

import com.example.tutorial.Main;
import com.sun.xml.internal.stream.Entity;

import cpw.mods.fml.common.registry.EntityRegistry;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;

public class EntityWatcher {
    
    public static void mainRegistry(){
        registerEntity();
    }
    
    public static void registerEntity(){
        createEntity(EntityWatcherMob.class, "Watcher", 0x0004FF, 0xFF00E1);
    }

    public static void createEntity(Class entityClass, String entityName, int solidColor, int spotColor){
        int randId = EntityRegistry.findGlobalUniqueEntityId();
        EntityRegistry.registerGlobalEntityID(entityClass, entityName, randId);
        EntityRegistry.registerModEntity(entityClass, entityName, randId, Main.instance, 60, 1, true);
        EntityRegistry.addSpawn(entityClass, 2, 0, 1, EnumCreatureType.creature, BiomeGenBase.hell);
        
        createEgg(randId,solidColor,spotColor);
    }
    
    private static void createEgg(int rId, int sC, int spC){
    EntityList.entityEggs.put(Integer.valueOf(rId), new EntityList.EntityEggInfo(rId, sC, spC));
    }
    
}
 

 

My Mob Class:

  Hide contents

package com.example.mob;

import javax.swing.text.html.parser.Entity;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class EntityWatcherMob extends EntityCreature{

    public EntityWatcherMob(World par1W) {
        super(par1W);
        this.setSize(0.4F, 0.7F);
        this.tasks.addTask(0, new EntityWatcherAI(this));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true));
        //this.tasks.addTask(1, new EntityAIWander(this,0.5));
        
    }
    
    @Override
    protected boolean isAIEnabled()
    {
       return true;
    }
    
    protected void applyEntityAttributes(){
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1);
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(64);
    }
    
}

 

My AI part:

  Hide contents

package com.example.mob;

import com.mojang.realmsclient.dto.PlayerInfo;
import com.sun.media.jfxmedia.events.PlayerStateEvent.PlayerState;

import ibxm.Player;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;

public class EntityWatcherAI extends EntityAIBase{

    public EntityWatcherMob watcher;
    //EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    //EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 64.0D);
    
    public EntityWatcherAI(EntityWatcherMob d){
        watcher=d;
        setMutexBits(1);
    }
    
    @Override
    public boolean shouldExecute(){
        EntityPlayer vic = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(watcher.isEntityAlive()){
            return true;
        }
        return false;
    }
    
    @Override
    public void startExecuting()
    {
        EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(player!=null){
            if(!(player.isInWater())){
            watcher.getNavigator().tryMoveToEntityLiving(player, watcher.getAIMoveSpeed());
            }
            else{
            watcher.attackEntityAsMob(player);
            }
        }
    }
    
    @Override
    public boolean continueExecuting(){
        EntityPlayer player = watcher.worldObj.getClosestPlayerToEntity(watcher, 32);
        if(player!=null){
            if(!(player.isInWater())){
            watcher.getNavigator().tryMoveToEntityLiving(player, watcher.getAIMoveSpeed());}
            else{
            watcher.attackEntityAsMob(player);}
            return true;
        }
        return false;
    }
    
}
 

 

 

I'm kinda new to modding, (besides some items), so if anyone could help me, that'd be great ! 

 

 

1.7.10 posts usually will get closed soon. Look at how vanilla code for following works (wolves) and try to copy that. For attacking you might need an own task.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

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