Jump to content

[1.8] setAlwaysRenderNameTag doesn't work


SteveKunG

Recommended Posts

 

//package stevekung.mods.entityghost.entities;

//

//import java.util.Calendar;

//import java.util.Collections;

//import java.util.List;

//

//import net.minecraft.entity.Entity;

//import net.minecraft.entity.SharedMonsterAttributes;

//import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

//import net.minecraft.entity.monster.EntityMob;

//import net.minecraft.entity.player.EntityPlayer;

//import net.minecraft.nbt.NBTTagCompound;

//import net.minecraft.pathfinding.PathNavigateGround;

//import net.minecraft.util.DamageSource;

//import net.minecraft.util.EntityDamageSource;

//import net.minecraft.util.EntityDamageSourceIndirect;

//import net.minecraft.util.MathHelper;

//import net.minecraft.util.Vec3;

//import net.minecraft.world.World;

//import stevekung.mods.entityghost.core.EntityGhostCore;

//

//public class EntityGhost extends EntityMob

//{

// //TODO New Year Feature

// //TODO Halloween Feature

//

// private Calendar calendar = Calendar.getInstance();

// private int teleportDelay;

// private boolean isHalloween = this.calendar.get(2) + 1 == 2 && this.calendar.get(5) == 14;

// private boolean isAprilFoolDay = this.calendar.get(2) + 1 == 4 && this.calendar.get(5) == 1;

// private boolean isNewYear = this.calendar.get(2) + 1 == 12 && this.calendar.get(5) >= 30 && this.calendar.get(5) <= 31 || this.calendar.get(2) + 1 == 1 && this.calendar.get(5) >= 1 && this.calendar.get(5) <= 2;

//

// public EntityGhost(World par1World)

// {

// super(par1World);

// ((PathNavigateGround)this.getNavigator()).func_179688_b(true);

// this.setSize(1.0F, 2.0F);

// this.stepHeight = 0.5F;

//

// /*if (this.worldObj.rand.nextInt(50) == 0)

// {

// this.setCustomNameTag("Entity 303");

// this.setAlwaysRenderNameTag(true);

// }*/

// }

//

// @Override

// protected void applyEntityAttributes()

// {

// super.applyEntityAttributes();

// this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(80.0D);

// this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.0D);

// this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(17.0D);

//

// if (this.isHalloween)

// {

// this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(150.0D);

// this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(3.0D);

// this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(25.0D);

// }

// else if (this.isAprilFoolDay)

// {

// this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(5.0D);

// this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(100000.0D);

// }

// else if (this.isNewYear)

// {

// this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0D);

// }

// }

//

// @Override

// protected void entityInit()

// {

// super.entityInit();

// }

//

// @Override

// public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)

// {

// super.writeEntityToNBT(par1NBTTagCompound);

// }

//

// @Override

// public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)

// {

// super.readEntityFromNBT(par1NBTTagCompound);

// }

//

// private boolean shouldAttackPlayer(EntityPlayer par1EntityPlayer)

// {

// Vec3 var3 = par1EntityPlayer.getLook(3.0F).normalize();

// Vec3 var4 = new Vec3(this.posX - par1EntityPlayer.posX, this.getBoundingBox().minY + this.height / 2.0F - (par1EntityPlayer.posY + par1EntityPlayer.getEyeHeight()), this.posZ - par1EntityPlayer.posZ);

// double var5 = var4.lengthVector();

// var4 = var4.normalize();

// double var7 = var3.dotProduct(var4);

// return var7 > 1.0D - 0.025D / var5 ? par1EntityPlayer.canEntityBeSeen(this) : true;

// }

//

// @Override

// public void onLivingUpdate()

// {

// for (int i = 0; i < 2; ++i)

// {

// EntityGhostCore.proxy.spawnParticle("ghostPortal", this.posX + (this.rand.nextDouble() - 0.5D) * this.width, this.posY + this.rand.nextDouble() * this.height - 0.25D, this.posZ + (this.rand.nextDouble() - 0.5D) * this.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D);

// }

//

// this.isJumping = false;

