Jump to content

[SOLVED][1.6.4] Mob Dealing Damage?


saxon564

Recommended Posts

Now that I have the textures fixed, and another bug repaired, now i want to get the mob to deal damage to a player. I've looked at the code of other mobs and pasted the code that made sence in, but the line i added just causes the mob to "crash" so it doesnt spawn or despawns if already spawned.

 

Here is the code I have:

 

package mods.mochickens.mobs;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class EntityBlueChicken extends EntityAnimal
{
    public boolean field_70885_d = false;
    public float field_70886_e = 0.0F;
    public float destPos = 0.0F;
    public float field_70884_g;
    public float field_70888_h;
    public float field_70889_i = 1.0F;

    /** The time until the next egg is spawned. */
    public int timeUntilNextEgg;

    public EntityBlueChicken(World par1World)
    {
        super(par1World);
        this.setSize(0.3F, 0.7F);
        this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        float f = 0.25F;
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
        this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
        this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false));
        this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
        this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
    }

    /**
     * Returns true if the newer Entity AI code should be run
     */
    public boolean isAIEnabled()
    {
        return true;
    }

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

    /**
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
     * use this to react to sunlight and start to burn.
     */
    public void onLivingUpdate()
    {
    	super.onLivingUpdate();
        this.field_70888_h = this.field_70886_e;
        this.field_70884_g = this.destPos;
        this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);

        if (this.destPos < 0.0F)
        {
            this.destPos = 0.0F;
        }

        if (this.destPos > 1.0F)
        {
            this.destPos = 1.0F;
        }

        if (!this.onGround && this.field_70889_i < 1.0F)
        {
            this.field_70889_i = 1.0F;
        }

        this.field_70889_i = (float)((double)this.field_70889_i * 0.9D);

        if (!this.onGround && this.motionY < 0.0D)
        {
            this.motionY *= 0.6D;
        }

        this.field_70886_e += this.field_70889_i * 2.0F;

        if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg <= 0)
        {
            this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            this.dropItem(Item.diamond.itemID, 1);
            this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        }
    }

    /**
     * Called when the mob is falling. Calculates and applies fall damage.
     */
    protected void fall(float par1) {}

    /**
     * Returns the sound this mob makes while it's alive.
     */
    protected String getLivingSound()
    {
        return "mob.chicken.say";
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    protected String getHurtSound()
    {
        return "mob.chicken.hurt";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    protected String getDeathSound()
    {
        return "mob.chicken.hurt";
    }

    /**
     * Plays step sound at given x, y, z for the entity
     */
    protected void playStepSound(int par1, int par2, int par3, int par4)
    {
        this.playSound("mob.chicken.step", 0.15F, 1.0F);
    }

    /**
     * Returns the item ID for the item the mob drops on death.
     */
    protected int getDropItemId()
    {
        return Item.diamond.itemID;
    }

    /**
     * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
     * par2 - Level of Looting used to kill this mob.
     */
    protected void dropFewItems(boolean par1, int par2)
    {
        int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

        for (int k = 0; k < j; ++k)
        {
            this.dropItem(Item.diamond.itemID, 1);
        }

        if (this.isBurning())
        {
            this.dropItem(Item.chickenCooked.itemID, 1);
        }
        else
        {
            this.dropItem(Item.chickenRaw.itemID, 1);
        }
    }

    /**
     * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
     */
    public EntityBlueChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable)
    {
        return new EntityBlueChicken(this.worldObj);
    }

    /**
     * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
     * the animal type)
     */
    public boolean isBreedingItem(ItemStack par1ItemStack)
    {
        return par1ItemStack != null && par1ItemStack.itemID == Item.diamond.itemID;
    }

    public EntityAgeable createChild(EntityAgeable par1EntityAgeable)
    {
        return this.spawnBabyAnimal(par1EntityAgeable);
    }
}

 

 

here is the line that ive been trying to add to the applyEntityAttributes() method:

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(3.0D);

 

Here is the error i have been getting:

 

2013-10-25 23:17:18 [iNFO] [sTDERR] java.lang.reflect.InvocationTargetException

2013-10-25 23:17:18 [iNFO] [sTDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

2013-10-25 23:17:18 [iNFO] [sTDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

2013-10-25 23:17:18 [iNFO] [sTDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

2013-10-25 23:17:18 [iNFO] [sTDERR] at java.lang.reflect.Constructor.newInstance(Unknown Source)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:205)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:175)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:81)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:152)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:429)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:556)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

