From 9d9aaac15aa44f21cb4c09dbdf7cf7b1cd0104d4 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 10 Jul 2020 16:38:16 -0400 Subject: [PATCH] Add fungi and chorus plant tree types. Closes #1411. --- worldedit-bukkit/build.gradle.kts | 4 ++-- .../com/sk89q/worldedit/bukkit/BukkitWorld.java | 3 +++ .../function/generator/ForestGenerator.java | 2 +- .../com/sk89q/worldedit/util/TreeGenerator.java | 13 +++++++++++-- .../com/sk89q/worldedit/fabric/FabricWorld.java | 5 +++++ .../java/com/sk89q/worldedit/forge/ForgeWorld.java | 5 +++++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/build.gradle.kts b/worldedit-bukkit/build.gradle.kts index f33a88ae7..4dbcea6c7 100644 --- a/worldedit-bukkit/build.gradle.kts +++ b/worldedit-bukkit/build.gradle.kts @@ -22,11 +22,11 @@ dependencies { "api"(project(":worldedit-core")) "api"(project(":worldedit-libs:bukkit")) - "api"("org.bukkit:bukkit:1.15.2-R0.1-SNAPSHOT") { + "api"("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") { exclude("junit", "junit") } "compileOnly"("org.jetbrains:annotations:19.0.0") - "compileOnly"("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT") + "compileOnly"("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") "implementation"("io.papermc:paperlib:1.0.2") "compileOnly"("com.sk89q:dummypermscompat:1.10") "implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index e4f7bc619..c1b3e4ce3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -310,6 +310,9 @@ public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) { public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt) { World world = getWorld(); TreeType bukkitType = toBukkitTreeType(type); + if (bukkitType == TreeType.CHORUS_PLANT) { + pt = pt.add(0, 1, 0); // bukkit skips the feature gen which does this offset normally, so we have to add it back + } return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType, new EditSessionBlockChangeDelegate(editSession)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java index 4510c2432..be6d17288 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java @@ -53,7 +53,7 @@ public boolean apply(BlockVector3 position) throws WorldEditException { BlockState block = editSession.getBlock(position); BlockType t = block.getBlockType(); - if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT || t == BlockTypes.PODZOL || t == BlockTypes.COARSE_DIRT) { + if (t.getMaterial().isSolid()) { return treeType.generate(editSession, position.add(0, 1, 0)); } else if (t.getMaterial().isReplacedDuringPlacement()) { // since the implementation's tree generators generally don't generate in non-air spots, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java index 32f1b87e3..4de5e5606 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java @@ -40,7 +40,7 @@ /** * Tree generator. */ -public class TreeGenerator { +public final class TreeGenerator { public enum TreeType { TREE("Oak tree", "oak", "tree", "regular"), @@ -82,10 +82,12 @@ public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxCha JUNGLE_BUSH("Jungle bush", "junglebush", "jungleshrub"), RED_MUSHROOM("Red mushroom", "redmushroom", "redgiantmushroom"), BROWN_MUSHROOM("Brown mushroom", "brownmushroom", "browngiantmushroom"), + CRIMSON_FUNGUS("Crimson fungus", "crimsonfungus", "rednethermushroom"), + WARPED_FUNGUS("Warped fungus", "warpedfungus", "greennethermushroom"), RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") { @Override public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { - TreeType[] choices = { RED_MUSHROOM, BROWN_MUSHROOM }; + TreeType[] choices = { RED_MUSHROOM, BROWN_MUSHROOM, CRIMSON_FUNGUS, WARPED_FUNGUS }; return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } }, @@ -99,6 +101,13 @@ public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxCha return true; } }, + CHORUS_PLANT("Chorus plant", "chorusplant") { + @Override + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { + // chorus plants have to generate starting in the end stone itself, not the air above the ground + return editSession.getWorld().generateTree(this, editSession, pos.subtract(0, 1, 0)); + } + }, RANDOM("Random tree", "rand", "random") { @Override public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java index 077ff7396..5f61c42af 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java @@ -92,7 +92,9 @@ import net.minecraft.world.gen.GeneratorOptions; import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.DefaultBiomeFeatures; +import net.minecraft.world.gen.feature.DefaultFeatureConfig; import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.HugeFungusFeatureConfig; import net.minecraft.world.level.ServerWorldProperties; import net.minecraft.world.level.storage.LevelStorage; @@ -445,6 +447,9 @@ private List> submitChunkLoadTasks(Region region, Serve case TALL_BIRCH: return Feature.TREE.configure(DefaultBiomeFeatures.LARGE_BIRCH_TREE_CONFIG); case RED_MUSHROOM: return Feature.HUGE_RED_MUSHROOM.configure(DefaultBiomeFeatures.HUGE_RED_MUSHROOM_CONFIG); case BROWN_MUSHROOM: return Feature.HUGE_BROWN_MUSHROOM.configure(DefaultBiomeFeatures.HUGE_BROWN_MUSHROOM_CONFIG); + case WARPED_FUNGUS: return Feature.HUGE_FUNGUS.configure(HugeFungusFeatureConfig.WARPED_FUNGUS_CONFIG); + case CRIMSON_FUNGUS: return Feature.HUGE_FUNGUS.configure(HugeFungusFeatureConfig.CRIMSON_FUNGUS_CONFIG); + case CHORUS_PLANT: return Feature.CHORUS_PLANT.configure(DefaultFeatureConfig.INSTANCE); case RANDOM: return createTreeFeatureGenerator(TreeType.values()[ThreadLocalRandom.current().nextInt(TreeType.values().length)]); default: return null; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index ca9392b88..8b7bccfe1 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -89,6 +89,8 @@ import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.HugeFungusConfig; +import net.minecraft.world.gen.feature.NoFeatureConfig; import net.minecraft.world.gen.settings.DimensionGeneratorSettings; import net.minecraft.world.server.ServerChunkProvider; import net.minecraft.world.server.ServerWorld; @@ -457,6 +459,9 @@ private List> submitChunkLoadTasks(Region region, Serv case TALL_BIRCH: return Feature.field_236291_c_.withConfiguration(DefaultBiomeFeatures.field_230130_i_); case RED_MUSHROOM: return Feature.HUGE_RED_MUSHROOM.withConfiguration(DefaultBiomeFeatures.BIG_RED_MUSHROOM); case BROWN_MUSHROOM: return Feature.HUGE_BROWN_MUSHROOM.withConfiguration(DefaultBiomeFeatures.BIG_BROWN_MUSHROOM); + case WARPED_FUNGUS: return Feature.field_236281_L_.withConfiguration(HugeFungusConfig.field_236299_b_); + case CRIMSON_FUNGUS: return Feature.field_236281_L_.withConfiguration(HugeFungusConfig.field_236301_d_); + case CHORUS_PLANT: return Feature.CHORUS_PLANT.withConfiguration(NoFeatureConfig.field_236559_b_); case RANDOM: return createTreeFeatureGenerator(TreeType.values()[ThreadLocalRandom.current().nextInt(TreeType.values().length)]); default: return null;