3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-09-29 02:21:06 +02:00

Upstream changes, use correct list of cached block changes

Dieser Commit ist enthalten in:
dordsor21 2024-06-07 19:14:23 +01:00
Ursprung 4906dfa347
Commit 7c1c92d6db
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
22 geänderte Dateien mit 224 neuen und 84 gelöschten Zeilen

Datei anzeigen

@ -947,7 +947,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@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.getId()));
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()));
@ -956,7 +956,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@Override
public boolean generateStructure(StructureType type, World world, EditSession session, BlockVector3 pt) {
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -9,6 +9,7 @@ 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.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.chunk.ChunkAccess;
@ -121,7 +122,22 @@ public class FaweBlockStateListPopulator extends BlockStateListPopulator {
@Override
public BlockState getBlockState(final BlockPos pos) {
return world.getBlockState(pos);
BlockState state = world.getBlockState(pos);
try {
state = new BlockState(
state.getBlock(),
state.getValues(),
PaperweightPlatformAdapter.getStatePropertiesCodec(state)
) {
@Override
public boolean is(Block block) {
return true;
}
};
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return state;
}
@Override

Datei anzeigen

@ -544,7 +544,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
ConfiguredFeature<?, ?> configuredFeature = serverLevel
.registryAccess()
.registryOrThrow(Registries.CONFIGURED_FEATURE)
.get(ResourceLocation.tryParse(feature.getId()));
.get(ResourceLocation.tryParse(feature.id()));
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
@ -559,10 +559,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
)) {
return null;
}
return populator.getList().stream().collect(Collectors.toMap(
CraftBlockState::getPosition,
craftBlockState -> craftBlockState
));
return new HashMap<>(populator.getLevel().capturedBlockStates);
} finally {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
@ -580,7 +577,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
Structure k = serverLevel
.registryAccess()
.registryOrThrow(Registries.STRUCTURE)
.get(ResourceLocation.tryParse(type.getId()));
.get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -11,6 +11,7 @@ import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.MapCodec;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -45,6 +46,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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.ChunkStatus;
import net.minecraft.world.level.chunk.GlobalPalette;
@ -99,6 +101,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final Field fieldTickingFluidCount;
private static final Field fieldTickingBlockCount;
private static final Field fieldPropertiesCodec;
private static final MethodHandle methodGetVisibleChunk;
private static final Field fieldThreadingDetector;
@ -154,6 +158,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldBiomes = tmpFieldBiomes;
fieldBiomes.setAccessible(true);
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
fieldPropertiesCodec.setAccessible(true);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
"getVisibleChunkIfPresent",
"b"
@ -705,6 +712,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return List.of();
}
public static MapCodec<net.minecraft.world.level.block.state.BlockState> getStatePropertiesCodec(
net.minecraft.world.level.block.state.BlockState state
) throws IllegalAccessException {
return (MapCodec<net.minecraft.world.level.block.state.BlockState>) fieldPropertiesCodec.get(state);
}
record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {
@Override

Datei anzeigen

@ -946,7 +946,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@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.getId()));
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()));
@ -955,7 +955,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@Override
public boolean generateStructure(StructureType type, World world, EditSession session, BlockVector3 pt) {
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -9,6 +9,7 @@ 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.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.chunk.ChunkAccess;
@ -121,7 +122,22 @@ public class FaweBlockStateListPopulator extends BlockStateListPopulator {
@Override
public BlockState getBlockState(final BlockPos pos) {
return world.getBlockState(pos);
BlockState state = world.getBlockState(pos);
try {
state = new BlockState(
state.getBlock(),
state.getValues(),
PaperweightPlatformAdapter.getStatePropertiesCodec(state)
) {
@Override
public boolean is(Block block) {
return true;
}
};
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return state;
}
@Override

Datei anzeigen

@ -544,7 +544,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
ConfiguredFeature<?, ?> configuredFeature = serverLevel
.registryAccess()
.registryOrThrow(Registries.CONFIGURED_FEATURE)
.get(ResourceLocation.tryParse(feature.getId()));
.get(ResourceLocation.tryParse(feature.id()));
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
@ -557,19 +557,16 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
serverLevel.random,
new BlockPos(pt.x(), pt.y(), pt.z())
)) {
return null;
}
return populator.getList().stream().collect(Collectors.toMap(
CraftBlockState::getPosition,
craftBlockState -> craftBlockState
));
return new HashMap<>(populator.getLevel().capturedBlockStates);
} finally {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
serverLevel.capturedBlockStates.clear();
}
});
return placeFeatureIntoSession(editSession, populator, placed);
//FAWE end
}
@ -580,7 +577,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
Structure k = serverLevel
.registryAccess()
.registryOrThrow(Registries.STRUCTURE)
.get(ResourceLocation.tryParse(type.getId()));
.get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -11,6 +11,7 @@ import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.MapCodec;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -45,6 +46,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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.ChunkStatus;
import net.minecraft.world.level.chunk.GlobalPalette;
@ -100,6 +102,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final Field fieldTickingBlockCount;
private static final Field fieldBiomes;
private static final Field fieldPropertiesCodec;
private static final MethodHandle methodGetVisibleChunk;
private static final Field fieldThreadingDetector;
@ -154,6 +158,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldBiomes = tmpFieldBiomes;
fieldBiomes.setAccessible(true);
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
fieldPropertiesCodec.setAccessible(true);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
"getVisibleChunkIfPresent",
"b"
@ -705,6 +712,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return List.of();
}
public static MapCodec<net.minecraft.world.level.block.state.BlockState> getStatePropertiesCodec(
net.minecraft.world.level.block.state.BlockState state
) throws IllegalAccessException {
return (MapCodec<net.minecraft.world.level.block.state.BlockState>) fieldPropertiesCodec.get(state);
}
record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {
@Override

Datei anzeigen

@ -970,7 +970,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@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.getId()));
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()));
@ -979,7 +980,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@Override
public boolean generateStructure(StructureType type, World world, EditSession session, BlockVector3 pt) {
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
Structure k = originalWorld
.registryAccess()
.registryOrThrow(Registries.STRUCTURE)
.get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -1,13 +1,18 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4;
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
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.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkSource;
@ -66,6 +71,11 @@ public class FaweBlockStateListPopulator extends BlockStateListPopulator {
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);
@ -97,4 +107,44 @@ public class FaweBlockStateListPopulator extends BlockStateListPopulator {
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) {
BlockState state = world.getBlockState(pos);
try {
state = new BlockState(
state.getBlock(),
(Reference2ObjectArrayMap<Property<?>, Comparable<?>>) state.getValues(),
PaperweightPlatformAdapter.getStatePropertiesCodec(state)
) {
@Override
public boolean is(Block block) {
return true;
}
};
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return state;
}
@Override
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
return world.setBlock(pos, state, flags);
}
}

