Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 172 lines 4.8 kB view raw
1package net.minecraft.server; 2 3// CraftBukkit start 4 5import org.bukkit.craftbukkit.entity.CraftEntity; 6import org.bukkit.event.entity.CreeperPowerEvent; 7import org.bukkit.event.entity.ExplosionPrimeEvent; 8// CraftBukkit end 9 10public class EntityCreeper extends EntityMonster { 11 12 int fuseTicks; 13 int b; 14 15 public EntityCreeper(World world) { 16 super(world); 17 this.texture = "/mob/creeper.png"; 18 } 19 20 protected void b() { 21 super.b(); 22 this.datawatcher.a(16, Byte.valueOf((byte) -1)); 23 this.datawatcher.a(17, Byte.valueOf((byte) 0)); 24 } 25 26 public void b(NBTTagCompound nbttagcompound) { 27 super.b(nbttagcompound); 28 if (this.datawatcher.a(17) == 1) { 29 nbttagcompound.a("powered", true); 30 } 31 } 32 33 public void a(NBTTagCompound nbttagcompound) { 34 super.a(nbttagcompound); 35 this.datawatcher.watch(17, Byte.valueOf((byte) (nbttagcompound.m("powered") ? 1 : 0))); 36 } 37 38 protected void b(Entity entity, float f) { 39 if (!this.world.isStatic) { 40 if (this.fuseTicks > 0) { 41 this.e(-1); 42 --this.fuseTicks; 43 if (this.fuseTicks < 0) { 44 this.fuseTicks = 0; 45 } 46 } 47 } 48 } 49 50 public void m_() { 51 this.b = this.fuseTicks; 52 if (this.world.isStatic) { 53 int i = this.x(); 54 55 if (i > 0 && this.fuseTicks == 0) { 56 this.world.makeSound(this, "random.fuse", 1.0F, 0.5F); 57 } 58 59 this.fuseTicks += i; 60 if (this.fuseTicks < 0) { 61 this.fuseTicks = 0; 62 } 63 64 if (this.fuseTicks >= 30) { 65 this.fuseTicks = 30; 66 } 67 } 68 69 super.m_(); 70 if (this.target == null && this.fuseTicks > 0) { 71 this.e(-1); 72 --this.fuseTicks; 73 if (this.fuseTicks < 0) { 74 this.fuseTicks = 0; 75 } 76 } 77 } 78 79 protected String h() { 80 return "mob.creeper"; 81 } 82 83 protected String i() { 84 return "mob.creeperdeath"; 85 } 86 87 public void die(Entity entity) { 88 super.die(entity); 89 if (entity instanceof EntityArrow) { 90 EntityLiving shooter = ((EntityArrow) entity).shooter; 91 if (shooter instanceof EntitySkeleton) { 92 this.b(Item.GOLD_RECORD.id + this.random.nextInt(2), 1); 93 } 94 } 95 } 96 97 protected void a(Entity entity, float f) { 98 if (!this.world.isStatic) { 99 int i = this.x(); 100 101 if ((i > 0 || f >= 3.0F) && (i <= 0 || f >= 7.0F)) { 102 this.e(-1); 103 --this.fuseTicks; 104 if (this.fuseTicks < 0) { 105 this.fuseTicks = 0; 106 } 107 } else { 108 if (this.fuseTicks == 0) { 109 this.world.makeSound(this, "random.fuse", 1.0F, 0.5F); 110 } 111 112 this.e(1); 113 ++this.fuseTicks; 114 if (this.fuseTicks >= 30) { 115 // CraftBukkit start 116 float radius = this.isPowered() ? 6.0F : 3.0F; 117 118 ExplosionPrimeEvent event = new ExplosionPrimeEvent(CraftEntity.getEntity(this.world.getServer(), this), radius, false); 119 this.world.getServer().getPluginManager().callEvent(event); 120 121 if (!event.isCancelled()) { 122 this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire()); 123 this.die(); 124 } else { 125 this.fuseTicks = 0; 126 } 127 // CraftBukkit end 128 } 129 130 this.e = true; 131 } 132 } 133 } 134 135 public boolean isPowered() { 136 return this.datawatcher.a(17) == 1; 137 } 138 139 protected int j() { 140 return Item.SULPHUR.id; 141 } 142 143 private int x() { 144 return this.datawatcher.a(16); 145 } 146 147 private void e(int i) { 148 this.datawatcher.watch(16, Byte.valueOf((byte) i)); 149 } 150 151 public void a(EntityWeatherStorm entityweatherstorm) { 152 super.a(entityweatherstorm); 153 154 // CraftBukkit start 155 CreeperPowerEvent event = new CreeperPowerEvent(this.getBukkitEntity(), entityweatherstorm.getBukkitEntity(), CreeperPowerEvent.PowerCause.LIGHTNING); 156 this.world.getServer().getPluginManager().callEvent(event); 157 158 if (event.isCancelled()) { 159 return; 160 } 161 162 this.setPowered(true); 163 } 164 165 public void setPowered(boolean powered) { 166 if (!powered) { 167 this.datawatcher.watch(17, Byte.valueOf((byte) 0)); 168 } else 169 // CraftBukkit end 170 this.datawatcher.watch(17, Byte.valueOf((byte) 1)); 171 } 172}