//

// /*if (this.entityToAttack != null)

// {

// this.faceEntity(this.entityToAttack, 100.0F, 100.0F);

// }

//

// EntityLivingBase entity = this;

//

// if (!this.worldObj.isRemote && this.isEntityAlive())

// {

// if (this.entityToAttack != null)

// {

// if (this.entityToAttack instanceof EntityPlayer && this.shouldAttackPlayer((EntityPlayer)this.entityToAttack))

// {

// if (this.entityToAttack.getDistanceSqToEntity(this) < 128.0D)

// {

// EntityPlayer player = (EntityPlayer) this.entityToAttack;

//

// entity.addPotionEffect(new PotionEffect(Potion.invisibility.id, 360, 0, true));

// player.addPotionEffect(new PotionEffect(Potion.blindness.id, 240, 0, true));

// player.addPotionEffect(new PotionEffect(Potion.confusion.id, 240, 0, true));

//

// if (this.worldObj.rand.nextInt(50) == 0)

// {

// this.teleportRandomly();

//

// EntitySquid squid = new EntitySquid(this.worldObj);

// squid.setAbsorptionAmount(12.0F);

// squid.setLocationAndAngles(player.posX, player.posY + 8, player.posZ, this.rotationYaw, 0.0F);

// this.worldObj.spawnEntityInWorld(squid);

//

// EntityTNTPrimed tnt = new EntityTNTPrimed(this.worldObj);

// tnt.fuse = 100;

// tnt.setLocationAndAngles(player.posX, player.posY + 8, player.posZ, this.rotationYaw, 0.0F);

// squid.mountEntity(tnt);

// this.worldObj.spawnEntityInWorld(tnt);

// }

// if (this.worldObj.rand.nextInt(100) == 0)

// {

// this.spawnZombie();

// this.spawnCreeper();

// }

//

// if (this.isAprilFoolDay)

// {

// this.setLocationAndAngles(this.posX, this.posY + 10.0D, this.posZ, this.rotationYaw, 0.0F);

// this.worldObj.spawnEntityInWorld(this);

// }

// }

// this.teleportDelay = 0;

// }

// else if (this.entityToAttack.getDistanceSqToEntity(this) > 256.0D && this.teleportDelay++ >= 30 && this.teleportToEntity(this.entityToAttack))

// {

// this.teleportDelay = 0;

// }

// }

// else

// {

// this.teleportDelay = 0;

// }

// }*/

// super.onLivingUpdate();

// }

//

// /*private void spawnZombie()

// {

// EntityPlayer player = (EntityPlayer)this.entityToAttack;

//

// if (this.worldObj.rand.nextInt(100) == 0)

// {

// for (int i = 0; i < 5; ++i)

// {

// EntityZombie zombie = new EntityZombie(this.worldObj);

// zombie.setAbsorptionAmount(20F);

//

// if (this.rand.nextInt(4) == 0)

// {

// zombie.setChild(true);

// }

//

// zombie.setCurrentItemOrArmor(4, new ItemStack(this.rand.nextFloat() < 0.1F ? Items.golden_helmet : Items.diamond_helmet));

// zombie.setCurrentItemOrArmor(0, new ItemStack(this.rand.nextFloat() < 0.1F ? Items.iron_sword : Items.diamond_sword));

// zombie.setLocationAndAngles(player.posX + this.rand.nextFloat(), player.posY + 10, player.posZ + this.rand.nextFloat(), this.rotationYaw, 0.0F);

// this.worldObj.spawnEntityInWorld(zombie);

// }

// }

// }

//

// private void spawnCreeper()

// {

// EntityPlayer player = (EntityPlayer)this.entityToAttack;

//

// if (this.worldObj.rand.nextInt(150) == 0)

// {

// for (int i = 0; i < 5; ++i)

// {

// EntityCreeper creeper = new EntityCreeper(this.worldObj);

// creeper.setAbsorptionAmount(20F);

// creeper.setLocationAndAngles(player.posX + this.rand.nextFloat(), player.posY + 10, player.posZ + this.rand.nextFloat(), this.rotationYaw, 0.0F);

