Paper/src/main/java/net/minecraft/server/EntityOcelot.java

235 Zeilen
7.8 KiB
Java

package net.minecraft.server;
public class EntityOcelot extends EntityTameableAnimal {
2013-07-01 13:03:00 +02:00
private PathfinderGoalTempt bq;
public EntityOcelot(World world) {
super(world);
2012-07-29 09:33:13 +02:00
this.a(0.6F, 0.8F);
this.getNavigation().a(true);
this.goalSelector.a(1, new PathfinderGoalFloat(this));
2013-07-01 13:03:00 +02:00
this.goalSelector.a(2, this.bp);
2013-11-04 14:07:38 +01:00
this.goalSelector.a(3, this.bq = new PathfinderGoalTempt(this, 0.6D, Items.RAW_FISH, true));
2013-07-01 13:03:00 +02:00
this.goalSelector.a(4, new PathfinderGoalAvoidPlayer(this, EntityHuman.class, 16.0F, 0.8D, 1.33D));
this.goalSelector.a(5, new PathfinderGoalFollowOwner(this, 1.0D, 10.0F, 5.0F));
this.goalSelector.a(6, new PathfinderGoalJumpOnBlock(this, 1.33D));
this.goalSelector.a(7, new PathfinderGoalLeapAtTarget(this, 0.3F));
this.goalSelector.a(8, new PathfinderGoalOcelotAttack(this));
2013-07-01 13:03:00 +02:00
this.goalSelector.a(9, new PathfinderGoalBreed(this, 0.8D));
this.goalSelector.a(10, new PathfinderGoalRandomStroll(this, 0.8D));
this.goalSelector.a(11, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 10.0F));
2013-07-01 13:03:00 +02:00
this.targetSelector.a(1, new PathfinderGoalRandomTargetNonTamed(this, EntityChicken.class, 750, false));
}
2013-11-04 14:07:38 +01:00
protected void c() {
super.c();
this.datawatcher.a(18, Byte.valueOf((byte) 0));
}
2014-03-21 05:26:30 +01:00
public void bo() {
2012-07-29 09:33:13 +02:00
if (this.getControllerMove().a()) {
2013-07-01 13:03:00 +02:00
double d0 = this.getControllerMove().b();
2013-07-01 13:03:00 +02:00
if (d0 == 0.6D) {
2012-07-29 09:33:13 +02:00
this.setSneaking(true);
this.setSprinting(false);
2013-07-01 13:03:00 +02:00
} else if (d0 == 1.33D) {
2012-07-29 09:33:13 +02:00
this.setSneaking(false);
this.setSprinting(true);
} else {
2012-07-29 09:33:13 +02:00
this.setSneaking(false);
this.setSprinting(false);
}
2012-07-29 09:33:13 +02:00
} else {
this.setSneaking(false);
this.setSprinting(false);
}
}
2013-01-17 10:28:44 +01:00
protected boolean isTypeNotPersistent() {
2014-03-21 05:26:30 +01:00
return !this.isTamed() /*&& this.ticksLived > 2400*/; // CraftBukkit
}
2014-03-21 05:26:30 +01:00
public boolean bj() {
return true;
}
2014-03-21 05:26:30 +01:00
protected void aC() {
super.aC();
2013-07-09 01:43:37 +02:00
this.getAttributeInstance(GenericAttributes.a).setValue(10.0D);
this.getAttributeInstance(GenericAttributes.d).setValue(0.30000001192092896D);
}
2013-07-01 13:03:00 +02:00
protected void b(float f) {}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setInt("CatType", this.getCatType());
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.setCatType(nbttagcompound.getInt("CatType"));
}
2013-11-04 14:07:38 +01:00
protected String t() {
2014-03-21 05:26:30 +01:00
return this.isTamed() ? (this.ce() ? "mob.cat.purr" : (this.random.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) : "";
}
2014-03-21 05:26:30 +01:00
protected String aS() {
return "mob.cat.hitt";
}
2014-03-21 05:26:30 +01:00
protected String aT() {
return "mob.cat.hitt";
}
2014-03-21 05:26:30 +01:00
protected float be() {
return 0.4F;
}
2013-11-04 14:07:38 +01:00
protected Item getLoot() {
return Items.LEATHER;
}
2014-03-21 05:26:30 +01:00
public boolean n(Entity entity) {
2013-07-01 13:03:00 +02:00
return entity.damageEntity(DamageSource.mobAttack(this), 3.0F);
}
2013-07-01 13:03:00 +02:00
public boolean damageEntity(DamageSource damagesource, float f) {
2012-11-06 13:05:28 +01:00
if (this.isInvulnerable()) {
return false;
} else {
2013-07-01 13:03:00 +02:00
this.bp.setSitting(false);
return super.damageEntity(damagesource, f);
2012-11-06 13:05:28 +01:00
}
}
protected void dropDeathLoot(boolean flag, int i) {
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this); // CraftBukkit - Call EntityDeathEvent
}
2013-07-01 13:03:00 +02:00
public boolean a(EntityHuman entityhuman) {
ItemStack itemstack = entityhuman.inventory.getItemInHand();
2012-07-29 09:33:13 +02:00
if (this.isTamed()) {
2014-04-11 03:04:38 +02:00
if (this.e(entityhuman) && !this.world.isStatic && !this.c(itemstack)) {
2013-07-01 13:03:00 +02:00
this.bp.setSitting(!this.isSitting());
2012-07-29 09:33:13 +02:00
}
2014-03-21 05:26:30 +01:00
} else if (this.bq.f() && itemstack != null && itemstack.getItem() == Items.RAW_FISH && entityhuman.f(this) < 9.0D) {
2012-07-29 09:33:13 +02:00
if (!entityhuman.abilities.canInstantlyBuild) {
--itemstack.count;
}
2012-07-29 09:33:13 +02:00
if (itemstack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
}
2012-07-29 09:33:13 +02:00
if (!this.world.isStatic) {
// CraftBukkit - added event call and isCancelled check
if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
this.setTamed(true);
this.setCatType(1 + this.world.random.nextInt(3));
2014-04-11 03:04:38 +02:00
this.setOwnerUUID(entityhuman.getUniqueID().toString());
2013-07-09 01:43:37 +02:00
this.i(true);
2013-07-01 13:03:00 +02:00
this.bp.setSitting(true);
2012-07-29 09:33:13 +02:00
this.world.broadcastEntityEffect(this, (byte) 7);
} else {
2013-07-09 01:43:37 +02:00
this.i(false);
2012-07-29 09:33:13 +02:00
this.world.broadcastEntityEffect(this, (byte) 6);
}
}
2012-07-29 09:33:13 +02:00
return true;
}
2012-07-29 09:33:13 +02:00
2013-07-01 13:03:00 +02:00
return super.a(entityhuman);
}
2012-11-06 13:05:28 +01:00
public EntityOcelot b(EntityAgeable entityageable) {
EntityOcelot entityocelot = new EntityOcelot(this.world);
if (this.isTamed()) {
2014-04-11 03:04:38 +02:00
entityocelot.setOwnerUUID(this.getOwnerUUID());
entityocelot.setTamed(true);
entityocelot.setCatType(this.getCatType());
}
return entityocelot;
}
public boolean c(ItemStack itemstack) {
2013-11-04 14:07:38 +01:00
return itemstack != null && itemstack.getItem() == Items.RAW_FISH;
}
public boolean mate(EntityAnimal entityanimal) {
if (entityanimal == this) {
return false;
} else if (!this.isTamed()) {
return false;
} else if (!(entityanimal instanceof EntityOcelot)) {
return false;
} else {
EntityOcelot entityocelot = (EntityOcelot) entityanimal;
2014-03-21 05:26:30 +01:00
return !entityocelot.isTamed() ? false : this.ce() && entityocelot.ce();
}
}
public int getCatType() {
return this.datawatcher.getByte(18);
}
public void setCatType(int i) {
this.datawatcher.watch(18, Byte.valueOf((byte) i));
}
public boolean canSpawn() {
if (this.world.random.nextInt(3) == 0) {
return false;
} else {
2012-07-29 09:33:13 +02:00
if (this.world.b(this.boundingBox) && this.world.getCubes(this, this.boundingBox).isEmpty() && !this.world.containsLiquid(this.boundingBox)) {
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.boundingBox.b);
int k = MathHelper.floor(this.locZ);
if (j < 63) {
return false;
}
2013-11-04 14:07:38 +01:00
Block block = this.world.getType(i, j - 1, k);
2013-11-04 14:07:38 +01:00
if (block == Blocks.GRASS || block.getMaterial() == Material.LEAVES) {
return true;
}
}
return false;
}
}
2013-11-04 14:07:38 +01:00
public String getName() {
return this.hasCustomName() ? this.getCustomName() : (this.isTamed() ? LocaleI18n.get("entity.Cat.name") : super.getName());
}
2013-07-01 13:03:00 +02:00
public GroupDataEntity a(GroupDataEntity groupdataentity) {
groupdataentity = super.a(groupdataentity);
if (this.world.random.nextInt(7) == 0) {
for (int i = 0; i < 2; ++i) {
EntityOcelot entityocelot = new EntityOcelot(this.world);
entityocelot.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
entityocelot.setAge(-24000);
this.world.addEntity(entityocelot);
}
}
2013-07-01 13:03:00 +02:00
return groupdataentity;
}
2012-11-06 13:05:28 +01:00
public EntityAgeable createChild(EntityAgeable entityageable) {
return this.b(entityageable);
}
}