Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 156 lines 5.5 kB view raw
1package net.minecraft.server; 2 3import java.util.Random; 4 5import uk.betacraft.uberbukkit.UberbukkitConfig; 6 7public class EntitySheep extends EntityAnimal { 8 9 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 } }; 10 11 public EntitySheep(World world) { 12 super(world); 13 this.texture = "/mob/sheep.png"; 14 this.b(0.9F, 1.3F); 15 } 16 17 protected void b() { 18 super.b(); 19 this.datawatcher.a(16, new Byte((byte) 0)); 20 } 21 22 public boolean damageEntity(Entity entity, int i) { 23 // uberbukkit 24 if (UberbukkitConfig.getInstance().getBoolean("mechanics.sheep_drop_wool_on_punch", false)) { 25 if (!this.world.isStatic && !this.isSheared() && entity instanceof EntityLiving) { 26 this.setSheared(true); 27 int j = 1 + this.random.nextInt(3); 28 for (int k = 0; k < j; ++k) { 29 EntityItem entityitem = this.a(new ItemStack(Block.WOOL.id, 1, this.getColor()), 1.0F); 30 entityitem.motY += (double) (this.random.nextFloat() * 0.05F); 31 entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); 32 entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); 33 } 34 } 35 } 36 37 return super.damageEntity(entity, i); 38 } 39 40 protected void q() { 41 // CraftBukkit start - whole method 42 java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>(); 43 44 if (!this.isSheared()) { 45 loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.WOOL, 1, (short) 0, (byte) this.getColor())); 46 } 47 48 org.bukkit.World bworld = this.world.getWorld(); 49 org.bukkit.entity.Entity entity = this.getBukkitEntity(); 50 51 org.bukkit.event.entity.EntityDeathEvent event = new org.bukkit.event.entity.EntityDeathEvent(entity, loot); 52 this.world.getServer().getPluginManager().callEvent(event); 53 54 for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { 55 bworld.dropItemNaturally(entity.getLocation(), stack); 56 } 57 // CraftBukkit end 58 } 59 60 protected int j() { 61 return Block.WOOL.id; 62 } 63 64 public boolean a(EntityHuman entityhuman) { 65 ItemStack itemstack = entityhuman.inventory.getItemInHand(); 66 67 if (itemstack != null && itemstack.id == Item.SHEARS.id && !this.isSheared()) { 68 if (!this.world.isStatic) { 69 this.setSheared(true); 70 int i = 2 + this.random.nextInt(3); 71 72 for (int j = 0; j < i; ++j) { 73 EntityItem entityitem = this.a(new ItemStack(Block.WOOL.id, 1, this.getColor()), 1.0F); 74 75 entityitem.motY += (double) (this.random.nextFloat() * 0.05F); 76 entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); 77 entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); 78 } 79 } 80 81 itemstack.damage(1, entityhuman); 82 } 83 84 return false; 85 } 86 87 public void b(NBTTagCompound nbttagcompound) { 88 super.b(nbttagcompound); 89 nbttagcompound.a("Sheared", this.isSheared()); 90 nbttagcompound.a("Color", (byte) this.getColor()); 91 } 92 93 public void a(NBTTagCompound nbttagcompound) { 94 super.a(nbttagcompound); 95 this.setSheared(nbttagcompound.m("Sheared")); 96 this.setColor(nbttagcompound.c("Color")); 97 } 98 99 protected String g() { 100 return "mob.sheep"; 101 } 102 103 protected String h() { 104 return "mob.sheep"; 105 } 106 107 protected String i() { 108 return "mob.sheep"; 109 } 110 111 public int getColor() { 112 return this.datawatcher.a(16) & 15; 113 } 114 115 public void setColor(int i) { 116 byte b0 = this.datawatcher.a(16); 117 118 this.datawatcher.watch(16, Byte.valueOf((byte) (b0 & 240 | i & 15))); 119 } 120 121 public boolean isSheared() { 122 return (this.datawatcher.a(16) & 16) != 0; 123 } 124 125 public void setSheared(boolean flag) { 126 byte b0 = this.datawatcher.a(16); 127 128 if (flag) { 129 this.datawatcher.watch(16, Byte.valueOf((byte) (b0 | 16))); 130 } else { 131 this.datawatcher.watch(16, Byte.valueOf((byte) (b0 & -17))); 132 } 133 } 134 135 public static int a(Random random) { 136 int i = random.nextInt(100); 137 138 // uberbukkit 139 boolean spawn_black = UberbukkitConfig.getInstance().getBoolean("mechanics.spawn_sheep_with_shades_of_black", true); 140 boolean spawn_brown_pink = UberbukkitConfig.getInstance().getBoolean("mechanics.spawn_brown_and_pink_sheep", true); 141 142 if (i < 5 && spawn_black) { 143 return 15; 144 } else if (i < 10 && spawn_black) { 145 return 7; 146 } else if (i < 15 && spawn_black) { 147 return 8; 148 } else if (i < 18 && spawn_brown_pink) { 149 return 12; 150 } else if (spawn_brown_pink && random.nextInt(500) == 0) { 151 return 6; 152 } else { 153 return 0; 154 } 155 } 156}