Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-07-05 18:28:03 +02:00
Merge 22b87eb3a5
into 4fe9c6bd74
Dieser Commit ist enthalten in:
Commit
951e3d67b7
|
@ -28,6 +28,7 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import com.sk89q.jnbt.NBTConstants;
|
import com.sk89q.jnbt.NBTConstants;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
@ -71,6 +72,7 @@ import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||||
import com.sk89q.worldedit.world.DataFixer;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import com.sk89q.worldedit.world.RegenOptions;
|
import com.sk89q.worldedit.world.RegenOptions;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
@ -78,9 +80,12 @@ 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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
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.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;
|
||||||
|
@ -92,6 +97,7 @@ import net.minecraft.server.level.ChunkHolder;
|
||||||
import net.minecraft.server.level.ServerChunkCache;
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.util.thread.BlockableEventLoop;
|
import net.minecraft.util.thread.BlockableEventLoop;
|
||||||
import net.minecraft.world.Clearable;
|
import net.minecraft.world.Clearable;
|
||||||
|
@ -104,6 +110,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.LevelSettings;
|
import net.minecraft.world.level.LevelSettings;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
@ -116,6 +123,10 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
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.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;
|
||||||
|
@ -137,6 +148,7 @@ import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.spigotmc.SpigotConfig;
|
import org.spigotmc.SpigotConfig;
|
||||||
import org.spigotmc.WatchdogThread;
|
import org.spigotmc.WatchdogThread;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -158,7 +170,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
@ -172,6 +183,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
private final Field chunkProviderExecutorField;
|
private final Field chunkProviderExecutorField;
|
||||||
private final Watchdog watchdog;
|
private final Watchdog watchdog;
|
||||||
|
|
||||||
|
private static final RandomSource random = RandomSource.create();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Code that may break between versions of Minecraft
|
// Code that may break between versions of Minecraft
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -307,6 +320,21 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
|
int internalId = Block.getId(blockState);
|
||||||
|
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
|
||||||
|
if (state == null) {
|
||||||
|
state = BukkitAdapter.adapt(CraftBlockData.createData(blockState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public net.minecraft.world.level.block.state.BlockState adapt(BlockState blockState) {
|
||||||
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
|
return Block.stateById(internalId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
checkNotNull(location);
|
checkNotNull(location);
|
||||||
|
@ -804,6 +832,62 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeRegistries() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
// Biomes
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.BIOME).keySet()) {
|
||||||
|
if (BiomeType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType type, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
|
||||||
|
ConfiguredFeature<?, ?> k = originalWorld.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(ResourceLocation.tryParse(type.id()));
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
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
|
// Code that is less likely to break
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
* 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.bukkit.adapter.ext.fawe.v1_19_R3;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
public class PaperweightServerLevelDelegateProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
private final EditSession editSession;
|
||||||
|
private final ServerLevel serverLevel;
|
||||||
|
private final PaperweightAdapter adapter;
|
||||||
|
|
||||||
|
private PaperweightServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.serverLevel = serverLevel;
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||||
|
serverLevel.getClass().getClassLoader(),
|
||||||
|
serverLevel.getClass().getInterfaces(),
|
||||||
|
new PaperweightServerLevelDelegateProxy(editSession, serverLevel, adapter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private BlockEntity getBlockEntity(BlockPos blockPos) {
|
||||||
|
BlockEntity tileEntity = this.serverLevel.getChunkAt(blockPos).getBlockEntity(blockPos);
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
|
||||||
|
newEntity.load((CompoundTag) adapter.fromNativeBinary(this.editSession.getFullBlock(BlockVector3.at(
|
||||||
|
blockPos.getX(),
|
||||||
|
blockPos.getY(),
|
||||||
|
blockPos.getZ()
|
||||||
|
)).getNbtReference().getValue()));
|
||||||
|
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockState getBlockState(BlockPos blockPos) {
|
||||||
|
return adapter.adapt(this.editSession.getBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(
|
||||||
|
BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()),
|
||||||
|
adapter.adapt(blockState)
|
||||||
|
);
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(
|
||||||
|
BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()),
|
||||||
|
BlockTypes.AIR.getDefaultState()
|
||||||
|
);
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean addEntity(Entity entity) {
|
||||||
|
Vec3 pos = entity.getPosition(0.0f);
|
||||||
|
Location location = new Location(BukkitAdapter.adapt(serverLevel.getWorld()), pos.x(), pos.y(), pos.z());
|
||||||
|
|
||||||
|
ResourceLocation id = serverLevel.registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getKey(entity.getType());
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
entity.saveWithoutId(tag);
|
||||||
|
BaseEntity baseEntity = new BaseEntity(
|
||||||
|
EntityTypes.get(id.toString()),
|
||||||
|
(com.sk89q.jnbt.CompoundTag) adapter.toNative(tag)
|
||||||
|
);
|
||||||
|
|
||||||
|
return editSession.createEntity(location, baseEntity) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "a_", "getBlockState", "addFreshEntityWithPassengers" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockState
|
||||||
|
return getBlockState(blockPos);
|
||||||
|
} else if (args.length >= 1 && args[0] instanceof Entity entity) {
|
||||||
|
// addFreshEntityWithPassengers
|
||||||
|
return addEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "c_", "getBlockEntity" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockEntity
|
||||||
|
return getBlockEntity(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "a", "setBlock", "removeBlock", "destroyBlock" -> {
|
||||||
|
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
||||||
|
// setBlock
|
||||||
|
return setBlock(blockPos, blockState);
|
||||||
|
} else if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
||||||
|
// removeBlock (and also matches destroyBlock)
|
||||||
|
return removeBlock(blockPos, bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "j", "addEntity" -> {
|
||||||
|
if (args.length >= 1 && args[0] instanceof Entity entity) {
|
||||||
|
return addEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return method.invoke(this.serverLevel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkSource;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R3.util.BlockStateListPopulator;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
|
||||||
|
|
||||||
|
private final ServerLevel world;
|
||||||
|
|
||||||
|
public FaweBlockStateListPopulator(ServerLevel world) {
|
||||||
|
super(world);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return world.getSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerLevel getLevel() {
|
||||||
|
return world.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return world.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSource getChunkSource() {
|
||||||
|
return world.getChunkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
|
||||||
|
return world.getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeManager getBiomeManager() {
|
||||||
|
return world.getBiomeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
|
||||||
|
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeaLevel() {
|
||||||
|
return world.getSeaLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return world.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShade(final Direction direction, final boolean shaded) {
|
||||||
|
return world.getShade(direction, shaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelLightEngine getLightEngine() {
|
||||||
|
return world.getLightEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
|
||||||
|
return world.getChunkIfLoadedImmediately(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getBlockStateIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getFluidIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldBorder getWorldBorder() {
|
||||||
|
return world.getWorldBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth) {
|
||||||
|
return world.setBlock(pos, state, flags, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeBlock(final BlockPos pos, final boolean move) {
|
||||||
|
return world.removeBlock(pos, move);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity breakingEntity, final int maxUpdateDepth) {
|
||||||
|
return world.destroyBlock(pos, drop, breakingEntity, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(final BlockPos pos) {
|
||||||
|
return world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
|
||||||
|
return world.setBlock(pos, state, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,10 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
@ -46,11 +49,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.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
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 io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
|
@ -58,17 +64,24 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
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 org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -77,6 +90,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
|
||||||
|
@ -510,6 +524,166 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
return ((CraftWorld) world).getHandle();
|
return ((CraftWorld) world).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
ChunkGenerator generator = serverLevel.getMinecraftWorld().getChunkSource().getGenerator();
|
||||||
|
|
||||||
|
ConfiguredFeature<?, ?> configuredFeature = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.CONFIGURED_FEATURE)
|
||||||
|
.get(ResourceLocation.tryParse(feature.id()));
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
if (!configuredFeature.place(
|
||||||
|
populator,
|
||||||
|
generator,
|
||||||
|
serverLevel.random,
|
||||||
|
new BlockPos(pt.x(), pt.y(), pt.z())
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(StructureType type, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
Structure k = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.STRUCTURE)
|
||||||
|
.get(ResourceLocation.tryParse(type.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = serverLevel.getChunkSource();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
StructureStart structureStart = k.generate(
|
||||||
|
serverLevel.registryAccess(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
chunkManager.getGenerator().getBiomeSource(),
|
||||||
|
chunkManager.randomState(),
|
||||||
|
serverLevel.getStructureManager(),
|
||||||
|
serverLevel.getSeed(),
|
||||||
|
chunkPos,
|
||||||
|
0,
|
||||||
|
serverLevel,
|
||||||
|
biome -> true
|
||||||
|
);
|
||||||
|
if (!structureStart.isValid()) {
|
||||||
|
return null;
|
||||||
|
} 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(
|
||||||
|
serverLevel,
|
||||||
|
serverLevel.structureManager(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
serverLevel.getRandom(),
|
||||||
|
new BoundingBox(
|
||||||
|
chunkPosx.getMinBlockX(),
|
||||||
|
serverLevel.getMinBuildHeight(),
|
||||||
|
chunkPosx.getMinBlockZ(),
|
||||||
|
chunkPosx.getMaxBlockX(),
|
||||||
|
serverLevel.getMaxBuildHeight(),
|
||||||
|
chunkPosx.getMaxBlockZ()
|
||||||
|
),
|
||||||
|
chunkPosx
|
||||||
|
));
|
||||||
|
return populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeFeatureIntoSession(
|
||||||
|
final EditSession editSession,
|
||||||
|
final FaweBlockStateListPopulator populator,
|
||||||
|
final Map<BlockPos, CraftBlockState> placed
|
||||||
|
) {
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<BlockPos, CraftBlockState> entry : placed.entrySet()) {
|
||||||
|
CraftBlockState craftBlockState = entry.getValue();
|
||||||
|
if (entry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos pos = entry.getKey();
|
||||||
|
editSession.setBlock(pos.getX(), pos.getY(), pos.getZ(), BukkitAdapter.adapt(craftBlockState.getBlockData()));
|
||||||
|
BlockEntity blockEntity = populator.getBlockEntity(pos);
|
||||||
|
if (blockEntity != null) {
|
||||||
|
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
|
||||||
|
editSession.setTile(pos.getX(), pos.getY(), pos.getZ(), (CompoundTag) toNative(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupFeatures() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
||||||
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
|
|
@ -47,6 +47,7 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.StateHolder;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.GlobalPalette;
|
import net.minecraft.world.level.chunk.GlobalPalette;
|
||||||
import net.minecraft.world.level.chunk.HashMapPalette;
|
import net.minecraft.world.level.chunk.HashMapPalette;
|
||||||
|
@ -60,7 +61,6 @@ import net.minecraft.world.level.entity.PersistentEntitySectionManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_19_R3.CraftChunk;
|
import org.bukkit.craftbukkit.v1_19_R3.CraftChunk;
|
||||||
import sun.misc.Unsafe;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -100,6 +100,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
private static final Field fieldTickingBlockCount;
|
private static final Field fieldTickingBlockCount;
|
||||||
private static final Field fieldBiomes;
|
private static final Field fieldBiomes;
|
||||||
|
|
||||||
|
private static final Field fieldPropertiesCodec;
|
||||||
|
|
||||||
private static final MethodHandle methodGetVisibleChunk;
|
private static final MethodHandle methodGetVisibleChunk;
|
||||||
|
|
||||||
private static final Field fieldThreadingDetector;
|
private static final Field fieldThreadingDetector;
|
||||||
|
@ -149,6 +151,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
fieldBiomes = tmpFieldBiomes;
|
fieldBiomes = tmpFieldBiomes;
|
||||||
fieldBiomes.setAccessible(true);
|
fieldBiomes.setAccessible(true);
|
||||||
|
|
||||||
|
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
|
||||||
|
fieldPropertiesCodec.setAccessible(true);
|
||||||
|
|
||||||
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
||||||
"getVisibleChunkIfPresent",
|
"getVisibleChunkIfPresent",
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import com.sk89q.jnbt.NBTConstants;
|
import com.sk89q.jnbt.NBTConstants;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
@ -78,10 +79,13 @@ 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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
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.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;
|
||||||
|
@ -93,6 +97,7 @@ import net.minecraft.server.level.ChunkHolder;
|
||||||
import net.minecraft.server.level.ServerChunkCache;
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.util.thread.BlockableEventLoop;
|
import net.minecraft.util.thread.BlockableEventLoop;
|
||||||
import net.minecraft.world.Clearable;
|
import net.minecraft.world.Clearable;
|
||||||
|
@ -105,6 +110,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.LevelSettings;
|
import net.minecraft.world.level.LevelSettings;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
@ -117,12 +123,17 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
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.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;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||||
|
@ -173,6 +184,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
private final Field chunkProviderExecutorField;
|
private final Field chunkProviderExecutorField;
|
||||||
private final Watchdog watchdog;
|
private final Watchdog watchdog;
|
||||||
|
|
||||||
|
private static final RandomSource random = RandomSource.create();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Code that may break between versions of Minecraft
|
// Code that may break between versions of Minecraft
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -308,6 +321,21 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
|
int internalId = Block.getId(blockState);
|
||||||
|
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
|
||||||
|
if (state == null) {
|
||||||
|
state = BukkitAdapter.adapt(CraftBlockData.createData(blockState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public net.minecraft.world.level.block.state.BlockState adapt(BlockState blockState) {
|
||||||
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
|
return Block.stateById(internalId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
checkNotNull(location);
|
checkNotNull(location);
|
||||||
|
@ -321,14 +349,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
|
||||||
final BlockPos blockPos = new BlockPos(x, y, z);
|
final BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
|
||||||
int internalId = Block.getId(blockData);
|
return adapt(blockData);
|
||||||
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
|
|
||||||
if (state == null) {
|
|
||||||
org.bukkit.block.Block bukkitBlock = location.getBlock();
|
|
||||||
state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -865,7 +886,53 @@ 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
|
||||||
|
for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType type, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
|
||||||
|
ConfiguredFeature<?, ?> k = originalWorld.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(ResourceLocation.tryParse(type.id()));
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
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
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* 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.bukkit.adapter.ext.fawe.v1_20_R1;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
public class PaperweightServerLevelDelegateProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
private final EditSession editSession;
|
||||||
|
private final ServerLevel serverLevel;
|
||||||
|
private final PaperweightAdapter adapter;
|
||||||
|
|
||||||
|
private PaperweightServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.serverLevel = serverLevel;
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||||
|
serverLevel.getClass().getClassLoader(),
|
||||||
|
serverLevel.getClass().getInterfaces(),
|
||||||
|
new PaperweightServerLevelDelegateProxy(editSession, serverLevel, adapter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private BlockEntity getBlockEntity(BlockPos blockPos) {
|
||||||
|
BlockEntity tileEntity = this.serverLevel.getChunkAt(blockPos).getBlockEntity(blockPos);
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
|
||||||
|
newEntity.load((CompoundTag) adapter.fromNativeBinary(this.editSession.getFullBlock(BlockVector3.at(blockPos.getX(),
|
||||||
|
blockPos.getY(), blockPos.getZ())).getNbtReference().getValue()));
|
||||||
|
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockState getBlockState(BlockPos blockPos) {
|
||||||
|
return adapter.adapt(this.editSession.getBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), adapter.adapt(blockState));
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), BlockTypes.AIR.getDefaultState());
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "a_", "getBlockState" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockState
|
||||||
|
return getBlockState(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "c_", "getBlockEntity" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockEntity
|
||||||
|
return getBlockEntity(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "a", "setBlock", "removeBlock", "destroyBlock" -> {
|
||||||
|
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
||||||
|
// setBlock
|
||||||
|
return setBlock(blockPos, blockState);
|
||||||
|
} else if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
||||||
|
// removeBlock (and also matches destroyBlock)
|
||||||
|
return removeBlock(blockPos, bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return method.invoke(this.serverLevel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R1;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkSource;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R1.util.BlockStateListPopulator;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
|
||||||
|
|
||||||
|
private final ServerLevel world;
|
||||||
|
|
||||||
|
public FaweBlockStateListPopulator(ServerLevel world) {
|
||||||
|
super(world);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return world.getSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerLevel getLevel() {
|
||||||
|
return world.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return world.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSource getChunkSource() {
|
||||||
|
return world.getChunkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
|
||||||
|
return world.getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeManager getBiomeManager() {
|
||||||
|
return world.getBiomeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
|
||||||
|
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeaLevel() {
|
||||||
|
return world.getSeaLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return world.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShade(final Direction direction, final boolean shaded) {
|
||||||
|
return world.getShade(direction, shaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelLightEngine getLightEngine() {
|
||||||
|
return world.getLightEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
|
||||||
|
return world.getChunkIfLoadedImmediately(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getBlockStateIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getFluidIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldBorder getWorldBorder() {
|
||||||
|
return world.getWorldBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth) {
|
||||||
|
return world.setBlock(pos, state, flags, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeBlock(final BlockPos pos, final boolean move) {
|
||||||
|
return world.removeBlock(pos, move);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity breakingEntity, final int maxUpdateDepth) {
|
||||||
|
return world.destroyBlock(pos, drop, breakingEntity, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(final BlockPos pos) {
|
||||||
|
return world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
|
||||||
|
return world.setBlock(pos, state, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,10 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
@ -46,11 +49,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.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
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 io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
|
@ -58,17 +64,24 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
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 org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -77,6 +90,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
||||||
|
@ -510,6 +524,167 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
return ((CraftWorld) world).getHandle();
|
return ((CraftWorld) world).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
//FAWE start
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
ChunkGenerator generator = serverLevel.getMinecraftWorld().getChunkSource().getGenerator();
|
||||||
|
|
||||||
|
ConfiguredFeature<?, ?> configuredFeature = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.CONFIGURED_FEATURE)
|
||||||
|
.get(ResourceLocation.tryParse(feature.id()));
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
if (!configuredFeature.place(
|
||||||
|
populator,
|
||||||
|
generator,
|
||||||
|
serverLevel.random,
|
||||||
|
new BlockPos(pt.x(), pt.y(), pt.z())
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(StructureType type, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
Structure k = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.STRUCTURE)
|
||||||
|
.get(ResourceLocation.tryParse(type.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = serverLevel.getChunkSource();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
StructureStart structureStart = k.generate(
|
||||||
|
serverLevel.registryAccess(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
chunkManager.getGenerator().getBiomeSource(),
|
||||||
|
chunkManager.randomState(),
|
||||||
|
serverLevel.getStructureManager(),
|
||||||
|
serverLevel.getSeed(),
|
||||||
|
chunkPos,
|
||||||
|
0,
|
||||||
|
serverLevel,
|
||||||
|
biome -> true
|
||||||
|
);
|
||||||
|
if (!structureStart.isValid()) {
|
||||||
|
return null;
|
||||||
|
} 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(
|
||||||
|
serverLevel,
|
||||||
|
serverLevel.structureManager(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
serverLevel.getRandom(),
|
||||||
|
new BoundingBox(
|
||||||
|
chunkPosx.getMinBlockX(),
|
||||||
|
serverLevel.getMinBuildHeight(),
|
||||||
|
chunkPosx.getMinBlockZ(),
|
||||||
|
chunkPosx.getMaxBlockX(),
|
||||||
|
serverLevel.getMaxBuildHeight(),
|
||||||
|
chunkPosx.getMaxBlockZ()
|
||||||
|
),
|
||||||
|
chunkPosx
|
||||||
|
));
|
||||||
|
return populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeFeatureIntoSession(
|
||||||
|
final EditSession editSession,
|
||||||
|
final FaweBlockStateListPopulator populator,
|
||||||
|
final Map<BlockPos, CraftBlockState> placed
|
||||||
|
) {
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<BlockPos, CraftBlockState> entry : placed.entrySet()) {
|
||||||
|
CraftBlockState craftBlockState = entry.getValue();
|
||||||
|
if (entry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos pos = entry.getKey();
|
||||||
|
editSession.setBlock(pos.getX(), pos.getY(), pos.getZ(), BukkitAdapter.adapt(craftBlockState.getBlockData()));
|
||||||
|
BlockEntity blockEntity = populator.getBlockEntity(pos);
|
||||||
|
if (blockEntity != null) {
|
||||||
|
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
|
||||||
|
editSession.setTile(pos.getX(), pos.getY(), pos.getZ(), (CompoundTag) toNative(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupFeatures() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
||||||
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
|
|
@ -48,6 +48,7 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.StateHolder;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.GlobalPalette;
|
import net.minecraft.world.level.chunk.GlobalPalette;
|
||||||
|
@ -102,6 +103,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
private static final Field fieldTickingFluidCount;
|
private static final Field fieldTickingFluidCount;
|
||||||
private static final Field fieldTickingBlockCount;
|
private static final Field fieldTickingBlockCount;
|
||||||
|
|
||||||
|
private static final Field fieldPropertiesCodec;
|
||||||
|
|
||||||
private static final MethodHandle methodGetVisibleChunk;
|
private static final MethodHandle methodGetVisibleChunk;
|
||||||
|
|
||||||
private static final Field fieldThreadingDetector;
|
private static final Field fieldThreadingDetector;
|
||||||
|
@ -158,6 +161,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
fieldBiomes = tmpFieldBiomes;
|
fieldBiomes = tmpFieldBiomes;
|
||||||
fieldBiomes.setAccessible(true);
|
fieldBiomes.setAccessible(true);
|
||||||
|
|
||||||
|
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
|
||||||
|
fieldPropertiesCodec.setAccessible(true);
|
||||||
|
|
||||||
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
||||||
"getVisibleChunkIfPresent",
|
"getVisibleChunkIfPresent",
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import com.sk89q.jnbt.NBTConstants;
|
import com.sk89q.jnbt.NBTConstants;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
@ -70,6 +71,7 @@ import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||||
import com.sk89q.worldedit.world.DataFixer;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import com.sk89q.worldedit.world.RegenOptions;
|
import com.sk89q.worldedit.world.RegenOptions;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
@ -77,10 +79,13 @@ 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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
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.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;
|
||||||
|
@ -92,6 +97,7 @@ import net.minecraft.server.level.ChunkHolder;
|
||||||
import net.minecraft.server.level.ServerChunkCache;
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.util.thread.BlockableEventLoop;
|
import net.minecraft.util.thread.BlockableEventLoop;
|
||||||
import net.minecraft.world.Clearable;
|
import net.minecraft.world.Clearable;
|
||||||
|
@ -104,6 +110,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.LevelSettings;
|
import net.minecraft.world.level.LevelSettings;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
@ -116,6 +123,10 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
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.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;
|
||||||
|
@ -137,6 +148,7 @@ import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.spigotmc.SpigotConfig;
|
import org.spigotmc.SpigotConfig;
|
||||||
import org.spigotmc.WatchdogThread;
|
import org.spigotmc.WatchdogThread;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -158,7 +170,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
@ -172,6 +183,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
private final Field chunkProviderExecutorField;
|
private final Field chunkProviderExecutorField;
|
||||||
private final Watchdog watchdog;
|
private final Watchdog watchdog;
|
||||||
|
|
||||||
|
private static final RandomSource random = RandomSource.create();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Code that may break between versions of Minecraft
|
// Code that may break between versions of Minecraft
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -305,6 +318,21 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
|
int internalId = Block.getId(blockState);
|
||||||
|
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
|
||||||
|
if (state == null) {
|
||||||
|
state = BukkitAdapter.adapt(CraftBlockData.createData(blockState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public net.minecraft.world.level.block.state.BlockState adapt(BlockState blockState) {
|
||||||
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
|
return Block.stateById(internalId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
checkNotNull(location);
|
checkNotNull(location);
|
||||||
|
@ -805,6 +833,62 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeRegistries() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
// Biomes
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.BIOME).keySet()) {
|
||||||
|
if (BiomeType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType type, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
|
||||||
|
ConfiguredFeature<?, ?> k = originalWorld.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(ResourceLocation.tryParse(type.id()));
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
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
|
// Code that is less likely to break
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* 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.bukkit.adapter.ext.fawe.v1_20_R2;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
public class PaperweightServerLevelDelegateProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
private final EditSession editSession;
|
||||||
|
private final ServerLevel serverLevel;
|
||||||
|
private final PaperweightAdapter adapter;
|
||||||
|
|
||||||
|
private PaperweightServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.serverLevel = serverLevel;
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||||
|
serverLevel.getClass().getClassLoader(),
|
||||||
|
serverLevel.getClass().getInterfaces(),
|
||||||
|
new PaperweightServerLevelDelegateProxy(editSession, serverLevel, adapter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private BlockEntity getBlockEntity(BlockPos blockPos) {
|
||||||
|
BlockEntity tileEntity = this.serverLevel.getChunkAt(blockPos).getBlockEntity(blockPos);
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
|
||||||
|
newEntity.load((CompoundTag) adapter.fromNativeBinary(this.editSession.getFullBlock(BlockVector3.at(blockPos.getX(),
|
||||||
|
blockPos.getY(), blockPos.getZ())).getNbtReference().getValue()));
|
||||||
|
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockState getBlockState(BlockPos blockPos) {
|
||||||
|
return adapter.adapt(this.editSession.getBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), adapter.adapt(blockState));
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), BlockTypes.AIR.getDefaultState());
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "a_", "getBlockState" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockState
|
||||||
|
return getBlockState(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "c_", "getBlockEntity" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockEntity
|
||||||
|
return getBlockEntity(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "a", "setBlock", "removeBlock", "destroyBlock" -> {
|
||||||
|
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
||||||
|
// setBlock
|
||||||
|
return setBlock(blockPos, blockState);
|
||||||
|
} else if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
||||||
|
// removeBlock (and also matches destroyBlock)
|
||||||
|
return removeBlock(blockPos, bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return method.invoke(this.serverLevel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkSource;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.util.BlockStateListPopulator;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
|
||||||
|
|
||||||
|
private final ServerLevel world;
|
||||||
|
|
||||||
|
public FaweBlockStateListPopulator(ServerLevel world) {
|
||||||
|
super(world);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return world.getSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerLevel getLevel() {
|
||||||
|
return world.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return world.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSource getChunkSource() {
|
||||||
|
return world.getChunkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
|
||||||
|
return world.getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeManager getBiomeManager() {
|
||||||
|
return world.getBiomeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
|
||||||
|
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeaLevel() {
|
||||||
|
return world.getSeaLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return world.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShade(final Direction direction, final boolean shaded) {
|
||||||
|
return world.getShade(direction, shaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelLightEngine getLightEngine() {
|
||||||
|
return world.getLightEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
|
||||||
|
return world.getChunkIfLoadedImmediately(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getBlockStateIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getFluidIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldBorder getWorldBorder() {
|
||||||
|
return world.getWorldBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth) {
|
||||||
|
return world.setBlock(pos, state, flags, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeBlock(final BlockPos pos, final boolean move) {
|
||||||
|
return world.removeBlock(pos, move);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity breakingEntity, final int maxUpdateDepth) {
|
||||||
|
return world.destroyBlock(pos, drop, breakingEntity, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(final BlockPos pos) {
|
||||||
|
return world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
|
||||||
|
return world.setBlock(pos, state, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,10 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
@ -45,11 +48,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.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
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 io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
|
@ -57,17 +63,24 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
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 org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -76,6 +89,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
||||||
|
@ -513,6 +527,169 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
return ((CraftWorld) world).getHandle();
|
return ((CraftWorld) world).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
//FAWE start
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
ChunkGenerator generator = serverLevel.getMinecraftWorld().getChunkSource().getGenerator();
|
||||||
|
|
||||||
|
ConfiguredFeature<?, ?> configuredFeature = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.CONFIGURED_FEATURE)
|
||||||
|
.get(ResourceLocation.tryParse(feature.id()));
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
if (!configuredFeature.place(
|
||||||
|
populator,
|
||||||
|
generator,
|
||||||
|
serverLevel.random,
|
||||||
|
new BlockPos(pt.x(), pt.y(), pt.z())
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(StructureType type, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
Structure k = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.STRUCTURE)
|
||||||
|
.get(ResourceLocation.tryParse(type.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = serverLevel.getChunkSource();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
StructureStart structureStart = k.generate(
|
||||||
|
serverLevel.registryAccess(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
chunkManager.getGenerator().getBiomeSource(),
|
||||||
|
chunkManager.randomState(),
|
||||||
|
serverLevel.getStructureManager(),
|
||||||
|
serverLevel.getSeed(),
|
||||||
|
chunkPos,
|
||||||
|
0,
|
||||||
|
populator,
|
||||||
|
biome -> true
|
||||||
|
);
|
||||||
|
if (!structureStart.isValid()) {
|
||||||
|
return null;
|
||||||
|
} 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(
|
||||||
|
populator,
|
||||||
|
serverLevel.structureManager(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
serverLevel.getRandom(),
|
||||||
|
new BoundingBox(
|
||||||
|
chunkPosx.getMinBlockX(),
|
||||||
|
serverLevel.getMinBuildHeight(),
|
||||||
|
chunkPosx.getMinBlockZ(),
|
||||||
|
chunkPosx.getMaxBlockX(),
|
||||||
|
serverLevel.getMaxBuildHeight(),
|
||||||
|
chunkPosx.getMaxBlockZ()
|
||||||
|
),
|
||||||
|
chunkPosx
|
||||||
|
));
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeFeatureIntoSession(
|
||||||
|
final EditSession editSession,
|
||||||
|
final FaweBlockStateListPopulator populator,
|
||||||
|
final Map<BlockPos, CraftBlockState> placed
|
||||||
|
) {
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<BlockPos, CraftBlockState> entry : placed.entrySet()) {
|
||||||
|
CraftBlockState craftBlockState = entry.getValue();
|
||||||
|
if (entry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos pos = entry.getKey();
|
||||||
|
editSession.setBlock(pos.getX(), pos.getY(), pos.getZ(), BukkitAdapter.adapt(craftBlockState.getBlockData()));
|
||||||
|
BlockEntity blockEntity = populator.getBlockEntity(pos);
|
||||||
|
if (blockEntity != null) {
|
||||||
|
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
|
||||||
|
editSession.setTile(pos.getX(), pos.getY(), pos.getZ(), (CompoundTag) toNative(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupFeatures() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
||||||
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.StateHolder;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.GlobalPalette;
|
import net.minecraft.world.level.chunk.GlobalPalette;
|
||||||
|
@ -99,6 +100,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
private static final Field fieldTickingFluidCount;
|
private static final Field fieldTickingFluidCount;
|
||||||
private static final Field fieldTickingBlockCount;
|
private static final Field fieldTickingBlockCount;
|
||||||
|
|
||||||
|
private static final Field fieldPropertiesCodec;
|
||||||
|
|
||||||
private static final MethodHandle methodGetVisibleChunk;
|
private static final MethodHandle methodGetVisibleChunk;
|
||||||
|
|
||||||
private static final Field fieldThreadingDetector;
|
private static final Field fieldThreadingDetector;
|
||||||
|
@ -152,6 +155,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
fieldBiomes = tmpFieldBiomes;
|
fieldBiomes = tmpFieldBiomes;
|
||||||
fieldBiomes.setAccessible(true);
|
fieldBiomes.setAccessible(true);
|
||||||
|
|
||||||
|
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
|
||||||
|
fieldPropertiesCodec.setAccessible(true);
|
||||||
|
|
||||||
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
||||||
"getVisibleChunkIfPresent",
|
"getVisibleChunkIfPresent",
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import com.mojang.serialization.Lifecycle;
|
import com.mojang.serialization.Lifecycle;
|
||||||
import com.sk89q.jnbt.NBTConstants;
|
import com.sk89q.jnbt.NBTConstants;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
@ -70,6 +71,7 @@ import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||||
import com.sk89q.worldedit.world.DataFixer;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import com.sk89q.worldedit.world.RegenOptions;
|
import com.sk89q.worldedit.world.RegenOptions;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
@ -77,10 +79,13 @@ 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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
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.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;
|
||||||
|
@ -92,6 +97,7 @@ import net.minecraft.server.level.ChunkHolder;
|
||||||
import net.minecraft.server.level.ServerChunkCache;
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.util.thread.BlockableEventLoop;
|
import net.minecraft.util.thread.BlockableEventLoop;
|
||||||
import net.minecraft.world.Clearable;
|
import net.minecraft.world.Clearable;
|
||||||
|
@ -104,6 +110,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.LevelSettings;
|
import net.minecraft.world.level.LevelSettings;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
@ -116,6 +123,10 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
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.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;
|
||||||
|
@ -137,6 +148,7 @@ import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.spigotmc.SpigotConfig;
|
import org.spigotmc.SpigotConfig;
|
||||||
import org.spigotmc.WatchdogThread;
|
import org.spigotmc.WatchdogThread;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -158,7 +170,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
@ -172,6 +183,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
private final Field chunkProviderExecutorField;
|
private final Field chunkProviderExecutorField;
|
||||||
private final Watchdog watchdog;
|
private final Watchdog watchdog;
|
||||||
|
|
||||||
|
private static final RandomSource random = RandomSource.create();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Code that may break between versions of Minecraft
|
// Code that may break between versions of Minecraft
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -305,6 +318,21 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockState adapt(net.minecraft.world.level.block.state.BlockState blockState) {
|
||||||
|
int internalId = Block.getId(blockState);
|
||||||
|
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
|
||||||
|
if (state == null) {
|
||||||
|
state = BukkitAdapter.adapt(CraftBlockData.createData(blockState));
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public net.minecraft.world.level.block.state.BlockState adapt(BlockState blockState) {
|
||||||
|
int internalId = BlockStateIdAccess.getBlockStateId(blockState);
|
||||||
|
return Block.stateById(internalId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(Location location) {
|
public BlockState getBlock(Location location) {
|
||||||
checkNotNull(location);
|
checkNotNull(location);
|
||||||
|
@ -805,6 +833,63 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeRegistries() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
// Biomes
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.BIOME).keySet()) {
|
||||||
|
if (BiomeType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
BiomeType.REGISTRY.register(name.toString(), new BiomeType(name.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name: server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType type, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
|
||||||
|
ConfiguredFeature<?, ?> k = originalWorld.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).get(ResourceLocation.tryParse(type.id()));
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
return k != null && k.place(proxyLevel, chunkManager.getGenerator(), random, new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = originalWorld.getChunkSource();
|
||||||
|
WorldGenLevel proxyLevel = PaperweightServerLevelDelegateProxy.newInstance(session, originalWorld, this);
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
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
|
// Code that is less likely to break
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* 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.bukkit.adapter.ext.fawe.v1_20_R3;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.WorldGenLevel;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
public class PaperweightServerLevelDelegateProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
private final EditSession editSession;
|
||||||
|
private final ServerLevel serverLevel;
|
||||||
|
private final PaperweightAdapter adapter;
|
||||||
|
|
||||||
|
private PaperweightServerLevelDelegateProxy(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.serverLevel = serverLevel;
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldGenLevel newInstance(EditSession editSession, ServerLevel serverLevel, PaperweightAdapter adapter) {
|
||||||
|
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||||
|
serverLevel.getClass().getClassLoader(),
|
||||||
|
serverLevel.getClass().getInterfaces(),
|
||||||
|
new PaperweightServerLevelDelegateProxy(editSession, serverLevel, adapter)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private BlockEntity getBlockEntity(BlockPos blockPos) {
|
||||||
|
BlockEntity tileEntity = this.serverLevel.getChunkAt(blockPos).getBlockEntity(blockPos);
|
||||||
|
if (tileEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockEntity newEntity = tileEntity.getType().create(blockPos, getBlockState(blockPos));
|
||||||
|
newEntity.load((CompoundTag) adapter.fromNativeBinary(this.editSession.getFullBlock(BlockVector3.at(blockPos.getX(),
|
||||||
|
blockPos.getY(), blockPos.getZ())).getNbtReference().getValue()));
|
||||||
|
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockState getBlockState(BlockPos blockPos) {
|
||||||
|
return adapter.adapt(this.editSession.getBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setBlock(BlockPos blockPos, BlockState blockState) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), adapter.adapt(blockState));
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeBlock(BlockPos blockPos, boolean bl) {
|
||||||
|
try {
|
||||||
|
return editSession.setBlock(BlockVector3.at(blockPos.getX(), blockPos.getY(), blockPos.getZ()), BlockTypes.AIR.getDefaultState());
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "a_", "getBlockState" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockState
|
||||||
|
return getBlockState(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "c_", "getBlockEntity" -> {
|
||||||
|
if (args.length == 1 && args[0] instanceof BlockPos blockPos) {
|
||||||
|
// getBlockEntity
|
||||||
|
return getBlockEntity(blockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "a", "setBlock", "removeBlock", "destroyBlock" -> {
|
||||||
|
if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof BlockState blockState) {
|
||||||
|
// setBlock
|
||||||
|
return setBlock(blockPos, blockState);
|
||||||
|
} else if (args.length >= 2 && args[0] instanceof BlockPos blockPos && args[1] instanceof Boolean bl) {
|
||||||
|
// removeBlock (and also matches destroyBlock)
|
||||||
|
return removeBlock(blockPos, bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> { }
|
||||||
|
}
|
||||||
|
|
||||||
|
return method.invoke(this.serverLevel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkSource;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R3.util.BlockStateListPopulator;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
|
||||||
|
|
||||||
|
private final ServerLevel world;
|
||||||
|
|
||||||
|
public FaweBlockStateListPopulator(ServerLevel world) {
|
||||||
|
super(world);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return world.getSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerLevel getLevel() {
|
||||||
|
return world.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return world.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSource getChunkSource() {
|
||||||
|
return world.getChunkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
|
||||||
|
return world.getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeManager getBiomeManager() {
|
||||||
|
return world.getBiomeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
|
||||||
|
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeaLevel() {
|
||||||
|
return world.getSeaLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return world.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShade(final Direction direction, final boolean shaded) {
|
||||||
|
return world.getShade(direction, shaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelLightEngine getLightEngine() {
|
||||||
|
return world.getLightEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
|
||||||
|
return world.getChunkIfLoadedImmediately(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getBlockStateIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getFluidIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldBorder getWorldBorder() {
|
||||||
|
return world.getWorldBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth) {
|
||||||
|
return world.setBlock(pos, state, flags, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeBlock(final BlockPos pos, final boolean move) {
|
||||||
|
return world.removeBlock(pos, move);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity breakingEntity, final int maxUpdateDepth) {
|
||||||
|
return world.destroyBlock(pos, drop, breakingEntity, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(final BlockPos pos) {
|
||||||
|
return world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
|
||||||
|
return world.setBlock(pos, state, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,10 +9,13 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
@ -45,11 +48,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.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
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 io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
|
@ -57,17 +63,24 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
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 org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -76,6 +89,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
|
||||||
|
@ -513,6 +527,170 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
return ((CraftWorld) world).getHandle();
|
return ((CraftWorld) world).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
//FAWE start
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
ChunkGenerator generator = serverLevel.getMinecraftWorld().getChunkSource().getGenerator();
|
||||||
|
|
||||||
|
ConfiguredFeature<?, ?> configuredFeature = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.CONFIGURED_FEATURE)
|
||||||
|
.get(ResourceLocation.tryParse(feature.id()));
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
if (!configuredFeature.place(
|
||||||
|
populator,
|
||||||
|
generator,
|
||||||
|
serverLevel.random,
|
||||||
|
new BlockPos(pt.x(), pt.y(), pt.z())
|
||||||
|
)) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(StructureType type, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
Structure k = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.STRUCTURE)
|
||||||
|
.get(ResourceLocation.tryParse(type.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = serverLevel.getChunkSource();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
StructureStart structureStart = k.generate(
|
||||||
|
serverLevel.registryAccess(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
chunkManager.getGenerator().getBiomeSource(),
|
||||||
|
chunkManager.randomState(),
|
||||||
|
serverLevel.getStructureManager(),
|
||||||
|
serverLevel.getSeed(),
|
||||||
|
chunkPos,
|
||||||
|
0,
|
||||||
|
populator,
|
||||||
|
biome -> true
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!structureStart.isValid()) {
|
||||||
|
return null;
|
||||||
|
} 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(
|
||||||
|
populator,
|
||||||
|
serverLevel.structureManager(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
serverLevel.getRandom(),
|
||||||
|
new BoundingBox(
|
||||||
|
chunkPosx.getMinBlockX(),
|
||||||
|
serverLevel.getMinBuildHeight(),
|
||||||
|
chunkPosx.getMinBlockZ(),
|
||||||
|
chunkPosx.getMaxBlockX(),
|
||||||
|
serverLevel.getMaxBuildHeight(),
|
||||||
|
chunkPosx.getMaxBlockZ()
|
||||||
|
),
|
||||||
|
chunkPosx
|
||||||
|
));
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeFeatureIntoSession(
|
||||||
|
final EditSession editSession,
|
||||||
|
final FaweBlockStateListPopulator populator,
|
||||||
|
final Map<BlockPos, CraftBlockState> placed
|
||||||
|
) {
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<BlockPos, CraftBlockState> entry : placed.entrySet()) {
|
||||||
|
CraftBlockState craftBlockState = entry.getValue();
|
||||||
|
if (entry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos pos = entry.getKey();
|
||||||
|
editSession.setBlock(pos.getX(), pos.getY(), pos.getZ(), BukkitAdapter.adapt(craftBlockState.getBlockData()));
|
||||||
|
BlockEntity blockEntity = populator.getBlockEntity(pos);
|
||||||
|
if (blockEntity != null) {
|
||||||
|
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
|
||||||
|
editSession.setTile(pos.getX(), pos.getY(), pos.getZ(), (CompoundTag) toNative(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupFeatures() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
||||||
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.StateHolder;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.chunk.GlobalPalette;
|
import net.minecraft.world.level.chunk.GlobalPalette;
|
||||||
|
@ -100,6 +101,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
private static final Field fieldTickingBlockCount;
|
private static final Field fieldTickingBlockCount;
|
||||||
private static final Field fieldBiomes;
|
private static final Field fieldBiomes;
|
||||||
|
|
||||||
|
private static final Field fieldPropertiesCodec;
|
||||||
|
|
||||||
private static final MethodHandle methodGetVisibleChunk;
|
private static final MethodHandle methodGetVisibleChunk;
|
||||||
|
|
||||||
private static final Field fieldThreadingDetector;
|
private static final Field fieldThreadingDetector;
|
||||||
|
@ -152,6 +155,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
fieldBiomes = tmpFieldBiomes;
|
fieldBiomes = tmpFieldBiomes;
|
||||||
fieldBiomes.setAccessible(true);
|
fieldBiomes.setAccessible(true);
|
||||||
|
|
||||||
|
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
|
||||||
|
fieldPropertiesCodec.setAccessible(true);
|
||||||
|
|
||||||
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
||||||
"getVisibleChunkIfPresent",
|
"getVisibleChunkIfPresent",
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -142,6 +142,7 @@ import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.spigotmc.SpigotConfig;
|
import org.spigotmc.SpigotConfig;
|
||||||
import org.spigotmc.WatchdogThread;
|
import org.spigotmc.WatchdogThread;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -163,7 +164,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeManager;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.border.WorldBorder;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkSource;
|
||||||
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
|
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import org.bukkit.craftbukkit.util.BlockStateListPopulator;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class FaweBlockStateListPopulator extends BlockStateListPopulator {
|
||||||
|
|
||||||
|
private final ServerLevel world;
|
||||||
|
|
||||||
|
public FaweBlockStateListPopulator(ServerLevel world) {
|
||||||
|
super(world);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return world.getSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerLevel getLevel() {
|
||||||
|
return world.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return world.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSource getChunkSource() {
|
||||||
|
return world.getChunkSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus leastStatus, final boolean create) {
|
||||||
|
return world.getChunk(chunkX, chunkZ, leastStatus, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeManager getBiomeManager() {
|
||||||
|
return world.getBiomeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Holder<Biome> getUncachedNoiseBiome(final int biomeX, final int biomeY, final int biomeZ) {
|
||||||
|
return world.getUncachedNoiseBiome(biomeX, biomeY, biomeZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSeaLevel() {
|
||||||
|
return world.getSeaLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return world.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShade(final Direction direction, final boolean shaded) {
|
||||||
|
return world.getShade(direction, shaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelLightEngine getLightEngine() {
|
||||||
|
return world.getLightEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
|
||||||
|
return world.getChunkIfLoadedImmediately(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getBlockStateIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
|
||||||
|
return world.getFluidIfLoaded(blockposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldBorder getWorldBorder() {
|
||||||
|
return world.getWorldBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags, final int maxUpdateDepth) {
|
||||||
|
return world.setBlock(pos, state, flags, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeBlock(final BlockPos pos, final boolean move) {
|
||||||
|
return world.removeBlock(pos, move);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean destroyBlock(final BlockPos pos, final boolean drop, final Entity breakingEntity, final int maxUpdateDepth) {
|
||||||
|
return world.destroyBlock(pos, drop, breakingEntity, maxUpdateDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(final BlockPos pos) {
|
||||||
|
return world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
|
||||||
|
return world.setBlock(pos, state, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,11 +9,14 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.fastasyncworldedit.core.queue.IChunkGet;
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.fastasyncworldedit.core.util.NbtUtils;
|
import com.fastasyncworldedit.core.util.NbtUtils;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
@ -47,33 +50,42 @@ 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.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
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 io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.core.component.DataComponentPatch;
|
import net.minecraft.core.component.DataComponentPatch;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.NbtOps;
|
import net.minecraft.nbt.NbtOps;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
|
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 org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -82,6 +94,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
|
@ -495,7 +508,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
registryAccess.registryOrThrow(Registries.ITEM).get(ResourceLocation.tryParse(baseItemStack.getType().id())),
|
registryAccess.registryOrThrow(Registries.ITEM).get(ResourceLocation.tryParse(baseItemStack.getType().id())),
|
||||||
baseItemStack.getAmount()
|
baseItemStack.getAmount()
|
||||||
);
|
);
|
||||||
final CompoundTag nbt = (net.minecraft.nbt.CompoundTag) fromNative(baseItemStack.getNbtData());
|
final net.minecraft.nbt.CompoundTag nbt = (net.minecraft.nbt.CompoundTag) fromNative(baseItemStack.getNbtData());
|
||||||
if (nbt != null) {
|
if (nbt != null) {
|
||||||
final DataComponentPatch patch = COMPONENTS_CODEC
|
final DataComponentPatch patch = COMPONENTS_CODEC
|
||||||
.parse(registryAccess.createSerializationContext(NbtOps.INSTANCE), nbt)
|
.parse(registryAccess.createSerializationContext(NbtOps.INSTANCE), nbt)
|
||||||
|
@ -528,6 +541,169 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
|
||||||
return ((CraftWorld) world).getHandle();
|
return ((CraftWorld) world).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
//FAWE start
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
ChunkGenerator generator = serverLevel.getMinecraftWorld().getChunkSource().getGenerator();
|
||||||
|
|
||||||
|
ConfiguredFeature<?, ?> configuredFeature = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.CONFIGURED_FEATURE)
|
||||||
|
.get(ResourceLocation.tryParse(feature.id()));
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
if (!configuredFeature.place(
|
||||||
|
populator,
|
||||||
|
generator,
|
||||||
|
serverLevel.random,
|
||||||
|
new BlockPos(pt.x(), pt.y(), pt.z())
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(StructureType type, World world, EditSession editSession, BlockVector3 pt) {
|
||||||
|
ServerLevel serverLevel = ((CraftWorld) world).getHandle();
|
||||||
|
Structure k = serverLevel
|
||||||
|
.registryAccess()
|
||||||
|
.registryOrThrow(Registries.STRUCTURE)
|
||||||
|
.get(ResourceLocation.tryParse(type.id()));
|
||||||
|
if (k == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerChunkCache chunkManager = serverLevel.getChunkSource();
|
||||||
|
|
||||||
|
ChunkPos chunkPos = new ChunkPos(new BlockPos(pt.x(), pt.y(), pt.z()));
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
|
||||||
|
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
|
||||||
|
serverLevel.captureTreeGeneration = true;
|
||||||
|
serverLevel.captureBlockStates = true;
|
||||||
|
try {
|
||||||
|
StructureStart structureStart = k.generate(
|
||||||
|
serverLevel.registryAccess(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
chunkManager.getGenerator().getBiomeSource(),
|
||||||
|
chunkManager.randomState(),
|
||||||
|
serverLevel.getStructureManager(),
|
||||||
|
serverLevel.getSeed(),
|
||||||
|
chunkPos,
|
||||||
|
0,
|
||||||
|
populator,
|
||||||
|
biome -> true
|
||||||
|
);
|
||||||
|
if (!structureStart.isValid()) {
|
||||||
|
return null;
|
||||||
|
} 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(
|
||||||
|
populator,
|
||||||
|
serverLevel.structureManager(),
|
||||||
|
chunkManager.getGenerator(),
|
||||||
|
serverLevel.getRandom(),
|
||||||
|
new BoundingBox(
|
||||||
|
chunkPosx.getMinBlockX(),
|
||||||
|
serverLevel.getMinBuildHeight(),
|
||||||
|
chunkPosx.getMinBlockZ(),
|
||||||
|
chunkPosx.getMaxBlockX(),
|
||||||
|
serverLevel.getMaxBuildHeight(),
|
||||||
|
chunkPosx.getMaxBlockZ()
|
||||||
|
),
|
||||||
|
chunkPosx
|
||||||
|
));
|
||||||
|
Map<BlockPos, CraftBlockState> placedBlocks = populator.getList().stream().collect(Collectors.toMap(
|
||||||
|
CraftBlockState::getPosition,
|
||||||
|
craftBlockState -> craftBlockState
|
||||||
|
));
|
||||||
|
placedBlocks.putAll(serverLevel.capturedBlockStates);
|
||||||
|
return placedBlocks;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
serverLevel.captureBlockStates = false;
|
||||||
|
serverLevel.captureTreeGeneration = false;
|
||||||
|
serverLevel.capturedBlockStates.clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return placeFeatureIntoSession(editSession, populator, placed);
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean placeFeatureIntoSession(
|
||||||
|
final EditSession editSession,
|
||||||
|
final FaweBlockStateListPopulator populator,
|
||||||
|
final Map<BlockPos, CraftBlockState> placed
|
||||||
|
) {
|
||||||
|
if (placed == null || placed.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<BlockPos, CraftBlockState> entry : placed.entrySet()) {
|
||||||
|
CraftBlockState craftBlockState = entry.getValue();
|
||||||
|
if (entry.getValue() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BlockPos pos = entry.getKey();
|
||||||
|
editSession.setBlock(pos.getX(), pos.getY(), pos.getZ(), BukkitAdapter.adapt(craftBlockState.getBlockData()));
|
||||||
|
BlockEntity blockEntity = populator.getBlockEntity(pos);
|
||||||
|
if (blockEntity != null) {
|
||||||
|
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId(DedicatedServer.getServer().registryAccess());
|
||||||
|
editSession.setTile(pos.getX(), pos.getY(), pos.getZ(), (CompoundTag) toNative(tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupFeatures() {
|
||||||
|
DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
|
// Features
|
||||||
|
for (ResourceLocation name : server.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).keySet()) {
|
||||||
|
if (ConfiguredFeatureType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
|
||||||
final RegistryAccess.Frozen registryAccess = DedicatedServer.getServer().registryAccess();
|
final RegistryAccess.Frozen registryAccess = DedicatedServer.getServer().registryAccess();
|
||||||
|
|
|
@ -44,6 +44,7 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.StateHolder;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.GlobalPalette;
|
import net.minecraft.world.level.chunk.GlobalPalette;
|
||||||
import net.minecraft.world.level.chunk.HashMapPalette;
|
import net.minecraft.world.level.chunk.HashMapPalette;
|
||||||
|
@ -98,6 +99,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
private static final Field fieldTickingBlockCount;
|
private static final Field fieldTickingBlockCount;
|
||||||
private static final Field fieldBiomes;
|
private static final Field fieldBiomes;
|
||||||
|
|
||||||
|
private static final Field fieldPropertiesCodec;
|
||||||
|
|
||||||
private static final MethodHandle methodGetVisibleChunk;
|
private static final MethodHandle methodGetVisibleChunk;
|
||||||
|
|
||||||
private static final Field fieldThreadingDetector;
|
private static final Field fieldThreadingDetector;
|
||||||
|
@ -143,6 +146,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
|
||||||
fieldBiomes = LevelChunkSection.class.getDeclaredField(Refraction.pickName("biomes", "i"));
|
fieldBiomes = LevelChunkSection.class.getDeclaredField(Refraction.pickName("biomes", "i"));
|
||||||
fieldBiomes.setAccessible(true);
|
fieldBiomes.setAccessible(true);
|
||||||
|
|
||||||
|
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
|
||||||
|
fieldPropertiesCodec.setAccessible(true);
|
||||||
|
|
||||||
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
|
||||||
"getVisibleChunkIfPresent",
|
"getVisibleChunkIfPresent",
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -396,4 +396,12 @@ public interface IBukkitAdapter {
|
||||||
return TaskManager.taskManager().sync(world::getEntities);
|
return TaskManager.taskManager().sync(world::getEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import Minecraft internal features into FAWE. Should be executed after worlds loading (in order to capture datapacks)
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
default void setupFeatures() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
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.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;
|
||||||
|
@ -519,6 +521,26 @@ public class BukkitWorld extends AbstractWorld {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) {
|
||||||
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||||
|
if (adapter != null) {
|
||||||
|
return adapter.generateFeature(type, getWorld(), editSession, position);
|
||||||
|
}
|
||||||
|
// No adapter, we can't generate this.
|
||||||
|
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
|
||||||
|
|
|
@ -21,8 +21,8 @@ package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
import com.fastasyncworldedit.bukkit.BukkitPermissionAttachmentManager;
|
import com.fastasyncworldedit.bukkit.BukkitPermissionAttachmentManager;
|
||||||
import com.fastasyncworldedit.bukkit.FaweBukkit;
|
import com.fastasyncworldedit.bukkit.FaweBukkit;
|
||||||
import com.fastasyncworldedit.core.util.UpdateNotification;
|
|
||||||
import com.fastasyncworldedit.core.Fawe;
|
import com.fastasyncworldedit.core.Fawe;
|
||||||
|
import com.fastasyncworldedit.core.util.UpdateNotification;
|
||||||
import com.fastasyncworldedit.core.util.WEManager;
|
import com.fastasyncworldedit.core.util.WEManager;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -252,6 +252,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||||
setupTags();
|
setupTags();
|
||||||
setupBiomes(false); // FAWE - load biomes later. Initialize biomes twice to allow for the registry to be present for
|
setupBiomes(false); // FAWE - load biomes later. Initialize biomes twice to allow for the registry to be present for
|
||||||
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
|
// plugins requiring WE biomes during startup, as well as allowing custom biomes loaded later on to be present in WE.
|
||||||
|
((BukkitImplAdapter<?>) adapter.value().get()).setupFeatures();
|
||||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
|
||||||
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
|
||||||
import com.sk89q.jnbt.AdventureNBTConverter;
|
import com.sk89q.jnbt.AdventureNBTConverter;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
import com.sk89q.worldedit.blocks.BaseItem;
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
@ -49,6 +50,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
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.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;
|
||||||
|
@ -280,6 +283,43 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
||||||
throw new UnsupportedOperationException("This adapter does not support clearing block contents.");
|
throw new UnsupportedOperationException("This adapter does not support clearing block contents.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a Minecraft feature at the given location.
|
||||||
|
*
|
||||||
|
* @param feature The feature
|
||||||
|
* @param world The world
|
||||||
|
* @param session The EditSession
|
||||||
|
* @param pt The location
|
||||||
|
* @return If it succeeded
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
default boolean generateFeature(ConfiguredFeatureType feature, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
default boolean generateStructure(StructureType feature, World world, EditSession session, BlockVector3 pt) {
|
||||||
|
throw new UnsupportedOperationException("This adapter does not support generating features.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize registries that require NMS access.
|
||||||
|
*/
|
||||||
|
default void initializeRegistries() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//FAWE start
|
//FAWE start
|
||||||
default BlockMaterial getMaterial(BlockType blockType) {
|
default BlockMaterial getMaterial(BlockType blockType) {
|
||||||
return getMaterial(blockType.getDefaultState());
|
return getMaterial(blockType.getDefaultState());
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* 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.fastasyncworldedit.core.command.factory;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.function.generator.StructureGenerator;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.function.Contextual;
|
||||||
|
import com.sk89q.worldedit.function.EditContext;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
|
|
||||||
|
public final class StructureGeneratorFactory implements Contextual<StructureGenerator> {
|
||||||
|
|
||||||
|
private final StructureType type;
|
||||||
|
|
||||||
|
public StructureGeneratorFactory(StructureType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StructureGenerator createFromContext(EditContext input) {
|
||||||
|
return new StructureGenerator((EditSession) input.getDestination(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "structure of type " + type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.fastasyncworldedit.core.command.tool;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.configuration.Caption;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.LocalConfiguration;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.command.tool.BlockTool;
|
||||||
|
import com.sk89q.worldedit.entity.Player;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.util.Direction;
|
||||||
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Places a feature
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public class FeaturePlacer implements BlockTool {
|
||||||
|
|
||||||
|
private final ConfiguredFeatureType feature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public FeaturePlacer(ConfiguredFeatureType feature) {
|
||||||
|
this.feature = feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(Actor player) {
|
||||||
|
return player.hasPermission("worldedit.tool.feature");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean actPrimary(
|
||||||
|
Platform server,
|
||||||
|
LocalConfiguration config,
|
||||||
|
Player player,
|
||||||
|
LocalSession session,
|
||||||
|
Location clicked,
|
||||||
|
@Nullable Direction face
|
||||||
|
) {
|
||||||
|
|
||||||
|
try (EditSession editSession = session.createEditSession(player)) {
|
||||||
|
try {
|
||||||
|
boolean successful = false;
|
||||||
|
|
||||||
|
final BlockVector3 pos = clicked.toVector().add().toBlockPoint();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (feature.place(editSession, pos)) {
|
||||||
|
successful = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!successful) {
|
||||||
|
player.print(Caption.of("worldedit.tool.feature.failed"));
|
||||||
|
}
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
player.print(Caption.of("worldedit.tool.max-block-changes"));
|
||||||
|
} finally {
|
||||||
|
session.remember(editSession);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.fastasyncworldedit.core.command.tool;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.configuration.Caption;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.LocalConfiguration;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.command.tool.BlockTool;
|
||||||
|
import com.sk89q.worldedit.entity.Player;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.util.Direction;
|
||||||
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Places a structure
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public class StructurePlacer implements BlockTool {
|
||||||
|
|
||||||
|
private final StructureType structure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public StructurePlacer(StructureType structure) {
|
||||||
|
this.structure = structure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(Actor player) {
|
||||||
|
return player.hasPermission("worldedit.tool.feature");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean actPrimary(
|
||||||
|
Platform server,
|
||||||
|
LocalConfiguration config,
|
||||||
|
Player player,
|
||||||
|
LocalSession session,
|
||||||
|
Location clicked,
|
||||||
|
@Nullable Direction face
|
||||||
|
) {
|
||||||
|
|
||||||
|
try (EditSession editSession = session.createEditSession(player)) {
|
||||||
|
try {
|
||||||
|
boolean successful = false;
|
||||||
|
|
||||||
|
final BlockVector3 pos = clicked.toVector().add().toBlockPoint();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (structure.place(editSession, pos)) {
|
||||||
|
successful = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!successful) {
|
||||||
|
player.print(Caption.of("worldedit.tool.feature.failed"));
|
||||||
|
}
|
||||||
|
} catch (MaxChangedBlocksException e) {
|
||||||
|
player.print(Caption.of("worldedit.tool.max-block-changes"));
|
||||||
|
} finally {
|
||||||
|
session.remember(editSession);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.fastasyncworldedit.core.function.generator;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.function.RegionFunction;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a structure at the given location
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public class StructureGenerator implements RegionFunction {
|
||||||
|
|
||||||
|
private final StructureType structureType;
|
||||||
|
private final EditSession editSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param editSession the edit session
|
||||||
|
* @param structureType the structure type
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public StructureGenerator(EditSession editSession, StructureType structureType) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.structureType = structureType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||||
|
return editSession.getWorld().generateStructure(structureType, editSession, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -36,6 +36,8 @@ 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.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.StructureType;
|
||||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -132,12 +134,10 @@ public class WorldWrapper extends AbstractWorld {
|
||||||
return parent.playEffect(position, type, data);
|
return parent.playEffect(position, type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FAWE start - allow block break effect of non-legacy blocks
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playBlockBreakEffect(Vector3 position, BlockType type) {
|
public boolean playBlockBreakEffect(Vector3 position, BlockType type) {
|
||||||
return parent.playBlockBreakEffect(position, type);
|
return parent.playBlockBreakEffect(position, type);
|
||||||
}
|
}
|
||||||
//FAWE end
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) {
|
public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) {
|
||||||
|
@ -206,12 +206,10 @@ public class WorldWrapper extends AbstractWorld {
|
||||||
return parent.getName();
|
return parent.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//FAWE start - allow history to read an unloaded world's name
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameUnsafe() {
|
public String getNameUnsafe() {
|
||||||
return parent.getNameUnsafe();
|
return parent.getNameUnsafe();
|
||||||
}
|
}
|
||||||
//FAWE end
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws
|
||||||
|
@ -261,12 +259,15 @@ public class WorldWrapper extends AbstractWorld {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//FAWE start
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<BaseItemStack> getBlockDrops(final BlockVector3 position) {
|
public Collection<BaseItemStack> getBlockDrops(final BlockVector3 position) {
|
||||||
return TaskManager.taskManager().sync(() -> parent.getBlockDrops(position));
|
return TaskManager.taskManager().sync(() -> parent.getBlockDrops(position));
|
||||||
}
|
}
|
||||||
//FAWE end
|
|
||||||
|
@Override
|
||||||
|
public boolean canPlaceAt(final BlockVector3 position, final BlockState blockState) {
|
||||||
|
return parent.canPlaceAt(position, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean regenerate(Region region, EditSession session) {
|
public boolean regenerate(Region region, EditSession session) {
|
||||||
|
@ -288,6 +289,16 @@ public class WorldWrapper extends AbstractWorld {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateStructure(final StructureType type, final EditSession editSession, final BlockVector3 position) {
|
||||||
|
return parent.generateStructure(type, editSession, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generateFeature(final ConfiguredFeatureType type, final EditSession editSession, final BlockVector3 position) {
|
||||||
|
return parent.generateFeature(type, editSession, position);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector3 getSpawnPosition() {
|
public BlockVector3 getSpawnPosition() {
|
||||||
return parent.getSpawnPosition();
|
return parent.getSpawnPosition();
|
||||||
|
|
|
@ -147,6 +147,8 @@ 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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -4017,5 +4019,33 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||||
}
|
}
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a feature into this EditSession
|
||||||
|
*
|
||||||
|
* @param feature feature to generate
|
||||||
|
* @param position position to generate at
|
||||||
|
* @return blocks affected
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public int generateFeature(ConfiguredFeatureType feature, BlockVector3 position) {
|
||||||
|
feature.place(this, position);
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a structure into this EditSession
|
||||||
|
*
|
||||||
|
* @param structure structure to generate
|
||||||
|
* @param position position to generate at
|
||||||
|
* @return blocks affected
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public int generateStructure(StructureType structure, BlockVector3 position) {
|
||||||
|
structure.place(this, position);
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
//FAWE end
|
//FAWE end
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
import com.fastasyncworldedit.core.Fawe;
|
import com.fastasyncworldedit.core.Fawe;
|
||||||
|
import com.fastasyncworldedit.core.command.factory.StructureGeneratorFactory;
|
||||||
import com.fastasyncworldedit.core.command.tool.brush.BlendBall;
|
import com.fastasyncworldedit.core.command.tool.brush.BlendBall;
|
||||||
import com.fastasyncworldedit.core.command.tool.brush.BlobBrush;
|
import com.fastasyncworldedit.core.command.tool.brush.BlobBrush;
|
||||||
import com.fastasyncworldedit.core.command.tool.brush.BrushSettings;
|
import com.fastasyncworldedit.core.command.tool.brush.BrushSettings;
|
||||||
|
@ -66,6 +67,7 @@ import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
|
import com.sk89q.worldedit.command.factory.FeatureGeneratorFactory;
|
||||||
import com.sk89q.worldedit.command.factory.ReplaceFactory;
|
import com.sk89q.worldedit.command.factory.ReplaceFactory;
|
||||||
import com.sk89q.worldedit.command.factory.TreeGeneratorFactory;
|
import com.sk89q.worldedit.command.factory.TreeGeneratorFactory;
|
||||||
import com.sk89q.worldedit.command.tool.BrushTool;
|
import com.sk89q.worldedit.command.tool.BrushTool;
|
||||||
|
@ -115,6 +117,8 @@ import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||||
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.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
import org.anarres.parallelgzip.ParallelGZIPOutputStream;
|
import org.anarres.parallelgzip.ParallelGZIPOutputStream;
|
||||||
import org.enginehub.piston.annotation.Command;
|
import org.enginehub.piston.annotation.Command;
|
||||||
import org.enginehub.piston.annotation.CommandContainer;
|
import org.enginehub.piston.annotation.CommandContainer;
|
||||||
|
@ -1556,7 +1560,43 @@ public class BrushCommands {
|
||||||
set(context, new ButcherBrush(flags), "worldedit.brush.butcher").setSize(radius);
|
set(context, new ButcherBrush(flags), "worldedit.brush.butcher").setSize(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "feature",
|
||||||
|
desc = "Feature brush, paints Minecraft generation features"
|
||||||
|
)
|
||||||
|
@CommandPermissions("worldedit.brush.feature")
|
||||||
|
public void feature(Player player, LocalSession localSession,
|
||||||
|
@Arg(desc = "The shape of the region")
|
||||||
|
RegionFactory shape,
|
||||||
|
@Arg(desc = "The size of the brush", def = "5")
|
||||||
|
double radius,
|
||||||
|
@Arg(desc = "The density of the brush", def = "5")
|
||||||
|
double density,
|
||||||
|
@Arg(desc = "The type of feature to use")
|
||||||
|
ConfiguredFeatureType type) throws WorldEditException {
|
||||||
|
setOperationBasedBrush(player, localSession, radius,
|
||||||
|
new Paint(new FeatureGeneratorFactory(type), density / 100), shape, "worldedit.brush.feature");
|
||||||
|
}
|
||||||
|
|
||||||
//FAWE start
|
//FAWE start
|
||||||
|
@Command(
|
||||||
|
name = "structure",
|
||||||
|
desc = "Structure brush, paints Minecraft generation structures"
|
||||||
|
)
|
||||||
|
@CommandPermissions("worldedit.brush.feature")
|
||||||
|
public void structure(Player player, LocalSession localSession,
|
||||||
|
@Arg(desc = "The shape of the region")
|
||||||
|
RegionFactory shape,
|
||||||
|
@Arg(desc = "The size of the brush", def = "5")
|
||||||
|
double radius,
|
||||||
|
@Arg(desc = "The density of the brush", def = "5")
|
||||||
|
double density,
|
||||||
|
@Arg(desc = "The type of feature to use")
|
||||||
|
StructureType type) throws WorldEditException {
|
||||||
|
setOperationBasedBrush(player, localSession, radius,
|
||||||
|
new Paint(new StructureGeneratorFactory(type), density / 100), shape, "worldedit.brush.structure");
|
||||||
|
}
|
||||||
|
|
||||||
public BrushSettings process(Player player, Arguments arguments, BrushSettings settings)
|
public BrushSettings process(Player player, Arguments arguments, BrushSettings settings)
|
||||||
throws WorldEditException {
|
throws WorldEditException {
|
||||||
LocalSession session = worldEdit.getSessionManager().get(player);
|
LocalSession session = worldEdit.getSessionManager().get(player);
|
||||||
|
|
|
@ -56,13 +56,15 @@ import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
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.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;
|
||||||
import org.enginehub.piston.annotation.param.Switch;
|
import org.enginehub.piston.annotation.param.Switch;
|
||||||
import org.jetbrains.annotations.Range;
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
import java.awt.RenderingHints;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
@ -351,6 +353,53 @@ public class GenerationCommands {
|
||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "/feature",
|
||||||
|
//FAWE start
|
||||||
|
aliases = {"/placefeature"},
|
||||||
|
//FAWE end
|
||||||
|
desc = "Generate Minecraft features"
|
||||||
|
)
|
||||||
|
@Logging(PLACEMENT)
|
||||||
|
@CommandPermissions("worldedit.generation.feature")
|
||||||
|
public int feature(
|
||||||
|
Actor actor, LocalSession session, EditSession editSession,
|
||||||
|
@Arg(desc = "Type of feature to place", def = "forest_rock")
|
||||||
|
ConfiguredFeatureType feature
|
||||||
|
) throws WorldEditException {
|
||||||
|
//FAWE start
|
||||||
|
int affected = editSession.generateFeature(feature, session.getPlacementPosition(actor));
|
||||||
|
|
||||||
|
if (affected == 0) {
|
||||||
|
actor.print(Caption.of("worldedit.generate.feature.failed"));
|
||||||
|
} else {
|
||||||
|
actor.print(Caption.of("worldedit.feature.created", TextComponent.of(affected)));
|
||||||
|
}
|
||||||
|
return affected;
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
//FAWE start
|
||||||
|
int affected = editSession.generateStructure(feature, session.getPlacementPosition(actor));
|
||||||
|
|
||||||
|
if (affected > 0) {
|
||||||
|
actor.printInfo(Caption.of("worldedit.structure.created", TextComponent.of(affected)));
|
||||||
|
} else {
|
||||||
|
actor.printError(Caption.of("worldedit.structure.failed"));
|
||||||
|
}
|
||||||
|
return affected;
|
||||||
|
//FAWE end
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "/hpyramid",
|
name = "/hpyramid",
|
||||||
desc = "Generate a hollow pyramid"
|
desc = "Generate a hollow pyramid"
|
||||||
|
@ -720,7 +769,7 @@ public class GenerationCommands {
|
||||||
)
|
)
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
@CommandPermissions("worldedit.generation.blob")
|
@CommandPermissions("worldedit.generation.blob")
|
||||||
public int blobBrush(
|
public int blob(
|
||||||
Actor actor, LocalSession session, EditSession editSession,
|
Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "Pattern")
|
@Arg(desc = "Pattern")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
|
@ -750,7 +799,7 @@ public class GenerationCommands {
|
||||||
if (actor instanceof Player && Settings.settings().GENERAL.UNSTUCK_ON_GENERATE) {
|
if (actor instanceof Player && Settings.settings().GENERAL.UNSTUCK_ON_GENERATE) {
|
||||||
((Player) actor).findFreePosition();
|
((Player) actor).findFreePosition();
|
||||||
}
|
}
|
||||||
actor.print(Caption.of("worldedit.sphere.created", TextComponent.of(affected)));
|
actor.print(Caption.of("worldedit.blob.created", TextComponent.of(affected)));
|
||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
//FAWE end
|
//FAWE end
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
|
import com.fastasyncworldedit.core.command.tool.FeaturePlacer;
|
||||||
|
import com.fastasyncworldedit.core.command.tool.StructurePlacer;
|
||||||
import com.fastasyncworldedit.core.command.tool.brush.InspectBrush;
|
import com.fastasyncworldedit.core.command.tool.brush.InspectBrush;
|
||||||
import com.fastasyncworldedit.core.configuration.Caption;
|
import com.fastasyncworldedit.core.configuration.Caption;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
|
@ -56,6 +58,8 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
import com.sk89q.worldedit.world.generation.StructureType;
|
||||||
import org.enginehub.piston.CommandManager;
|
import org.enginehub.piston.CommandManager;
|
||||||
import org.enginehub.piston.CommandManagerService;
|
import org.enginehub.piston.CommandManagerService;
|
||||||
import org.enginehub.piston.CommandMetadata;
|
import org.enginehub.piston.CommandMetadata;
|
||||||
|
@ -244,6 +248,36 @@ public class ToolCommands {
|
||||||
setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip");
|
setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
@Command(
|
||||||
|
name = "featureplacer",
|
||||||
|
aliases = {"/featureplacer", "featuretool", "/featuretool"},
|
||||||
|
desc = "Feature placer tool"
|
||||||
|
)
|
||||||
|
@CommandPermissions("worldedit.tool.feature")
|
||||||
|
public void feature(
|
||||||
|
Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Type of feature to place", def = "forest_rock")
|
||||||
|
ConfiguredFeatureType feature
|
||||||
|
) throws WorldEditException {
|
||||||
|
setTool(player, session, new FeaturePlacer(feature), "worldedit.tool.feature.equip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "structureplacer",
|
||||||
|
aliases = {"/structureplacer", "structuretool", "/structuretool"},
|
||||||
|
desc = "Structure placer tool"
|
||||||
|
)
|
||||||
|
@CommandPermissions("worldedit.tool.structure")
|
||||||
|
public void structure(
|
||||||
|
Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Type of structure to place", def = "")
|
||||||
|
StructureType feature
|
||||||
|
) throws WorldEditException {
|
||||||
|
setTool(player, session, new StructurePlacer(feature), "worldedit.tool.structure.equip");
|
||||||
|
}
|
||||||
|
//FAWE end
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "stacker",
|
name = "stacker",
|
||||||
desc = "Block stacker tool"
|
desc = "Block stacker tool"
|
||||||
|
|
|
@ -32,6 +32,8 @@ import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
import com.sk89q.worldedit.world.fluid.FluidCategory;
|
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.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;
|
||||||
|
@ -62,7 +64,9 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
|
||||||
FluidType.class,
|
FluidType.class,
|
||||||
FluidCategory.class,
|
FluidCategory.class,
|
||||||
GameMode.class,
|
GameMode.class,
|
||||||
WeatherType.class
|
WeatherType.class,
|
||||||
|
ConfiguredFeatureType.class,
|
||||||
|
StructureType.class
|
||||||
)
|
)
|
||||||
.stream()
|
.stream()
|
||||||
.map(c -> (Class<Keyed>) c)
|
.map(c -> (Class<Keyed>) c)
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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.command.factory;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.function.Contextual;
|
||||||
|
import com.sk89q.worldedit.function.EditContext;
|
||||||
|
import com.sk89q.worldedit.function.generator.FeatureGenerator;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
|
||||||
|
public final class FeatureGeneratorFactory implements Contextual<FeatureGenerator> {
|
||||||
|
private final ConfiguredFeatureType type;
|
||||||
|
|
||||||
|
public FeatureGeneratorFactory(ConfiguredFeatureType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureGenerator createFromContext(EditContext input) {
|
||||||
|
return new FeatureGenerator((EditSession) input.getDestination(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "feature of type " + type;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,6 @@ import com.fastasyncworldedit.core.extent.processor.lighting.Relighter;
|
||||||
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
|
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
|
||||||
import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
||||||
import com.sk89q.worldedit.LocalConfiguration;
|
import com.sk89q.worldedit.LocalConfiguration;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
|
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
|
||||||
import com.sk89q.worldedit.registry.Keyed;
|
import com.sk89q.worldedit.registry.Keyed;
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* 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.function.generator;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.function.RegionFunction;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.world.generation.ConfiguredFeatureType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a feature at the given location
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public class FeatureGenerator implements RegionFunction {
|
||||||
|
|
||||||
|
private final ConfiguredFeatureType featureType;
|
||||||
|
private final EditSession editSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param editSession the edit session
|
||||||
|
* @param featureType the feature type
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public FeatureGenerator(EditSession editSession, ConfiguredFeatureType featureType) {
|
||||||
|
this.editSession = editSession;
|
||||||
|
this.featureType = featureType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||||
|
return editSession.getWorld().generateFeature(featureType, editSession, position);
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,6 +46,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
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.StructureType;
|
||||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -311,6 +313,34 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a structure at the given position
|
||||||
|
*
|
||||||
|
* @param type The structure type
|
||||||
|
* @param editSession The {@link EditSession}
|
||||||
|
* @param position The position
|
||||||
|
* @return True if the generation was successful
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
default boolean generateStructure(StructureType type, EditSession editSession, BlockVector3 position) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a feature at the given position.
|
||||||
|
*
|
||||||
|
* @param type The feature type
|
||||||
|
* @param editSession The {@link EditSession}
|
||||||
|
* @param position The position
|
||||||
|
* @return True if the generation was successful
|
||||||
|
*
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
default boolean generateFeature(ConfiguredFeatureType type, EditSession editSession, BlockVector3 position) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the chunk at the given position if it isn't loaded.
|
* Load the chunk at the given position if it isn't loaded.
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class BiomeType implements RegistryItem, Keyed, BiomePattern {
|
||||||
/**
|
/**
|
||||||
* Gets the ID of this biome.
|
* Gets the ID of this biome.
|
||||||
*
|
*
|
||||||
* @return The id
|
* @return the id
|
||||||
* @deprecated use {@link #id()}
|
* @deprecated use {@link #id()}
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true, since = "TODO")
|
@Deprecated(forRemoval = true, since = "TODO")
|
||||||
|
|
|
@ -40,19 +40,20 @@ public class FluidType implements RegistryItem, Keyed {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID of this block.
|
* Gets the ID of this fluid.
|
||||||
*
|
*
|
||||||
* @return The id
|
* @return The id
|
||||||
* @since TODO
|
* @since TODO
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String id() {
|
public String id() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID of this block.
|
* Gets the ID of this fluid.
|
||||||
*
|
*
|
||||||
* @return The id
|
* @return the id
|
||||||
* @deprecated use {@link #id()}
|
* @deprecated use {@link #id()}
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true, since = "TODO")
|
@Deprecated(forRemoval = true, since = "TODO")
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.registry.Keyed;
|
||||||
|
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||||
|
|
||||||
|
public record ConfiguredFeatureType(String id) implements Keyed {
|
||||||
|
|
||||||
|
public static final NamespacedRegistry<ConfiguredFeatureType> REGISTRY = new NamespacedRegistry<>("configured feature type");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Place this feature into an {@link EditSession}
|
||||||
|
*
|
||||||
|
* @param extent EditSession to place into
|
||||||
|
* @param position position to use for placement
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
|
public boolean place(EditSession extent, BlockVector3 position) {
|
||||||
|
return extent.getWorld().generateFeature(this, extent, position);
|
||||||
|
}
|
||||||
|
//FAWE end
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.registry.Keyed;
|
||||||
|
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||||
|
|
||||||
|
public record StructureType(String id) implements Keyed {
|
||||||
|
|
||||||
|
public static final NamespacedRegistry<StructureType> REGISTRY = new NamespacedRegistry<>("structure type");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FAWE start
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Place this structure into an {@link EditSession}
|
||||||
|
*
|
||||||
|
* @param extent EditSession to place into
|
||||||
|
* @param position position to use for placement
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
|
public boolean place(EditSession extent, BlockVector3 position) {
|
||||||
|
return extent.getWorld().generateStructure(this, extent, position);
|
||||||
|
}
|
||||||
|
//FAWE end
|
||||||
|
}
|
|
@ -508,11 +508,17 @@
|
||||||
"worldedit.hcyl.thickness-too-large": "Thickness cannot be larger than x or z radii.",
|
"worldedit.hcyl.thickness-too-large": "Thickness cannot be larger than x or z radii.",
|
||||||
"worldedit.sphere.invalid-radius": "You must either specify 1 or 3 radius values.",
|
"worldedit.sphere.invalid-radius": "You must either specify 1 or 3 radius values.",
|
||||||
"worldedit.sphere.created": "{0} blocks have been created.",
|
"worldedit.sphere.created": "{0} blocks have been created.",
|
||||||
|
"worldedit.blob.created": "{0} blocks have been created.",
|
||||||
|
"worldedit.feature.created": "Feature created, {0} blocks placed.",
|
||||||
|
"worldedit.generate.feature.failed": "This feature cannot go here. Ensure the area meets the requirements.",
|
||||||
"worldedit.forestgen.created": "{0} trees created.",
|
"worldedit.forestgen.created": "{0} trees created.",
|
||||||
"worldedit.pumpkins.created": "{0} pumpkin patches created.",
|
"worldedit.pumpkins.created": "{0} pumpkin patches created.",
|
||||||
|
"worldedit.feature.failed": "Failed to generate feature. Is it a valid spot for it?",
|
||||||
"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, {0} blocks placed.",
|
||||||
|
"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}",
|
||||||
|
@ -550,6 +556,8 @@
|
||||||
"worldedit.tool.deltree.not-floating": "That's not a floating tree.",
|
"worldedit.tool.deltree.not-floating": "That's not a floating tree.",
|
||||||
"worldedit.tool.tree.equip": "Tree tool bound to {0}.",
|
"worldedit.tool.tree.equip": "Tree tool bound to {0}.",
|
||||||
"worldedit.tool.tree.obstructed": "A tree can't go there.",
|
"worldedit.tool.tree.obstructed": "A tree can't go there.",
|
||||||
|
"worldedit.tool.feature.equip": "Feature placer tool bound to {0}.",
|
||||||
|
"worldedit.tool.feature.obstructed": "This feature cannot go there. Ensure the area meets the requirements.",
|
||||||
"worldedit.tool.info.equip": "Info tool bound to {0}.",
|
"worldedit.tool.info.equip": "Info tool bound to {0}.",
|
||||||
"worldedit.tool.inspect.equip": "Inspect tool bound to {0}.",
|
"worldedit.tool.inspect.equip": "Inspect tool bound to {0}.",
|
||||||
"worldedit.tool.info.blockstate.hover": "Block state",
|
"worldedit.tool.info.blockstate.hover": "Block state",
|
||||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren