Skip to content
Permalink
Browse files

Better organized trilobite AI (not done)

  • Loading branch information...
Ri5ux committed Apr 1, 2019
1 parent b72bc33 commit dc2e0cda188ee95cb29aa4b5e7726faa802efbb6
Showing with 119 additions and 55 deletions.
  1. +119 −55 src/main/java/org/avp/entities/living/species/species223ode/EntityTrilobite.java
@@ -1,7 +1,6 @@
package org.avp.entities.living.species.species223ode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.avp.AliensVsPredator;
@@ -132,6 +131,7 @@ public EntityTrilobite(World world)
super(world);
this.setSize(3F, 1.98F);
this.experienceValue = 32;
this.jumpMovementFactor = 1.0F;
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(3, new EntityAICustomAttackOnCollide(this, 0.800000011920929D, true));
this.tasks.addTask(8, new EntityAIWander(this, 0.800000011920929D));
@@ -179,52 +179,142 @@ public void onEntityUpdate()
{
super.onEntityUpdate();
}

@Override
public void onUpdate()
public void updatePassenger(Entity passenger)
{
super.onUpdate();
super.updatePassenger(passenger);
}

if (!this.isFertile())
private void updateHitbox()
{
if (this.world.getWorldTime() % 20 == 0)
{
this.setNoAI(true);
if (!this.isFertile() && this.getRidingEntity() == null)
{
this.height = 0.5F;
}

if (!this.isFertile() && this.getRidingEntity() != null)
{
this.height = 3F;
}

this.motionY -= 0.25F;
int[] tentacles = this.getDetachedTentacles();
boolean hasAllTentacles = true;

this.motionX *= 0.98F;
this.motionY *= 0.98F;
this.motionZ *= 0.98F;
this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
for (int i = 0; i < this.getAmountOfTentacles(); i++)
{
if (tentacles[i] == 1)
{
hasAllTentacles = false;
}
}

if (!hasAllTentacles)
{
this.width = 2;
}
}
}

@Override
protected void updateAnimations()
{
super.updateAnimations();

if (this.collidedHorizontally)
if (this.getAttackTarget() != null)
{
this.motionY += 0.25F;
if (this.getActiveAnimation() == ANIMATION_HUG_WALL)
{
Entity entityIn = this.getAttackTarget();
float angle = (float) (MathHelper.atan2(entityIn.posZ - this.posZ, entityIn.posX - this.posX) * (180D / Math.PI)) - 90.0F;
angle = MathHelper.floor((angle / 90) + 0.5) * 90F;
this.rotationYaw = angle;
}

double distanceX = this.prevPosX - this.posX;
double distanceZ = this.prevPosZ - this.posZ;

double motion = distanceX * distanceZ;

if ((this.collidedHorizontally) && this.getActiveAnimation() == NO_ANIMATION && Math.abs(motion) < 0.3D && Math.abs(motion) > 0.0D)
{
AnimationHandler.INSTANCE.sendAnimationMessage(this, ANIMATION_HUG_WALL);
}
}

this.jumpMovementFactor = 1.0F;
if (this.world.getWorldTime() % 20 == 0)
if (this.getRidingEntity() == null && this.getActiveAnimation() == IMPREGNATION_ANIMATION)
{
if (isFertile())
{
ArrayList<EntityLivingBase> targetHosts = (ArrayList<EntityLivingBase>) world.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expand(1.0D, 16.0D, 1.0D), this.getImpregnationEntitiySelector());
this.setActiveAnimation(NO_ANIMATION);
}
}

if (targetHosts != null && targetHosts.size() > 0)
{
Collections.sort(targetHosts, new EntityAINearestAttackableTarget.Sorter(this));
@Override
public void onUpdate()
{
super.onUpdate();

EntityLivingBase targetHost = targetHosts.get(0);
this.setAttackTarget(targetHost);
this.updateHitbox();
this.negateFallDamage();
this.slideUpSurface();

if (!targetHosts.contains(this.getAttackTarget()))
{
this.setAttackTarget(null);
}
if (this.getAttackTarget() != null)
{
if (this.world.getWorldTime() % 5 == 0)
{
if (!this.getImpregnationEntitiySelector().apply(this.getAttackTarget()))
{
this.setAttackTarget(null);
}
}
}

this.negateFallDamage();
// if (this.world.getWorldTime() % 20 == 0)
// {
// if (isFertile())
// {
// ArrayList<EntityLivingBase> targetHosts = (ArrayList<EntityLivingBase>) world.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expand(1.0D, 16.0D, 1.0D), this.getImpregnationEntitiySelector());
//
// if (targetHosts != null && targetHosts.size() > 0)
// {
// Collections.sort(targetHosts, new EntityAINearestAttackableTarget.Sorter(this));
//
// EntityLivingBase targetHost = targetHosts.get(0);
// this.setAttackTarget(targetHost);
//
// if (!targetHosts.contains(this.getAttackTarget()))
// {
// this.setAttackTarget(null);
// }
// }
// }
// }

this.handleInfertileState();
}

private void slideUpSurface()
{
if (this.collidedHorizontally)
{
this.motionY += 0.25F;
}
}

private void handleInfertileState()
{
if (!this.isFertile())
{
this.setNoAI(true);

this.motionY -= 0.25F;

this.motionX *= 0.98F;
this.motionY *= 0.98F;
this.motionZ *= 0.98F;
this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
}

if (this.isAttachedToHost())
{
@@ -291,32 +381,6 @@ public float updateRotation(float x, float y, float z)
this.detachFromHost();
}
}

if (this.getAttackTarget() != null)
{
if (this.getActiveAnimation() == ANIMATION_HUG_WALL)
{
Entity entityIn = this.getAttackTarget();
float angle = (float) (MathHelper.atan2(entityIn.posZ - this.posZ, entityIn.posX - this.posX) * (180D / Math.PI)) - 90.0F;
angle = MathHelper.floor((angle / 90) + 0.5) * 90F;
this.rotationYaw = angle;
}

double distanceX = this.prevPosX - this.posX;
double distanceZ = this.prevPosZ - this.posZ;

double motion = distanceX * distanceZ;

if ((this.collidedHorizontally) && this.getActiveAnimation() == NO_ANIMATION && Math.abs(motion) < 0.3D && Math.abs(motion) > 0.0D)
{
AnimationHandler.INSTANCE.sendAnimationMessage(this, ANIMATION_HUG_WALL);
}
}

if (this.getRidingEntity() == null && this.getActiveAnimation() == IMPREGNATION_ANIMATION)
{
this.setActiveAnimation(NO_ANIMATION);
}
}

@Override
@@ -568,7 +632,7 @@ public void detachTentacle()
{
this.dropTentacle();
}

return tentacles;
}
else

0 comments on commit dc2e0cd

Please sign in to comment.
You can’t perform that action at this time.