Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 14 additions & 114 deletions src/main/java/net/minecraft/server/BlockSapling.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,142 +47,42 @@ public void grow(World world, int i, int j, int k, Random random, boolean boneme
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;


SproutSapling sapling = new SproutSapling(i,j,k,world,l,player,this);;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got double semi-colons at the end of this line.

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);
}
sapling.calcTree(TreeType.REDWOOD, new WorldGenMegaTree(false, random.nextBoolean()));
sapling.notFlag(new WorldGenTaiga2(true));
break;

case 2:
treeType = TreeType.BIRCH; // CraftBukkit
object = new WorldGenForest(true, false);
// CraftBukkit
sapling.setTreeAndGen(new WorldGenForest(true, false), TreeType.BIRCH);
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);
}
sapling.calcTree(TreeType.JUNGLE, new WorldGenJungleTree(true, 10, 20, 3, 3));
sapling.setTreeAndGen(new WorldGenTrees(true, 4 + random.nextInt(7), 3, 3, false), TreeType.SMALL_JUNGLE);
break;

case 4:
treeType = TreeType.ACACIA; // CraftBukkit
object = new WorldGenAcaciaTree(true);
sapling.setTreeAndGen(new WorldGenAcaciaTree(true), TreeType.ACACIA);
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) {
sapling.calcTree(TreeType.DARK_OAK, new WorldGenForestTree(true));
if (!sapling.getFlag()) {
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);
}
}
}
sapling.worldSetter();
sapling.growTree(itemstack);
}

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;
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/net/minecraft/server/SproutSapling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package net.minecraft.server;

import net.minecraft.server.BlockSapling.TreeGenerator;

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;

import java.util.Random;

public class SproutSapling {

private int i;
private int i1 = 0;
private int j;
private int j1 = 0;
private int k;
private World world;
private int type;
private TreeType treeType;
private boolean bonemeal;
private Player player;
private TreeGenerator object;
private boolean flag = false;
private BlockSapling sapling;

public SproutSapling(int tempI, int tempJ, int tempK, World tempWorld, int tempType, Player tempPlayer, BlockSapling tempSapling){
i = tempI;
j = tempJ;
k = tempK;
sapling = tempSapling;
world = tempWorld;
type = tempType;
player = tempPlayer;
Random random = new Random();
if (random.nextInt(10) == 0) {
treeType = TreeType.BIG_TREE;
object = new WorldGenBigTree(true);
} else {
treeType = TreeType.TREE;
object = new WorldGenTrees(true);
}
}

public void calcTree(TreeType tempType, TreeGenerator tempGenerator){
treeType = tempType; // CraftBukkit
label78:
for (i1 = 0; i1 >= -1; --i1) {
for (j1 = 0; j1 >= -1; --j1) {
if (sapling.a(world, i + i1, j, k + j1, type)
&& sapling.a(world, i + i1 + 1, j, k + j1, type)
&& sapling.a(world, i + i1, j, k + j1 + 1, type)
&& sapling.a(world, i + i1 + 1, j, k + j1 + 1, type)) {
object = tempGenerator;
flag = true;
break label78;
}
}
}
}

public void notFlag(TreeGenerator tempGenerator){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notFlag isn't a great name for a method. Can we try to figure out what this actually does and give it a real name?

if(!flag){
j1 = 0;
i1 = 0;
object = tempGenerator;
}
}

public void setTreeAndGen(TreeGenerator tempGenerator, TreeType tempType){
if(!flag){
object = tempGenerator;
treeType = tempType;
j1 = 0;
i1 = 0;
}
}

public boolean getFlag(){
return flag;
}

public void worldSetter(){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not a great name. (I realize that figuring out what the heck these things do isn't easy, though.)

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);
}
}

public void growTree(ItemStack itemstack) {
Random random = new Random();
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
boolean grownTree;
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, sapling, type, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1, sapling, type, 4);
world.setTypeAndData(i + i1, j, k + j1 + 1, sapling, type, 4);
world.setTypeAndData(i + i1 + 1, j, k + j1 + 1, sapling, type, 4);
} else {
world.setTypeAndData(i, j, k, sapling, type, 4);
}
}
}
}
Loading