//

// if (this.rand.nextInt(4) == 0)

// {

// creeper.getDataWatcher().updateObject(17, Byte.valueOf((byte) 1));

// }

//

// this.worldObj.spawnEntityInWorld(creeper);

// }

// }

// }*/

//

// protected boolean teleportRandomly()

// {

// double var1 = this.posX + (this.rand.nextDouble() - 0.5D) * 64.0D;

// double var3 = this.posY + (this.rand.nextInt(64) - 32);

// double var5 = this.posZ + (this.rand.nextDouble() - 0.5D) * 64.0D;

// return this.teleportTo(var1, var3, var5);

// }

//

// protected boolean teleportToEntity(Entity par1Entity)

// {

// Vec3 var2 = new Vec3(this.posX - par1Entity.posX, this.getBoundingBox().minY + this.height / 2.0F - par1Entity.posY + par1Entity.getEyeHeight(), this.posZ - par1Entity.posZ);

// var2 = var2.normalize();

// double var3 = 16.0D;

// double var5 = this.posX + (this.rand.nextDouble() - 0.5D) * 8.0D - var2.xCoord * var3;

// double var7 = this.posY + (this.rand.nextInt(16) - 8) - var2.yCoord * var3;

// double var9 = this.posZ + (this.rand.nextDouble() - 0.5D) * 8.0D - var2.zCoord * var3;

// return this.teleportTo(var5, var7, var9);

// }

//

// protected boolean teleportTo(double par1, double par3, double par5)

// {

// double var7 = this.posX;

// double var9 = this.posY;

// double var11 = this.posZ;

// this.posX = par1;

// this.posY = par3;

// this.posZ = par5;

// boolean var13 = false;

// int var14 = MathHelper.floor_double(this.posX);

// int var15 = MathHelper.floor_double(this.posY);

// int var16 = MathHelper.floor_double(this.posZ);

// return var13;

//

// /*if (this.worldObj.blockExists(var14, var15, var16))

// {

// boolean var17 = false;

//

// while (!var17 && var15 > 0)

// {

// Block var18 = this.worldObj.getBlock(var14, var15 - 1, var16);

//

// if (var18.getMaterial().blocksMovement())

// {

// var17 = true;

// }

// else

// {

// --this.posY;

// --var15;

// }

// }

//

// if (var17)

// {

// this.setPosition(this.posX, this.posY, this.posZ);

//

// if (this.worldObj.getCollidingBoundingBoxes(this, this.getBoundingBox()).isEmpty() && !this.worldObj.isAnyLiquid(this.getBoundingBox()))

// {

// var13 = true;

// }

// }

// }

//

// if (!var13)

// {

// this.setPosition(var7, var9, var11);

// return false;

// }

// else

// {

// short var30 = 128;

//

// for (int var31 = 0; var31 < var30; ++var31)

// {

// double var19 = var31 / (var30 - 1.0D);

// float var21 = (this.rand.nextFloat() - 0.5F) * 0.2F;

// float var22 = (this.rand.nextFloat() - 0.5F) * 0.2F;

// float var23 = (this.rand.nextFloat() - 0.5F) * 0.2F;

// double var24 = var7 + (this.posX - var7) * var19 + (this.rand.nextDouble() - 0.5D) * this.width * 2.0D;

// double var26 = var9 + (this.posY - var9) * var19 + this.rand.nextDouble() * this.height;

// double var28 = var11 + (this.posZ - var11) * var19 + (this.rand.nextDouble() - 0.5D) * this.width * 2.0D;

// EntityGhostCore.proxy.spawnParticle("ghostPortal", var24, var26, var28, var21, var22, var23);

// }

// this.worldObj.playSoundEffect(var7, var9, var11, "mob.endermen.portal", 1.0F, 1.0F);

// this.playSound("mob.endermen.portal", 1.0F, 1.0F);

// return true;

// }*/

// }

//

// @Override

// protected String getHurtSound()

// {

// return "entityghost:mob.mob_hurt";

// }

//

// @Override

// protected String getDeathSound()

