From baf3ebfa1267c7b5ca446120423ce9762e1c0179 Mon Sep 17 00:00:00 2001 From: KitsuShadow Date: Mon, 20 Jul 2015 20:29:24 -0400 Subject: [PATCH] fluidAI --- .../entityAI/EntityAIWaterMob.class | Bin 0 -> 6918 bytes .../entityAI/EntityAIWaterMob.java | 229 ++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 bin/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.class create mode 100644 src/main/java/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.java diff --git a/bin/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.class b/bin/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.class new file mode 100644 index 0000000000000000000000000000000000000000..0628ff61a959eefab86001da505ea40aba44e568 GIT binary patch literal 6918 zcmbtY33y!9b^gz2q_N~HOO|91-fd*885zdd7-P$z#j@~#ykHp#yJ^VN%+u&uGxNkO zvJI_)Hc4X=2huhTG9jU9z=4p>wS<9$kffn4HEG&(OPel9(=`ie5}KsY(Er}|MjDM| zO25jUci-L4`k!;|eJ}p}ndbm(l3POv2(FI1>FB7F&lRF+JK@;lRw|yghVxN7lXvpR zyJFE@{>z}1x3hcPp%8+Cwv3&Rrk#vkx;Q#!<#Nur?QfacP$gLRh8tpC87FO}a)L!x zK5xZGV;M4|ECPuM7J7sIW44{(NUxwechpJy{ZQV@Chh!foaqtxy+hM)he_01VJAFY z1S|UH6~~)yCqpOKW#n)&Ns=Xr8qM&4m2e6avVNws+jf#8c{1xtW?ff{SCg_biEg)$ ziQDX?-K^bXrL818RXd!FlfOZ*vbBu=Q8$}PL__e^!r%8gRd^<{E;pom(|G%C!(_7JWWY@OGpC2RNER@TntJkU%8uvV>|C7~ z0BL$G8uPqgT-aWNE$Gzd?-Inz9p)Rt+p;rjTlqrPZtpu{jayOrKN;PbVl1@B4j(SF z;KjIw2WqeryFws@=Z}>VLmHzi^x{SW&q^e8pRR6=l`)&^u5K%58-&&MF?jbD(nEIk zpmv3zq0f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?s9f$exU@K$^_VBzzD zVLTtm;tPQj_+sE!@uk4S_;TQ*cp<=a6}W&GO?=;gDjlqTd@l*aWS=?LtO|6`d<&6Fi%D74rfh^!{W=w|3_&XR2i`gkyo%hijjy8rhS&M^P&lJU OkMJPaPxA%j;Qs)Sq#I=b literal 0 HcmV?d00001 diff --git a/src/main/java/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.java b/src/main/java/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.java new file mode 100644 index 00000000..c4efed81 --- /dev/null +++ b/src/main/java/com/kitsu/medievalcraft/entityAI/EntityAIWaterMob.java @@ -0,0 +1,229 @@ +package com.kitsu.medievalcraft.entityAI; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.passive.EntitySquid; +import net.minecraft.entity.passive.EntityWaterMob; +import net.minecraft.entity.passive.IAnimals; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class EntityAIWaterMob extends EntityWaterMob implements IAnimals{ + + protected int attackInterval = 50; + protected float attackSpeed = 1.2F; + protected float swimSpeed = 0.5F; + private double targetX; + private double targetY; + private double targetZ; + private Entity targetedEntity; + private boolean isAttacking; + protected float swimRadius = 4.0F; + protected float swimRadiusHeight = 4.0F; + protected boolean Agrooed = false; + protected boolean landBounce = true; + protected float moreDamage = 0.5F; + + + public EntityAIWaterMob(World world) + { + super(world); + this.targetTasks.addTask(0, new EntityAINearestAttackableTarget(this, EntitySquid.class, 32, true, true, IMob.mobSelector)); + } + + + protected boolean canTriggerWalking() + { + return false; + } + + protected boolean isAIEnabled() + { + return true; + } + public boolean canBreatheUnderwater() + { + return true; + } + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage); + } + + public boolean isInWater() + { + return this.worldObj.handleMaterialAcceleration(this.boundingBox, Material.water, this); + } + + public void onUpdate() + { + super.onUpdate(); + if (isInWater()) { + this.motionY *= 0.1D; + } + } + public void applyEntityCollision(Entity entity) + { + super.applyEntityCollision(entity); + if ((this.Agrooed) && (this.targetedEntity == entity)) + { + attackEntityAsMob(entity); + + } + } + + + protected Entity findPreyHuman() + { + EntityPlayer player = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); + return (player != null) && (canEntityBeSeen(player)) ? player : null; + + } + + protected Entity findPreySquid() + { + //EntitySquid squid = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); + //AxisAlignedBB ab = new AxisAlignedBB(-16d, -16d, -16d, 16d, 16d, 16d); + EntitySquid squid = (EntitySquid) this.worldObj.getEntitiesWithinAABB(EntitySquid.class, AxisAlignedBB.getBoundingBox(-106d, -106d, -106d, 106d, 106d, 106d)); + System.out.println("Finding Squid"); + return (squid != null) && (canEntityBeSeen(squid)) ? squid : null; + + } + + public boolean attackEntityAsMob(Entity entity) + { + float f = (float)getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); + + return entity.attackEntityFrom(DamageSource.causeMobDamage(this), f + moreDamage); + + } + + + public void onEntityUpdate() + { + int air = getAir(); + super.onEntityUpdate(); + if ((isEntityAlive()) && (!isInWater())) + { + air--; + setAir(air); + if (getAir() == -20) + { + setAir(0); + attackEntityFrom(DamageSource.drown, 2.0F); + } + } + else + { + setAir(300); + } + } + + + protected void updateAITasks() + { + super.updateAITasks(); + if (isInWater()) + { + double dx = this.targetX - this.posX; + double dy = this.targetY - this.posY; + double dz = this.targetZ - this.posZ; + double dist = MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz); + if ((dist < 1.0D) || (dist > 1000.0D)) + { + this.targetX = (this.posX + (this.rand.nextFloat() * 2.0F - 1.0F) * this.swimRadius); + this.targetY = (this.posY + (this.rand.nextFloat() * 2.0F - 1.0F) * this.swimRadiusHeight); + this.targetZ = (this.posZ + (this.rand.nextFloat() * 2.0F - 1.0F) * this.swimRadius); + this.isAttacking = false; + } + if (this.worldObj.getBlock(MathHelper.floor_double(this.targetX), MathHelper.floor_double(this.targetY + this.height), MathHelper.floor_double(this.targetZ)).getMaterial() == Material.water) + { + this.motionX += dx / dist * 0.05D * this.swimSpeed; + this.motionY += dy / dist * 0.1D * this.swimSpeed; + this.motionZ += dz / dist * 0.05D * this.swimSpeed; + } + else + { + this.targetX = this.posX; + this.targetY = (this.posY + 0.1D); + this.targetZ = this.posZ; + } + if (this.isAttacking) + { + this.motionX *= this.attackSpeed; + this.motionY *= this.attackSpeed; + this.motionZ *= this.attackSpeed; + } + if ((this.Agrooed) && (this.rand.nextInt(this.attackInterval) == 0)) + { + this.targetedEntity = findPreyHuman(); + if ((this.targetedEntity != null) && (this.targetedEntity.isInWater())) + { + this.targetX = this.targetedEntity.posX; + this.targetY = this.targetedEntity.posY; + this.targetZ = this.targetedEntity.posZ; + this.isAttacking = true; + } + this.targetedEntity = findPreySquid(); + if ((this.targetedEntity != null) && (this.targetedEntity.isInWater())) + { + this.targetX = this.targetedEntity.posX; + this.targetY = this.targetedEntity.posY; + this.targetZ = this.targetedEntity.posZ; + this.isAttacking = true; + } + } + this.renderYawOffset += (-(float)Math.atan2(this.motionX, this.motionZ) * 180.0F / 3.141593F - this.renderYawOffset) * 0.5F; + this.rotationYaw = this.renderYawOffset; + float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); + this.rotationPitch += ((float)Math.atan2(this.motionY, f) * 180.0F / 3.141593F - this.rotationPitch) * 0.5F; + } + else + { + this.motionX = 0.0D; + this.motionY -= 0.08D; + this.motionY *= 0.9800000190734863D; + this.motionZ = 0.0D; + if ((this.landBounce) && (this.onGround) && (this.rand.nextInt(30) == 0)) + { + this.motionY = 0.300000011920929D; + this.motionX = (-0.4F + this.rand.nextFloat() * 0.8F); + this.motionZ = (-0.4F + this.rand.nextFloat() * 0.8F); + } + } + } + +} + +/*when you extend it, +you want to add these to your constructor: + +this.Agrooed = true; + this.swimRadius = 25F; + this.swimSpeed = 0.5F; + this.attackInterval = 23; + this.landBounce = true; + +what these stand for are pretty self explanitory. add this to your class: + + @Override + protected Entity findPrey() + { + AxisAlignedBB area = this.boundingBox.expand(16.0D, 16.0D, 16.0D); + + EntityPlayer player = (EntityPlayer)super.findPrey(); + if (player != null) { + return player; + } + + return worldObj.findNearestEntityWithinAABB(EntityPlayer.class, area, this); + */ +