summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/BlockTallPlant.java
blob: f8adc614f9d4f21459cc794189e7187c82363085 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package net.minecraft.server;

import java.util.Random;

public class BlockTallPlant extends BlockPlant implements IBlockFragilePlantElement {

    public static final String[] a = new String[] { "sunflower", "syringa", "grass", "fern", "rose", "paeonia"};

    public BlockTallPlant() {
        super(Material.PLANT);
        this.c(0.0F);
        this.a(h);
        this.c("doublePlant");
    }

    public int b() {
        return 40;
    }

    public void updateShape(IBlockAccess iblockaccess, int i, int j, int k) {
        this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }

    public int e(IBlockAccess iblockaccess, int i, int j, int k) {
        int l = iblockaccess.getData(i, j, k);

        return !c(l) ? l & 7 : iblockaccess.getData(i, j - 1, k) & 7;
    }

    public boolean canPlace(World world, int i, int j, int k) {
        return super.canPlace(world, i, j, k) && world.isEmpty(i, j + 1, k);
    }

    protected void e(World world, int i, int j, int k) {
        if (!this.j(world, i, j, k)) {
            int l = world.getData(i, j, k);

            if (!c(l)) {
                this.b(world, i, j, k, l, 0);
                if (world.getType(i, j + 1, k) == this) {
                    world.setTypeAndData(i, j + 1, k, Blocks.AIR, 0, 2);
                }
            }

            world.setTypeAndData(i, j, k, Blocks.AIR, 0, 2);
        }
    }

    public boolean j(World world, int i, int j, int k) {
        int l = world.getData(i, j, k);

        return c(l) ? world.getType(i, j - 1, k) == this : world.getType(i, j + 1, k) == this && super.j(world, i, j, k);
    }

    public Item getDropType(int i, Random random, int j) {
        if (c(i)) {
            return null;
        } else {
            int k = d(i);

            return k != 3 && k != 2 ? Item.getItemOf(this) : null;
        }
    }

    public int getDropData(int i) {
        return c(i) ? 0 : i & 7;
    }

    public static boolean c(int i) {
        return (i & 8) != 0;
    }

    public static int d(int i) {
        return i & 7;
    }

    public void c(World world, int i, int j, int k, int l, int i1) {
        world.setTypeAndData(i, j, k, this, l, i1);
        org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this, 8); // CraftBukkit
    }

    public void postPlace(World world, int i, int j, int k, EntityLiving entityliving, ItemStack itemstack) {
        int l = ((MathHelper.floor((double) (entityliving.yaw * 4.0F / 360.0F) + 0.5D) & 3) + 2) % 4;

        world.setTypeAndData(i, j + 1, k, this, 8 | l, 2);
    }

    public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
        if (world.isStatic || entityhuman.bF() == null || entityhuman.bF().getItem() != Items.SHEARS || c(l) || !this.b(world, i, j, k, l, entityhuman)) {
            super.a(world, entityhuman, i, j, k, l);
        }
    }

    public void a(World world, int i, int j, int k, int l, EntityHuman entityhuman) {
        if (c(l)) {
            if (world.getType(i, j - 1, k) == this) {
                if (!entityhuman.abilities.canInstantlyBuild) {
                    int i1 = world.getData(i, j - 1, k);
                    int j1 = d(i1);

                    if (j1 != 3 && j1 != 2) {
                        world.setAir(i, j - 1, k, true);
                    } else {
                        if (!world.isStatic && entityhuman.bF() != null && entityhuman.bF().getItem() == Items.SHEARS) {
                            this.b(world, i, j, k, i1, entityhuman);
                        }

                        world.setAir(i, j - 1, k);
                    }
                } else {
                    world.setAir(i, j - 1, k);
                }
            }
        } else if (entityhuman.abilities.canInstantlyBuild && world.getType(i, j + 1, k) == this) {
            world.setTypeAndData(i, j + 1, k, Blocks.AIR, 0, 2);
        }

        super.a(world, i, j, k, l, entityhuman);
    }

    private boolean b(World world, int i, int j, int k, int l, EntityHuman entityhuman) {
        int i1 = d(l);

        if (i1 != 3 && i1 != 2) {
            return false;
        } else {
            entityhuman.a(StatisticList.MINE_BLOCK_COUNT[Block.getId(this)], 1);
            byte b0 = 1;

            if (i1 == 3) {
                b0 = 2;
            }

            this.a(world, i, j, k, new ItemStack(Blocks.LONG_GRASS, 2, b0));
            return true;
        }
    }

    public int getDropData(World world, int i, int j, int k) {
        int l = world.getData(i, j, k);

        return c(l) ? d(world.getData(i, j - 1, k)) : d(l);
    }

    public boolean a(World world, int i, int j, int k, boolean flag) {
        int l = this.e((IBlockAccess) world, i, j, k);

        return l != 2 && l != 3;
    }

    public boolean a(World world, Random random, int i, int j, int k) {
        return true;
    }

    public void b(World world, Random random, int i, int j, int k) {
        int l = this.e((IBlockAccess) world, i, j, k);

        this.a(world, i, j, k, new ItemStack(this, 1, l));
    }
}