3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 10:30:04 +01:00

fix: Use WE PaperweightAdapter for seed replacement (#1440)

* Use WE PaperweightAdapter for seed replacement
also, only replace when necessary

* fix comments

* ci: Provide basic Jenkinsfile for ghprb pipeline (#1451)

Co-authored-by: Alex <mc.cache@web.de>
Dieser Commit ist enthalten in:
Hannes Greule 2021-12-07 12:59:58 +01:00 committet von GitHub
Ursprung 781bfc542f
Commit 5367921496
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 22 neuen und 38 gelöschten Zeilen

10
Jenkinsfile vendored Normale Datei
Datei anzeigen

@ -0,0 +1,10 @@
pipeline {
agent any
stages {
stage('Build pull request') {
steps {
sh './gradlew clean build'
}
}
}
}

Datei anzeigen

@ -658,7 +658,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
}
}
private WorldGenSettings replaceSeed(ServerLevel originalWorld, long seed, WorldGenSettings originalOpts) {
// FAWE start - private -> public static
public static WorldGenSettings replaceSeed(ServerLevel originalWorld, long seed, WorldGenSettings originalOpts) {
// FAWE end
RegistryWriteOps<net.minecraft.nbt.Tag> nbtReadRegOps = RegistryWriteOps.create(
NbtOps.INSTANCE,
originalWorld.getServer().registryAccess()
@ -685,8 +687,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
);
}
// FAWE start - private -> private static
@SuppressWarnings("unchecked")
private Dynamic<net.minecraft.nbt.Tag> recursivelySetSeed(
private static Dynamic<net.minecraft.nbt.Tag> recursivelySetSeed(
// FAWE end
Dynamic<net.minecraft.nbt.Tag> dynamic,
long seed,
Set<Dynamic<net.minecraft.nbt.Tag>> seen

Datei anzeigen

@ -9,9 +9,9 @@ import com.fastasyncworldedit.core.util.TaskManager;
import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.Lifecycle;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.PaperweightAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.PaperweightGetBlocks;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
@ -21,12 +21,9 @@ import com.sk89q.worldedit.world.RegenOptions;
import io.papermc.lib.PaperLib;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.data.worldgen.biome.Biomes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.resources.RegistryReadOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
@ -78,12 +75,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BooleanSupplier;
@ -220,19 +215,11 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
MinecraftServer server = originalServerWorld.getCraftServer().getServer();
PrimaryLevelData levelProperties = (PrimaryLevelData) server.getWorldData();
RegistryReadOps<net.minecraft.nbt.Tag> nbtRegOps = RegistryReadOps.createAndLoad(
NbtOps.INSTANCE, server.resources.getResourceManager(),
RegistryAccess.builtin()
);
WorldGenSettings newOpts = WorldGenSettings.CODEC
.encodeStart(nbtRegOps, levelProperties.worldGenSettings())
.flatMap(tag -> WorldGenSettings.CODEC.parse(this.recursivelySetSeed(
new Dynamic<>(nbtRegOps, tag),
seed,
new HashSet<>()
)))
.result()
.orElseThrow(() -> new IllegalStateException("Unable to map GeneratorOptions"));
WorldGenSettings originalOpts = levelProperties.worldGenSettings();
WorldGenSettings newOpts = options.getSeed().isPresent()
? PaperweightAdapter.replaceSeed(originalServerWorld, seed, originalOpts)
: originalOpts;
LevelSettings newWorldSettings = new LevelSettings(
"worldeditregentempworld",
originalWorldData.settings.gameType(),
@ -438,23 +425,6 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
}
}
private Dynamic<net.minecraft.nbt.Tag> recursivelySetSeed(
Dynamic<net.minecraft.nbt.Tag> dynamic,
long seed,
Set<Dynamic<net.minecraft.nbt.Tag>> dynamicSet
) {
return !dynamicSet.add(dynamic) ? dynamic : dynamic.updateMapValues((pair) -> {
if (pair.getFirst().asString("").equals("seed")) {
return pair.mapSecond((v) -> v.createLong(seed));
} else {
return ((Dynamic) pair.getSecond()).getValue() instanceof CompoundTag
? pair.mapSecond((v) -> this.recursivelySetSeed((Dynamic) v, seed, dynamicSet))
: pair;
}
});
}
private BiomeSource fastOverworldBiomeSource(BiomeSource biomeSource) throws Exception {
Field legacyBiomeInitLayerField = OverworldBiomeSource.class.getDeclaredField(
Refraction.pickName("legacyBiomeInitLayer", "i"));