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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.TreeType;
import org.bukkit.craftbukkit.CraftBlockChangeDelegate;
import org.bukkit.craftbukkit.util.StructureGrowDelegate;
import org.bukkit.entity.Player;
import org.bukkit.event.world.StructureGrowEvent;
// CraftBukkit end
public class BlockSapling extends BlockPlant implements IBlockFragilePlantElement {
public static final String[] a = new String[] { "oak", "spruce", "birch", "jungle", "acacia", "roofed_oak"};
private static final IIcon[] b = new IIcon[a.length];
protected BlockSapling() {
float f = 0.4F;
this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
this.a(CreativeModeTab.c);
}
public void a(World world, int i, int j, int k, Random random) {
if (!world.isStatic) {
super.a(world, i, j, k, random);
if (world.getLightLevel(i, j + 1, k) >= 9 && random.nextInt(7) == 0) {
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack
}
}
}
// CraftBukkit - added bonemeal, player and itemstack
public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
int l = world.getData(i, j, k);
if ((l & 8) == 0) {
world.setData(i, j, k, l | 8, 4);
} else {
this.d(world, i, j, k, random, bonemeal, player, itemstack); // CraftBukkit
}
}
// CraftBukkit - Added bonemeal, player and itemstack
public void d(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
int l = world.getData(i, j, k) & 7;
// CraftBukkit start - Records tree generation and calls StructureGrowEvent
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
TreeType treeType = null;
boolean grownTree = false;
// Turn ternary operator into if statement to set treeType
//Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
TreeGenerator object; // Changed to TreeGenerator
if (random.nextInt(10) == 0) {
treeType = TreeType.BIG_TREE;
object = new WorldGenBigTree(true);
} else {
treeType = TreeType.TREE;
object = new WorldGenTrees(true);
}
// CraftBukkit end
int i1 = 0;
int j1 = 0;
boolean flag = false;
switch (l) {
case 0:
default:
break;
case 1:
treeType = TreeType.REDWOOD; // CraftBukkit
label78:
for (i1 = 0; i1 >= -1; --i1) {
for (j1 = 0; j1 >= -1; --j1) {
if (this.a(world, i + i1, j, k + j1, 1) && this.a(world, i + i1 + 1, j, k + j1, 1) && this.a(world, i + i1, j, k + j1 + 1, 1) && this.a(world, i + i1 + 1, j, k + j1 + 1, 1)) {
object = new WorldGenMegaTree(false, random.nextBoolean());
flag = true;
break label78;
}
}
}
if (!flag) {
j1 = 0;
i1 = 0;
object = new WorldGenTaiga2(true);
}
break;
case 2:
treeType = TreeType.BIRCH; // CraftBukkit
object = new WorldGenForest(true, false);
break;
case 3:
label93:
for (i1 = 0; i1 >= -1; --i1) {
for (j1 = 0; j1 >= -1; --j1) {
if (this.a(world, i + i1, j, k + j1, 3) && this.a(world, i + i1 + 1, j, k + j1, 3) && this.a(world, i + i1, j, k + j1 + 1, 3) && this.a(world, i + i1 + 1, j, k + j1 + 1, 3)) {
treeType = TreeType.JUNGLE; // CraftBukkit
object = new WorldGenJungleTree(true, 10, 20, 3, 3);
flag = true;
break label93;
}
}
}
if (!flag) {
j1 = 0;
i1 = 0;
treeType = TreeType.SMALL_JUNGLE; // CraftBukkit
object = new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false);
}
break;
case 4:
treeType = TreeType.ACACIA; // CraftBukkit
object = new WorldGenAcaciaTree(true);
break;
case 5:
label108:
for (i1 = 0; i1 >= -1; --i1) {
for (j1 = 0; j1 >= -1; --j1) {
if (this.a(world, i + i1, j, k + j1, 5) && this.a(world, i + i1 + 1, j, k + j1, 5) && this.a(world, i + i1, j, k + j1 + 1, 5) && this.a(world, i + i1 + 1, j, k + j1 + 1, 5)) {
object = new WorldGenForestTree(true);
treeType = TreeType.DARK_OAK; // CraftBukkit
flag = true;
break label108;
}
}
}
if (!flag) {
return;
}
}
Block block = Blocks.AIR;
if (flag) {
world.setTypeAndData(i + i1, j, k + j1, block, 0, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1, block, 0, 4);
world.setTypeAndData(i + i1, j, k + j1 + 1, block, 0, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, block, 0, 4);
} else {
world.setTypeAndData(i, j, k, block, 0, 4);
}
// CraftBukkit start
grownTree = object.generate(new CraftBlockChangeDelegate(delegate), random, i + i1, j, k + j1);
if (grownTree) {
Location location = new Location(world.getWorld(), i, j, k);
StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks());
org.bukkit.Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
grownTree = false;
} else {
for (org.bukkit.block.BlockState state : event.getBlocks()) {
state.update(true);
}
if (event.isFromBonemeal() && itemstack != null) {
--itemstack.count;
}
}
} else if (bonemeal && itemstack != null) {
// We always consume bonemeal when trying to grow
--itemstack.count;
}
// No need to generate the tree again.
if (!grownTree) {
// CraftBukkit end
if (flag) {
world.setTypeAndData(i + i1, j, k + j1, this, l, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1, this, l, 4);
world.setTypeAndData(i + i1, j, k + j1 + 1, this, l, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, this, l, 4);
} else {
world.setTypeAndData(i, j, k, this, l, 4);
}
}
}
public boolean a(World world, int i, int j, int k, int l) {
return world.getType(i, j, k) == this && (world.getData(i, j, k) & 7) == l;
}
public int getDropData(int i) {
return MathHelper.a(i & 7, 0, 5);
}
public boolean a(World world, int i, int j, int k, boolean flag) {
return true;
}
public boolean a(World world, Random random, int i, int j, int k) {
return (double) world.random.nextFloat() < 0.45D;
}
public void b(World world, Random random, int i, int j, int k) {
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack
}
// CraftBukkit start
public interface TreeGenerator {
public boolean a(World world, Random random, int i, int j, int k);
public boolean generate(org.bukkit.craftbukkit.CraftBlockChangeDelegate world, Random random, int i, int j, int k);
}
// CraftBukkit end
}
|