2013-10-25 23:17:18 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException

2013-10-25 23:17:18 [iNFO] [sTDERR] at mods.mochickens.mobs.EntityBlueChicken.applyEntityAttributes(EntityBlueChicken.java:64)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:193)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:85)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:40)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.EntityAgeable.<init>(EntityAgeable.java:16)

2013-10-25 23:17:18 [iNFO] [sTDERR] at net.minecraft.entity.passive.EntityAnimal.<init>(EntityAnimal.java:31)

2013-10-25 23:17:18 [iNFO] [sTDERR] at mods.mochickens.mobs.EntityBlueChicken.<init>(EntityBlueChicken.java:37)

2013-10-25 23:17:18 [iNFO] [sTDERR] ... 20 more

2013-10-25 23:17:18 [WARNING] [Minecraft-Server] Skipping Entity with id 301

 

Link to comment
Share on other sites

Try looking for attackEntityAsMob(Entity par1Entity) and adding that to your class

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

added that method and the problem persists. i really have no idea what exactly i need to do to get it to work.

 

Updated Code:

package mods.mochickens.mobs;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class EntityBlueChicken extends EntityAnimal
{
    public boolean field_70885_d = false;
    public float field_70886_e = 0.0F;
    public float destPos = 0.0F;
    public float field_70884_g;
    public float field_70888_h;
    public float field_70889_i = 1.0F;

    /** The time until the next egg is spawned. */
    public int timeUntilNextEgg;

    public EntityBlueChicken(World par1World)
    {
        super(par1World);
        this.setSize(0.3F, 0.7F);
        this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        float f = 0.25F;
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
        this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
        this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false));
        this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
        this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
    }

    /**
     * Returns true if the newer Entity AI code should be run
     */
    public boolean isAIEnabled()
    {
        return true;
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(3.0D);
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(4.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.25D);
    }
    
    public boolean attackEntityAsMob(Entity par1Entity)
    {
        return true;
    }


    /**
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
     * use this to react to sunlight and start to burn.
     */
    public void onLivingUpdate()
    {
    	super.onLivingUpdate();
        this.field_70888_h = this.field_70886_e;
        this.field_70884_g = this.destPos;
        this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);

        if (this.destPos < 0.0F)
        {
            this.destPos = 0.0F;
        }

        if (this.destPos > 1.0F)
        {
            this.destPos = 1.0F;
        }

        if (!this.onGround && this.field_70889_i < 1.0F)
        {
            this.field_70889_i = 1.0F;
        }

        this.field_70889_i = (float)((double)this.field_70889_i * 0.9D);

        if (!this.onGround && this.motionY < 0.0D)
        {
            this.motionY *= 0.6D;
        }

        this.field_70886_e += this.field_70889_i * 2.0F;

        if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg <= 0)
        {
            this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            this.dropItem(Item.diamond.itemID, 1);
            this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        }
    }

    /**
     * Called when the mob is falling. Calculates and applies fall damage.
     */
    protected void fall(float par1) {}

    /**
     * Returns the sound this mob makes while it's alive.
     */
    protected String getLivingSound()
    {
        return "mob.chicken.say";
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    protected String getHurtSound()
    {
        return "mob.chicken.hurt";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    protected String getDeathSound()
    {
        return "mob.chicken.hurt";
    }

    /**
     * Plays step sound at given x, y, z for the entity
     */
    protected void playStepSound(int par1, int par2, int par3, int par4)
    {
        this.playSound("mob.chicken.step", 0.15F, 1.0F);
    }

    /**
     * Returns the item ID for the item the mob drops on death.
     */
    protected int getDropItemId()
    {
        return Item.diamond.itemID;
    }

    /**
     * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
     * par2 - Level of Looting used to kill this mob.
     */
    protected void dropFewItems(boolean par1, int par2)
    {
        int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

        for (int k = 0; k < j; ++k)
        {
            this.dropItem(Item.diamond.itemID, 1);
        }

        if (this.isBurning())
        {
            this.dropItem(Item.chickenCooked.itemID, 1);
        }
        else
        {
            this.dropItem(Item.chickenRaw.itemID, 1);
        }
    }

    /**
     * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
     */
    public EntityBlueChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable)
    {
        return new EntityBlueChicken(this.worldObj);
    }

    /**
     * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
     * the animal type)
     */
    public boolean isBreedingItem(ItemStack par1ItemStack)
    {
        return par1ItemStack != null && par1ItemStack.itemID == Item.diamond.itemID;
    }

    public EntityAgeable createChild(EntityAgeable par1EntityAgeable)
    {
        return this.spawnBabyAnimal(par1EntityAgeable);
    }
}

 

