Catfish55 Posted May 19, 2014 Posted May 19, 2014 So, the line: this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(value); doesn't seem to change anything unless the new AI is enabled. However, with new AI enabled, it really messes with some of the things I've added. Is there a good way to make it move faster otherwise I've tried doing all sorts of adjustments of movement speed in the onLivingUpdate tick. Quote
jabelar Posted May 19, 2014 Posted May 19, 2014 I've always used the new AI so never really looked at this before. However, looking at it quickly it seems that you probably need to look at overriding at the following: In your entity class, maybe Override the getAISpeed() method. In the EntityLivingBase class, the method is defined as: public float getAIMoveSpeed() { return this.isAIEnabled() ? this.landMovementFactor : 0.1F; } So just change that 0.1F to what you want. Not sure but that might do it. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Catfish55 Posted May 19, 2014 Author Posted May 19, 2014 I've always used the new AI so never really looked at this before. However, looking at it quickly it seems that you probably need to look at overriding at the following: In your entity class, maybe Override the getAISpeed() method. In the EntityLivingBase class, the method is defined as: public float getAIMoveSpeed() { return this.isAIEnabled() ? this.landMovementFactor : 0.1F; } So just change that 0.1F to what you want. Not sure but that might do it. Modified what you suggested a little bit and it work now, except when they go in water. I removed the this.landMovementFactor because it wasn't a variable that was recognized. Also, the problem with new AI is it seems to cause my mobs to randomly lose aggro on the player, and when I adjust the movement speed they don't face the way they are running. Quote
jabelar Posted May 19, 2014 Posted May 19, 2014 When they are swimming, they call a method called moveFlying() ("flying" is used for both swimming and flying because it means gravity is active on entity) which is called by moveEntityWithHeading(). In that method it also checks for the isAIEnabled() so you have to override that one as well. This is what the current class looks like: public void moveEntityWithHeading(float par1, float par2) { double d0; if (this.isInWater() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, this.isAIEnabled() ? 0.04F : 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.800000011920929D; this.motionY *= 0.800000011920929D; this.motionZ *= 0.800000011920929D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else if (this.handleLavaMovement() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.5D; this.motionY *= 0.5D; this.motionZ *= 0.5D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else { float f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } float f3 = 0.16277136F / (f2 * f2 * f2); float f4; if (this.onGround) { f4 = this.getAIMoveSpeed() * f3; } else { f4 = this.jumpMovementFactor; } this.moveFlying(par1, par2, f4); f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } if (this.isOnLadder()) { float f5 = 0.15F; if (this.motionX < (double)(-f5)) { this.motionX = (double)(-f5); } if (this.motionX > (double)f5) { this.motionX = (double)f5; } if (this.motionZ < (double)(-f5)) { this.motionZ = (double)(-f5); } if (this.motionZ > (double)f5) { this.motionZ = (double)f5; } this.fallDistance = 0.0F; if (this.motionY < -0.15D) { this.motionY = -0.15D; } boolean flag = this.isSneaking() && this instanceof EntityPlayer; if (flag && this.motionY < 0.0D) { this.motionY = 0.0D; } } this.moveEntity(this.motionX, this.motionY, this.motionZ); if (this.isCollidedHorizontally && this.isOnLadder()) { this.motionY = 0.2D; } if (this.worldObj.isRemote && (!this.worldObj.blockExists((int)this.posX, 0, (int)this.posZ) || !this.worldObj.getChunkFromBlockCoords((int)this.posX, (int)this.posZ).isChunkLoaded)) { if (this.posY > 0.0D) { this.motionY = -0.1D; } else { this.motionY = 0.0D; } } else { this.motionY -= 0.08D; } this.motionY *= 0.9800000190734863D; this.motionX *= (double)f2; this.motionZ *= (double)f2; } this.prevLimbSwingAmount = this.limbSwingAmount; d0 = this.posX - this.prevPosX; double d1 = this.posZ - this.prevPosZ; float f6 = MathHelper.sqrt_double(d0 * d0 + d1 * d1) * 4.0F; if (f6 > 1.0F) { f6 = 1.0F; } this.limbSwingAmount += (f6 - this.limbSwingAmount) * 0.4F; this.limbSwing += this.limbSwingAmount; } So you need to override the whole method and change the line near the top where it checks if isAIEnabled(). Regarding the rest of your comments about AI, I'm in the process of writing a tutorial on it. There are a couple of tricks related to how you disable AI when other AI is running (the setMutexBits() method is used but it is a little tricky without explanation) as well as the priority order you have the task list. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Catfish55 Posted May 19, 2014 Author Posted May 19, 2014 When they are swimming, they call a method called moveFlying() ("flying" is used for both swimming and flying because it means gravity is active on entity) which is called by moveEntityWithHeading(). In that method it also checks for the isAIEnabled() so you have to override that one as well. This is what the current class looks like: public void moveEntityWithHeading(float par1, float par2) { double d0; if (this.isInWater() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, this.isAIEnabled() ? 0.04F : 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.800000011920929D; this.motionY *= 0.800000011920929D; this.motionZ *= 0.800000011920929D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else if (this.handleLavaMovement() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.5D; this.motionY *= 0.5D; this.motionZ *= 0.5D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else { float f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } float f3 = 0.16277136F / (f2 * f2 * f2); float f4; if (this.onGround) { f4 = this.getAIMoveSpeed() * f3; } else { f4 = this.jumpMovementFactor; } this.moveFlying(par1, par2, f4); f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } if (this.isOnLadder()) { float f5 = 0.15F; if (this.motionX < (double)(-f5)) { this.motionX = (double)(-f5); } if (this.motionX > (double)f5) { this.motionX = (double)f5; } if (this.motionZ < (double)(-f5)) { this.motionZ = (double)(-f5); } if (this.motionZ > (double)f5) { this.motionZ = (double)f5; } this.fallDistance = 0.0F; if (this.motionY < -0.15D) { this.motionY = -0.15D; } boolean flag = this.isSneaking() && this instanceof EntityPlayer; if (flag && this.motionY < 0.0D) { this.motionY = 0.0D; } } this.moveEntity(this.motionX, this.motionY, this.motionZ); if (this.isCollidedHorizontally && this.isOnLadder()) { this.motionY = 0.2D; } if (this.worldObj.isRemote && (!this.worldObj.blockExists((int)this.posX, 0, (int)this.posZ) || !this.worldObj.getChunkFromBlockCoords((int)this.posX, (int)this.posZ).isChunkLoaded)) { if (this.posY > 0.0D) { this.motionY = -0.1D; } else { this.motionY = 0.0D; } } else { this.motionY -= 0.08D; } this.motionY *= 0.9800000190734863D; this.motionX *= (double)f2; this.motionZ *= (double)f2; } this.prevLimbSwingAmount = this.limbSwingAmount; d0 = this.posX - this.prevPosX; double d1 = this.posZ - this.prevPosZ; float f6 = MathHelper.sqrt_double(d0 * d0 + d1 * d1) * 4.0F; if (f6 > 1.0F) { f6 = 1.0F; } this.limbSwingAmount += (f6 - this.limbSwingAmount) * 0.4F; this.limbSwing += this.limbSwingAmount; } So you need to override the whole method and change the line near the top where it checks if isAIEnabled(). Regarding the rest of your comments about AI, I'm in the process of writing a tutorial on it. There are a couple of tricks related to how you disable AI when other AI is running (the setMutexBits() method is used but it is a little tricky without explanation) as well as the priority order you have the task list. How do you adjust the priorities on the task list? Also, it worked, thanks! Quote
jabelar Posted May 20, 2014 Posted May 20, 2014 How do you adjust the priorities on the task list? Also, it worked, thanks! I'm just writing a tutorial on this, and it isn't really finished, but you might find it useful so far: http://jabelarminecraft.blogspot.com/p/custom-entity-ai.html Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
SanAndreaP Posted May 20, 2014 Posted May 20, 2014 When they are swimming, they call a method called moveFlying() ("flying" is used for both swimming and flying because it means gravity is active on entity) which is called by moveEntityWithHeading(). In that method it also checks for the isAIEnabled() so you have to override that one as well. This is what the current class looks like: public void moveEntityWithHeading(float par1, float par2) { double d0; if (this.isInWater() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, this.isAIEnabled() ? 0.04F : 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.800000011920929D; this.motionY *= 0.800000011920929D; this.motionZ *= 0.800000011920929D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else if (this.handleLavaMovement() && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).capabilities.isFlying)) { d0 = this.posY; this.moveFlying(par1, par2, 0.02F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.5D; this.motionY *= 0.5D; this.motionZ *= 0.5D; this.motionY -= 0.02D; if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ)) { this.motionY = 0.30000001192092896D; } } else { float f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } float f3 = 0.16277136F / (f2 * f2 * f2); float f4; if (this.onGround) { f4 = this.getAIMoveSpeed() * f3; } else { f4 = this.jumpMovementFactor; } this.moveFlying(par1, par2, f4); f2 = 0.91F; if (this.onGround) { f2 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.91F; } if (this.isOnLadder()) { float f5 = 0.15F; if (this.motionX < (double)(-f5)) { this.motionX = (double)(-f5); } if (this.motionX > (double)f5) { this.motionX = (double)f5; } if (this.motionZ < (double)(-f5)) { this.motionZ = (double)(-f5); } if (this.motionZ > (double)f5) { this.motionZ = (double)f5; } this.fallDistance = 0.0F; if (this.motionY < -0.15D) { this.motionY = -0.15D; } boolean flag = this.isSneaking() && this instanceof EntityPlayer; if (flag && this.motionY < 0.0D) { this.motionY = 0.0D; } } this.moveEntity(this.motionX, this.motionY, this.motionZ); if (this.isCollidedHorizontally && this.isOnLadder()) { this.motionY = 0.2D; } if (this.worldObj.isRemote && (!this.worldObj.blockExists((int)this.posX, 0, (int)this.posZ) || !this.worldObj.getChunkFromBlockCoords((int)this.posX, (int)this.posZ).isChunkLoaded)) { if (this.posY > 0.0D) { this.motionY = -0.1D; } else { this.motionY = 0.0D; } } else { this.motionY -= 0.08D; } this.motionY *= 0.9800000190734863D; this.motionX *= (double)f2; this.motionZ *= (double)f2; } this.prevLimbSwingAmount = this.limbSwingAmount; d0 = this.posX - this.prevPosX; double d1 = this.posZ - this.prevPosZ; float f6 = MathHelper.sqrt_double(d0 * d0 + d1 * d1) * 4.0F; if (f6 > 1.0F) { f6 = 1.0F; } this.limbSwingAmount += (f6 - this.limbSwingAmount) * 0.4F; this.limbSwing += this.limbSwingAmount; } So you need to override the whole method and change the line near the top where it checks if isAIEnabled(). Or, you know, just override moveFlying and call the super method with a different 3rd parameter: moveFlying(par1, par2, par3) { if isInWater then par3 = aCustomValue super.moveFlying(par1, par2, par3) } No need to copy-paste this monstrosity for a tiny change like this. Quote Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
jabelar Posted May 20, 2014 Posted May 20, 2014 Or, you know, just override moveFlying and call the super method with a different 3rd parameter: moveFlying(par1, par2, par3) { if isInWater then par3 = aCustomValue super.moveFlying(par1, par2, par3) } No need to copy-paste this monstrosity for a tiny change like this. True it is way more elegant in this case, but the problem is that in general (as you know) you have to think carefully about this sort of thing since the moveFlying() method is called from other places and if a person not so confident in coding does this they might forget to handle the lava case or whatever that also calls the method. A surgical change of just the lines you know are "wrong" (in this case any checks of isAIEnabled) is a bit safer for a beginning coder. (Remember we're helping someone who couldn't figure out where to make the change on their own.) I admit in this case copying a large method for change of one line is not elegant though. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.