From 585a62f3d308cfc30b7ef7d0fc11281c767b45e8 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 23 Dec 2011 00:54:34 +0100 Subject: [PATCH] [Bleeding] Undo changes to the tree WorldGenerators. - All StructureGrowEvent handling for these is in BlockSapling now, using a BlockChangeDelegate to collect the data. - Moved StructureGrowDelegate into a separate class By: Zeerix --- .../org/bukkit/craftbukkit/CraftWorld.java | 8 ++-- .../util/StructureGrowDelegate.java | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/util/StructureGrowDelegate.java diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 744113b735..0b434f32cf 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -365,16 +365,16 @@ public class CraftWorld implements World { public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { switch (type) { case BIG_TREE: - return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); + return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); case BIRCH: - return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); + return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); case REDWOOD: - return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); + return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); case TALL_REDWOOD: return new WorldGenTaiga1().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); case TREE: default: - return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); + return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/StructureGrowDelegate.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/StructureGrowDelegate.java new file mode 100644 index 0000000000..125772d41d --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/StructureGrowDelegate.java @@ -0,0 +1,48 @@ +package org.bukkit.craftbukkit.util; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.server.World; + +import org.bukkit.BlockChangeDelegate; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.material.MaterialData; + +public class StructureGrowDelegate implements BlockChangeDelegate { + private final CraftWorld world; + private final List blocks = new ArrayList(); + + public StructureGrowDelegate(World world) { + this.world = world.getWorld(); + } + + @Override + public boolean setRawTypeId(int x, int y, int z, int type) { + return setRawTypeIdAndData(x, y, z, type, 0); + } + + @Override + public boolean setRawTypeIdAndData(int x, int y, int z, int type, int data) { + BlockState state = world.getBlockAt(x, y, z).getState(); + state.setTypeId(type); + state.setData(new MaterialData(type, (byte) data)); + blocks.add(state); + return true; + } + + @Override + public int getTypeId(int x, int y, int z) { + return world.getBlockTypeIdAt(x, y, z); + } + + @Override + public int getHeight() { + return world.getMaxHeight(); + } + + public List getBlocks() { + return blocks; + } +}