summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/BlockCactus.java
blob: cd158e34c50b076b095c91c47b9732a22adf2129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package net.minecraft.server;

// CraftBukkit start
import org.bukkit.LivingEntity;
import org.bukkit.craftbukkit.CraftBlock;
import org.bukkit.craftbukkit.CraftEntity;
import org.bukkit.craftbukkit.CraftLivingEntity;
import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.event.entity.EntityDamagedByBlockEvent;
import org.bukkit.event.entity.EntityDamagedEvent;
// CraftBukkit end

import java.util.Random;

public class BlockCactus extends Block {

    protected BlockCactus(int i, int j) {
        super(i, j, Material.u);
        a(true);
    }

    public void a(World world, int i, int j, int k, Random random) {
        if (world.e(i, j + 1, k)) {
            int l;

            for (l = 1; world.a(i, j - l, k) == bh; l++) {
                ;
            }
            if (l < 3) {
                int i1 = world.b(i, j, k);

                if (i1 == 15) {
                    world.d(i, j + 1, k, bh);
                    world.b(i, j, k, 0);
                } else {
                    world.b(i, j, k, i1 + 1);
                }
            }
        }
    }

    public AxisAlignedBB d(World world, int i, int j, int k) {
        float f1 = 0.0625F;

        return AxisAlignedBB.b((float) i + f1, j, (float) k + f1, (float) (i + 1) - f1, (float) (j + 1) - f1, (float) (k + 1) - f1);
    }

    public int a(int i) {
        if (i == 1) {
            return bg - 1;
        }
        if (i == 0) {
            return bg + 1;
        } else {
            return bg;
        }
    }

    public boolean a() {
        return false;
    }

    public boolean a(World world, int i, int j, int k) {
        if (!super.a(world, i, j, k)) {
            return false;
        } else {
            return f(world, i, j, k);
        }
    }

    public void b(World world, int i, int j, int k, int l) {
        if (!f(world, i, j, k)) {
            a_(world, i, j, k, world.b(i, j, k));
            world.d(i, j, k, 0);
        }
    }

    public boolean f(World world, int i, int j, int k) {
        if (world.c(i - 1, j, k).a()) {
            return false;
        }
        if (world.c(i + 1, j, k).a()) {
            return false;
        }
        if (world.c(i, j, k - 1).a()) {
            return false;
        }
        if (world.c(i, j, k + 1).a()) {
            return false;
        } else {
            int l = world.a(i, j - 1, k);

            return l == Block.aV.bh || l == Block.E.bh;
        }
    }

    public void a(World world, int i, int j, int k, Entity entity) {
        // CraftBukkit start - ENTITY_DAMAGEBY_BLOCK event
        CraftEntity toPassIn = null;
        if (entity instanceof EntityPlayerMP) {
            toPassIn = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entity);
        } else if (entity instanceof EntityLiving) {
            toPassIn = new CraftLivingEntity(((WorldServer) world).getServer(), (EntityLiving) entity);
        }

        if(toPassIn != null) {
            EntityDamagedByBlockEvent edbbe = new EntityDamagedByBlockEvent(((WorldServer) world).getWorld().getBlockAt(i, j, k), toPassIn, EntityDamagedEvent.DamageCause.CONTACT, 1);
            ((WorldServer) world).getServer().getPluginManager().callEvent(edbbe);

            if (edbbe.isCancelled())
                return;
        }
        // CraftBukkit end TODO: Other entities (when their respective classes are added) hitting a Cactus
        entity.a(((Entity) (null)), 1);
    }
}