From 0c8db1e1feb1645991508c28c8f4bc714a842453 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 25 Dec 2021 19:03:30 +0100 Subject: [PATCH] feat: Add a bunch of new types to the flora generator --- .../function/generator/FloraGenerator.java | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java index d199fcb61..5ea9aa66e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java @@ -20,10 +20,13 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -40,6 +43,11 @@ public class FloraGenerator implements RegionFunction { private final boolean biomeAware = false; private final Pattern desertPattern = getDesertPattern(); private final Pattern temperatePattern = getTemperatePattern(); + //FAWE start + private final Pattern mushroomPattern = mushroomPattern(); + private final Pattern netherPattern = netherPattern(); + private final Pattern warpedNyliumPattern = warpedNyliumPattern(); + //FAWE end /** * Create a new flora generator. @@ -101,17 +109,75 @@ public class FloraGenerator implements RegionFunction { return pattern; } + //FAWE start + /** + * Get a pattern for plants to place inside a mushroom environment. + * + * @return a pattern that places flora + */ + public static Pattern mushroomPattern() { + RandomPattern pattern = new RandomPattern(); + pattern.add(BlockTypes.RED_MUSHROOM.getDefaultState(), 10); + pattern.add(BlockTypes.BROWN_MUSHROOM.getDefaultState(), 10); + return pattern; + } + + /** + * Get a pattern for plants to place inside a nether environment. + * + * @return a pattern that places flora + */ + public static Pattern netherPattern() { + RandomPattern pattern = new RandomPattern(); + pattern.add(BlockTypes.CRIMSON_ROOTS.getDefaultState(), 10); + pattern.add(BlockTypes.CRIMSON_FUNGUS.getDefaultState(), 20); + pattern.add(BlockTypes.WARPED_FUNGUS.getDefaultState(), 5); + return pattern; + } + + /** + * Get a pattern for plants to place inside a nether environment. + * + * @return a pattern that places flora + */ + public static Pattern warpedNyliumPattern() { + RandomPattern pattern = new RandomPattern(); + pattern.add(BlockTypes.WARPED_ROOTS.getDefaultState(), 15); + pattern.add(BlockTypes.NETHER_SPROUTS.getDefaultState(), 20); + pattern.add(BlockTypes.WARPED_FUNGUS.getDefaultState(), 7); + pattern.add(BlockTypes.CRIMSON_ROOTS.getDefaultState(), 10); + return pattern; + } + //FAWE end + @Override public boolean apply(BlockVector3 position) throws WorldEditException { + //FAWE start + int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getDataVersion(); + //FAWE end BlockState block = editSession.getBlock(position); if (block.getBlockType() == BlockTypes.GRASS_BLOCK) { editSession.setBlock(position.add(0, 1, 0), temperatePattern.applyBlock(position)); return true; - } else if (block.getBlockType() == BlockTypes.SAND) { + //FAWE start - add red sand + } else if (block.getBlockType() == BlockTypes.SAND || block.getBlockType() == BlockTypes.RED_SAND) { + //FAWE end editSession.setBlock(position.add(0, 1, 0), desertPattern.applyBlock(position)); return true; + //FAWE start - add new types + } else if (block.getBlockType() == BlockTypes.MYCELIUM || block.getBlockType() == BlockTypes.NETHERRACK) { + editSession.setBlock(position.add(0, 1, 0), mushroomPattern.applyBlock(position)); + return true; + } else if (dataVersion >= Constants.DATA_VERSION_MC_1_16) { + if (block.getBlockType() == BlockTypes.SOUL_SOIL || block.getBlockType() == BlockTypes.CRIMSON_NYLIUM) { + editSession.setBlock(position.add(0, 1, 0), netherPattern.applyBlock(position)); + return true; + } else if (block.getBlockType() == BlockTypes.WARPED_NYLIUM) { + editSession.setBlock(position.add(0, 1, 0), warpedNyliumPattern.applyBlock(position)); + } } + //FAWE end return false; }