Waabbuffet Posted June 14, 2015 Posted June 14, 2015 I created this entity warrior that follows you and attacks whatever you attack. The only problem is when he attacks he goes super sonic, and runs circles around the target hes attacking. The code for the class is here. How do i fix this? public class IamAWarrior extends EntityTameable{ EntityPlayer player = Minecraft.getMinecraft().thePlayer; public IamAWarrior(World par1World) { super(par1World); this.setSize(0.6F, 0.8F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 4.0D, true)); this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(9, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.setTamed(true); } protected void applyEntityAttributes(){ super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D); //this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D); } @Override protected boolean isAIEnabled() { return true; } @Override protected boolean canDespawn() { return false; } @Override public boolean attackEntityAsMob(Entity p_70652_1_) { int i = 10; return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i); } @Override public void writeEntityToNBT(NBTTagCompound cmp) { super.writeEntityToNBT(cmp); cmp.setString("Owners Name", player.getUniqueID().toString()); } @Override public void readEntityFromNBT(NBTTagCompound cmp) { super.readEntityFromNBT(cmp); this.func_152115_b(cmp.getString("Owners Name")); } @Override public EntityAgeable createChild(EntityAgeable entityageable) { return null; } } Quote
coolAlias Posted June 14, 2015 Posted June 14, 2015 The second parameter in EntityAIAttackOnCollide is the speed at which your entity will move towards the target. Most of the time, it should be the same as or just slightly more than your entity's movement speed, yet you set it to 4.0D, which is roughly 4 blocks per tick. Take it down a notch Quote http://i.imgur.com/NdrFdld.png[/img]
Waabbuffet Posted June 14, 2015 Author Posted June 14, 2015 OHH lol ok thanks for the quick reply. One more thing how do i make him hold a iron sword? Quote
coolAlias Posted June 14, 2015 Posted June 14, 2015 OHH lol ok thanks for the quick reply. One more thing how do i make him hold a iron sword? There's a whole topic about it that may help, but basically: 1. Set your entity's held item to what you want (use addRandomArmor or whatever else you need upon spawning) 2. To make your life easy, extend both RenderBiped and ModelBiped where appropriate 3. Make sure whatever attack AI you are using calls #swingItem when attacking - EntityAIAttackOnCollide does this. 4. Make sure you call updateArmSwingProgress() from your entity's onLivingUpdate method, otherwise the swing animation won't work despite your entity holding the sword Quote http://i.imgur.com/NdrFdld.png[/img]
Waabbuffet Posted June 14, 2015 Author Posted June 14, 2015 Alright thanks ill take a look, last thing . The entity doesnt seem to remember that i am the owner when i log out completely and come back, how do i fix this? Quote
coolAlias Posted June 14, 2015 Posted June 14, 2015 Alright thanks ill take a look, last thing . The entity doesnt seem to remember that i am the owner when i log out completely and come back, how do i fix this? Are you logging in with the same name each time? The default development environment settings log you in with a new user name each time - you need to set it in the run-time configuration: --username Me. You can even add your password (if the username is your real one) to log in using your actual account, if you want. Quote http://i.imgur.com/NdrFdld.png[/img]
Waabbuffet Posted June 14, 2015 Author Posted June 14, 2015 yea you are right, dam you are good at this! ;D Quote
coolAlias Posted June 14, 2015 Posted June 14, 2015 yea you are right, dam you are good at this! ;D Heh, more like I've just run into all the same problems before Quote http://i.imgur.com/NdrFdld.png[/img]
Recommended Posts
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.