Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3// CraftBukkit start
4
5import org.bukkit.event.entity.EntityDamageByBlockEvent;
6import org.bukkit.event.entity.EntityDamageEvent;
7
8import java.util.Random;
9
10// CraftBukkit end
11
12public class BlockCactus extends Block {
13
14 protected BlockCactus(int i, int j) {
15 super(i, j, Material.CACTUS);
16 this.a(true);
17 }
18
19 public void a(World world, int i, int j, int k, Random random) {
20 if (world.isEmpty(i, j + 1, k)) {
21 int l;
22
23 for (l = 1; world.getTypeId(i, j - l, k) == this.id; ++l) {
24 ;
25 }
26
27 if (l < 3) {
28 int i1 = world.getData(i, j, k);
29
30 if (i1 == 15) {
31 world.setTypeId(i, j + 1, k, this.id);
32 world.setData(i, j, k, 0);
33 } else {
34 world.setData(i, j, k, i1 + 1);
35 }
36 }
37 }
38 }
39
40 public AxisAlignedBB e(World world, int i, int j, int k) {
41 float f = 0.0625F;
42
43 return AxisAlignedBB.b((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));
44 }
45
46 public int a(int i) {
47 return i == 1 ? this.textureId - 1 : (i == 0 ? this.textureId + 1 : this.textureId);
48 }
49
50 public boolean b() {
51 return false;
52 }
53
54 public boolean a() {
55 return false;
56 }
57
58 public boolean canPlace(World world, int i, int j, int k) {
59 return !super.canPlace(world, i, j, k) ? false : this.f(world, i, j, k);
60 }
61
62 public void doPhysics(World world, int i, int j, int k, int l) {
63 if (!this.f(world, i, j, k)) {
64 this.g(world, i, j, k, world.getData(i, j, k));
65 world.setTypeId(i, j, k, 0);
66 }
67 }
68
69 public boolean f(World world, int i, int j, int k) {
70 if (world.getMaterial(i - 1, j, k).isBuildable()) {
71 return false;
72 } else if (world.getMaterial(i + 1, j, k).isBuildable()) {
73 return false;
74 } else if (world.getMaterial(i, j, k - 1).isBuildable()) {
75 return false;
76 } else if (world.getMaterial(i, j, k + 1).isBuildable()) {
77 return false;
78 } else {
79 int l = world.getTypeId(i, j - 1, k);
80
81 return l == Block.CACTUS.id || l == Block.SAND.id;
82 }
83 }
84
85 public void a(World world, int i, int j, int k, Entity entity) {
86 // CraftBukkit start - ENTITY_DAMAGEBY_BLOCK event
87 if (entity instanceof EntityLiving) {
88 org.bukkit.block.Block damager = world.getWorld().getBlockAt(i, j, k);
89 org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
90
91 EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, EntityDamageEvent.DamageCause.CONTACT, 1);
92 world.getServer().getPluginManager().callEvent(event);
93
94 if (!event.isCancelled()) {
95 entity.damageEntity((Entity) null, event.getDamage());
96 }
97 return;
98 }
99 // CraftBukkit end
100
101 entity.damageEntity((Entity) null, 1);
102 }
103}