// {

// return "entityghost:mob.mob_hurt";

// }

//

// @Override

// public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)

// {

// if (this.isEntityInvulnerable(par1DamageSource))

// {

// return false;

// }

// else

// {

// if (par1DamageSource instanceof EntityDamageSource && par1DamageSource.getEntity() instanceof EntityPlayer)

// {

// }

//

// if (par1DamageSource instanceof EntityDamageSourceIndirect)

// {

// for (int i = 0; i < 64; ++i)

// {

// if (this.teleportRandomly())

// {

// return true;

// }

// }

// return false;

// }

// else

// {

// return super.attackEntityFrom(par1DamageSource, par2);

// }

// }

// }

//

// class AIFindPlayer extends EntityAINearestAttackableTarget

// {

// private EntityPlayer field_179448_g;

// private int field_179450_h;

// private int field_179451_i;

// private EntityGhost field_179449_j = EntityGhost.this;

//

// public AIFindPlayer()

// {

// super(EntityGhost.this, EntityPlayer.class, true);

// }

//

// public boolean shouldExecute()

// {

// double d0 = this.getTargetDistance();

// List list = this.taskOwner.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.taskOwner.getEntityBoundingBox().expand(d0, 4.0D, d0), this.targetEntitySelector);

// Collections.sort(list, this.theNearestAttackableTargetSorter);

//

// if (list.isEmpty())

// {

// return false;

// }

// else

// {

// this.field_179448_g = (EntityPlayer)list.get(0);

// return true;

// }

// }

//

// public void startExecuting()

// {

// this.field_179450_h = 5;

// this.field_179451_i = 0;

// }

//

// public void resetTask()

// {

// this.field_179448_g = null;

// super.resetTask();

// }

//

// public boolean continueExecuting()

// {

// if (this.field_179448_g != null)

// {

// if (!this.field_179449_j.shouldAttackPlayer(this.field_179448_g))

// {

// return false;

// }

// else

// {

// this.field_179449_j.faceEntity(this.field_179448_g, 10.0F, 10.0F);

// return true;

// }

// }

// else

// {

// return super.continueExecuting();

// }

// }

//

// public void updateTask()

// {

// if (this.field_179448_g != null)

// {

// if (--this.field_179450_h <= 0)

// {

// this.targetEntity = this.field_179448_g;

// this.field_179448_g = null;

// super.startExecuting();

// }

// }

// else

// {

// if (this.targetEntity != null)

// {

// if (this.targetEntity instanceof EntityPlayer && this.field_179449_j.shouldAttackPlayer((EntityPlayer)this.targetEntity))

// {

// if (this.targetEntity.getDistanceSqToEntity(this.field_179449_j) < 16.0D)

// {

// this.field_179449_j.teleportRandomly();

// }

//

// this.field_179451_i = 0;

// }

// else if (this.targetEntity.getDistanceSqToEntity(this.field_179449_j) > 256.0D && this.field_179451_i++ >= 30 && this.field_179449_j.teleportToEntity(this.targetEntity))

// {

// this.field_179451_i = 0;

// }

// }

// super.updateTask();

// }

// }

// }

//}

 

package stevekung.mods.entityghost.entities;

 

import java.util.Calendar;

import java.util.Collections;

import java.util.List;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.item.EntityTNTPrimed;

import net.minecraft.entity.monster.EntityCreeper;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.passive.EntitySquid;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.init.Items;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.pathfinding.PathNavigateGround;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.BlockPos;

import net.minecraft.util.DamageSource;

import net.minecraft.util.EntityDamageSource;

import net.minecraft.util.EntityDamageSourceIndirect;

import net.minecraft.util.Vec3;

import net.minecraft.world.World;

import stevekung.mods.entityghost.core.EntityGhostCore;

 

public class EntityGhost extends EntityMob

