From e5fe051340dcc6d3f68fca54fc35ab77ba26090e Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 9 Nov 2019 11:32:24 -0500 Subject: [PATCH] Use persistent leaves for garden patch generator (/pumpkins) --- .../function/generator/GardenPatchGenerator.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java index 5d1aa01c5..19f5ed855 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java @@ -26,7 +26,6 @@ import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Random; @@ -39,6 +38,7 @@ public class GardenPatchGenerator implements RegionFunction { private final Random random = new Random(); private final EditSession editSession; private Pattern plant = getPumpkinPattern(); + private Pattern leafPattern = BlockTypes.OAK_LEAVES.getDefaultState().with(BlockTypes.OAK_LEAVES.getProperty("persistent"), true); private int affected; /** @@ -96,7 +96,7 @@ public class GardenPatchGenerator implements RegionFunction { } } - setBlockIfAir(editSession, pos, BlockTypes.OAK_LEAVES.getDefaultState()); + setBlockIfAir(editSession, pos, leafPattern); affected++; int t = random.nextInt(4); @@ -166,10 +166,9 @@ public class GardenPatchGenerator implements RegionFunction { return false; } - BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) { - editSession.setBlock(position, leavesBlock); + editSession.setBlock(position, leafPattern); } placeVine(position, position.add(0, 0, 1)); @@ -193,12 +192,12 @@ public class GardenPatchGenerator implements RegionFunction { * Set a block only if there's no block already there. * * @param position the position - * @param block the block to set + * @param pattern the pattern to set * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - private static > boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { - return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); + private static boolean setBlockIfAir(EditSession session, BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException { + return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, pattern); } /**