Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use persistent leaves for garden patch generator (/pumpkins)
  • Loading branch information
wizjany committed Nov 10, 2019
1 parent 575463a commit e5fe051
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -26,7 +26,6 @@
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;


import java.util.Random; import java.util.Random;
Expand All @@ -39,6 +38,7 @@ public class GardenPatchGenerator implements RegionFunction {
private final Random random = new Random(); private final Random random = new Random();
private final EditSession editSession; private final EditSession editSession;
private Pattern plant = getPumpkinPattern(); private Pattern plant = getPumpkinPattern();
private Pattern leafPattern = BlockTypes.OAK_LEAVES.getDefaultState().with(BlockTypes.OAK_LEAVES.getProperty("persistent"), true);
private int affected; private int affected;


/** /**
Expand Down Expand Up @@ -96,7 +96,7 @@ private void placeVine(BlockVector3 basePos, BlockVector3 pos) throws MaxChanged
} }
} }


setBlockIfAir(editSession, pos, BlockTypes.OAK_LEAVES.getDefaultState()); setBlockIfAir(editSession, pos, leafPattern);
affected++; affected++;


int t = random.nextInt(4); int t = random.nextInt(4);
Expand Down Expand Up @@ -166,10 +166,9 @@ public boolean apply(BlockVector3 position) throws WorldEditException {
return false; return false;
} }


BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();


if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) { if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) {
editSession.setBlock(position, leavesBlock); editSession.setBlock(position, leafPattern);
} }


placeVine(position, position.add(0, 0, 1)); placeVine(position, position.add(0, 0, 1));
Expand All @@ -193,12 +192,12 @@ public static Pattern getPumpkinPattern() {
* Set a block only if there's no block already there. * Set a block only if there's no block already there.
* *
* @param position the position * @param position the position
* @param block the block to set * @param pattern the pattern to set
* @return if block was changed * @return if block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { private static boolean setBlockIfAir(EditSession session, BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException {
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, pattern);
} }


/** /**
Expand Down

0 comments on commit e5fe051

Please sign in to comment.