Skip to content
Permalink
Browse files

Use persistent leaves for garden patch generator (/pumpkins)

  • Loading branch information
wizjany committed Nov 9, 2019
1 parent 575463a commit e5fe051340dcc6d3f68fca54fc35ab77ba26090e
@@ -26,7 +26,6 @@
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 @@
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 @@ private void placeVine(BlockVector3 basePos, BlockVector3 pos) throws MaxChanged
}
}

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

int t = random.nextInt(4);
@@ -166,10 +166,9 @@ public boolean apply(BlockVector3 position) throws WorldEditException {
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 static Pattern getPumpkinPattern() {
* 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 <B extends BlockStateHolder<B>> 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);
}

/**

0 comments on commit e5fe051

Please sign in to comment.
You can’t perform that action at this time.