2011-04-22 10:18:24 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.util.Iterator;
|
2011-04-22 10:18:24 +02:00
|
|
|
import java.util.List;
|
2011-04-26 03:19:44 +02:00
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import org.bukkit.event.block.BlockIgniteEvent; // CraftBukkit
|
2011-04-22 10:18:24 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public class EntityLightning extends EntityWeather {
|
2011-04-22 10:18:24 +02:00
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
private int lifeTicks;
|
2011-04-22 10:18:24 +02:00
|
|
|
public long a = 0L;
|
|
|
|
private int c;
|
2011-04-26 03:19:44 +02:00
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
private org.bukkit.craftbukkit.CraftWorld cworld;
|
2011-05-07 04:25:44 +02:00
|
|
|
public boolean isEffect = false;
|
2011-04-22 10:18:24 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public EntityLightning(World world, double d0, double d1, double d2) {
|
2011-05-07 04:25:44 +02:00
|
|
|
this(world, d0, d1, d2, false);
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public EntityLightning(World world, double d0, double d1, double d2, boolean isEffect) {
|
2011-06-12 00:02:58 +02:00
|
|
|
// CraftBukkit end
|
2011-04-26 03:19:44 +02:00
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
super(world);
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2011-05-07 04:25:44 +02:00
|
|
|
this.isEffect = isEffect;
|
2011-06-27 00:25:01 +02:00
|
|
|
this.cworld = world.getWorld();
|
2011-04-22 10:18:24 +02:00
|
|
|
// CraftBukkit end
|
2011-04-26 03:19:44 +02:00
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
this.setPositionRotation(d0, d1, d2, 0.0F, 0.0F);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.lifeTicks = 2;
|
2011-04-22 10:18:24 +02:00
|
|
|
this.a = this.random.nextLong();
|
|
|
|
this.c = this.random.nextInt(3) + 1;
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit
|
2011-09-24 23:03:31 +02:00
|
|
|
if (!isEffect && world.difficulty >= 2 && world.areChunksLoaded(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2), 10)) {
|
2011-04-22 10:18:24 +02:00
|
|
|
int i = MathHelper.floor(d0);
|
|
|
|
int j = MathHelper.floor(d1);
|
|
|
|
int k = MathHelper.floor(d2);
|
|
|
|
|
|
|
|
if (world.getTypeId(i, j, k) == 0 && Block.FIRE.canPlace(world, i, j, k)) {
|
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(i, j, k), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
2011-06-27 00:25:01 +02:00
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
world.setTypeId(i, j, k, Block.FIRE.id);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
j = MathHelper.floor(d0) + this.random.nextInt(3) - 1;
|
|
|
|
k = MathHelper.floor(d1) + this.random.nextInt(3) - 1;
|
|
|
|
int l = MathHelper.floor(d2) + this.random.nextInt(3) - 1;
|
|
|
|
|
|
|
|
if (world.getTypeId(j, k, l) == 0 && Block.FIRE.canPlace(world, j, k, l)) {
|
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(j, k, l), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
2011-06-27 00:25:01 +02:00
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
world.setTypeId(j, k, l, Block.FIRE.id);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void h_() {
|
|
|
|
super.h_();
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.lifeTicks == 2) {
|
2011-04-22 10:18:24 +02:00
|
|
|
this.world.makeSound(this.locX, this.locY, this.locZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
|
|
|
|
this.world.makeSound(this.locX, this.locY, this.locZ, "random.explode", 2.0F, 0.5F + this.random.nextFloat() * 0.2F);
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
--this.lifeTicks;
|
|
|
|
if (this.lifeTicks < 0) {
|
2011-04-22 10:18:24 +02:00
|
|
|
if (this.c == 0) {
|
|
|
|
this.die();
|
2011-06-27 00:25:01 +02:00
|
|
|
} else if (this.lifeTicks < -this.random.nextInt(10)) {
|
2011-04-22 10:18:24 +02:00
|
|
|
--this.c;
|
2011-06-27 00:25:01 +02:00
|
|
|
this.lifeTicks = 1;
|
2011-04-22 10:18:24 +02:00
|
|
|
this.a = this.random.nextLong();
|
2011-05-26 14:48:22 +02:00
|
|
|
// CraftBukkit
|
2011-06-27 00:25:01 +02:00
|
|
|
if (!this.isEffect && this.world.areChunksLoaded(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ), 10)) {
|
2011-04-22 10:18:24 +02:00
|
|
|
int i = MathHelper.floor(this.locX);
|
|
|
|
int j = MathHelper.floor(this.locY);
|
|
|
|
int k = MathHelper.floor(this.locZ);
|
|
|
|
|
|
|
|
if (this.world.getTypeId(i, j, k) == 0 && Block.FIRE.canPlace(this.world, i, j, k)) {
|
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(i, j, k), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2011-04-22 10:18:24 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
this.world.setTypeId(i, j, k, Block.FIRE.id);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (this.lifeTicks >= 0 && !this.isEffect) { // CraftBukkit
|
2011-04-22 10:18:24 +02:00
|
|
|
double d0 = 3.0D;
|
2012-07-29 09:33:13 +02:00
|
|
|
List list = this.world.getEntities(this, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + 6.0D + d0, this.locZ + d0));
|
|
|
|
Iterator iterator = list.iterator();
|
2011-04-22 10:18:24 +02:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
2011-04-22 10:18:24 +02:00
|
|
|
|
|
|
|
entity.a(this);
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.world.s = 2;
|
2011-04-22 10:18:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected void a() {}
|
2011-04-22 10:18:24 +02:00
|
|
|
|
|
|
|
protected void a(NBTTagCompound nbttagcompound) {}
|
|
|
|
|
|
|
|
protected void b(NBTTagCompound nbttagcompound) {}
|
|
|
|
}
|