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
|
2012-07-22 08:18:00 +02:00
|
|
|
import org.bukkit.event.entity.SheepRegrowWoolEvent;
|
|
|
|
import org.bukkit.event.player.PlayerShearEntityEvent;
|
2012-01-22 03:28:32 +01:00
|
|
|
// CraftBukkit end
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
public class EntitySheep extends EntityAnimal {
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
private final InventoryCrafting bq = new InventoryCrafting(new ContainerSheepBreed(this), 2, 1);
|
|
|
|
public static final float[][] bp = new float[][] { { 1.0F, 1.0F, 1.0F}, { 0.85F, 0.5F, 0.2F}, { 0.7F, 0.3F, 0.85F}, { 0.4F, 0.6F, 0.85F}, { 0.9F, 0.9F, 0.2F}, { 0.5F, 0.8F, 0.1F}, { 0.95F, 0.5F, 0.65F}, { 0.3F, 0.3F, 0.3F}, { 0.6F, 0.6F, 0.6F}, { 0.3F, 0.5F, 0.6F}, { 0.5F, 0.25F, 0.7F}, { 0.2F, 0.3F, 0.7F}, { 0.4F, 0.3F, 0.2F}, { 0.4F, 0.5F, 0.2F}, { 0.6F, 0.2F, 0.2F}, { 0.1F, 0.1F, 0.1F}};
|
|
|
|
private int br;
|
|
|
|
private PathfinderGoalEatTile bs = new PathfinderGoalEatTile(this);
|
2011-07-03 03:28:45 +02:00
|
|
|
|
|
|
|
public EntitySheep(World world) {
|
|
|
|
super(world);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(0.9F, 1.3F);
|
|
|
|
this.getNavigation().a(true);
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(0, new PathfinderGoalFloat(this));
|
2013-07-01 13:03:00 +02:00
|
|
|
this.goalSelector.a(1, new PathfinderGoalPanic(this, 1.25D));
|
|
|
|
this.goalSelector.a(2, new PathfinderGoalBreed(this, 1.0D));
|
|
|
|
this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.1D, Item.WHEAT.id, false));
|
|
|
|
this.goalSelector.a(4, new PathfinderGoalFollowParent(this, 1.1D));
|
|
|
|
this.goalSelector.a(5, this.bs);
|
|
|
|
this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, 1.0D));
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
|
|
|
|
this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bq.setItem(0, new ItemStack(Item.INK_SACK, 1, 0));
|
|
|
|
this.bq.setItem(1, new ItemStack(Item.INK_SACK, 1, 0));
|
|
|
|
this.bq.resultInventory = new InventoryCraftResult(); // CraftBukkit - add result slot for event
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected boolean bb() {
|
2012-03-01 11:49:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected void be() {
|
|
|
|
this.br = this.bs.f();
|
|
|
|
super.be();
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void c() {
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.world.isStatic) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.br = Math.max(0, this.br - 1);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
super.c();
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected void ax() {
|
|
|
|
super.ax();
|
|
|
|
this.a(GenericAttributes.a).a(8.0D);
|
|
|
|
this.a(GenericAttributes.d).a(0.23000000417232513D);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected void a() {
|
|
|
|
super.a();
|
2011-07-03 03:28:45 +02:00
|
|
|
this.datawatcher.a(16, new Byte((byte) 0));
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
protected void dropDeathLoot(boolean flag, int i) {
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Whole method
|
2011-07-03 03:28:45 +02:00
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.craftbukkit.event.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;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public boolean a(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
|
2012-07-22 08:18:00 +02:00
|
|
|
PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity());
|
2012-01-22 03:28:32 +01:00
|
|
|
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);
|
2012-03-27 17:37:00 +02:00
|
|
|
|
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);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2011-07-03 03:28:45 +02:00
|
|
|
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);
|
2012-11-06 13:05:28 +01:00
|
|
|
this.makeSound("mob.sheep.shear", 1.0F, 1.0F);
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
return super.a(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
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected String r() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.sheep.say";
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected String aK() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.sheep.say";
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected String aL() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.sheep.say";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(int i, int j, int k, int l) {
|
2012-11-06 13:05:28 +01:00
|
|
|
this.makeSound("mob.sheep.step", 0.15F, 1.0F);
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public EntitySheep b(EntityAgeable entityageable) {
|
|
|
|
EntitySheep entitysheep = (EntitySheep) entityageable;
|
2011-11-20 09:01:14 +01:00
|
|
|
EntitySheep entitysheep1 = new EntitySheep(this.world);
|
2012-11-06 13:05:28 +01:00
|
|
|
int i = this.a(this, entitysheep);
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
entitysheep1.setColor(15 - i);
|
2011-11-20 09:01:14 +01:00
|
|
|
return entitysheep1;
|
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public void n() {
|
2012-03-01 11:49:23 +01:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
SheepRegrowWoolEvent event = new SheepRegrowWoolEvent((org.bukkit.entity.Sheep) this.getBukkitEntity());
|
2012-03-01 11:49:23 +01:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
this.setSheared(false);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
if (this.isBaby()) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.a(60);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public GroupDataEntity a(GroupDataEntity groupdataentity) {
|
|
|
|
groupdataentity = super.a(groupdataentity);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.setColor(a(this.world.random));
|
2013-07-01 13:03:00 +02:00
|
|
|
return groupdataentity;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2012-11-06 13:05:28 +01:00
|
|
|
|
|
|
|
private int a(EntityAnimal entityanimal, EntityAnimal entityanimal1) {
|
|
|
|
int i = this.b(entityanimal);
|
|
|
|
int j = this.b(entityanimal1);
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bq.getItem(0).setData(i);
|
|
|
|
this.bq.getItem(1).setData(j);
|
|
|
|
ItemStack itemstack = CraftingManager.getInstance().craft(this.bq, ((EntitySheep) entityanimal).world);
|
2012-11-06 13:05:28 +01:00
|
|
|
int k;
|
|
|
|
|
|
|
|
if (itemstack != null && itemstack.getItem().id == Item.INK_SACK.id) {
|
|
|
|
k = itemstack.getData();
|
|
|
|
} else {
|
|
|
|
k = this.world.random.nextBoolean() ? i : j;
|
|
|
|
}
|
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int b(EntityAnimal entityanimal) {
|
|
|
|
return 15 - ((EntitySheep) entityanimal).getColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityAgeable createChild(EntityAgeable entityageable) {
|
|
|
|
return this.b(entityageable);
|
|
|
|
}
|
2011-07-03 03:28:45 +02:00
|
|
|
}
|