Datei anzeigen

@ -558,7 +558,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
ConfiguredFeature<?, ?> configuredFeature = serverLevel
.registryAccess()
.registryOrThrow(Registries.CONFIGURED_FEATURE)
.get(ResourceLocation.tryParse(feature.getId()));
.get(ResourceLocation.tryParse(feature.id()));
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
@ -573,10 +573,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
)) {
return null;
}
return populator.getList().stream().collect(Collectors.toMap(
CraftBlockState::getPosition,
craftBlockState -> craftBlockState
));
return new HashMap<>(populator.getLevel().capturedBlockStates);
} finally {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
@ -594,7 +591,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
Structure k = serverLevel
.registryAccess()
.registryOrThrow(Registries.STRUCTURE)
.get(ResourceLocation.tryParse(type.getId()));
.get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -11,6 +11,7 @@ import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.MapCodec;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -45,6 +46,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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.GlobalPalette;
import net.minecraft.world.level.chunk.HashMapPalette;
@ -100,6 +102,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final Field fieldTickingBlockCount;
private static final Field fieldBiomes;
private static final Field fieldPropertiesCodec;
private static final MethodHandle methodGetVisibleChunk;
private static final Field fieldThreadingDetector;
@ -154,6 +158,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldBiomes = tmpFieldBiomes;
fieldBiomes.setAccessible(true);
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
fieldPropertiesCodec.setAccessible(true);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
"getVisibleChunkIfPresent",
"b"
@ -705,6 +712,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return List.of();
}
public static MapCodec<net.minecraft.world.level.block.state.BlockState> getStatePropertiesCodec(
net.minecraft.world.level.block.state.BlockState state
) throws IllegalAccessException {
return (MapCodec<net.minecraft.world.level.block.state.BlockState>) fieldPropertiesCodec.get(state);
}
record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {
@Override

Datei anzeigen

@ -510,23 +510,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
ServerLevel worldServer = craftWorld.getHandle();
String entityId = state.getType().id();
LinCompoundTag nativeTag = state.getNbt();
net.minecraft.nbt.CompoundTag tag;
if (nativeTag != null) {
tag = (net.minecraft.nbt.CompoundTag) fromNativeLin(nativeTag);
removeUnwantedEntityTagsRecursively(tag);
} else {
tag = new net.minecraft.nbt.CompoundTag();
}
tag.putString("id", entityId);
Entity createdEntity = EntityType.loadEntityRecursive(tag, craftWorld.getHandle(), (loadedEntity) -> {
loadedEntity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
return loadedEntity;
});
Entity createdEntity = createEntityFromId(state.getType().id(), craftWorld.getHandle());
if (createdEntity != null) {
worldServer.addFreshEntityWithPassengers(createdEntity, SpawnReason.CUSTOM);
@ -977,7 +961,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@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.getId()));
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()));
@ -986,7 +970,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
@Override
public boolean generateStructure(StructureType type, World world, EditSession session, BlockVector3 pt) {
ServerLevel originalWorld = ((CraftWorld) world).getHandle();
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.getId()));
Structure k = originalWorld.registryAccess().registryOrThrow(Registries.STRUCTURE).get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -1,13 +1,17 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1;
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
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.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkSource;
@ -97,4 +101,44 @@ public class FaweBlockStateListPopulator extends BlockStateListPopulator {
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) {
BlockState state = world.getBlockState(pos);
try {
state = new BlockState(
state.getBlock(),
(Reference2ObjectArrayMap<Property<?>, Comparable<?>>) state.getValues(),
PaperweightPlatformAdapter.getStatePropertiesCodec(state)
) {
@Override
public boolean is(Block block) {
return true;
}
};
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return state;
}
@Override
public boolean setBlock(final BlockPos pos, final BlockState state, final int flags) {
return world.setBlock(pos, state, flags);
}
}

