Posted September 5, 201411 yr When you punch an untamed wolf it turns angry and attacks you. The EntityWolf class adds an EntityAIHurtByTarget to its targetTasks list which I've duplicated but my custom mob still doesn't attack me when I punch it so I'm obviously missing something but I don't know what it is. I like trains.
September 5, 201411 yr First: Show your class. Second: There is called a method attackEntityFrom(DamageSource damage, float f). This method is called when the mob is attacked. Maybe this is a good tip for you.
September 5, 201411 yr Take a look here. I'm not sure about the AI for land mobs though. Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
September 5, 201411 yr Author This is my entity's code: package untouchedwagons.minecraft.mindcrackermobs.entity.mindcrackers; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import java.util.Random; public class EntityCustomMob extends EntityAnimal { public EntityCustomMob(World world) { super(world); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIWander(this, 1D)); this.tasks.addTask(3, new EntityAILookIdle(this)); this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1, true)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.isImmuneToFire = true; } @Override public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) return false; Entity damage_source = p_70097_1_.getEntity(); if (damage_source instanceof EntityPlayer) { this.setRevengeTarget((EntityPlayer) damage_source); this.attackingPlayer = (net.minecraft.entity.player.EntityPlayer) damage_source; this.entityToAttack = damage_source; } return super.attackEntityFrom(p_70097_1_, p_70097_2_); } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(16.0D); } } I see that your entity has an 'updateAITasks' method which does some stuff if the entity is angry. I guess I need to implement that stuff I like trains.
September 5, 201411 yr Author I've managed to get my mob to path to the attacker but never actually does any damage: package untouchedwagons.minecraft.mindcrackermobs.entity.mindcrackers; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import java.util.Random; public class EntityCustomMob extends EntityAnimal { public EntityCustomMob(World world) { super(world); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIWander(this, 1D)); this.tasks.addTask(3, new EntityAILookIdle(this)); this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1, true)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.isImmuneToFire = true; } @Override public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) return false; boolean state = super.attackEntityFrom(p_70097_1_, p_70097_2_); Entity damage_source = p_70097_1_.getEntity(); if (damage_source instanceof EntityPlayer) { this.setTarget(damage_source); this.setRevengeTarget((EntityPlayer)damage_source); } return state; } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D); } @Override public boolean attackEntityAsMob(Entity target) { float damage = (float)this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); int knockback = 0; if (target instanceof EntityLivingBase) { damage += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase)target); knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase)target); } boolean flag = target.attackEntityFrom(DamageSource.causeMobDamage(this), damage); if (flag) { if (knockback > 0) { target.addVelocity((double) (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F) ); this.motionX *= 0.6D; this.motionZ *= 0.6D; } int j = EnchantmentHelper.getFireAspectModifier(this); if (j > 0) { target.setFire(j * 4); } if (target instanceof EntityLivingBase) { EnchantmentHelper.func_151384_a((EntityLivingBase)target, this); } EnchantmentHelper.func_151385_b(this, target); } return flag; } } I like trains.
September 6, 201411 yr There's another AI task you need to use (I'm not at my computer now so I don't know what it is) and make sure attackEntityAsMob returns false if the mob isn't angry, or it will hurt you to run into it. Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
September 6, 201411 yr For the problem of an entity trying to attack without doing damage, I have a tutorial for that: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-custom-entity.html Check out my tutorials here: http://jabelarminecraft.blogspot.com/
September 6, 201411 yr Author There's another AI task you need to use (I'm not at my computer now so I don't know what it is) and make sure attackEntityAsMob returns false if the mob isn't angry, or it will hurt you to run into it. Okay For the problem of an entity trying to attack without doing damage, I have a tutorial for that: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-custom-entity.html Cool I'll take a look at that I like trains.
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.