Package de.kumpelblase2.remoteentities.entities

Source Code of de.kumpelblase2.remoteentities.entities.RemoteSkeletonEntity

package de.kumpelblase2.remoteentities.entities;

import net.minecraft.server.v1_7_R1.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.util.Vector;
import de.kumpelblase2.remoteentities.api.*;
import de.kumpelblase2.remoteentities.api.features.InventoryFeature;
import de.kumpelblase2.remoteentities.api.thinking.*;
import de.kumpelblase2.remoteentities.api.thinking.goals.*;
import de.kumpelblase2.remoteentities.nms.PathfinderGoalSelectorHelper;

public class RemoteSkeletonEntity extends EntitySkeleton implements RemoteEntityHandle
{
  private RemoteEntity m_remoteEntity;
  protected int m_lastBouncedId;
  protected long m_lastBouncedTime;

  public RemoteSkeletonEntity(World world)
  {
    super(world);
    new PathfinderGoalSelectorHelper(this.goalSelector).clearGoals();
    new PathfinderGoalSelectorHelper(this.targetSelector).clearGoals();
  }

  public RemoteSkeletonEntity(World world, RemoteEntity inEntity)
  {
    this(world);
    this.m_remoteEntity = inEntity;
    this.setEquipment(0, new ItemStack(Items.BOW));
  }

  @Override
  public Inventory getInventory()
  {
    if(!this.m_remoteEntity.getFeatures().hasFeature(InventoryFeature.class))
      return null;

    return this.m_remoteEntity.getFeatures().getFeature(InventoryFeature.class).getInventory();
  }

  @Override
  public RemoteEntity getRemoteEntity()
  {
    return this.m_remoteEntity;
  }

  @Override
  public void setupStandardGoals()
  {
    Mind mind = this.getRemoteEntity().getMind();
    mind.addMovementDesires(getDefaultMovementDesires());
    mind.addTargetingDesires(getDefaultTargetingDesires());
  }

  @Override
  public void h()
  {
    super.h();
    if(this.getRemoteEntity() != null)
      this.getRemoteEntity().getMind().tick();
  }

  @Override
  public void g(double x, double y, double z)
  {
    if(this.m_remoteEntity == null)
    {
      super.g(x, y, z);
      return;
    }

    Vector vector = ((RemoteBaseEntity)this.m_remoteEntity).onPush(x, y, z);
    if(vector != null)
      super.g(vector.getX(), vector.getY(), vector.getZ());
  }

  @Override
  public void move(double d0, double d1, double d2)
  {
    if(this.m_remoteEntity != null && this.m_remoteEntity.isStationary())
      return;

    super.move(d0, d1, d2);
  }

  @Override
  public void e(float inXMotion, float inZMotion)
  {
    float[] motion = new float[] { inXMotion, inZMotion, (float)this.motY };
    if(this.m_remoteEntity.getMind().hasBehavior(RideBehavior.class))
      this.m_remoteEntity.getMind().getBehavior(RideBehavior.class).ride(motion);

    this.motY = (double)motion[2];
    super.e(motion[0], motion[1]);
  }

  @Override
  public void collide(Entity inEntity)
  {
    if(this.getRemoteEntity() == null)
    {
      super.collide(inEntity);
      return;
    }

    if(((RemoteBaseEntity)this.m_remoteEntity).onCollide(inEntity.getBukkitEntity()))
      super.collide(inEntity);
  }

  @Override
  public boolean a(EntityHuman entity)
  {
    if(this.getRemoteEntity() == null)
      return super.a(entity);

    if(!(entity.getBukkitEntity() instanceof Player))
      return super.a(entity);

    return ((RemoteBaseEntity)this.m_remoteEntity).onInteract((Player)entity.getBukkitEntity()) && super.a(entity);
  }

  @Override
  public void die(DamageSource damagesource)
  {
    ((RemoteBaseEntity)this.m_remoteEntity).onDeath();
    super.die(damagesource);
  }

  @Override
  public Entity findTarget()
  {
    return this.getGoalTarget();
  }

  @Override
  protected String t()
  {
    return this.m_remoteEntity.getSound(EntitySound.RANDOM);
  }

  @Override
  protected String aT()
  {
    return this.m_remoteEntity.getSound(EntitySound.HURT);
  }

  @Override
  protected String aU()
  {
    return this.m_remoteEntity.getSound(EntitySound.DEATH);
  }

  @Override
  protected void a(int i, int j, int k, Block l) {
    this.makeSound(this.m_remoteEntity.getSound(EntitySound.STEP), 0.15F, 1.0F);
  }

  @Override
  public void a(EntityLiving entityliving, float f) {
    //Taken from EntitySkeleton.java#204 - 224
    //modified to work with custom sounds
    EntityArrow entityarrow = new EntityArrow(this.world, this, entityliving, 1.6F, (float) (14 - this.world.difficulty.a() * 4));
    int i = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, this.be());
    int j = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, this.be());

    entityarrow.b((double) (f * 2.0F) + this.random.nextGaussian() * 0.25D + (double) ((float) this.world.difficulty.a() * 0.11F));
    if (i > 0) {
      entityarrow.b(entityarrow.e() + (double) i * 0.5D + 0.5D);
    }

    if (j > 0) {
      entityarrow.a(j);
    }

    if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, this.be()) > 0 || this.getSkeletonType() == 1) {
      entityarrow.setOnFire(100);
    }

    this.makeSound(this.m_remoteEntity.getSound(EntitySound.ATTACK), 1.0F, 1.0F / (this.aI().nextFloat() * 0.4F + 0.8F));
    this.world.addEntity(entityarrow);
  }

  public static DesireItem[] getDefaultMovementDesires()
  {
    return new DesireItem[] {
        new DesireItem(new DesireSwim(), 1),
        new DesireItem(new DesireRestrictSun(), 2),
        new DesireItem(new DesireAvoidSun(), 3),
        new DesireItem(new DesireRangedAttack(RemoteProjectileType.ENTITY_DEFAULT, 60), 4),
        new DesireItem(new DesireWanderAround(), 5),
        new DesireItem(new DesireLookAtNearest(EntityHuman.class, 8), 6),
        new DesireItem(new DesireLookRandomly(), 6)
    };
  }

  public static DesireItem[] getDefaultTargetingDesires()
  {
    return new DesireItem[] {
        new DesireItem(new DesireFindAttackingTarget(16, false, false), 1),
        new DesireItem(new DesireFindNearestTarget(EntityHuman.class, 16, false, true, 0), 2)
    };
  }
}
TOP

Related Classes of de.kumpelblase2.remoteentities.entities.RemoteSkeletonEntity

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.