diff options
author | bloodshot <jdroque@gmail.com> | 2014-01-06 00:17:16 -0500 |
---|---|---|
committer | Nate Mortensen <nate.richard.mortensen@gmail.com> | 2014-04-23 21:25:55 -0600 |
commit | 576758bc55941e673b1c4bf5727a1e1329ef29cd (patch) | |
tree | b3e114f8d5852efafe2827a9a392d11a7ce519f2 /src/main/java/net/minecraft/server/BlockSapling.java | |
parent | de97b62b8945ec7a05c7b6813a6317606f46faaf (diff) | |
download | craftbukkit-576758bc55941e673b1c4bf5727a1e1329ef29cd.tar craftbukkit-576758bc55941e673b1c4bf5727a1e1329ef29cd.tar.gz craftbukkit-576758bc55941e673b1c4bf5727a1e1329ef29cd.tar.lz craftbukkit-576758bc55941e673b1c4bf5727a1e1329ef29cd.tar.xz craftbukkit-576758bc55941e673b1c4bf5727a1e1329ef29cd.zip |
Refactored BlockPlaceEvent and BlockChangeDelegate. Adds BUKKIT-5558
23 classes have been removed as they are no longer needed using the new
capture logic. This should help quite a bit with future MC updates.
BlockPlaceEvent Refactor
Before calling Item.interactWith, a recording flag is turned on for
setTypeAndData to capture a blockstate for each block that attempts to be set.
When a block place event is cancelled, the recorded blockstate, stack
size, and metadata will revert back to the captured state. If the event is
not cancelled, a notification will be sent to clients and block physics
will be updated.
BlockChangeDelegate Refactor
Now that we have the ability to capture blockstates through world, there
is no need to modify world gen classes with BlockChangeDelegate. Instead
we will simply capture blocks during world generation in order to "replay"
all of the captured blockstates to send back to delegates.
StructureGrowDelegate and BlockSapling.TreeGenerator have also been
removed as part of this change. BlockSapling and BlockMushroom will
capture blockstates the same as block placement and revert back any grow
events if needed.
Diffstat (limited to 'src/main/java/net/minecraft/server/BlockSapling.java')
-rw-r--r-- | src/main/java/net/minecraft/server/BlockSapling.java | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index 830eb65d..ab8b07c7 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -3,11 +3,11 @@ package net.minecraft.server; import java.util.Random; // CraftBukkit start +import java.util.List; + 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.block.BlockState; import org.bukkit.event.world.StructureGrowEvent; // CraftBukkit end @@ -15,6 +15,7 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen public static final String[] a = new String[] { "oak", "spruce", "birch", "jungle", "acacia", "roofed_oak"}; private static final IIcon[] b = new IIcon[a.length]; + public static TreeType treeType; // CraftBukkit protected BlockSapling() { float f = 0.4F; @@ -27,32 +28,50 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen 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 start + world.captureTreeGeneration = true; + // CraftBukkit end + this.grow(world, i, j, k, random); + // CraftBukkit start + world.captureTreeGeneration = false; + if (world.capturedBlockStates.size() > 0) + { + TreeType treeType = BlockSapling.treeType; + BlockSapling.treeType = null; + Location location = new Location(world.getWorld(), i, j, k); + List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone(); + world.capturedBlockStates.clear(); + StructureGrowEvent event = null; + if (treeType != null) { + event = new StructureGrowEvent(location, treeType, false, null, blocks); + org.bukkit.Bukkit.getPluginManager().callEvent(event); + } + if (event == null || !event.isCancelled()) { + for (BlockState blockstate : blocks) { + blockstate.update(true); + } + } + } + // CraftBukkit end } } } - // 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) { + public void grow(World world, int i, int j, int k, Random random) { 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 + this.d(world, i, j, k, random); } } - // 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) { + public void d(World world, int i, int j, int k, Random random) { 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 + // CraftBukkit start - Turn ternary operator into if statement to set treeType + // Object object = random.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true); + Object object; if (random.nextInt(10) == 0) { treeType = TreeType.BIG_TREE; object = new WorldGenBigTree(true); @@ -71,11 +90,11 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen 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)) { + treeType = TreeType.TALL_REDWOOD; // CraftBukkit object = new WorldGenMegaTree(false, random.nextBoolean()); flag = true; break label78; @@ -86,6 +105,7 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen if (!flag) { j1 = 0; i1 = 0; + treeType = TreeType.REDWOOD; // CraftBukkit object = new WorldGenTaiga2(true); } break; @@ -150,29 +170,7 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen 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 (!((WorldGenerator) object).a(world, random, i + i1, j, k + j1)) { if (flag) { world.setTypeAndData(i + i1, j, k + j1, this, l, 4); world.setTypeAndData(i + i1 + 1, j, k + j1, this, l, 4); @@ -201,15 +199,6 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen } 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); + this.grow(world, i, j, k, random); } - // CraftBukkit end } |