
net.minecraft.server.EntityGuardian Maven / Gradle / Ivy
package net.minecraft.server;
import com.google.common.base.Predicate;
import org.bukkit.entity.Guardian;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class EntityGuardian extends EntityMonster {
public PathfinderGoalRandomStroll goalRandomStroll; // CraftBukkit - public
private float a;
private float b;
private float c;
private float bm;
private float bn;
private EntityLiving bo;
private int bp;
private boolean bq;
@NotNull
@Override
public Guardian getEntityBukkit() {
return (Guardian) super.getEntityBukkit();
}
public EntityGuardian(World world) {
super(world);
this.experienceValue = 10;
this.setSize(0.85F, 0.85F);
this.goalSelector.addTask(4, new PathfinderGoalGuardianAttack(this));
PathfinderGoalMoveTowardsRestriction pathfindergoalmovetowardsrestriction;
this.goalSelector.addTask(5, pathfindergoalmovetowardsrestriction = new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
this.goalSelector.addTask(7, this.goalRandomStroll = new PathfinderGoalRandomStroll(this, 1.0D, 80));
this.goalSelector.addTask(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
this.goalSelector.addTask(8, new PathfinderGoalLookAtPlayer(this, EntityGuardian.class, 12.0F, 0.01F));
this.goalSelector.addTask(9, new PathfinderGoalRandomLookaround(this));
this.goalRandomStroll.setMutexBits(3);
pathfindergoalmovetowardsrestriction.setMutexBits(3);
this.targetSelector.addTask(1, new PathfinderGoalNearestAttackableTarget(this, EntityLiving.class, 10, true, false, new EntitySelectorGuardianTargetHumanSquid(this)));
this.moveController = new ControllerMoveGuardian(this);
this.b = this.a = this.random.nextFloat();
}
public void initAttributes() { // CraftBukkit - public
super.initAttributes();
this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(6.0D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.5D);
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(16.0D);
this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(30.0D);
}
public void loadEntityData(NBTTagCompound tag) {
super.loadEntityData(tag);
this.setElder(tag.getBoolean("Elder"));
}
public void saveEntityData(NBTTagCompound tag) {
super.saveEntityData(tag);
tag.setBoolean("Elder", this.isElder());
}
protected NavigationAbstract b(World world) {
return new NavigationGuardian(this, world);
}
protected void entityInit() {
super.entityInit();
this.datawatcher.a(16, 0);
this.datawatcher.a(17, 0);
}
private boolean a(int i) {
return (this.datawatcher.getInt(16) & i) != 0;
}
private void a(int i, boolean flag) {
int j = this.datawatcher.getInt(16);
if (flag) {
this.datawatcher.watch(16, j | i);
} else {
this.datawatcher.watch(16, j & ~i);
}
}
public boolean n() {
return this.a(2);
}
private void l(boolean flag) {
this.a(2, flag);
}
public int cm() {
return this.isElder() ? 60 : 80;
}
public boolean isElder() {
return this.a(4);
}
public void setElder(boolean flag) {
this.a(4, flag);
if (flag) {
this.setSize(1.9975F, 1.9975F);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.30000001192092896D);
this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(8.0D);
this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(80.0D);
this.enablePersistence();
this.goalRandomStroll.setTimeBetweenMovement(400);
}
}
private void b(int i) {
this.datawatcher.watch(17, i);
}
public boolean cp() {
return this.datawatcher.getInt(17) != 0;
}
public EntityLiving cq() {
if (!this.cp()) {
return null;
} else if (this.world.isClientSide) {
if (this.bo != null) {
return this.bo;
} else {
Entity entity = this.world.a(this.datawatcher.getInt(17));
if (entity instanceof EntityLiving) {
this.bo = (EntityLiving) entity;
return this.bo;
} else {
return null;
}
}
} else {
return this.getGoalTarget();
}
}
public void onDataWatcherUpdate(int i) {
super.onDataWatcherUpdate(i);
if (i == 16) {
if (this.isElder() && this.width < 1.0F) {
this.setSize(1.9975F, 1.9975F);
}
} else if (i == 17) {
this.bp = 0;
this.bo = null;
}
}
public int getTalkInterval() {
return 160;
}
protected String getLivingSound() {
return !this.isInWater() ? "mob.guardian.land.idle" : (this.isElder() ? "mob.guardian.elder.idle" : "mob.guardian.idle");
}
protected String getHurtSound() {
return !this.isInWater() ? "mob.guardian.land.hit" : (this.isElder() ? "mob.guardian.elder.hit" : "mob.guardian.hit");
}
protected String getDeathSound() {
return !this.isInWater() ? "mob.guardian.land.death" : (this.isElder() ? "mob.guardian.elder.death" : "mob.guardian.death");
}
protected boolean canTriggerWalking() {
return false;
}
public float getHeadHeight() {
return this.length * 0.5F;
}
public float a(BlockPosition blockposition) {
return this.world.getType(blockposition).getBlock().getMaterial() == Material.WATER ? 10.0F + this.world.o(blockposition) - 0.5F : super.a(blockposition);
}
public void onLivingUpdate() {
if (this.world.isClientSide) {
this.b = this.a;
if (!this.isInWater()) {
this.c = 2.0F;
if (this.motY > 0.0D && this.bq && !this.isSilent()) {
this.world.a(this.locX, this.locY, this.locZ, "mob.guardian.flop", 1.0F, 1.0F, false);
}
this.bq = this.motY < 0.0D && this.world.d((new BlockPosition(this)).down(), false);
} else if (this.n()) {
if (this.c < 0.5F) {
this.c = 4.0F;
} else {
this.c += (0.5F - this.c) * 0.1F;
}
} else {
this.c += (0.125F - this.c) * 0.2F;
}
this.a += this.c;
this.bn = this.bm;
if (!this.isInWater()) {
this.bm = this.random.nextFloat();
} else if (this.n()) {
this.bm += (0.0F - this.bm) * 0.25F;
} else {
this.bm += (1.0F - this.bm) * 0.06F;
}
if (this.n() && this.isInWater()) {
Vec3D vec3d = this.getLook(0.0F);
for (int i = 0; i < 2; ++i) {
this.world.addParticle(EnumParticle.WATER_BUBBLE, this.locX + (this.random.nextDouble() - 0.5D) * (double) this.width - vec3d.a * 1.5D, this.locY + this.random.nextDouble() * (double) this.length - vec3d.b * 1.5D, this.locZ + (this.random.nextDouble() - 0.5D) * (double) this.width - vec3d.c * 1.5D, 0.0D, 0.0D, 0.0D);
}
}
if (this.cp()) {
if (this.bp < this.cm()) {
++this.bp;
}
EntityLiving entityliving = this.cq();
if (entityliving != null) {
this.getControllerLook().a(entityliving, 90.0F, 90.0F);
this.getControllerLook().a();
double d0 = this.q(0.0F);
double d1 = entityliving.locX - this.locX;
double d2 = entityliving.locY + (double) (entityliving.length * 0.5F) - (this.locY + (double) this.getHeadHeight());
double d3 = entityliving.locZ - this.locZ;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
d1 /= d4;
d2 /= d4;
d3 /= d4;
double d5 = this.random.nextDouble();
while (d5 < d4) {
d5 += 1.8D - d0 + this.random.nextDouble() * (1.7D - d0);
this.world.addParticle(EnumParticle.WATER_BUBBLE, this.locX + d1 * d5, this.locY + d2 * d5 + (double) this.getHeadHeight(), this.locZ + d3 * d5, 0.0D, 0.0D, 0.0D);
}
}
}
}
if (this.inWater) {
this.setAirTicks(300);
} else if (this.onGround) {
this.motY += 0.5D;
this.motX += (this.random.nextFloat() * 2.0F - 1.0F) * 0.4F;
this.motZ += (this.random.nextFloat() * 2.0F - 1.0F) * 0.4F;
this.yaw = this.random.nextFloat() * 360.0F;
this.onGround = false;
this.isAirBorne = true;
}
if (this.cp()) {
this.yaw = this.rotationYawHead;
}
super.onLivingUpdate();
}
public float q(float f) {
return ((float) this.bp + f) / (float) this.cm();
}
protected void updateAITasks() {
super.updateAITasks();
if (this.isElder()) {
boolean flag = true;
boolean flag1 = true;
boolean flag2 = true;
boolean flag3 = true;
if ((this.ticksLived + this.getId()) % 1200 == 0) {
MobEffectList mobeffectlist = MobEffectList.SLOWER_DIG;
List list = this.world.b(EntityPlayer.class, new Predicate() {
public boolean a(EntityPlayer entityplayer) {
return EntityGuardian.this.getDistanceSquaredToEntity(entityplayer) < 2500.0D && entityplayer.playerInteractManager.c();
}
public boolean apply(Object object) {
return this.a((EntityPlayer) object);
}
});
for (EntityPlayer o : list) {
if (!o.hasEffect(mobeffectlist) || o.getEffect(mobeffectlist).getAmplifier() < 2 || o.getEffect(mobeffectlist).getDuration() < 1200) {
o.playerConnection.sendPacket(new PacketPlayOutGameStateChange(10, 0.0F));
o.addEffect(new MobEffect(mobeffectlist.id, 6000, 2));
}
}
}
if (!this.ck()) {
this.a(new BlockPosition(this), 16);
}
}
}
protected void dropDeathLoot(boolean wasRecentlyHit, int lootingModifier) {
int j = this.random.nextInt(3) + this.random.nextInt(lootingModifier + 1);
if (j > 0) {
this.dropItem(new ItemStack(Items.PRISMARINE_SHARD, j, 0), 1.0F);
}
if (this.random.nextInt(3 + lootingModifier) > 1) {
this.dropItem(new ItemStack(Items.FISH, 1, ItemFish.EnumFish.COD.a()), 1.0F);
} else if (this.random.nextInt(3 + lootingModifier) > 1) {
this.dropItem(new ItemStack(Items.PRISMARINE_CRYSTALS, 1, 0), 1.0F);
}
if (wasRecentlyHit && this.isElder()) {
this.dropItem(new ItemStack(Blocks.SPONGE, 1, 1), 1.0F);
}
}
protected void getRareDrop() {
ItemStack itemstack = WeightedRandom.a(this.random, EntityFishingHook.j()).a(this.random);
this.dropItem(itemstack, 1.0F);
}
protected boolean n_() {
return true;
}
public boolean isNotColliding() {
return this.world.a(this.getBoundingBox(), this) && this.world.getCubes(this, this.getBoundingBox()).isEmpty();
}
public boolean getCanSpawnHere() {
return (this.random.nextInt(20) == 0 || !this.world.j(new BlockPosition(this))) && super.getCanSpawnHere();
}
public boolean damageEntity(DamageSource damagesource, float f) {
if (!this.n() && !damagesource.isMagic() && damagesource.i() instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) damagesource.i();
if (!damagesource.isExplosion()) {
entityliving.damageEntity(DamageSource.a(this), 2.0F);
entityliving.playSound("damage.thorns", 0.5F, 1.0F);
}
}
this.goalRandomStroll.f();
return super.damageEntity(damagesource, f);
}
public int getVerticalFaceSpeed() {
return 180;
}
public void moveEntityWithHeading(float strafe, float forward) {
if (this.isServerWorld()) {
if (this.isInWater()) {
this.moveFlying(strafe, forward, 0.1F);
this.move(this.motX, this.motY, this.motZ);
this.motX *= 0.8999999761581421D;
this.motY *= 0.8999999761581421D;
this.motZ *= 0.8999999761581421D;
if (!this.n() && this.getGoalTarget() == null) {
this.motY -= 0.005D;
}
} else {
super.moveEntityWithHeading(strafe, forward);
}
} else {
super.moveEntityWithHeading(strafe, forward);
}
}
static class ControllerMoveGuardian extends ControllerMove {
private final EntityGuardian g;
public ControllerMoveGuardian(EntityGuardian entityguardian) {
super(entityguardian);
this.g = entityguardian;
}
public void c() {
if (this.f && !this.g.getNavigation().noPath()) {
double d0 = this.b - this.g.locX;
double d1 = this.c - this.g.locY;
double d2 = this.d - this.g.locZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
d3 = MathHelper.sqrt(d3);
d1 /= d3;
float f = (float) (MathHelper.b(d2, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
this.g.yaw = this.a(this.g.yaw, f, 30.0F);
this.g.renderYawOffset = this.g.yaw;
float f1 = (float) (this.e * this.g.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue());
this.g.setAIMoveSpeed(this.g.getAIMoveSpeed() + (f1 - this.g.getAIMoveSpeed()) * 0.125F);
double d4 = Math.sin((double) (this.g.ticksLived + this.g.getId()) * 0.5D) * 0.05D;
double d5 = Math.cos(this.g.yaw * 3.1415927F / 180.0F);
double d6 = Math.sin(this.g.yaw * 3.1415927F / 180.0F);
this.g.motX += d4 * d5;
this.g.motZ += d4 * d6;
d4 = Math.sin((double) (this.g.ticksLived + this.g.getId()) * 0.75D) * 0.05D;
this.g.motY += d4 * (d6 + d5) * 0.25D;
this.g.motY += (double) this.g.getAIMoveSpeed() * d1 * 0.1D;
ControllerLook controllerlook = this.g.getControllerLook();
double d7 = this.g.locX + d0 / d3 * 2.0D;
double d8 = (double) this.g.getHeadHeight() + this.g.locY + d1 / d3;
double d9 = this.g.locZ + d2 / d3 * 2.0D;
double d10 = controllerlook.e();
double d11 = controllerlook.f();
double d12 = controllerlook.g();
if (!controllerlook.b()) {
d10 = d7;
d11 = d8;
d12 = d9;
}
this.g.getControllerLook().a(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F);
this.g.l(true);
} else {
this.g.setAIMoveSpeed(0.0F);
this.g.l(false);
}
}
}
static class PathfinderGoalGuardianAttack extends PathfinderGoal {
private final EntityGuardian a;
private int b;
public PathfinderGoalGuardianAttack(EntityGuardian entityguardian) {
this.a = entityguardian;
this.setMutexBits(3);
}
public boolean a() {
EntityLiving entityliving = this.a.getGoalTarget();
return entityliving != null && entityliving.isAlive();
}
public boolean b() {
return super.b() && (this.a.isElder() || this.a.getDistanceSquaredToEntity(this.a.getGoalTarget()) > 9.0D);
}
public void c() {
this.b = -10;
this.a.getNavigation().clearPathEntity();
this.a.getControllerLook().a(this.a.getGoalTarget(), 90.0F, 90.0F);
this.a.isAirBorne = true;
}
public void d() {
this.a.b(0);
this.a.setGoalTarget(null);
this.a.goalRandomStroll.f();
}
public void e() {
EntityLiving entityliving = this.a.getGoalTarget();
this.a.getNavigation().clearPathEntity();
this.a.getControllerLook().a(entityliving, 90.0F, 90.0F);
if (!this.a.hasLineOfSight(entityliving)) {
this.a.setGoalTarget(null);
} else {
++this.b;
if (this.b == 0) {
this.a.b(this.a.getGoalTarget().getId());
this.a.world.broadcastEntityEffect(this.a, (byte) 21);
} else if (this.b >= this.a.cm()) {
float f = 1.0F;
if (this.a.world.getDifficulty() == EnumDifficulty.HARD) {
f += 2.0F;
}
if (this.a.isElder()) {
f += 2.0F;
}
entityliving.damageEntity(DamageSource.b(this.a, this.a), f);
entityliving.damageEntity(DamageSource.mobAttack(this.a), (float) this.a.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue());
this.a.setGoalTarget(null);
}
super.e();
}
}
}
static class EntitySelectorGuardianTargetHumanSquid implements Predicate {
private final EntityGuardian a;
public EntitySelectorGuardianTargetHumanSquid(EntityGuardian entityguardian) {
this.a = entityguardian;
}
public boolean a(EntityLiving entityliving) {
return (entityliving instanceof EntityHuman || entityliving instanceof EntitySquid) && entityliving.getDistanceSquaredToEntity(this.a) > 9.0D;
}
public boolean apply(EntityLiving object) { // CraftBukkit - fix decompile error
return this.a(object);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy