2011-01-03 10:41:43 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import org.bukkit.event.entity.EntityDamageByBlockEvent; // CraftBukkit
|
|
|
|
|
2011-01-03 10:41:43 +01:00
|
|
|
public class BlockCactus extends Block {
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected BlockCactus() {
|
|
|
|
super(Material.CACTUS);
|
|
|
|
this.a(true);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(CreativeModeTab.c);
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.isEmpty(i, j + 1, k)) {
|
2011-01-03 10:41:43 +01:00
|
|
|
int l;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (l = 1; world.getType(i, j - l, k) == this; ++l) {
|
2011-01-03 10:41:43 +01:00
|
|
|
;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-03 10:41:43 +01:00
|
|
|
if (l < 3) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i1 = world.getData(i, j, k);
|
2011-01-03 10:41:43 +01:00
|
|
|
|
|
|
|
if (i1 == 15) {
|
2013-11-04 14:07:38 +01:00
|
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this, 0); // CraftBukkit
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setData(i, j, k, 0, 4);
|
2013-11-04 14:07:38 +01:00
|
|
|
this.doPhysics(world, i, j + 1, k, this);
|
2011-01-03 10:41:43 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setData(i, j, k, i1 + 1, 4);
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public AxisAlignedBB a(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
float f = 0.0625F;
|
2011-01-03 10:41:43 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
return AxisAlignedBB.a().a((double) ((float) i + f), (double) j, (double) ((float) k + f), (double) ((float) (i + 1) - f), (double) ((float) (j + 1) - f), (double) ((float) (k + 1) - f));
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean d() {
|
2011-05-26 14:48:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean c() {
|
2011-01-03 10:41:43 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public int b() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return 13;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean canPlace(World world, int i, int j, int k) {
|
2013-11-04 14:07:38 +01:00
|
|
|
return !super.canPlace(world, i, j, k) ? false : this.j(world, i, j, k);
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void doPhysics(World world, int i, int j, int k, Block block) {
|
|
|
|
if (!this.j(world, i, j, k)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setAir(i, j, k, true);
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean j(World world, int i, int j, int k) {
|
|
|
|
if (world.getType(i - 1, j, k).getMaterial().isBuildable()) {
|
2011-01-03 10:41:43 +01:00
|
|
|
return false;
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (world.getType(i + 1, j, k).getMaterial().isBuildable()) {
|
2011-01-03 10:41:43 +01:00
|
|
|
return false;
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (world.getType(i, j, k - 1).getMaterial().isBuildable()) {
|
2011-01-03 10:41:43 +01:00
|
|
|
return false;
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (world.getType(i, j, k + 1).getMaterial().isBuildable()) {
|
2011-01-03 10:41:43 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block = world.getType(i, j - 1, k);
|
2011-01-03 10:41:43 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
return block == Blocks.CACTUS || block == Blocks.SAND;
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(World world, int i, int j, int k, Entity entity) {
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit start - EntityDamageByBlock event
|
2011-02-23 13:56:36 +01:00
|
|
|
if (entity instanceof EntityLiving) {
|
2011-06-27 00:25:01 +02:00
|
|
|
org.bukkit.block.Block damager = world.getWorld().getBlockAt(i, j, k);
|
2011-02-23 13:56:36 +01:00
|
|
|
org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
|
2011-01-18 08:29:41 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, org.bukkit.event.entity.EntityDamageEvent.DamageCause.CONTACT, 1D);
|
2011-06-27 00:25:01 +02:00
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
if (!event.isCancelled()) {
|
2012-07-01 12:04:06 +02:00
|
|
|
damagee.setLastDamageCause(event);
|
2013-07-01 13:03:00 +02:00
|
|
|
entity.damageEntity(DamageSource.CACTUS, (float) event.getDamage());
|
2011-01-12 06:48:19 +01:00
|
|
|
}
|
|
|
|
return;
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit end
|
2011-06-27 00:25:01 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
entity.damageEntity(DamageSource.CACTUS, 1.0F);
|
2011-01-03 10:41:43 +01:00
|
|
|
}
|
|
|
|
}
|