{

private Calendar calendar = Calendar.getInstance();

private boolean isHalloween = this.calendar.get(2) + 1 == 2 && this.calendar.get(5) == 14;

private boolean isAprilFoolDay = this.calendar.get(2) + 1 == 4 && this.calendar.get(5) == 1;

private boolean isNewYear = this.calendar.get(2) + 1 == 12 && this.calendar.get(5) >= 30 && this.calendar.get(5) <= 31 || this.calendar.get(2) + 1 == 1 && this.calendar.get(5) >= 1 && this.calendar.get(5) <= 2;

 

public EntityGhost(World world)

{

super(world);

((PathNavigateGround)this.getNavigator()).func_179688_b(true);

this.setSize(1.0F, 2.0F);

this.stepHeight = 0.5F;

 

if (this.worldObj.rand.nextInt(50) == 0)

{

this.setCustomNameTag("Entity 303");

this.setAlwaysRenderNameTag(true);

}

 

this.tasks.addTask(0, new EntityAISwimming(this));

this.tasks.addTask(2, new EntityAIAttackOnCollide(this, 1.0D, false));

this.tasks.addTask(7, new EntityAIWander(this, 1.0D));

this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));

this.tasks.addTask(8, new EntityAILookIdle(this));

this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0]));

this.targetTasks.addTask(2, new EntityGhost.AIFindPlayer());

}

 

@Override

protected void applyEntityAttributes()

{

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(0.5D);

 

if (this.isHalloween)

{

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(120.0D);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(3.0D);

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(25.0D);

}

else if (this.isAprilFoolDay)

{

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(1.0D);

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(100000.0D);

}

else if (this.isNewYear)

{

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0D);

}

}

 

@Override

public void writeEntityToNBT(NBTTagCompound nbt)

{

super.writeEntityToNBT(nbt);

}

 

@Override

public void readEntityFromNBT(NBTTagCompound nbt)

{

super.readEntityFromNBT(nbt);

}

 

private boolean shouldAttackPlayer(EntityPlayer player)

{

return true;

}

 

@Override

public float getEyeHeight()

{

return 1.75F;

}

 

@Override

public void onLivingUpdate()

{

EntityGhost ghost = this;

 

if (this.worldObj.isRemote)

{

for (int i = 0; i < 2; ++i)

{

if (!ghost.isPotionActive(Potion.invisibility))

{

EntityGhostCore.proxy.spawnParticle("ghostPortal", this.posX + (this.rand.nextDouble() - 0.5D) * this.width, this.posY + this.rand.nextDouble() * this.height - 0.25D, this.posZ + (this.rand.nextDouble() - 0.5D) * this.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D);

}

}

}

if (this.attackingPlayer instanceof EntityPlayer && this.shouldAttackPlayer(this.attackingPlayer))

{

if (this.attackingPlayer.getDistanceSqToEntity(this) < 128.0D)

{

EntityPlayer player = this.attackingPlayer;

 

ghost.addPotionEffect(new PotionEffect(Potion.invisibility.id, 360, 0, true, true));

player.addPotionEffect(new PotionEffect(Potion.blindness.id, 240, 0, true, true));

player.addPotionEffect(new PotionEffect(Potion.confusion.id, 240, 0, true, false));

 

if (this.worldObj.rand.nextInt(50) == 0)

{

this.teleportRandomly();

 

EntitySquid squid = new EntitySquid(this.worldObj);

squid.setAbsorptionAmount(12.0F);

squid.setLocationAndAngles(player.posX, player.posY + 8, player.posZ, this.rotationYaw, 0.0F);

this.worldObj.spawnEntityInWorld(squid);

 

EntityTNTPrimed tnt = new EntityTNTPrimed(this.worldObj);

tnt.fuse = 100;

tnt.setLocationAndAngles(player.posX, player.posY + 8, player.posZ, this.rotationYaw, 0.0F);

squid.mountEntity(tnt);

this.worldObj.spawnEntityInWorld(tnt);

}

if (this.worldObj.rand.nextInt(100) == 0)

{

this.spawnZombie();

this.spawnCreeper();

}

 

if (this.isAprilFoolDay)

{

this.setLocationAndAngles(this.posX, this.posY + 10.0D, this.posZ, this.rotationYaw, 0.0F);

this.worldObj.spawnEntityInWorld(this);

}

}

}

this.isJumping = false;

super.onLivingUpdate();

}

 