most recent error:

 

2013-10-26 00:26:31 [iNFO] [sTDERR] java.lang.reflect.InvocationTargetException

2013-10-26 00:26:31 [iNFO] [sTDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

2013-10-26 00:26:31 [iNFO] [sTDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

2013-10-26 00:26:31 [iNFO] [sTDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

2013-10-26 00:26:31 [iNFO] [sTDERR] at java.lang.reflect.Constructor.newInstance(Unknown Source)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:205)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:175)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:81)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:152)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:429)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:556)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

2013-10-26 00:26:31 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException

2013-10-26 00:26:31 [iNFO] [sTDERR] at mods.mochickens.mobs.EntityBlueChicken.applyEntityAttributes(EntityBlueChicken.java:65)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:193)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:85)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:40)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.EntityAgeable.<init>(EntityAgeable.java:16)

2013-10-26 00:26:31 [iNFO] [sTDERR] at net.minecraft.entity.passive.EntityAnimal.<init>(EntityAnimal.java:31)

2013-10-26 00:26:31 [iNFO] [sTDERR] at mods.mochickens.mobs.EntityBlueChicken.<init>(EntityBlueChicken.java:38)

2013-10-26 00:26:31 [iNFO] [sTDERR] ... 20 more

2013-10-26 00:26:31 [WARNING] [Minecraft-Server] Skipping Entity with id 301

 

Link to comment
Share on other sites

Maybe it is because your BlueChicken extends EntityAnimal instead of EntityCreature?

 

I think zombies use EntityMob, but yes.  EntityAnimal doesn't have the attack function.  Which is why wolves are in the hostile mobs package.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I've looked at the wolf class because i do want it to be possible to tame the mob, so i set the extending class to EntityTameable. which still didnt fix the problem. the error sounds like the collision is returning null. at this point im wondering if there is a way to manually code this in. if i make it extend EntityCreature or EntityMob its breaks the mating part of it as well as means i cant make it tameable. code and error did not change except for trying to extend the different entities and ended on EntityTamable.

 

@Draco EntityWolf is in the passive package, not the hostile package.

Link to comment
Share on other sites

@Draco EntityWolf is in the passive package, not the hostile package.

 

...You are correct.  It's iron golems that are in hostile.

(And this emphasizes why the package differentiation is almost meaningless).

 

I unfortunately don't have a solution for you.  All my mob coding has been taking something that's close to what I want and modifying it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If you use attackEntityAsMob as Draco suggested, you can inflict damage directly to the entity attacked by using the attackEntityFrom method with no need for using attributes.

public boolean attackEntityAsMob(Entity par1Entity)
{
  // This will inflice 3 damage as a mob to the entity struck:
  par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F);
  this.setLastAttacker(par1Entity);
  return false;
}

If you really want to use the attribute system, you will have to add the correct attribute to the attribute map before you can set it, if it has not been added already by a super class.

Link to comment
Share on other sites

Thanks! i had actually just figured it out myself, but used a lot more lines of code because i copied it from the EntityMob class. I think i'll use the way i found because it shows more of how i can customize what happens to the player, but your help was still much appreciated. now on to making it so you can tame it and it will stop attacking you. think this will be a bit easier than the damage thing was, though once i thought of it i realized that it was an easy thing to get working. anyway thanks for your help!

 

Code i am using for those that are seeing this in the future:

public boolean attackEntityAsMob(Entity par1Entity)
    {
    	EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D);
    	float f = (float) 3.0D;
        int i = 0;

        if (entityplayer instanceof EntityLivingBase)
        {
            f += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase)entityplayer);
            i += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase)entityplayer);
        }

        boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), f);

        if (flag)
        {
            if (i > 0)
            {
            	entityplayer.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
                this.motionX *= 0.6D;
                this.motionZ *= 0.6D;
            }

            int j = EnchantmentHelper.getFireAspectModifier(this);

            if (j > 0)
            {
            	entityplayer.setFire(j * 4);
            }

            if (entityplayer instanceof EntityLivingBase)
            {
                EnchantmentThorns.func_92096_a(this, (EntityLivingBase)entityplayer, this.rand);
            }
        }

        return flag;
    }

(some of this isnt needed but im keeping it for refernce)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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