Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.SharedConstants;
Expand Down Expand Up @@ -978,6 +979,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.SharedConstants;
Expand Down Expand Up @@ -942,6 +943,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.SharedConstants;
Expand Down Expand Up @@ -940,6 +941,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.SharedConstants;
Expand Down Expand Up @@ -977,6 +978,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.SharedConstants;
Expand Down Expand Up @@ -975,6 +976,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import io.papermc.paper.world.PaperWorldLoader;
Expand Down Expand Up @@ -967,6 +968,7 @@ public void initializeRegistries() {
}
}
}
WorldEditTreeTypes.init();

// BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().lookupOrThrow(Registries.BIOME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.WorldEditTreeGeneration;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import io.papermc.lib.PaperLib;
Expand Down Expand Up @@ -318,6 +319,10 @@ public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession

@Override
public boolean generateTree(com.sk89q.worldedit.world.generation.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
Boolean customResult = WorldEditTreeGeneration.handleWorldEditTrees(this, type, editSession, position);
if (customResult != null) {
return customResult;
}
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.generateTree(type, getWorld(), editSession, position);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.world.generation;

import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nullable;

public final class WorldEditTreeGeneration {

private WorldEditTreeGeneration() {
}

@SuppressWarnings("deprecation")
@Nullable
public static Boolean handleWorldEditTrees(World world, TreeType type, EditSession editSession, BlockVector3 position)
throws MaxChangedBlocksException {
if (type == WorldEditTreeTypes.RANDOM) {
var treeTypes = List.copyOf(TreeType.REGISTRY.values());
TreeType randomType = treeTypes.get(ThreadLocalRandom.current().nextInt(treeTypes.size()));
return world.generateTree(randomType, editSession, position);
}

if (type == WorldEditTreeTypes.PINE) {
// TODO Move this into this file once the legacy system is stripped away
return com.sk89q.worldedit.util.TreeGenerator.TreeType.PINE.generate(editSession, position);
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.world.generation;

/**
* This class holds custom trees added by WorldEdit.
*/
public final class WorldEditTreeTypes {

public static final TreeType RANDOM = create("random");
public static final TreeType PINE = create("pine");

private WorldEditTreeTypes() {
}

public static void init() {
register(RANDOM);
register(PINE);
}

private static TreeType create(String id) {
return new TreeType("worldedit:" + id);
}

private static void register(TreeType type) {
if (TreeType.REGISTRY.get(type.id()) == null) {
TreeType.REGISTRY.register(type.id(), type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeGeneration;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
Expand Down Expand Up @@ -486,6 +487,10 @@ public boolean generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType type

@Override
public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
Boolean customResult = WorldEditTreeGeneration.handleWorldEditTrees(this, type, editSession, position);
if (customResult != null) {
return customResult;
}
ServerLevel world = (ServerLevel) getWorld();
PlacedFeature generator = world.registryAccess().lookupOrThrow(Registries.PLACED_FEATURE).getValue(Identifier.tryParse(type.id()));
ServerChunkCache chunkManager = world.getChunkSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
Expand Down Expand Up @@ -319,6 +320,7 @@ private void setupRegistries(MinecraftServer server) {
}
}
}
WorldEditTreeTypes.init();

// ... :|
GameModes.get("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.WorldEditTreeGeneration;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
Expand Down Expand Up @@ -474,6 +475,10 @@ public boolean generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType type

@Override
public boolean generateTree(com.sk89q.worldedit.world.generation.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
Boolean customResult = WorldEditTreeGeneration.handleWorldEditTrees(this, type, editSession, position);
if (customResult != null) {
return customResult;
}
ServerLevel world = getWorld();
PlacedFeature generator = world.registryAccess().lookupOrThrow(Registries.PLACED_FEATURE).getValue(Identifier.tryParse(type.id()));
ServerChunkCache chunkManager = world.getChunkSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
Expand Down Expand Up @@ -246,6 +247,7 @@ private void setupRegistries(MinecraftServer server) {
}
}
}
WorldEditTreeTypes.init();

// ... :|
GameModes.get("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeGeneration;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
Expand Down Expand Up @@ -381,6 +382,10 @@ public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession

@Override
public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
Boolean customResult = WorldEditTreeGeneration.handleWorldEditTrees(this, type, editSession, position);
if (customResult != null) {
return customResult;
}
ServerLevel world = (ServerLevel) getWorld();
PlacedFeature generator = world.registryAccess().lookupOrThrow(Registries.PLACED_FEATURE).getValue(Identifier.tryParse(type.id()));
return generator != null && generator.place(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.generation.TreeType;
import com.sk89q.worldedit.world.generation.WorldEditTreeTypes;
import com.sk89q.worldedit.world.item.ItemCategory;
import net.kyori.adventure.audience.Audience;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -223,6 +224,7 @@ public void serverStarted(StartedEngineEvent<Server> event) {
}
}
});
WorldEditTreeTypes.init();
event.game().registry(RegistryTypes.BLOCK_TYPE).tags().forEach(blockTypeTag -> {
String id = blockTypeTag.key().asString();
if (!BlockCategory.REGISTRY.keySet().contains(id)) {
Expand Down