private void spawnZombie()

{

EntityPlayer player = (EntityPlayer)this.attackingPlayer;

 

if (this.worldObj.rand.nextInt(100) == 0)

{

for (int i = 0; i < 5; ++i)

{

EntityZombie zombie = new EntityZombie(this.worldObj);

zombie.setAbsorptionAmount(20F);

 

if (this.rand.nextInt(4) == 0)

{

zombie.setChild(true);

}

zombie.setCurrentItemOrArmor(4, new ItemStack(this.rand.nextFloat() < 0.1F ? Items.golden_helmet : Items.diamond_helmet));

zombie.setCurrentItemOrArmor(0, new ItemStack(this.rand.nextFloat() < 0.1F ? Items.iron_sword : Items.diamond_sword));

zombie.setLocationAndAngles(player.posX + this.rand.nextFloat(), player.posY + 10, player.posZ + this.rand.nextFloat(), this.rotationYaw, 0.0F);

this.worldObj.spawnEntityInWorld(zombie);

}

}

}

 

private void spawnCreeper()

{

EntityPlayer player = (EntityPlayer)this.attackingPlayer;

 

if (this.worldObj.rand.nextInt(150) == 0)

{

for (int i = 0; i < 5; ++i)

{

EntityCreeper creeper = new EntityCreeper(this.worldObj);

creeper.setAbsorptionAmount(20F);

creeper.setLocationAndAngles(player.posX + this.rand.nextFloat(), player.posY + 10, player.posZ + this.rand.nextFloat(), this.rotationYaw, 0.0F);

 

if (this.rand.nextInt(4) == 0)

{

creeper.getDataWatcher().updateObject(17, Byte.valueOf((byte) 1));

}

this.worldObj.spawnEntityInWorld(creeper);

}

}

}

 

protected boolean teleportRandomly()

{

double d0 = this.posX + (this.rand.nextDouble() - 0.5D) * 64.0D;

double d1 = this.posY + (this.rand.nextInt(64) - 32);

double d2 = this.posZ + (this.rand.nextDouble() - 0.5D) * 64.0D;

return this.teleportTo(d0, d1, d2);

}

 

protected boolean teleportToEntity(Entity entity)

{

Vec3 vec3 = new Vec3(this.posX - entity.posX, this.getEntityBoundingBox().minY + this.height / 2.0F - entity.posY + entity.getEyeHeight(), this.posZ - entity.posZ);

vec3 = vec3.normalize();

double d0 = 16.0D;

double d1 = this.posX + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3.xCoord * d0;

double d2 = this.posY + (this.rand.nextInt(16) - 8) - vec3.yCoord * d0;

double d3 = this.posZ + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3.zCoord * d0;

return this.teleportTo(d1, d2, d3);

}

 

protected boolean teleportTo(double x, double y, double z)

{

double d3 = this.posX;

double d4 = this.posY;

double d5 = this.posZ;

boolean flag = false;

BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ);

 

if (this.worldObj.isBlockLoaded(blockpos))

{

boolean flag1 = false;

 

while (!flag1 && blockpos.getY() > 0)

{

BlockPos blockpos1 = blockpos.down();

Block block = this.worldObj.getBlockState(blockpos1).getBlock();

 

if (block.getMaterial().blocksMovement())

{

flag1 = true;

}

else

{

--this.posY;

blockpos = blockpos1;

}

}

 

if (flag1)

{

super.setPositionAndUpdate(this.posX, this.posY, this.posZ);

 

if (this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty() && !this.worldObj.isAnyLiquid(this.getEntityBoundingBox()))

{

flag = true;

}

}

}

 

if (!flag)

{

this.setPosition(d3, d4, d5);

return false;

}

else

{

short short1 = 128;

 

for (int i = 0; i < short1; ++i)

{

EntityGhost ghost = this;

double d9 = i / (short1 - 1.0D);

float f = (this.rand.nextFloat() - 0.5F) * 0.2F;

float f1 = (this.rand.nextFloat() - 0.5F) * 0.2F;

float f2 = (this.rand.nextFloat() - 0.5F) * 0.2F;

double d6 = d3 + (this.posX - d3) * d9 + (this.rand.nextDouble() - 0.5D) * this.width * 2.0D;

double d7 = d4 + (this.posY - d4) * d9 + this.rand.nextDouble() * this.height;

double d8 = d5 + (this.posZ - d5) * d9 + (this.rand.nextDouble() - 0.5D) * this.width * 2.0D;

 

if (!ghost.isPotionActive(Potion.invisibility))

{

EntityGhostCore.proxy.spawnParticle("ghostPortal", d6, d7, d8, f, f1, f2);

}

}

this.worldObj.playSoundEffect(d3, d4, d5, "mob.endermen.portal", 1.0F, 1.0F);

this.playSound("mob.endermen.portal", 1.0F, 1.0F);

return true;

}

}

 

@Override

protected String getHurtSound()

{

return "entityghost:mob.mob_hurt";

}

 

@Override

protected String getDeathSound()

{

return "entityghost:mob.mob_hurt";

}

 

@Override

public boolean attackEntityFrom(DamageSource source, float amount)

{

if (this.isEntityInvulnerable(source))

{

return false;

}

else

{

if (source.getEntity() == null)

{

if (source instanceof EntityDamageSource && source.getEntity() instanceof EntityPlayer)

{

if (source.getEntity() instanceof EntityPlayerMP && ((EntityPlayerMP)source.getEntity()).theItemInWorldManager.isCreative())

{

return false;

}

}

if (source instanceof EntityDamageSourceIndirect)

{

for (int i = 0; i < 64; ++i)

{

if (this.teleportRandomly())

{

return true;

}

}

return false;

}

}

 

boolean flag = super.attackEntityFrom(source, amount);

 

if (source.isUnblockable() && this.rand.nextInt(10) != 0)

{

this.teleportRandomly();

}

return flag;

}

}

 

private class AIFindPlayer extends EntityAINearestAttackableTarget

{

private EntityPlayer player;

private int field_179450_h;

private int field_179451_i;

private EntityGhost ghost = EntityGhost.this;

 

public AIFindPlayer()

{

super(EntityGhost.this, EntityPlayer.class, true);

}

 

@Override

public boolean shouldExecute()

{

double d0 = this.getTargetDistance();

List list = this.taskOwner.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.taskOwner.getEntityBoundingBox().expand(d0, 64.0D, d0), this.targetEntitySelector);

Collections.sort(list, this.theNearestAttackableTargetSorter);

 

if (list.isEmpty())

{

return false;

}

else

{

this.player = (EntityPlayer)list.get(0);

return true;

}

}

 

@Override

public void startExecuting()

{

this.field_179450_h = 5;

this.field_179451_i = 0;

}

 

@Override

public void resetTask()

{

this.player = null;

super.resetTask();

}

 

@Override

public boolean continueExecuting()

{

if (this.player != null)

{

if (!this.ghost.shouldAttackPlayer(this.player))

{

return false;

}

else

{

this.ghost.faceEntity(this.player, 10.0F, 10.0F);

return true;

}

}

else

{

return super.continueExecuting();

}

}

 

@Override

public void updateTask()

{

if (this.player != null)

{

if (--this.field_179450_h <= 0)

{

this.targetEntity = this.player;

this.player = null;

super.startExecuting();

}

}

else

{

if (this.targetEntity != null)

{

if (this.targetEntity instanceof EntityPlayer && this.ghost.shouldAttackPlayer((EntityPlayer)this.targetEntity))

{

if (this.targetEntity.getDistanceSqToEntity(this.ghost) < 64.0D)

{

this.ghost.teleportRandomly();

}

this.field_179451_i = 0;

}

else if (this.targetEntity.getDistanceSqToEntity(this.ghost) > 256.0D && this.field_179451_i++ >= 30 && this.ghost.teleportToEntity(this.targetEntity))

{

this.field_179451_i = 0;

}

}

super.updateTask();

}

}

}

}

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.