Datei anzeigen

@ -513,7 +513,8 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
public org.bukkit.inventory.ItemStack adapt(BaseItemStack baseItemStack) {
final RegistryAccess.Frozen registryAccess = DedicatedServer.getServer().registryAccess();
ItemStack stack = new ItemStack(
registryAccess.registryOrThrow(Registries.ITEM).get(ResourceLocation.tryParse(baseItemStack.getType().id())),
DedicatedServer.getServer().registryAccess().registryOrThrow(Registries.ITEM)
.get(ResourceLocation.tryParse(baseItemStack.getType().id())),
baseItemStack.getAmount()
);
final net.minecraft.nbt.CompoundTag nbt = (net.minecraft.nbt.CompoundTag) fromNative(baseItemStack.getNbtData());
@ -558,7 +559,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
ConfiguredFeature<?, ?> configuredFeature = serverLevel
.registryAccess()
.registryOrThrow(Registries.CONFIGURED_FEATURE)
.get(ResourceLocation.tryParse(feature.getId()));
.get(ResourceLocation.tryParse(feature.id()));
FaweBlockStateListPopulator populator = new FaweBlockStateListPopulator(serverLevel);
Map<BlockPos, CraftBlockState> placed = TaskManager.taskManager().sync(() -> {
@ -573,10 +574,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
)) {
return null;
}
return populator.getList().stream().collect(Collectors.toMap(
CraftBlockState::getPosition,
craftBlockState -> craftBlockState
));
return new HashMap<>(populator.getLevel().capturedBlockStates);
} finally {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
@ -595,7 +593,7 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
Structure k = serverLevel
.registryAccess()
.registryOrThrow(Registries.STRUCTURE)
.get(ResourceLocation.tryParse(type.getId()));
.get(ResourceLocation.tryParse(type.id()));
if (k == null) {
return false;
}

Datei anzeigen

@ -12,6 +12,7 @@ import com.fastasyncworldedit.core.math.IntPair;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TaskManager;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.MapCodec;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
@ -44,6 +45,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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.GlobalPalette;
import net.minecraft.world.level.chunk.HashMapPalette;
@ -99,6 +101,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final Field fieldTickingBlockCount;
private static final Field fieldBiomes;
private static final Field fieldPropertiesCodec;
private static final MethodHandle methodGetVisibleChunk;
private static final Field fieldThreadingDetector;
@ -151,6 +155,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldBiomes = tmpFieldBiomes;
fieldBiomes.setAccessible(true);
fieldPropertiesCodec = StateHolder.class.getDeclaredField(Refraction.pickName("propertiesCodec", "f"));
fieldPropertiesCodec.setAccessible(true);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
"getVisibleChunkIfPresent",
"b"
@ -679,6 +686,12 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
}
}
public static MapCodec<net.minecraft.world.level.block.state.BlockState> getStatePropertiesCodec(
net.minecraft.world.level.block.state.BlockState state
) throws IllegalAccessException {
return (MapCodec<net.minecraft.world.level.block.state.BlockState>) fieldPropertiesCodec.get(state);
}
record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {
@Override

Datei anzeigen

@ -23,7 +23,6 @@ import com.fastasyncworldedit.core.extent.processor.lighting.Relighter;
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.registry.Keyed;

Datei anzeigen

@ -29,7 +29,7 @@ public class Pre13HangingCompatibilityHandler implements EntityNBTCompatibilityH
@Override
public LinCompoundTag updateNbt(EntityType type, LinCompoundTag tag) {
if (!type.getId().startsWith("minecraft:")) {
if (!type.id().startsWith("minecraft:")) {
return tag;
}
Direction newDirection;

Datei anzeigen

@ -131,7 +131,9 @@ public class AnvilChunk13 implements Chunk {
try {
blockState = getBlockStateWith(blockState, property, value);
} catch (IllegalArgumentException e) {
throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().id() + ", " + property.getName() + ": " + value);
throw new InvalidFormatException("Invalid block state for " + blockState
.getBlockType()
.id() + ", " + property.getName() + ": " + value);
}
}
}

Datei anzeigen

@ -105,7 +105,9 @@ public class AnvilChunk18 implements Chunk {
try {
blockState = getBlockStateWith(blockState, property, value);
} catch (IllegalArgumentException e) {
throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().getId() + ", " + property.getName() + ": " + value);
throw new InvalidFormatException("Invalid block state for " + blockState
.getBlockType()
.id() + ", " + property.getName() + ": " + value);
}
}
}
@ -197,9 +199,9 @@ public class AnvilChunk18 implements Chunk {
@Override
public BaseBlock getBlock(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
int z = position.getZ() - rootZ * 16;
int x = position.x() - rootX * 16;
int y = position.y();
int z = position.z() - rootZ * 16;
int section = y >> 4;
int yIndex = y & 0x0F;

Datei anzeigen

@ -24,26 +24,17 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
public class ConfiguredFeatureType implements Keyed {
public record ConfiguredFeatureType(String id) implements Keyed {
public static final NamespacedRegistry<ConfiguredFeatureType> REGISTRY = new NamespacedRegistry<>("configured feature type");
private final String id;
public ConfiguredFeatureType(String id) {
this.id = id;
}
@Override
public String getId() {
return this.id;
}
@Override
public String toString() {
return this.id;
}
//FAWE start
/**
* Place this feature into an {@link EditSession}
*

Datei anzeigen

@ -24,26 +24,17 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
public class StructureType implements Keyed {
public record StructureType(String id) implements Keyed {
public static final NamespacedRegistry<StructureType> REGISTRY = new NamespacedRegistry<>("structure type");
private final String id;
public StructureType(String id) {
this.id = id;
}
@Override
public String getId() {
return this.id;
}
@Override
public String toString() {
return this.id;
}
//FAWE start
/**
* Place this structure into an {@link EditSession}
*