2011-02-04 04:03:11 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-03-11 05:19:09 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
|
|
|
// CraftBukkit end
|
2011-02-04 04:03:11 +01:00
|
|
|
|
|
|
|
public class EntityCreeper extends EntityMonster {
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
private int bp;
|
2012-10-25 05:53:23 +02:00
|
|
|
private int fuseTicks;
|
|
|
|
private int maxFuseTicks = 30;
|
|
|
|
private int explosionRadius = 3;
|
2012-03-11 05:19:09 +01:00
|
|
|
private int record = -1; // CraftBukkit
|
2011-02-04 04:03:11 +01:00
|
|
|
|
|
|
|
public EntityCreeper(World world) {
|
|
|
|
super(world);
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(1, new PathfinderGoalFloat(this));
|
|
|
|
this.goalSelector.a(2, new PathfinderGoalSwell(this));
|
2013-07-01 13:03:00 +02:00
|
|
|
this.goalSelector.a(3, new PathfinderGoalAvoidPlayer(this, EntityOcelot.class, 6.0F, 1.0D, 1.2D));
|
|
|
|
this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, 1.0D, false));
|
|
|
|
this.goalSelector.a(5, new PathfinderGoalRandomStroll(this, 0.8D));
|
2012-03-01 11:49:23 +01:00
|
|
|
this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
|
|
|
|
this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this));
|
2013-07-01 13:03:00 +02:00
|
|
|
this.targetSelector.a(1, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
|
2012-03-01 11:49:23 +01:00
|
|
|
this.targetSelector.a(2, new PathfinderGoalHurtByTarget(this, false));
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected void az() {
|
|
|
|
super.az();
|
2013-07-09 01:43:37 +02:00
|
|
|
this.getAttributeInstance(GenericAttributes.d).setValue(0.25D);
|
2013-07-01 13:03:00 +02:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
public boolean bf() {
|
2012-03-01 11:49:23 +01:00
|
|
|
return true;
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
public int as() {
|
2013-07-01 13:03:00 +02:00
|
|
|
return this.getGoalTarget() == null ? 3 : 3 + (int) (this.getHealth() - 1.0F);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected void b(float f) {
|
|
|
|
super.b(f);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.fuseTicks = (int) ((float) this.fuseTicks + f * 1.5F);
|
|
|
|
if (this.fuseTicks > this.maxFuseTicks - 5) {
|
|
|
|
this.fuseTicks = this.maxFuseTicks - 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected void a() {
|
|
|
|
super.a();
|
2011-02-04 04:03:11 +01:00
|
|
|
this.datawatcher.a(16, Byte.valueOf((byte) -1));
|
2011-04-20 22:47:26 +02:00
|
|
|
this.datawatcher.a(17, Byte.valueOf((byte) 0));
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2011-09-24 23:03:31 +02:00
|
|
|
if (this.datawatcher.getByte(17) == 1) {
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setBoolean("powered", true);
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
nbttagcompound.setShort("Fuse", (short) this.maxFuseTicks);
|
|
|
|
nbttagcompound.setByte("ExplosionRadius", (byte) this.explosionRadius);
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2011-11-30 00:17:43 +01:00
|
|
|
this.datawatcher.watch(17, Byte.valueOf((byte) (nbttagcompound.getBoolean("powered") ? 1 : 0)));
|
2012-10-25 05:53:23 +02:00
|
|
|
if (nbttagcompound.hasKey("Fuse")) {
|
|
|
|
this.maxFuseTicks = nbttagcompound.getShort("Fuse");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbttagcompound.hasKey("ExplosionRadius")) {
|
|
|
|
this.explosionRadius = nbttagcompound.getByte("ExplosionRadius");
|
|
|
|
}
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void l_() {
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.isAlive()) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bp = this.fuseTicks;
|
2013-07-09 01:43:37 +02:00
|
|
|
int i = this.bV();
|
2011-02-04 04:03:11 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (i > 0 && this.fuseTicks == 0) {
|
2012-11-06 13:05:28 +01:00
|
|
|
this.makeSound("random.fuse", 1.0F, 0.5F);
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.fuseTicks += i;
|
|
|
|
if (this.fuseTicks < 0) {
|
|
|
|
this.fuseTicks = 0;
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.fuseTicks >= this.maxFuseTicks) {
|
|
|
|
this.fuseTicks = this.maxFuseTicks;
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!this.world.isStatic) {
|
2012-10-25 05:53:23 +02:00
|
|
|
boolean flag = this.world.getGameRules().getBoolean("mobGriefing");
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
float radius = this.isPowered() ? 6.0F : 3.0F;
|
|
|
|
|
|
|
|
ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), radius, false);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire(), flag);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.die();
|
|
|
|
} else {
|
|
|
|
this.fuseTicks = 0;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
super.l_();
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected String aO() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.creeper.say";
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-09-19 20:25:08 +02:00
|
|
|
protected String aP() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.creeper.death";
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public void die(DamageSource damagesource) {
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Rearranged the method (super call to end, drop to dropDeathLoot)
|
2011-09-15 18:36:27 +02:00
|
|
|
if (damagesource.getEntity() instanceof EntitySkeleton) {
|
2012-11-06 13:05:28 +01:00
|
|
|
int i = Item.RECORD_1.id + this.random.nextInt(Item.RECORD_12.id - Item.RECORD_1.id + 1);
|
|
|
|
|
|
|
|
// this.b(i, 1); // CraftBukkit
|
|
|
|
this.record = i;
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-03-11 05:19:09 +01:00
|
|
|
super.die(damagesource);
|
|
|
|
// CraftBukkit end
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Whole method
|
2012-03-11 05:19:09 +01:00
|
|
|
protected void dropDeathLoot(boolean flag, int i) {
|
|
|
|
int j = this.getLootId();
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
|
2012-03-11 05:19:09 +01:00
|
|
|
|
|
|
|
if (j > 0) {
|
|
|
|
int k = this.random.nextInt(3);
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
k += this.random.nextInt(i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k > 0) {
|
|
|
|
loot.add(new org.bukkit.inventory.ItemStack(j, k));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop a music disc?
|
|
|
|
if (this.record != -1) {
|
|
|
|
loot.add(new org.bukkit.inventory.ItemStack(this.record, 1));
|
|
|
|
this.record = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CraftEventFactory.callEntityDeathEvent(this, loot); // raise event even for those times when the entity does not drop loot
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public boolean m(Entity entity) {
|
2012-03-01 11:49:23 +01:00
|
|
|
return true;
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public boolean isPowered() {
|
2011-09-24 23:03:31 +02:00
|
|
|
return this.datawatcher.getByte(17) == 1;
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
protected int getLootId() {
|
2011-02-04 04:03:11 +01:00
|
|
|
return Item.SULPHUR.id;
|
|
|
|
}
|
|
|
|
|
2013-07-09 01:43:37 +02:00
|
|
|
public int bV() {
|
2011-09-24 23:03:31 +02:00
|
|
|
return this.datawatcher.getByte(16);
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void a(int i) {
|
2011-06-27 00:25:01 +02:00
|
|
|
this.datawatcher.watch(16, Byte.valueOf((byte) i));
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|
2011-04-20 22:47:26 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void a(EntityLightning entitylightning) {
|
|
|
|
super.a(entitylightning);
|
2011-04-26 01:47:25 +02:00
|
|
|
// CraftBukkit start
|
2012-07-29 09:33:13 +02:00
|
|
|
if (CraftEventFactory.callCreeperPowerEvent(this, entitylightning, org.bukkit.event.entity.CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) {
|
2011-05-26 14:48:22 +02:00
|
|
|
return;
|
2011-04-26 01:47:25 +02:00
|
|
|
}
|
2011-05-26 14:48:22 +02:00
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
this.setPowered(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPowered(boolean powered) {
|
|
|
|
if (!powered) {
|
|
|
|
this.datawatcher.watch(17, Byte.valueOf((byte) 0));
|
2012-03-11 05:19:09 +01:00
|
|
|
} else {
|
|
|
|
this.datawatcher.watch(17, Byte.valueOf((byte) 1));
|
|
|
|
}
|
2011-06-27 00:25:01 +02:00
|
|
|
// CraftBukkit end
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
2011-02-04 04:03:11 +01:00
|
|
|
}
|