3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00
Paper/src/main/java/net/minecraft/server/EntityCreeper.java

177 Zeilen
5.3 KiB
Java

2011-02-04 04:03:11 +01:00
package net.minecraft.server;
// CraftBukkit start
import java.util.List;
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 {
int fuseTicks;
2011-02-04 04:03:11 +01:00
int b;
private int record = -1; // CraftBukkit
2011-02-04 04:03:11 +01:00
public EntityCreeper(World world) {
super(world);
this.texture = "/mob/creeper.png";
2012-03-01 11:49:23 +01:00
this.goalSelector.a(1, new PathfinderGoalFloat(this));
this.goalSelector.a(2, new PathfinderGoalSwell(this));
this.goalSelector.a(3, new PathfinderGoalAvoidPlayer(this, EntityOcelot.class, 6.0F, 0.25F, 0.3F));
this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, 0.25F, false));
this.goalSelector.a(5, new PathfinderGoalRandomStroll(this, 0.2F));
this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this));
this.targetSelector.a(1, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 16.0F, 0, false));
this.targetSelector.a(2, new PathfinderGoalHurtByTarget(this, false));
}
public boolean c_() {
return true;
2011-02-04 04:03:11 +01:00
}
2011-11-20 09:01:14 +01:00
public int getMaxHealth() {
return 20;
}
2011-04-20 22:47:26 +02:00
protected void b() {
super.b();
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);
if (this.datawatcher.getByte(17) == 1) {
nbttagcompound.setBoolean("powered", true);
2011-04-20 22:47:26 +02:00
}
2011-02-04 04:03:11 +01:00
}
2011-04-20 22:47:26 +02:00
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.datawatcher.watch(17, Byte.valueOf((byte) (nbttagcompound.getBoolean("powered") ? 1 : 0)));
2011-04-20 22:47:26 +02:00
}
2012-03-01 11:49:23 +01:00
public void G_() {
if (this.isAlive()) {
this.b = this.fuseTicks;
int i = this.A();
2011-02-04 04:03:11 +01:00
if (i > 0 && this.fuseTicks == 0) {
this.world.makeSound(this, "random.fuse", 1.0F, 0.5F);
2011-02-04 04:03:11 +01:00
}
this.fuseTicks += i;
if (this.fuseTicks < 0) {
this.fuseTicks = 0;
2011-02-04 04:03:11 +01:00
}
if (this.fuseTicks >= 30) {
this.fuseTicks = 30;
2012-03-01 11:49:23 +01:00
// CraftBukkit start
float radius = this.isPowered() ? 6.0F : 3.0F;
2011-02-04 04:03:11 +01:00
2012-03-01 11:49:23 +01:00
ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), radius, false);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire());
this.die();
} else {
this.fuseTicks = 0;
}
// CraftBukkit end
2011-05-26 14:48:22 +02:00
}
}
2012-03-01 11:49:23 +01:00
super.G_();
2011-02-04 04:03:11 +01:00
}
2012-03-01 11:49:23 +01:00
protected String j() {
2011-02-04 04:03:11 +01:00
return "mob.creeper";
}
2012-03-01 11:49:23 +01:00
protected String k() {
2011-02-04 04:03:11 +01:00
return "mob.creeperdeath";
}
2011-09-15 02:23:52 +02:00
public void die(DamageSource damagesource) {
// 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) {
// this.b(Item.RECORD_1.id + this.random.nextInt(10), 1); // CraftBukkit
this.record = Item.RECORD_1.id + this.random.nextInt(10);
2011-02-04 04:03:11 +01:00
}
super.die(damagesource);
// CraftBukkit end
2011-02-04 04:03:11 +01:00
}
// CraftBukkit start - whole method
protected void dropDeathLoot(boolean flag, int i) {
int j = this.getLootId();
List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
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-03-01 11:49:23 +01:00
public boolean a(Entity entity) {
return true;
2011-02-04 04:03:11 +01:00
}
public boolean isPowered() {
return this.datawatcher.getByte(17) == 1;
2011-04-20 22:47:26 +02:00
}
protected int getLootId() {
2011-02-04 04:03:11 +01:00
return Item.SULPHUR.id;
}
2012-03-01 11:49:23 +01:00
public int A() {
return this.datawatcher.getByte(16);
2011-02-04 04:03:11 +01:00
}
2012-03-01 11:49:23 +01:00
public void c(int i) {
this.datawatcher.watch(16, Byte.valueOf((byte) i));
2011-02-04 04:03:11 +01:00
}
2011-04-20 22:47:26 +02:00
public void a(EntityWeatherLighting entityweatherlighting) {
super.a(entityweatherlighting);
2011-05-26 14:48:22 +02:00
// CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callCreeperPowerEvent(this, entityweatherlighting, org.bukkit.event.entity.CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) {
2011-05-26 14:48:22 +02:00
return;
}
2011-05-26 14:48:22 +02:00
this.setPowered(true);
}
public void setPowered(boolean powered) {
if (!powered) {
this.datawatcher.watch(17, Byte.valueOf((byte) 0));
} else {
this.datawatcher.watch(17, Byte.valueOf((byte) 1));
}
// CraftBukkit end
2011-04-20 22:47:26 +02:00
}
2011-02-04 04:03:11 +01:00
}