Add fungi and chorus plant tree types.

Closes #1411.
This commit is contained in:
wizjany 2020-07-10 16:38:16 -04:00
parent 22acd2b486
commit 9d9aaac15a
6 changed files with 27 additions and 5 deletions

View File

@ -22,11 +22,11 @@
dependencies { dependencies {
"api"(project(":worldedit-core")) "api"(project(":worldedit-core"))
"api"(project(":worldedit-libs:bukkit")) "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") exclude("junit", "junit")
} }
"compileOnly"("org.jetbrains:annotations:19.0.0") "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") "implementation"("io.papermc:paperlib:1.0.2")
"compileOnly"("com.sk89q:dummypermscompat:1.10") "compileOnly"("com.sk89q:dummypermscompat:1.10")
"implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") "implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")

View File

@ -310,6 +310,9 @@ public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) {
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt) { public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt) {
World world = getWorld(); World world = getWorld();
TreeType bukkitType = toBukkitTreeType(type); 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, return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType,
new EditSessionBlockChangeDelegate(editSession)); new EditSessionBlockChangeDelegate(editSession));
} }

View File

@ -53,7 +53,7 @@ public boolean apply(BlockVector3 position) throws WorldEditException {
BlockState block = editSession.getBlock(position); BlockState block = editSession.getBlock(position);
BlockType t = block.getBlockType(); 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)); return treeType.generate(editSession, position.add(0, 1, 0));
} else if (t.getMaterial().isReplacedDuringPlacement()) { } else if (t.getMaterial().isReplacedDuringPlacement()) {
// since the implementation's tree generators generally don't generate in non-air spots, // since the implementation's tree generators generally don't generate in non-air spots,

View File

@ -40,7 +40,7 @@
/** /**
* Tree generator. * Tree generator.
*/ */
public class TreeGenerator { public final class TreeGenerator {
public enum TreeType { public enum TreeType {
TREE("Oak tree", "oak", "tree", "regular"), 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"), JUNGLE_BUSH("Jungle bush", "junglebush", "jungleshrub"),
RED_MUSHROOM("Red mushroom", "redmushroom", "redgiantmushroom"), RED_MUSHROOM("Red mushroom", "redmushroom", "redgiantmushroom"),
BROWN_MUSHROOM("Brown mushroom", "brownmushroom", "browngiantmushroom"), BROWN_MUSHROOM("Brown mushroom", "brownmushroom", "browngiantmushroom"),
CRIMSON_FUNGUS("Crimson fungus", "crimsonfungus", "rednethermushroom"),
WARPED_FUNGUS("Warped fungus", "warpedfungus", "greennethermushroom"),
RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") { RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") {
@Override @Override
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { 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); 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; 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") { RANDOM("Random tree", "rand", "random") {
@Override @Override
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {

View File

@ -92,7 +92,9 @@
import net.minecraft.world.gen.GeneratorOptions; import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DefaultBiomeFeatures; 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.Feature;
import net.minecraft.world.gen.feature.HugeFungusFeatureConfig;
import net.minecraft.world.level.ServerWorldProperties; import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.level.storage.LevelStorage; import net.minecraft.world.level.storage.LevelStorage;
@ -445,6 +447,9 @@ private List<CompletableFuture<Chunk>> submitChunkLoadTasks(Region region, Serve
case TALL_BIRCH: return Feature.TREE.configure(DefaultBiomeFeatures.LARGE_BIRCH_TREE_CONFIG); 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 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 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)]); case RANDOM: return createTreeFeatureGenerator(TreeType.values()[ThreadLocalRandom.current().nextInt(TreeType.values().length)]);
default: default:
return null; return null;

View File

@ -89,6 +89,8 @@
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature; 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.gen.settings.DimensionGeneratorSettings;
import net.minecraft.world.server.ServerChunkProvider; import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
@ -457,6 +459,9 @@ private List<CompletableFuture<IChunk>> submitChunkLoadTasks(Region region, Serv
case TALL_BIRCH: return Feature.field_236291_c_.withConfiguration(DefaultBiomeFeatures.field_230130_i_); 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 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 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)]); case RANDOM: return createTreeFeatureGenerator(TreeType.values()[ThreadLocalRandom.current().nextInt(TreeType.values().length)]);
default: default:
return null; return null;