3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-17 08:30:04 +01:00

Add structure generator command

(cherry picked from commit 5ca80395a35100c2d7686ad8839baaa57f8db07c)
Dieser Commit ist enthalten in:
Madeline Miller 2023-04-09 18:18:23 +10:00 committet von dordsor21
Ursprung 17d7850cf3
Commit e5e73c4723
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
8 geänderte Dateien mit 131 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -67,12 +67,14 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet; import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
@ -111,6 +113,9 @@ import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldOptions; import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.PrimaryLevelData; import net.minecraft.world.level.storage.PrimaryLevelData;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@ -894,12 +899,19 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString())); BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString()));
} }
} }
// Features // Features
for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) { for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) { if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
ConfiguredFeatureType.REGISTRY.register(name.toString(), new ConfiguredFeatureType(name.toString())); ConfiguredFeatureType.REGISTRY.register(name.toString(), new ConfiguredFeatureType(name.toString()));
} }
} }
// Structures
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.STRUCTURE).keySet()) {
if (StructureType.REGISTRY.get(name.toString()) == null) {
StructureType.REGISTRY.register(name.toString(), new StructureType(name.toString()));
}
}
// BiomeCategories // BiomeCategories
Registry<Biome> biomeRegistry = server.registryAccess().registryOrThrow(Registries.BIOME); Registry<Biome> biomeRegistry = server.registryAccess().registryOrThrow(Registries.BIOME);
@ -939,6 +951,29 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ())); return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()));
} }
public boolean generateStructure(StructureType type, World world, EditSession session, BlockVector3 pt) {
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
if (k == null) {
return false;
}
ServerChunkCache chunkManager = originalWorld.getChunkSource();
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()));
StructureStart structureStart = k.generate(originalWorld.registryAccess(), chunkManager.getGenerator(), chunkManager.getGenerator().getBiomeSource(), chunkManager.randomState(), chunkManager.chunkMap.structureTemplateManager, originalWorld.getSeed(), chunkPos, 0, proxyLevel, biome -> true);
if (!structureStart.isValid()) {
return false;
} else {
BoundingBox boundingBox = structureStart.getBoundingBox();
ChunkPos min = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.minX()), SectionPos.blockToSectionCoord(boundingBox.minZ()));
ChunkPos max = new ChunkPos(SectionPos.blockToSectionCoord(boundingBox.maxX()), SectionPos.blockToSectionCoord(boundingBox.maxZ()));
ChunkPos.rangeClosed(min, max).forEach((chunkPosx) -> structureStart.placeInChunk(proxyLevel, originalWorld.structureManager(), chunkManager.getGenerator(), originalWorld.getRandom(), new BoundingBox(chunkPosx.getMinBlockX(), originalWorld.getMinBuildHeight(), chunkPosx.getMinBlockZ(), chunkPosx.getMaxBlockX(), originalWorld.getMaxBuildHeight(), chunkPosx.getMaxBlockZ()), chunkPosx));
return true;
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Code that is less likely to break // Code that is less likely to break
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

Datei anzeigen

@ -55,6 +55,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes; import com.sk89q.worldedit.world.weather.WeatherTypes;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
@ -530,6 +531,16 @@ public class BukkitWorld extends AbstractWorld {
return false; return false;
} }
@Override
public boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.generateStructure(type, getWorld(), editSession, position);
}
// No adapter, we can't generate this.
return false;
}
private static volatile boolean hasWarnedImplError = false; private static volatile boolean hasWarnedImplError = false;
@Override @Override

Datei anzeigen

@ -50,6 +50,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import org.bukkit.Keyed; import org.bukkit.Keyed;
@ -337,6 +338,19 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
throw new UnsupportedOperationException("This adapter does not support generating features."); throw new UnsupportedOperationException("This adapter does not support generating features.");
} }
/**
* Generates a Minecraft structure at the given location.
*
* @param feature The feature
* @param world The world
* @param session The EditSession
* @param pt The location
* @return If it succeeded
*/
default boolean generateStructure(StructureType feature, World world, EditSession session, BlockVector3 pt) {
throw new UnsupportedOperationException("This adapter does not support generating features.");
}
//FAWE start //FAWE start
default BlockMaterial getMaterial(BlockType blockType) { default BlockMaterial getMaterial(BlockType blockType) {
return getMaterial(blockType.getDefaultState()); return getMaterial(blockType.getDefaultState());

Datei anzeigen

@ -58,6 +58,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
@ -377,6 +378,23 @@ public class GenerationCommands {
return 0; return 0;
} }
@Command(
name = "/structure",
desc = "Generate Minecraft structures"
)
@CommandPermissions("worldedit.generation.structure")
@Logging(POSITION)
public int structure(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The structure")
StructureType feature) throws WorldEditException {
if (editSession.getWorld().generateStructure(feature, editSession, session.getPlacementPosition(actor))) {
actor.printInfo(Caption.of("worldedit.structure.created"));
} else {
actor.printError(Caption.of("worldedit.structure.failed"));
}
return 0;
}
@Command( @Command(
name = "/hpyramid", name = "/hpyramid",
desc = "Generate a hollow pyramid" desc = "Generate a hollow pyramid"

Datei anzeigen

@ -33,6 +33,7 @@ import com.sk89q.worldedit.world.fluid.FluidCategory;
import com.sk89q.worldedit.world.fluid.FluidType; import com.sk89q.worldedit.world.fluid.FluidType;
import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.item.ItemCategory; import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherType;
@ -64,7 +65,8 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
FluidCategory.class, FluidCategory.class,
GameMode.class, GameMode.class,
WeatherType.class, WeatherType.class,
ConfiguredFeatureType.class ConfiguredFeatureType.class,
StructureType.class
) )
.stream() .stream()
.map(c -> (Class<Keyed>) c) .map(c -> (Class<Keyed>) c)

Datei anzeigen

@ -47,6 +47,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
import com.sk89q.worldedit.world.generation.StructureType;
import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -312,6 +313,10 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws
MaxChangedBlocksException; MaxChangedBlocksException;
default boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
return false;
}
/** /**
* Generate a feature at the given position. * Generate a feature at the given position.
* *

Datei anzeigen

@ -0,0 +1,43 @@
/*
* 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.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
public class StructureType implements Keyed {
public static final NamespacedRegistry<StructureType> REGISTRY = new NamespacedRegistry<>("structure type");
private final String id;
public StructureType(String id) {
this.id = id;
}
@Override
public String getId() {
return this.id;
}
@Override
public String toString() {
return this.id;
}
}

Datei anzeigen

@ -519,6 +519,8 @@
"worldedit.pyramid.created": "{0} blocks have been created.", "worldedit.pyramid.created": "{0} blocks have been created.",
"worldedit.generate.created": "{0} blocks have been created.", "worldedit.generate.created": "{0} blocks have been created.",
"worldedit.generatebiome.changed": "{0} biomes affected.", "worldedit.generatebiome.changed": "{0} biomes affected.",
"worldedit.structure.created": "Structure created.",
"worldedit.structure.failed": "Failed to generate structure. Is it a valid spot for it?",
"worldedit.reload.config": "Configuration reloaded!", "worldedit.reload.config": "Configuration reloaded!",
"worldedit.report.written": "FAWE report written to {0}", "worldedit.report.written": "FAWE report written to {0}",
"worldedit.report.error": "Failed to write report: {0}", "worldedit.report.error": "Failed to write report: {0}",