2011-07-03 03:28:45 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-01-22 03:28:32 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.Material;
|
2011-09-21 16:41:24 +02:00
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
2012-02-21 13:51:56 +01:00
|
|
|
import org.bukkit.entity.Sheep;
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit end
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
public class EntitySheep extends EntityAnimal {
|
|
|
|
|
|
|
|
public static final float[][] a = new float[][] { { 1.0F, 1.0F, 1.0F}, { 0.95F, 0.7F, 0.2F}, { 0.9F, 0.5F, 0.85F}, { 0.6F, 0.7F, 0.95F}, { 0.9F, 0.9F, 0.2F}, { 0.5F, 0.8F, 0.1F}, { 0.95F, 0.7F, 0.8F}, { 0.3F, 0.3F, 0.3F}, { 0.6F, 0.6F, 0.6F}, { 0.3F, 0.6F, 0.7F}, { 0.7F, 0.4F, 0.9F}, { 0.2F, 0.4F, 0.8F}, { 0.5F, 0.4F, 0.3F}, { 0.4F, 0.5F, 0.2F}, { 0.8F, 0.3F, 0.3F}, { 0.1F, 0.1F, 0.1F}};
|
2012-01-12 23:10:13 +01:00
|
|
|
private int b;
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
public EntitySheep(World world) {
|
|
|
|
super(world);
|
|
|
|
this.texture = "/mob/sheep.png";
|
|
|
|
this.b(0.9F, 1.3F);
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public int getMaxHealth() {
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2011-07-03 03:28:45 +02:00
|
|
|
protected void b() {
|
|
|
|
super.b();
|
|
|
|
this.datawatcher.a(16, new Byte((byte) 0));
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
protected void dropDeathLoot(boolean flag, int i) {
|
2011-07-03 03:28:45 +02:00
|
|
|
// CraftBukkit start - whole method
|
|
|
|
java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
|
|
|
|
|
|
|
|
if (!this.isSheared()) {
|
|
|
|
loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.WOOL, 1, (short) 0, (byte) this.getColor()));
|
|
|
|
}
|
|
|
|
|
2011-09-21 16:41:24 +02:00
|
|
|
CraftEventFactory.callEntityDeathEvent(this, loot);
|
2011-07-03 03:28:45 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
protected int getLootId() {
|
2011-07-03 03:28:45 +02:00
|
|
|
return Block.WOOL.id;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public void d() {
|
|
|
|
super.d();
|
|
|
|
if (this.b > 0) {
|
|
|
|
--this.b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void o_() {
|
|
|
|
if (this.b <= 0) {
|
|
|
|
super.o_();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void m_() {
|
|
|
|
super.m_();
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int k;
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
if (!this.E() && this.b <= 0 && (this.isBaby() && this.random.nextInt(50) == 0 || this.random.nextInt(1000) == 0)) {
|
2012-01-12 23:10:13 +01:00
|
|
|
i = MathHelper.floor(this.locX);
|
|
|
|
j = MathHelper.floor(this.locY);
|
|
|
|
k = MathHelper.floor(this.locZ);
|
|
|
|
if (this.world.getTypeId(i, j, k) == Block.LONG_GRASS.id && this.world.getData(i, j, k) == 1 || this.world.getTypeId(i, j - 1, k) == Block.GRASS.id) {
|
|
|
|
this.b = 40;
|
|
|
|
this.world.a(this, (byte) 10);
|
|
|
|
}
|
|
|
|
} else if (this.b == 4) {
|
|
|
|
i = MathHelper.floor(this.locX);
|
|
|
|
j = MathHelper.floor(this.locY);
|
|
|
|
k = MathHelper.floor(this.locZ);
|
|
|
|
boolean flag = false;
|
|
|
|
|
|
|
|
if (this.world.getTypeId(i, j, k) == Block.LONG_GRASS.id) {
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit start
|
2012-02-21 13:51:56 +01:00
|
|
|
if (!CraftEventFactory.callEntityChangeBlockEvent(this.getBukkitEntity(), this.world.getWorld().getBlockAt(i, j, k), Material.AIR).isCancelled()) {
|
2012-01-22 03:28:32 +01:00
|
|
|
this.world.f(2001, i, j, k, Block.LONG_GRASS.id + 256);
|
|
|
|
this.world.setTypeId(i, j, k, 0);
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-01-12 23:10:13 +01:00
|
|
|
} else if (this.world.getTypeId(i, j - 1, k) == Block.GRASS.id) {
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit start
|
2012-02-21 13:51:56 +01:00
|
|
|
if (!CraftEventFactory.callEntityChangeBlockEvent(this.getBukkitEntity(), this.world.getWorld().getBlockAt(i, j - 1, k), Material.DIRT).isCancelled()) {
|
2012-01-22 03:28:32 +01:00
|
|
|
this.world.f(2001, i, j - 1, k, Block.GRASS.id);
|
|
|
|
this.world.setTypeId(i, j - 1, k, Block.DIRT.id);
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-01-12 23:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
if (!this.isBaby()) {
|
2012-02-21 13:51:56 +01:00
|
|
|
org.bukkit.event.entity.SheepRegrowWoolEvent event = new org.bukkit.event.entity.SheepRegrowWoolEvent((Sheep) this.getBukkitEntity());
|
2012-01-22 03:28:32 +01:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
this.setSheared(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
if (this.isBaby()) {
|
2012-01-12 23:10:13 +01:00
|
|
|
int l = this.getAge() + 1200;
|
|
|
|
|
|
|
|
if (l > 0) {
|
|
|
|
l = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setAge(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean v() {
|
|
|
|
return this.b > 0;
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public boolean b(EntityHuman entityhuman) {
|
2011-07-03 03:28:45 +02:00
|
|
|
ItemStack itemstack = entityhuman.inventory.getItemInHand();
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
if (itemstack != null && itemstack.id == Item.SHEARS.id && !this.isSheared() && !this.isBaby()) {
|
2011-07-03 03:28:45 +02:00
|
|
|
if (!this.world.isStatic) {
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
org.bukkit.event.player.PlayerShearEntityEvent event = new org.bukkit.event.player.PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity());
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-07-03 03:28:45 +02:00
|
|
|
this.setSheared(true);
|
2012-01-12 23:10:13 +01:00
|
|
|
int i = 1 + this.random.nextInt(3);
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
EntityItem entityitem = this.a(new ItemStack(Block.WOOL.id, 1, this.getColor()), 1.0F);
|
|
|
|
|
|
|
|
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
|
|
|
|
entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
|
|
|
|
entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
itemstack.damage(1, entityhuman);
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
return super.b(entityhuman);
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setBoolean("Sheared", this.isSheared());
|
|
|
|
nbttagcompound.setByte("Color", (byte) this.getColor());
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2011-11-30 00:17:43 +01:00
|
|
|
this.setSheared(nbttagcompound.getBoolean("Sheared"));
|
|
|
|
this.setColor(nbttagcompound.getByte("Color"));
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String c_() {
|
2011-07-03 03:28:45 +02:00
|
|
|
return "mob.sheep";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String m() {
|
2011-07-03 03:28:45 +02:00
|
|
|
return "mob.sheep";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String n() {
|
2011-07-03 03:28:45 +02:00
|
|
|
return "mob.sheep";
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getColor() {
|
2011-09-24 23:03:31 +02:00
|
|
|
return this.datawatcher.getByte(16) & 15;
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setColor(int i) {
|
2011-09-24 23:03:31 +02:00
|
|
|
byte b0 = this.datawatcher.getByte(16);
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
this.datawatcher.watch(16, Byte.valueOf((byte) (b0 & 240 | i & 15)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSheared() {
|
2011-09-24 23:03:31 +02:00
|
|
|
return (this.datawatcher.getByte(16) & 16) != 0;
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSheared(boolean flag) {
|
2011-09-24 23:03:31 +02:00
|
|
|
byte b0 = this.datawatcher.getByte(16);
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
this.datawatcher.watch(16, Byte.valueOf((byte) (b0 | 16)));
|
|
|
|
} else {
|
|
|
|
this.datawatcher.watch(16, Byte.valueOf((byte) (b0 & -17)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int a(Random random) {
|
|
|
|
int i = random.nextInt(100);
|
|
|
|
|
|
|
|
return i < 5 ? 15 : (i < 10 ? 7 : (i < 15 ? 8 : (i < 18 ? 12 : (random.nextInt(500) == 0 ? 6 : 0))));
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
protected EntityAnimal createChild(EntityAnimal entityanimal) {
|
|
|
|
EntitySheep entitysheep = (EntitySheep) entityanimal;
|
|
|
|
EntitySheep entitysheep1 = new EntitySheep(this.world);
|
|
|
|
|
|
|
|
if (this.random.nextBoolean()) {
|
|
|
|
entitysheep1.setColor(this.getColor());
|
|
|
|
} else {
|
|
|
|
entitysheep1.setColor(entitysheep.getColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
return entitysheep1;
|
|
|
|
}
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|