mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-02-05 13:00:30 +08:00
Added strings and implement on other platforms
This commit is contained in:
parent
5ca80395a3
commit
91dd9deca8
@ -65,10 +65,12 @@
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||
import com.sk89q.worldedit.world.generation.StructureType;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.ByteArrayTag;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
@ -121,6 +123,9 @@
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldOptions;
|
||||
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.PrimaryLevelData;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
@ -905,6 +910,29 @@ public boolean generateFeature(ConfiguredFeatureType type, World world, EditSess
|
||||
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(), originalWorld.getStructureManager(), 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
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -927,7 +927,7 @@ public boolean generateStructure(StructureType type, World world, EditSession se
|
||||
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);
|
||||
StructureStart structureStart = k.generate(originalWorld.registryAccess(), chunkManager.getGenerator(), chunkManager.getGenerator().getBiomeSource(), chunkManager.randomState(), originalWorld.getStructureManager(), originalWorld.getSeed(), chunkPos, 0, proxyLevel, biome -> true);
|
||||
|
||||
if (!structureStart.isValid()) {
|
||||
return false;
|
||||
|
@ -250,6 +250,8 @@
|
||||
"worldedit.pyramid.created": "{0} blocks have been created.",
|
||||
"worldedit.generate.created": "{0} blocks have been created.",
|
||||
"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.report.written": "WorldEdit report written to {0}",
|
||||
|
@ -62,12 +62,14 @@
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.features.EndFeatures;
|
||||
import net.minecraft.data.worldgen.features.TreeFeatures;
|
||||
@ -98,6 +100,9 @@
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldOptions;
|
||||
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.LevelData;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
@ -480,6 +485,30 @@ public boolean generateFeature(ConfiguredFeatureType type, EditSession editSessi
|
||||
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, FabricAdapter.toBlockPos(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
|
||||
ServerLevel world = (ServerLevel) getWorld();
|
||||
Structure k = world.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
|
||||
if (k == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerChunkCache chunkManager = world.getChunkSource();
|
||||
WorldGenLevel proxyLevel = FabricServerLevelDelegateProxy.newInstance(editSession, world);
|
||||
ChunkPos chunkPos = new ChunkPos(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
|
||||
StructureStart structureStart = k.generate(world.registryAccess(), chunkManager.getGenerator(), chunkManager.getGenerator().getBiomeSource(), chunkManager.randomState(), world.getStructureManager(), world.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, world.structureManager(), chunkManager.getGenerator(), world.getRandom(), new BoundingBox(chunkPosx.getMinBlockX(), world.getMinBuildHeight(), chunkPosx.getMinBlockZ(), chunkPosx.getMaxBlockX(), world.getMaxBuildHeight(), chunkPosx.getMaxBlockZ()), chunkPosx));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(BlockVector3 pt) {
|
||||
getWorld().getChunk(FabricAdapter.toBlockPos(pt));
|
||||
|
@ -59,12 +59,14 @@
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.features.EndFeatures;
|
||||
import net.minecraft.data.worldgen.features.TreeFeatures;
|
||||
@ -94,6 +96,9 @@
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldOptions;
|
||||
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.LevelData;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
@ -464,6 +469,30 @@ public boolean generateFeature(ConfiguredFeatureType type, EditSession editSessi
|
||||
return k != null && k.place(levelProxy, chunkManager.getGenerator(), random, ForgeAdapter.toBlockPos(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
|
||||
ServerLevel world = getWorld();
|
||||
Structure k = world.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
|
||||
if (k == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerChunkCache chunkManager = world.getChunkSource();
|
||||
WorldGenLevel proxyLevel = ForgeServerLevelDelegateProxy.newInstance(editSession, world);
|
||||
ChunkPos chunkPos = new ChunkPos(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
|
||||
StructureStart structureStart = k.generate(world.registryAccess(), chunkManager.getGenerator(), chunkManager.getGenerator().getBiomeSource(), chunkManager.randomState(), world.getStructureManager(), world.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, world.structureManager(), chunkManager.getGenerator(), world.getRandom(), new BoundingBox(chunkPosx.getMinBlockX(), world.getMinBuildHeight(), chunkPosx.getMinBlockZ(), chunkPosx.getMaxBlockX(), world.getMaxBuildHeight(), chunkPosx.getMaxBlockZ()), chunkPosx));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(BlockVector3 pt) {
|
||||
getWorld().getChunk(ForgeAdapter.toBlockPos(pt));
|
||||
|
Loading…
Reference in New Issue
Block a user