From f4f0dca3bd3b883cc2ae57b4576cc0f44f9a7b04 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 14:33:31 -0700 Subject: [PATCH 01/17] add papermc maven to build setting --- settings.gradle.kts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index f0612e154..16353b28c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,9 +24,12 @@ include(":platforms:bukkit:common") pluginManagement { repositories { - maven(url = "https://maven.fabricmc.net") { + maven("https://maven.fabricmc.net") { name = "Fabric" } + maven("https://papermc.io/repo/repository/maven-public/") { + name = "PaperMC" + } gradlePluginPortal() } } From 2141e7489e615cdf363fb10028002a1bb2958905 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 16:12:21 -0700 Subject: [PATCH 02/17] add 1.19 NMS module --- platforms/bukkit/build.gradle.kts | 3 + .../bukkit/nms/v1_19_R1/build.gradle.kts | 16 ++ .../bukkit/nms/v1_19_R1/NMSBiomeInfo.java | 10 + .../bukkit/nms/v1_19_R1/NMSBiomeInjector.java | 188 ++++++++++++++ .../bukkit/nms/v1_19_R1/NMSBiomeProvider.java | 54 ++++ .../v1_19_R1/NMSChunkGeneratorDelegate.java | 239 ++++++++++++++++++ .../bukkit/nms/v1_19_R1/NMSInitializer.java | 15 ++ .../nms/v1_19_R1/NMSInjectListener.java | 52 ++++ .../nms/v1_19_R1/NMSWorldProperties.java | 36 +++ .../terra/bukkit/nms/v1_19_R1/Registries.java | 30 +++ 10 files changed, 643 insertions(+) create mode 100644 platforms/bukkit/nms/v1_19_R1/build.gradle.kts create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 97ca84242..94c915197 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -4,6 +4,9 @@ import java.nio.channels.Channels import java.nio.file.Files import java.nio.file.StandardCopyOption +plugins { + id("xyz.jpenilla.run-paper") version "1.0.6" +} val mcVersion = "1.18.2" val testDir = "target/server" diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts new file mode 100644 index 000000000..868c0a8de --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + id("io.papermc.paperweight.userdev") version "1.3.3" +} + +dependencies { + api(project(":platforms:bukkit:common")) + paperDevBundle("1.19-R0.1-SNAPSHOT") + + compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18.2-R0.1-SNAPSHOT") +} + +tasks { + assemble { + dependsOn(reobfJar) + } +} \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java new file mode 100644 index 000000000..7a6f08424 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import com.dfsek.terra.api.properties.Properties; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.BiomeBase; + + +public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java new file mode 100644 index 000000000..451fc5863 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java @@ -0,0 +1,188 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import com.google.common.collect.ImmutableMap; +import com.mojang.serialization.Lifecycle; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.IRegistryWritable; +import net.minecraft.core.RegistryMaterials; +import net.minecraft.data.RegistryGeneration; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.resources.ResourceKey; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.BiomeFog.GrassColor; +import net.minecraft.world.level.biome.BiomeSettingsGeneration; +import net.minecraft.world.level.biome.BiomeSettingsMobs; +import org.bukkit.NamespacedKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.world.biome.Biome; +import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; +import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; +import com.dfsek.terra.registry.master.ConfigRegistry; + + +public class NMSBiomeInjector { + private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class); + private static final Map> terraBiomeMap = new HashMap<>(); + + + public static void registerBiomes(ConfigRegistry configRegistry) { + try { + LOGGER.info("Hacking biome registry..."); + IRegistryWritable biomeRegistry = (IRegistryWritable) Registries.biomeRegistry(); + Field frozen = RegistryMaterials.class.getDeclaredField("bL"); // registry frozen field + frozen.setAccessible(true); + frozen.set(biomeRegistry, false); + + configRegistry.forEach(pack -> pack.getRegistry(Biome.class).forEach((key, biome) -> { + try { + BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); + NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); + MinecraftKey vanillaMinecraftKey = new MinecraftKey(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); + BiomeBase platform = createBiome( + biome, + biomeRegistry.a(vanillaMinecraftKey) // get + ); + + ResourceKey delegateKey = ResourceKey.a(IRegistry.aP, new MinecraftKey("terra", createBiomeID(pack, key))); + + RegistryGeneration.a(RegistryGeneration.i, delegateKey, platform); + biomeRegistry.a(delegateKey, platform, Lifecycle.stable()); + platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); + + terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.a()); + + LOGGER.debug("Registered biome: " + delegateKey); + } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + })); + + frozen.set(biomeRegistry, true); // freeze registry again :) + + LOGGER.info("Doing tag garbage...."); + Map, List>> collect = biomeRegistry + .g() // streamKeysAndEntries + .collect(HashMap::new, + (map, pair) -> + map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().a().toList())), + HashMap::putAll); + + terraBiomeMap + .forEach((vb, terraBiomes) -> + getEntry(biomeRegistry, vb) + .ifPresentOrElse( + vanilla -> terraBiomes + .forEach(tb -> getEntry(biomeRegistry, tb) + .ifPresentOrElse( + terra -> { + LOGGER.debug(vanilla.e().orElseThrow().a() + + " (vanilla for " + + terra.e().orElseThrow().a() + + ": " + + vanilla.c().toList()); + + vanilla.c() + .forEach( + tag -> collect + .computeIfAbsent(tag, + t -> new ArrayList<>()) + .add(terra)); + }, + () -> LOGGER.error( + "No such biome: {}", + tb))), + () -> LOGGER.error("No vanilla biome: {}", vb))); + + biomeRegistry.k(); // clearTags + biomeRegistry.a(ImmutableMap.copyOf(collect)); // populateTags + + } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + public static Optional> getEntry(IRegistry registry, MinecraftKey identifier) { + return registry.b(identifier) + .flatMap(registry::c) + .map(registry::c); + } + + private static BiomeBase createBiome(Biome biome, BiomeBase vanilla) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + BiomeBase.a builder = new BiomeBase.a(); // Builder + + Field f = BiomeBase.class.getDeclaredField("l"); // category + f.setAccessible(true); + builder.a((BiomeBase.Geography) f.get(vanilla)) + .a(vanilla.c()); // getPrecipitation + + + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); // spawn settings + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(vanilla); + builder.a(biomeSettingMobs); + + + BiomeSettingsGeneration.a generationBuilder = new BiomeSettingsGeneration.a(); // builder + builder.a(generationBuilder.a()) + .a(vanilla.c()) + .b(vanilla.h()) // precipitation + .a(vanilla.i()); // temp + + + BiomeFog.a effects = new BiomeFog.a(); // Builder + effects.a(GrassColor.a); // magic + + VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); + + // fog + effects.a(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.f())); + + // water + effects.b(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.k())); + + // water fog + effects.c(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.l())); + + // sky + effects.d(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.a())); + + if(vanillaBiomeProperties.getFoliageColor() == null) { + vanilla.j().e().ifPresent(effects::e); + } else { + // foliage + effects.e(vanillaBiomeProperties.getFoliageColor()); + } + + if(vanillaBiomeProperties.getGrassColor() == null) { + vanilla.j().f().ifPresent(effects::f); + } else { + // grass + effects.f(vanillaBiomeProperties.getGrassColor()); + } + + builder.a(effects.a()); // build() + + return builder.a(); // build() + } + + public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { + return pack.getID() + .toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT); + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java new file mode 100644 index 000000000..cd689435c --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java @@ -0,0 +1,54 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import com.mojang.serialization.Codec; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Climate.Sampler; +import net.minecraft.world.level.biome.WorldChunkManager; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; + +import com.dfsek.terra.api.util.generic.Lazy; +import com.dfsek.terra.api.world.biome.generation.BiomeProvider; +import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; + + +public class NMSBiomeProvider extends WorldChunkManager { + private final BiomeProvider delegate; + private final WorldChunkManager vanilla; + private final long seed; + + private static final Lazy> biomeRegistry = Lazy.lazy(() -> { + DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); + return dedicatedserver.aU().b(IRegistry.aP); + }); + + public NMSBiomeProvider(BiomeProvider delegate, WorldChunkManager vanilla, long seed) { + super(delegate.stream().map(biome -> biomeRegistry.value().g(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()))); + this.delegate = delegate; + this.vanilla = vanilla; + this.seed = seed; + } + + @Override + protected Codec a() { + return WorldChunkManager.a; + } + + @Override + public WorldChunkManager a(long seed) { + return withSeed(seed); + } + + public WorldChunkManager withSeed(long seed) { + return new NMSBiomeProvider(delegate, vanilla, seed); + } + + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler sampler) { + //return CraftBlock.biomeToBiomeBase(biomeRegistry.value(), ((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getHandle()); + return biomeRegistry.value().g(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()); + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java new file mode 100644 index 000000000..5696f0001 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java @@ -0,0 +1,239 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.util.generic.Lazy; +import com.dfsek.terra.api.world.biome.generation.BiomeProvider; +import com.dfsek.terra.api.world.info.WorldProperties; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistryCustom; +import net.minecraft.core.SectionPosition; +import net.minecraft.server.level.RegionLimitedWorldAccess; +import net.minecraft.world.level.BlockColumn; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.LevelHeightAccessor; +import net.minecraft.world.level.StructureManager; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.biome.Climate; +import net.minecraft.world.level.biome.Climate.Sampler; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.ChunkGeneratorAbstract; +import net.minecraft.world.level.levelgen.HeightMap; +import net.minecraft.world.level.levelgen.WorldGenStage; +import net.minecraft.world.level.levelgen.blending.Blender; +import net.minecraft.world.level.levelgen.structure.StructureSet; +import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; +import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; +import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureManager; +import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.stream.Collectors; + + +public class NMSChunkGeneratorDelegate extends ChunkGenerator { + private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); + private final NMSBiomeProvider biomeSource; + private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; + + private final ChunkGenerator vanilla; + private final ConfigPack pack; + + private final long seed; + + private final Map>> h = new Object2ObjectArrayMap<>(); + private static final Lazy> EMPTY = Lazy.lazy(List::of); + + + public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { + super(Registries.structureSet(), Optional.empty(), biomeProvider, biomeProvider, seed); + this.delegate = pack.getGeneratorProvider().newInstance(pack); + this.vanilla = vanilla; + this.biomeSource = biomeProvider; + this.pack = pack; + this.seed = seed; + } + + @Override //applyCarvers + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long var2, BiomeManager var4, StructureManager var5, + IChunkAccess ichunkaccess, WorldGenStage.Features var7) { + // no-op + } + + @Override // getSeaLevel + public int g() { + return vanilla.g(); + } + + @Override //fillFromNoise + public CompletableFuture a(Executor executor, Blender blender, StructureManager structuremanager, + IChunkAccess ichunkaccess) { + return vanilla.a(executor, blender, structuremanager, ichunkaccess); + } + + + @Override //buildSurface. Used to be buildBase + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, IChunkAccess ichunkaccess) { + + } + + @Override + protected Codec b() { + return ChunkGeneratorAbstract.a; + } + + @Override // getColumn + public BlockColumn a(int x, int z, LevelHeightAccessor height) { + IBlockData[] array = new IBlockData[height.v_()]; + WorldProperties properties = new NMSWorldProperties(seed, height); + BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); + for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { + array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) + .getHandle()).getState(); + } + return new BlockColumn(getMinimumY(), array); + } + + @Override // withSeed + public ChunkGenerator a(long seed) { + return new NMSChunkGeneratorDelegate(vanilla, pack, biomeSource, seed); + } + + //spawnOriginalMobs + public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { + vanilla.a(regionlimitedworldaccess); + } + + // getGenDepth + public int f() { + return vanilla.f(); + } + + // climateSampler + public Sampler d() { + return Climate.a(); + } + + //getMinY + @Override + public int h() { + return vanilla.h(); + } + + @Override // getBaseHeight + public int a(int x, int z, HeightMap.Type heightmap, LevelHeightAccessor height) { + WorldProperties properties = new NMSWorldProperties(seed, height); + int y = properties.getMaxHeight(); + BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); + while(y >= getMinimumY() && !heightmap.e().test( + ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { + y--; + } + return y; + } + + @Override + public void a(IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, + DefinedStructureManager definedstructuremanager, long i) { + super.a(iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i); + } + + @Nullable + @Override + public List a(ConcentricRingsStructurePlacement concentricringsstructureplacement) { + this.i(); + return this.h.getOrDefault(concentricringsstructureplacement, EMPTY).value(); + } + + private volatile boolean rings = false; + + @Override + public synchronized void i() { + if(!this.rings) { + super.i(); + this.populateStrongholdData(); + this.rings = true; + } + } + + private void populateStrongholdData() { + LOGGER.info("Generating safe stronghold data. This may take up to a minute."); + Set> set = this.d.b(); + a().map(h -> h.a()).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric. + StructurePlacement structureplacement = holder.b(); + if(structureplacement instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { + if(holder.a().stream().anyMatch((structureset_a1) -> structureset_a1.a(set::contains))) { + this.h.put(concentricringsstructureplacement, + Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement))); + } + } + }); + } + + private List generateRingPositions(StructureSet holder, + ConcentricRingsStructurePlacement concentricringsstructureplacement) { + if(concentricringsstructureplacement.d() == 0) { + return List.of(); + } + List list = new ArrayList<>(); + Set> set = holder.a().stream().flatMap((structureset_a) -> (structureset_a.a().a()).a().a()).collect( + Collectors.toSet()); + int i = concentricringsstructureplacement.b(); + int j = concentricringsstructureplacement.d(); + int k = concentricringsstructureplacement.c(); + Random random = new Random(); + random.setSeed(this.j); + double d0 = random.nextDouble() * Math.PI * 2.0; + int l = 0; + int i1 = 0; + + for(int j1 = 0; j1 < j; ++j1) { + double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5) * (double) i * 2.5; + int k1 = (int) Math.round(Math.cos(d0) * d1); + int l1 = (int) Math.round(Math.sin(d0) * d1); + int i2 = SectionPosition.a(k1, 8); + int j2 = SectionPosition.a(l1, 8); + Objects.requireNonNull(set); + Pair> pair = this.c.a(i2, 0, j2, 112, set::contains, random, this.d()); + if(pair != null) { + BlockPosition blockposition = pair.getFirst(); + k1 = SectionPosition.a(blockposition.u()); + l1 = SectionPosition.a(blockposition.w()); + } + + list.add(new ChunkCoordIntPair(k1, l1)); + d0 += 6.283185307179586 / (double) k; + ++l; + if(l == k) { + ++i1; + l = 0; + k += 2 * k / (i1 + 1); + k = Math.min(k, j - j1); + d0 += random.nextDouble() * Math.PI * 2.0; + } + } + return list; + + } + + public int getMinimumY() { + return h(); + } + + @Override //addDebugScreenInfo + public void a(List arg0, BlockPosition arg1) { + + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java new file mode 100644 index 000000000..61efc587d --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInitializer.java @@ -0,0 +1,15 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import org.bukkit.Bukkit; + +import com.dfsek.terra.bukkit.PlatformImpl; +import com.dfsek.terra.bukkit.nms.Initializer; + + +public class NMSInitializer implements Initializer { + @Override + public void initialize(PlatformImpl platform) { + NMSBiomeInjector.registerBiomes(platform.getRawConfigRegistry()); + Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java new file mode 100644 index 000000000..84ca1ffb7 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.level.chunk.ChunkGenerator; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldInitEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; + + +public class NMSInjectListener implements Listener { + private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class); + private static final Set INJECTED = new HashSet<>(); + private static final ReentrantLock INJECT_LOCK = new ReentrantLock(); + + @EventHandler + public void onWorldInit(WorldInitEvent event) { + if (!INJECTED.contains(event.getWorld()) && event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) { + INJECT_LOCK.lock(); + INJECTED.add(event.getWorld()); + LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); + CraftWorld craftWorld = (CraftWorld) event.getWorld(); + WorldServer serverWorld = craftWorld.getHandle(); + + ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); + + ChunkGenerator vanilla = serverWorld.k().g(); + NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.e(), craftWorld.getSeed()); + NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); + + custom.conf = vanilla.conf; // world config from Spigot + + serverWorld.k().a.u = custom; + + LOGGER.info("Successfully injected into world."); + + serverWorld.k().a.u.i(); // generate stronghold data now + + INJECT_LOCK.unlock(); + } + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java new file mode 100644 index 000000000..c27e7d2c7 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java @@ -0,0 +1,36 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import net.minecraft.world.level.LevelHeightAccessor; + +import com.dfsek.terra.api.world.info.WorldProperties; + + +public class NMSWorldProperties implements WorldProperties { + private final long seed; + private final LevelHeightAccessor height; + + public NMSWorldProperties(long seed, LevelHeightAccessor height) { + this.seed = seed; + this.height = height; + } + + @Override + public Object getHandle() { + return height; + } + + @Override + public long getSeed() { + return seed; + } + + @Override + public int getMaxHeight() { + return height.ag(); + } + + @Override + public int getMinHeight() { + return height.u_(); + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java new file mode 100644 index 000000000..e3c2f8566 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java @@ -0,0 +1,30 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import net.minecraft.core.IRegistry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.levelgen.structure.StructureSet; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; + + +public class Registries { + private static IRegistry getRegistry(ResourceKey> key) { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + return dedicatedserver + .aU() // getRegistryManager + .b( // getRegistry + key + ); + } + + public static IRegistry biomeRegistry() { + return getRegistry(IRegistry.aP); + } + + public static IRegistry structureSet() { + return getRegistry(IRegistry.aM); + } +} From 69b994df0d1da0589e755c1f18c3327ad9017fb8 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 17:04:00 -0700 Subject: [PATCH 03/17] 1.19 bukkit compiles now --- .../bukkit/nms/v1_19_R1/build.gradle.kts | 6 +- .../bukkit/nms/v1_19_R1/NMSBiomeInfo.java | 8 +- .../bukkit/nms/v1_19_R1/NMSBiomeInjector.java | 133 +++++----- .../bukkit/nms/v1_19_R1/NMSBiomeProvider.java | 43 +--- .../v1_19_R1/NMSChunkGeneratorDelegate.java | 235 +++++------------- .../nms/v1_19_R1/NMSInjectListener.java | 14 +- .../nms/v1_19_R1/NMSWorldProperties.java | 4 +- .../terra/bukkit/nms/v1_19_R1/Reflection.java | 25 ++ .../terra/bukkit/nms/v1_19_R1/Registries.java | 20 +- 9 files changed, 176 insertions(+), 312 deletions(-) create mode 100644 platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts index 868c0a8de..c0208ad40 100644 --- a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts +++ b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts @@ -1,12 +1,14 @@ plugins { id("io.papermc.paperweight.userdev") version "1.3.3" } +repositories { + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") +} dependencies { api(project(":platforms:bukkit:common")) paperDevBundle("1.19-R0.1-SNAPSHOT") - - compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18.2-R0.1-SNAPSHOT") + implementation("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT") } tasks { diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java index 7a6f08424..31024cf32 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInfo.java @@ -1,10 +1,10 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; -import com.dfsek.terra.api.properties.Properties; - import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Biome; + +import com.dfsek.terra.api.properties.Properties; -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { +public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java index 451fc5863..f77fbefab 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java @@ -3,23 +3,19 @@ import com.google.common.collect.ImmutableMap; import com.mojang.serialization.Lifecycle; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.core.IRegistryWritable; -import net.minecraft.core.RegistryMaterials; -import net.minecraft.data.RegistryGeneration; -import net.minecraft.resources.MinecraftKey; +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.WritableRegistry; +import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; -import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSpecialEffects; import org.bukkit.NamespacedKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,7 +25,6 @@ import java.util.Optional; import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.world.biome.Biome; import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; import com.dfsek.terra.registry.master.ConfigRegistry; @@ -37,49 +32,48 @@ public class NMSBiomeInjector { private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class); - private static final Map> terraBiomeMap = new HashMap<>(); + private static final Map> terraBiomeMap = new HashMap<>(); public static void registerBiomes(ConfigRegistry configRegistry) { try { LOGGER.info("Hacking biome registry..."); - IRegistryWritable biomeRegistry = (IRegistryWritable) Registries.biomeRegistry(); - Field frozen = RegistryMaterials.class.getDeclaredField("bL"); // registry frozen field - frozen.setAccessible(true); - frozen.set(biomeRegistry, false); + WritableRegistry biomeRegistry = (WritableRegistry) Registries.biomeRegistry(); - configRegistry.forEach(pack -> pack.getRegistry(Biome.class).forEach((key, biome) -> { + Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); + + configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { try { BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - MinecraftKey vanillaMinecraftKey = new MinecraftKey(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - BiomeBase platform = createBiome( + ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); + Biome platform = createBiome( biome, - biomeRegistry.a(vanillaMinecraftKey) // get + Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)) // get ); - ResourceKey delegateKey = ResourceKey.a(IRegistry.aP, new MinecraftKey("terra", createBiomeID(pack, key))); + ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", createBiomeID(pack, key))); - RegistryGeneration.a(RegistryGeneration.i, delegateKey, platform); - biomeRegistry.a(delegateKey, platform, Lifecycle.stable()); + BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); + biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.a()); + terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); LOGGER.debug("Registered biome: " + delegateKey); } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } })); - - frozen.set(biomeRegistry, true); // freeze registry again :) + + Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .g() // streamKeysAndEntries + Map, List>> collect = biomeRegistry + .getTags() // streamKeysAndEntries .collect(HashMap::new, (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().a().toList())), + map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), HashMap::putAll); terraBiomeMap @@ -90,13 +84,13 @@ public static void registerBiomes(ConfigRegistry configRegistry) { .forEach(tb -> getEntry(biomeRegistry, tb) .ifPresentOrElse( terra -> { - LOGGER.debug(vanilla.e().orElseThrow().a() + + LOGGER.debug(vanilla.unwrapKey().orElseThrow().location() + " (vanilla for " + - terra.e().orElseThrow().a() + + terra.unwrapKey().orElseThrow().location() + ": " + - vanilla.c().toList()); + vanilla.tags().toList()); - vanilla.c() + vanilla.tags() .forEach( tag -> collect .computeIfAbsent(tag, @@ -108,77 +102,64 @@ public static void registerBiomes(ConfigRegistry configRegistry) { tb))), () -> LOGGER.error("No vanilla biome: {}", vb))); - biomeRegistry.k(); // clearTags - biomeRegistry.a(ImmutableMap.copyOf(collect)); // populateTags + biomeRegistry.resetTags(); + biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception) { + } catch(SecurityException | IllegalArgumentException exception) { throw new RuntimeException(exception); } } - public static Optional> getEntry(IRegistry registry, MinecraftKey identifier) { - return registry.b(identifier) - .flatMap(registry::c) - .map(registry::c); + @SuppressWarnings("unchecked, rawtypes") + public static Optional> getEntry(Registry registry, ResourceLocation identifier) { + return (Optional) registry.getOptional(identifier) + .flatMap(registry::getResourceKey) + .map(registry::getHolder); } - private static BiomeBase createBiome(Biome biome, BiomeBase vanilla) + private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - BiomeBase.a builder = new BiomeBase.a(); // Builder - - Field f = BiomeBase.class.getDeclaredField("l"); // category - f.setAccessible(true); - builder.a((BiomeBase.Geography) f.get(vanilla)) - .a(vanilla.c()); // getPrecipitation + Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); + builder + .precipitation(vanilla.getPrecipitation()) + .temperature(vanilla.getBaseTemperature()) + .mobSpawnSettings(vanilla.getMobSettings()) + .generationSettings(vanilla.getGenerationSettings()); - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); // spawn settings - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(vanilla); - builder.a(biomeSettingMobs); - - - BiomeSettingsGeneration.a generationBuilder = new BiomeSettingsGeneration.a(); // builder - builder.a(generationBuilder.a()) - .a(vanilla.c()) - .b(vanilla.h()) // precipitation - .a(vanilla.i()); // temp + + + BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - BiomeFog.a effects = new BiomeFog.a(); // Builder - effects.a(GrassColor.a); // magic + effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - // fog - effects.a(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.f())); + effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - // water - effects.b(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.k())); + .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - // water fog - effects.c(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.l())); + .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - // sky - effects.d(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.a())); + .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.j().e().ifPresent(effects::e); + vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); } else { - // foliage - effects.e(vanillaBiomeProperties.getFoliageColor()); + effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); } if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.j().f().ifPresent(effects::f); + vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); } else { // grass - effects.f(vanillaBiomeProperties.getGrassColor()); + effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); } - builder.a(effects.a()); // build() + builder.specialEffects(effects.build()); - return builder.a(); // build() + return builder.build(); } public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java index cd689435c..36433165b 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeProvider.java @@ -2,53 +2,34 @@ import com.mojang.serialization.Codec; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.core.Registry; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.biome.WorldChunkManager; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.jetbrains.annotations.NotNull; -import com.dfsek.terra.api.util.generic.Lazy; import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -public class NMSBiomeProvider extends WorldChunkManager { +public class NMSBiomeProvider extends BiomeSource { private final BiomeProvider delegate; - private final WorldChunkManager vanilla; private final long seed; + private final Registry biomeRegistry = Registries.biomeRegistry(); - private static final Lazy> biomeRegistry = Lazy.lazy(() -> { - DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); - return dedicatedserver.aU().b(IRegistry.aP); - }); - - public NMSBiomeProvider(BiomeProvider delegate, WorldChunkManager vanilla, long seed) { - super(delegate.stream().map(biome -> biomeRegistry.value().g(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()))); + public NMSBiomeProvider(BiomeProvider delegate, long seed) { + super(delegate.stream().map(biome -> Registries.biomeRegistry().getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()))); this.delegate = delegate; - this.vanilla = vanilla; this.seed = seed; } @Override - protected Codec a() { - return WorldChunkManager.a; - } - - @Override - public WorldChunkManager a(long seed) { - return withSeed(seed); - } - - public WorldChunkManager withSeed(long seed) { - return new NMSBiomeProvider(delegate, vanilla, seed); + protected @NotNull Codec codec() { + return BiomeSource.CODEC; } @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler sampler) { - //return CraftBlock.biomeToBiomeBase(biomeRegistry.value(), ((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getHandle()); - return biomeRegistry.value().g(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()); + public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { + return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()); } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java index 5696f0001..32a785ec5 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java @@ -1,51 +1,33 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.util.generic.Lazy; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.api.world.info.WorldProperties; - -import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistryCustom; -import net.minecraft.core.SectionPosition; -import net.minecraft.server.level.RegionLimitedWorldAccess; -import net.minecraft.world.level.BlockColumn; -import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.WorldGenRegion; import net.minecraft.world.level.LevelHeightAccessor; +import net.minecraft.world.level.NoiseColumn; import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.biome.Climate; -import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.ChunkGeneratorAbstract; -import net.minecraft.world.level.levelgen.HeightMap; -import net.minecraft.world.level.levelgen.WorldGenStage; +import net.minecraft.world.level.levelgen.GenerationStep.Carving; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.blending.Blender; -import net.minecraft.world.level.levelgen.structure.StructureSet; -import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; -import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureManager; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nullable; -import java.util.*; +import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import java.util.stream.Collectors; + +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.world.biome.generation.BiomeProvider; +import com.dfsek.terra.api.world.info.WorldProperties; public class NMSChunkGeneratorDelegate extends ChunkGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); - private final NMSBiomeProvider biomeSource; private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; private final ChunkGenerator vanilla; @@ -53,91 +35,62 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator { private final long seed; - private final Map>> h = new Object2ObjectArrayMap<>(); - private static final Lazy> EMPTY = Lazy.lazy(List::of); - - public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { - super(Registries.structureSet(), Optional.empty(), biomeProvider, biomeProvider, seed); + super(Registries.structureSet(), Optional.empty(), biomeProvider); this.delegate = pack.getGeneratorProvider().newInstance(pack); this.vanilla = vanilla; - this.biomeSource = biomeProvider; this.pack = pack; this.seed = seed; } - - @Override //applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long var2, BiomeManager var4, StructureManager var5, - IChunkAccess ichunkaccess, WorldGenStage.Features var7) { - // no-op - } - - @Override // getSeaLevel - public int g() { - return vanilla.g(); - } - - @Override //fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return vanilla.a(executor, blender, structuremanager, ichunkaccess); - } - - - @Override //buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, IChunkAccess ichunkaccess) { - + + @Override + protected @NotNull Codec codec() { + return ChunkGenerator.CODEC; } @Override - protected Codec b() { - return ChunkGeneratorAbstract.a; + public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, + @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) { + // no-op } - @Override // getColumn - public BlockColumn a(int x, int z, LevelHeightAccessor height) { - IBlockData[] array = new IBlockData[height.v_()]; - WorldProperties properties = new NMSWorldProperties(seed, height); - BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { - array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) - .getHandle()).getState(); - } - return new BlockColumn(getMinimumY(), array); + @Override + public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, @NotNull ChunkAccess chunk) { + // no-op } - @Override // withSeed - public ChunkGenerator a(long seed) { - return new NMSChunkGeneratorDelegate(vanilla, pack, biomeSource, seed); + @Override + public void spawnOriginalMobs(@NotNull WorldGenRegion region) { + vanilla.spawnOriginalMobs(region); } - //spawnOriginalMobs - public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { - vanilla.a(regionlimitedworldaccess); + @Override + public int getGenDepth() { + return vanilla.getGenDepth(); } - // getGenDepth - public int f() { - return vanilla.f(); + @Override + public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, @NotNull RandomState noiseConfig, + @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { + return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk); } - // climateSampler - public Sampler d() { - return Climate.a(); + @Override + public int getSeaLevel() { + return vanilla.getSeaLevel(); } - //getMinY @Override - public int h() { - return vanilla.h(); + public int getMinY() { + return vanilla.getMinY(); } - @Override // getBaseHeight - public int a(int x, int z, HeightMap.Type heightmap, LevelHeightAccessor height) { - WorldProperties properties = new NMSWorldProperties(seed, height); + @Override + public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { + WorldProperties properties = new NMSWorldProperties(seed, world); int y = properties.getMaxHeight(); BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - while(y >= getMinimumY() && !heightmap.e().test( + while(y >= getMinY() && !heightmap.isOpaque().test( ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { y--; } @@ -145,95 +98,19 @@ public int a(int x, int z, HeightMap.Type heightmap, LevelHeightAccessor height) } @Override - public void a(IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, - DefinedStructureManager definedstructuremanager, long i) { - super.a(iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i); - } - - @Nullable - @Override - public List a(ConcentricRingsStructurePlacement concentricringsstructureplacement) { - this.i(); - return this.h.getOrDefault(concentricringsstructureplacement, EMPTY).value(); - } - - private volatile boolean rings = false; - - @Override - public synchronized void i() { - if(!this.rings) { - super.i(); - this.populateStrongholdData(); - this.rings = true; - } - } - - private void populateStrongholdData() { - LOGGER.info("Generating safe stronghold data. This may take up to a minute."); - Set> set = this.d.b(); - a().map(h -> h.a()).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric. - StructurePlacement structureplacement = holder.b(); - if(structureplacement instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { - if(holder.a().stream().anyMatch((structureset_a1) -> structureset_a1.a(set::contains))) { - this.h.put(concentricringsstructureplacement, - Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement))); - } - } - }); - } - - private List generateRingPositions(StructureSet holder, - ConcentricRingsStructurePlacement concentricringsstructureplacement) { - if(concentricringsstructureplacement.d() == 0) { - return List.of(); - } - List list = new ArrayList<>(); - Set> set = holder.a().stream().flatMap((structureset_a) -> (structureset_a.a().a()).a().a()).collect( - Collectors.toSet()); - int i = concentricringsstructureplacement.b(); - int j = concentricringsstructureplacement.d(); - int k = concentricringsstructureplacement.c(); - Random random = new Random(); - random.setSeed(this.j); - double d0 = random.nextDouble() * Math.PI * 2.0; - int l = 0; - int i1 = 0; - - for(int j1 = 0; j1 < j; ++j1) { - double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5) * (double) i * 2.5; - int k1 = (int) Math.round(Math.cos(d0) * d1); - int l1 = (int) Math.round(Math.sin(d0) * d1); - int i2 = SectionPosition.a(k1, 8); - int j2 = SectionPosition.a(l1, 8); - Objects.requireNonNull(set); - Pair> pair = this.c.a(i2, 0, j2, 112, set::contains, random, this.d()); - if(pair != null) { - BlockPosition blockposition = pair.getFirst(); - k1 = SectionPosition.a(blockposition.u()); - l1 = SectionPosition.a(blockposition.w()); - } - - list.add(new ChunkCoordIntPair(k1, l1)); - d0 += 6.283185307179586 / (double) k; - ++l; - if(l == k) { - ++i1; - l = 0; - k += 2 * k / (i1 + 1); - k = Math.min(k, j - j1); - d0 += random.nextDouble() * Math.PI * 2.0; - } + public @NotNull NoiseColumn getBaseColumn(int x, int z, @NotNull LevelHeightAccessor world, @NotNull RandomState noiseConfig) { + BlockState[] array = new BlockState[world.getHeight()]; + WorldProperties properties = new NMSWorldProperties(seed, world); + BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); + for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { + array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) + .getHandle()).getState(); } - return list; - + return new NoiseColumn(getMinY(), array); } - public int getMinimumY() { - return h(); - } - - @Override //addDebugScreenInfo - public void a(List arg0, BlockPosition arg1) { + @Override + public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java index 84ca1ffb7..c647afbd5 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSInjectListener.java @@ -1,9 +1,9 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; -import net.minecraft.server.level.WorldServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkGenerator; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.WorldInitEvent; @@ -30,22 +30,20 @@ public void onWorldInit(WorldInitEvent event) { INJECTED.add(event.getWorld()); LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); CraftWorld craftWorld = (CraftWorld) event.getWorld(); - WorldServer serverWorld = craftWorld.getHandle(); + ServerLevel serverWorld = craftWorld.getHandle(); ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - ChunkGenerator vanilla = serverWorld.k().g(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.e(), craftWorld.getSeed()); + ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); + NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); custom.conf = vanilla.conf; // world config from Spigot - serverWorld.k().a.u = custom; + serverWorld.getChunkSource().chunkMap.generator = custom; LOGGER.info("Successfully injected into world."); - serverWorld.k().a.u.i(); // generate stronghold data now - INJECT_LOCK.unlock(); } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java index c27e7d2c7..b068231f8 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSWorldProperties.java @@ -26,11 +26,11 @@ public long getSeed() { @Override public int getMaxHeight() { - return height.ag(); + return height.getMaxBuildHeight(); } @Override public int getMinHeight() { - return height.u_(); + return height.getMinBuildHeight(); } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java new file mode 100644 index 000000000..35beefb41 --- /dev/null +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java @@ -0,0 +1,25 @@ +package com.dfsek.terra.bukkit.nms.v1_19_R1; + +import net.minecraft.core.MappedRegistry; +import xyz.jpenilla.reflectionremapper.ReflectionRemapper; +import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; +import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; +import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; + + +public class Reflection { + public static final MappedRegistryProxy MAPPED_REGISTRY; + + static { + ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); + ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, Reflection.class.getClassLoader()); + + MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); + } + + @Proxies + public interface MappedRegistryProxy { + @FieldSetter("frozen") + void setFrozen(MappedRegistry instance, boolean frozen); + } +} diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java index e3c2f8566..622589a77 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Registries.java @@ -1,30 +1,30 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; -import net.minecraft.core.IRegistry; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.structure.StructureSet; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; public class Registries { - private static IRegistry getRegistry(ResourceKey> key) { + private static Registry getRegistry(ResourceKey> key) { CraftServer craftserver = (CraftServer) Bukkit.getServer(); DedicatedServer dedicatedserver = craftserver.getServer(); return dedicatedserver - .aU() // getRegistryManager - .b( // getRegistry + .registryAccess() + .registryOrThrow( // getRegistry key ); } - public static IRegistry biomeRegistry() { - return getRegistry(IRegistry.aP); + public static Registry biomeRegistry() { + return getRegistry(Registry.BIOME_REGISTRY); } - public static IRegistry structureSet() { - return getRegistry(IRegistry.aM); + public static Registry structureSet() { + return getRegistry(Registry.STRUCTURE_SET_REGISTRY); } } From b3efaa4f6a8d38609caa5c7e54b1a9aff74be45c Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 17:33:14 -0700 Subject: [PATCH 04/17] use paperweight for 1.18.2 --- platforms/bukkit/build.gradle.kts | 1 + .../bukkit/nms/v1_18_R2/build.gradle.kts | 19 ++++++++++++++++--- .../bukkit/nms/v1_19_R1/build.gradle.kts | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 94c915197..6e0bf4927 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -19,6 +19,7 @@ val purpurURL = "https://api.purpurmc.org/v2/purpur/%version%/latest/download" dependencies { shaded(project(":platforms:bukkit:common")) shaded(project(":platforms:bukkit:nms:v1_18_R2")) + shaded(project(":platforms:bukkit:nms:v1_19_R1")) } val throttleCoreCount = 0 diff --git a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts b/platforms/bukkit/nms/v1_18_R2/build.gradle.kts index f3cb6a90a..ddf11570f 100644 --- a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts +++ b/platforms/bukkit/nms/v1_18_R2/build.gradle.kts @@ -1,6 +1,19 @@ +plugins { + id("io.papermc.paperweight.userdev") version "1.3.3" +} + +repositories { + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") +} + dependencies { api(project(":platforms:bukkit:common")) - - compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-20220519.005047-123") - compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18.2-R0.1-SNAPSHOT") + paperDevBundle("1.18.2-R0.1-SNAPSHOT") + implementation("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT") +} + +tasks { + assemble { + dependsOn(reobfJar) + } } \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts index c0208ad40..5561d17c8 100644 --- a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts +++ b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("io.papermc.paperweight.userdev") version "1.3.3" } + repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") } From 0c2a8c6bbc565dfd97a5a5803ccfda70c748f47d Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 18:13:00 -0700 Subject: [PATCH 05/17] use mapped 1.18 NMS --- .../bukkit/nms/v1_18_R2/NMSBiomeInfo.java | 8 +- .../bukkit/nms/v1_18_R2/NMSBiomeInjector.java | 152 ++++++-------- .../bukkit/nms/v1_18_R2/NMSBiomeProvider.java | 53 +++-- .../v1_18_R2/NMSChunkGeneratorDelegate.java | 194 +++++++++--------- .../nms/v1_18_R2/NMSInjectListener.java | 12 +- .../nms/v1_18_R2/NMSWorldProperties.java | 4 +- .../terra/bukkit/nms/v1_18_R2/Reflection.java | 35 ++++ .../terra/bukkit/nms/v1_18_R2/Registries.java | 22 +- .../bukkit/nms/v1_19_R1/NMSBiomeInjector.java | 7 +- 9 files changed, 249 insertions(+), 238 deletions(-) create mode 100644 platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java index 2cba0bfe2..7e04ef178 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInfo.java @@ -1,10 +1,10 @@ package com.dfsek.terra.bukkit.nms.v1_18_R2; -import com.dfsek.terra.api.properties.Properties; - import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Biome; + +import com.dfsek.terra.api.properties.Properties; -public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { +public record NMSBiomeInfo(ResourceKey biomeKey) implements Properties { } diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java index cbd8ab74b..544072061 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java @@ -3,23 +3,19 @@ import com.google.common.collect.ImmutableMap; import com.mojang.serialization.Lifecycle; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.core.IRegistryWritable; -import net.minecraft.core.RegistryMaterials; -import net.minecraft.data.RegistryGeneration; -import net.minecraft.resources.MinecraftKey; +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.WritableRegistry; +import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; -import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSpecialEffects; import org.bukkit.NamespacedKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,7 +25,6 @@ import java.util.Optional; import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.api.world.biome.Biome; import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; import com.dfsek.terra.registry.master.ConfigRegistry; @@ -37,49 +32,48 @@ public class NMSBiomeInjector { private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class); - private static final Map> terraBiomeMap = new HashMap<>(); + private static final Map> terraBiomeMap = new HashMap<>(); public static void registerBiomes(ConfigRegistry configRegistry) { try { LOGGER.info("Hacking biome registry..."); - IRegistryWritable biomeRegistry = (IRegistryWritable) Registries.biomeRegistry(); - Field frozen = RegistryMaterials.class.getDeclaredField("bL"); // registry frozen field - frozen.setAccessible(true); - frozen.set(biomeRegistry, false); + WritableRegistry biomeRegistry = (WritableRegistry) Registries.biomeRegistry(); - configRegistry.forEach(pack -> pack.getRegistry(Biome.class).forEach((key, biome) -> { + Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, false); + + configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> { try { BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome(); NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); - MinecraftKey vanillaMinecraftKey = new MinecraftKey(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); - BiomeBase platform = createBiome( + ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey()); + Biome platform = createBiome( biome, - biomeRegistry.a(vanillaMinecraftKey) // get + biomeRegistry.get(vanillaMinecraftKey) // get ); - ResourceKey delegateKey = ResourceKey.a(IRegistry.aP, new MinecraftKey("terra", createBiomeID(pack, key))); + ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", createBiomeID(pack, key))); - RegistryGeneration.a(RegistryGeneration.i, delegateKey, platform); - biomeRegistry.a(delegateKey, platform, Lifecycle.stable()); + BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); + biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); platformBiome.getContext().put(new NMSBiomeInfo(delegateKey)); - terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.a()); + terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location()); LOGGER.debug("Registered biome: " + delegateKey); } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } })); - - frozen.set(biomeRegistry, true); // freeze registry again :) + + Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) LOGGER.info("Doing tag garbage...."); - Map, List>> collect = biomeRegistry - .g() // streamKeysAndEntries + Map, List>> collect = biomeRegistry + .getTags() // streamKeysAndEntries .collect(HashMap::new, (map, pair) -> - map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().a().toList())), + map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), HashMap::putAll); terraBiomeMap @@ -90,13 +84,13 @@ public static void registerBiomes(ConfigRegistry configRegistry) { .forEach(tb -> getEntry(biomeRegistry, tb) .ifPresentOrElse( terra -> { - LOGGER.debug(vanilla.e().orElseThrow().a() + + LOGGER.debug(vanilla.unwrapKey().orElseThrow().location() + " (vanilla for " + - terra.e().orElseThrow().a() + + terra.unwrapKey().orElseThrow().location() + ": " + - vanilla.c().toList()); + vanilla.tags().toList()); - vanilla.c() + vanilla.tags() .forEach( tag -> collect .computeIfAbsent(tag, @@ -108,77 +102,63 @@ public static void registerBiomes(ConfigRegistry configRegistry) { tb))), () -> LOGGER.error("No vanilla biome: {}", vb))); - biomeRegistry.k(); // clearTags - biomeRegistry.a(ImmutableMap.copyOf(collect)); // populateTags + biomeRegistry.resetTags(); // clearTags + biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); // populateTags - } catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception) { + } catch(SecurityException | IllegalArgumentException exception) { throw new RuntimeException(exception); } } - public static Optional> getEntry(IRegistry registry, MinecraftKey identifier) { - return registry.b(identifier) - .flatMap(registry::c) - .map(registry::c); + public static Optional> getEntry(Registry registry, ResourceLocation identifier) { + return registry.getOptional(identifier) + .flatMap(registry::getResourceKey) + .map(registry::getOrCreateHolder); } - private static BiomeBase createBiome(Biome biome, BiomeBase vanilla) + private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - BiomeBase.a builder = new BiomeBase.a(); // Builder - - Field f = BiomeBase.class.getDeclaredField("l"); // category - f.setAccessible(true); - builder.a((BiomeBase.Geography) f.get(vanilla)) - .a(vanilla.c()); // getPrecipitation - - - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); // spawn settings - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(vanilla); - builder.a(biomeSettingMobs); - + Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); // Builder - BiomeSettingsGeneration.a generationBuilder = new BiomeSettingsGeneration.a(); // builder - builder.a(generationBuilder.a()) - .a(vanilla.c()) - .b(vanilla.h()) // precipitation - .a(vanilla.i()); // temp + builder.biomeCategory(Reflection.BIOME.getCategory(vanilla)) + .precipitation(vanilla.getPrecipitation()) // getPrecipitation + .mobSpawnSettings(vanilla.getMobSettings()) + .generationSettings(vanilla.getGenerationSettings()) + .temperature(vanilla.getBaseTemperature()) + .downfall(vanilla.getDownfall()); + + - BiomeFog.a effects = new BiomeFog.a(); // Builder - effects.a(GrassColor.a); // magic - + BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); + + effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); + VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); - - // fog - effects.a(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.f())); - - // water - effects.b(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.k())); - - // water fog - effects.c(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.l())); - - // sky - effects.d(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.a())); - + + effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) + + .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) + + .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) + + .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); + if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.j().e().ifPresent(effects::e); + vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); } else { - // foliage - effects.e(vanillaBiomeProperties.getFoliageColor()); + effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); } - + if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.j().f().ifPresent(effects::f); + vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); } else { - // grass - effects.f(vanillaBiomeProperties.getGrassColor()); + effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); } + + builder.specialEffects(effects.build()); - builder.a(effects.a()); // build() - - return builder.a(); // build() + return builder.build(); // build() } public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java index c4fc62749..6d44d19d5 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeProvider.java @@ -1,54 +1,49 @@ package com.dfsek.terra.bukkit.nms.v1_18_R2; +import com.dfsek.terra.api.world.biome.generation.BiomeProvider; +import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; + import com.mojang.serialization.Codec; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.core.Registry; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.biome.WorldChunkManager; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.jetbrains.annotations.NotNull; -import com.dfsek.terra.api.util.generic.Lazy; -import com.dfsek.terra.api.world.biome.generation.BiomeProvider; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; - -public class NMSBiomeProvider extends WorldChunkManager { +public class NMSBiomeProvider extends BiomeSource { private final BiomeProvider delegate; - private final WorldChunkManager vanilla; + private final BiomeSource vanilla; private final long seed; + private final Registry biomeRegistry = Registries.biomeRegistry(); - private static final Lazy> biomeRegistry = Lazy.lazy(() -> { - DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); - return dedicatedserver.aU().b(IRegistry.aP); - }); - - public NMSBiomeProvider(BiomeProvider delegate, WorldChunkManager vanilla, long seed) { - super(delegate.stream().map(biome -> biomeRegistry.value().g(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()))); + public NMSBiomeProvider(BiomeProvider delegate, BiomeSource vanilla, long seed) { + super(delegate.stream() + .map(biome -> Registries.biomeRegistry() + .getOrCreateHolder(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() + .get(NMSBiomeInfo.class) + .biomeKey()))); this.delegate = delegate; this.vanilla = vanilla; this.seed = seed; } @Override - protected Codec a() { - return WorldChunkManager.a; + protected Codec codec() { + return BiomeSource.CODEC; } @Override - public WorldChunkManager a(long seed) { - return withSeed(seed); - } - - public WorldChunkManager withSeed(long seed) { + public @NotNull BiomeSource withSeed(long seed) { return new NMSBiomeProvider(delegate, vanilla, seed); } @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler sampler) { - //return CraftBlock.biomeToBiomeBase(biomeRegistry.value(), ((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getHandle()); - return biomeRegistry.value().g(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()).getContext().get(NMSBiomeInfo.class).biomeKey()); + public @NotNull Holder getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { + return biomeRegistry.getOrCreateHolder(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed).getPlatformBiome()) + .getContext() + .get(NMSBiomeInfo.class) + .biomeKey()); } } diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java index b9c4ceb10..12a9d2711 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java @@ -8,31 +8,29 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import net.minecraft.core.BlockPosition; +import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; -import net.minecraft.core.IRegistryCustom; -import net.minecraft.core.SectionPosition; -import net.minecraft.server.level.RegionLimitedWorldAccess; -import net.minecraft.world.level.BlockColumn; -import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.core.SectionPos; +import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.NoiseColumn; +import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.ChunkGeneratorAbstract; -import net.minecraft.world.level.levelgen.HeightMap; -import net.minecraft.world.level.levelgen.WorldGenStage; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; -import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureManager; import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,8 +51,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator { private final long seed; - private final Map>> h = new Object2ObjectArrayMap<>(); - private static final Lazy> EMPTY = Lazy.lazy(List::of); + private final Map>> ringPositions = new Object2ObjectArrayMap<>(); + private static final Lazy> EMPTY = Lazy.lazy(List::of); public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) { @@ -66,103 +64,95 @@ public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBio this.seed = seed; } - @Override //applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long var2, BiomeManager var4, StructureManager var5, - IChunkAccess ichunkaccess, WorldGenStage.Features var7) { + @Override + public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull BiomeManager biomeAccess, @NotNull StructureFeatureManager structureAccessor, + @NotNull ChunkAccess chunk, GenerationStep.@NotNull Carving generationStep) { // no-op } - @Override // getSeaLevel - public int g() { - return vanilla.g(); + @Override + public int getSeaLevel() { + return vanilla.getSeaLevel(); } @Override //fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return vanilla.a(executor, blender, structuremanager, ichunkaccess); + public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, @NotNull StructureFeatureManager structureAccessor, + @NotNull ChunkAccess chunk) { + return vanilla.fillFromNoise(executor, blender, structureAccessor, chunk); } - - @Override //buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, IChunkAccess ichunkaccess) { - + @Override + public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureFeatureManager structures, @NotNull ChunkAccess chunk) { + // no-op } @Override - protected Codec b() { - return ChunkGeneratorAbstract.a; + protected @NotNull Codec codec() { + return ChunkGenerator.CODEC; } @Override // getColumn - public BlockColumn a(int x, int z, LevelHeightAccessor height) { - IBlockData[] array = new IBlockData[height.v_()]; + public @NotNull NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height) { + BlockState[] array = new BlockState[height.getHeight()]; WorldProperties properties = new NMSWorldProperties(seed, height); BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); for(int y = properties.getMaxHeight() - 1; y >= properties.getMinHeight(); y--) { array[y - properties.getMinHeight()] = ((CraftBlockData) delegate.getBlock(properties, x, y, z, biomeProvider) .getHandle()).getState(); } - return new BlockColumn(getMinimumY(), array); + return new NoiseColumn(getMinY(), array); } @Override // withSeed - public ChunkGenerator a(long seed) { + public @NotNull ChunkGenerator withSeed(long seed) { return new NMSChunkGeneratorDelegate(vanilla, pack, biomeSource, seed); } - //spawnOriginalMobs - public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { - vanilla.a(regionlimitedworldaccess); + @Override + public void spawnOriginalMobs(@NotNull WorldGenRegion regionlimitedworldaccess) { + vanilla.spawnOriginalMobs(regionlimitedworldaccess); } - // getGenDepth - public int f() { - return vanilla.f(); + @Override + public int getGenDepth() { + return vanilla.getGenDepth(); } - // climateSampler - public Sampler d() { - return Climate.a(); + @Override + public @NotNull Sampler climateSampler() { + return Climate.empty(); } - //getMinY @Override - public int h() { - return vanilla.h(); + public int getMinY() { + return vanilla.getMinY(); } - @Override // getBaseHeight - public int a(int x, int z, HeightMap.Type heightmap, LevelHeightAccessor height) { - WorldProperties properties = new NMSWorldProperties(seed, height); + @Override + public int getBaseHeight(int x, int z, Heightmap.@NotNull Types heightmap, @NotNull LevelHeightAccessor world) { + WorldProperties properties = new NMSWorldProperties(seed, world); int y = properties.getMaxHeight(); BiomeProvider biomeProvider = pack.getBiomeProvider().caching(properties); - while(y >= getMinimumY() && !heightmap.e().test( + while(y >= getMinY() && !heightmap.isOpaque().test( ((CraftBlockData) delegate.getBlock(properties, x, y - 1, z, biomeProvider).getHandle()).getState())) { y--; } return y; } - @Override - public void a(IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, - DefinedStructureManager definedstructuremanager, long i) { - super.a(iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i); - } - @Nullable @Override - public List a(ConcentricRingsStructurePlacement concentricringsstructureplacement) { - this.i(); - return this.h.getOrDefault(concentricringsstructureplacement, EMPTY).value(); + public List getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement concentricringsstructureplacement) { + ensureStructuresGenerated(); + return ringPositions.getOrDefault(concentricringsstructureplacement, EMPTY).value(); } private volatile boolean rings = false; @Override - public synchronized void i() { + public synchronized void ensureStructuresGenerated() { if(!this.rings) { - super.i(); + super.ensureStructuresGenerated(); this.populateStrongholdData(); this.rings = true; } @@ -170,70 +160,82 @@ public synchronized void i() { private void populateStrongholdData() { LOGGER.info("Generating safe stronghold data. This may take up to a minute."); - Set> set = this.d.b(); - a().map(h -> h.a()).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric. - StructurePlacement structureplacement = holder.b(); + Set> set = this.runtimeBiomeSource.possibleBiomes(); + possibleStructureSets().map(Holder::value).forEach((holder) -> { // we dont need the spigot crap because it doesnt touch concentric. + StructurePlacement structureplacement = holder.placement(); if(structureplacement instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { - if(holder.a().stream().anyMatch((structureset_a1) -> structureset_a1.a(set::contains))) { - this.h.put(concentricringsstructureplacement, - Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement))); + if(holder.structures().stream().anyMatch((structureset_a1) -> structureset_a1.generatesInMatchingBiome(set::contains))) { + this.ringPositions.put(concentricringsstructureplacement, + Lazy.lazy(() -> this.generateRingPositions(holder, concentricringsstructureplacement))); } } }); } - private List generateRingPositions(StructureSet holder, - ConcentricRingsStructurePlacement concentricringsstructureplacement) { - if(concentricringsstructureplacement.d() == 0) { + private List generateRingPositions(StructureSet holder, + ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot + if(concentricringsstructureplacement.count() == 0) { return List.of(); } - List list = new ArrayList<>(); - Set> set = holder.a().stream().flatMap((structureset_a) -> (structureset_a.a().a()).a().a()).collect( - Collectors.toSet()); - int i = concentricringsstructureplacement.b(); - int j = concentricringsstructureplacement.d(); - int k = concentricringsstructureplacement.c(); + + List list = new ArrayList<>(); + Set> set = holder + .structures() + .stream() + .flatMap((structureset_a) -> structureset_a.structure().value().biomes().stream()) + .collect(Collectors.toSet()); + int i = concentricringsstructureplacement.distance(); + int j = concentricringsstructureplacement.count(); + int k = concentricringsstructureplacement.spread(); Random random = new Random(); - random.setSeed(this.j); - double d0 = random.nextDouble() * Math.PI * 2.0; + + // Paper start + if(this.conf.strongholdSeed != null && this.structureSets.getResourceKey(holder).orElse(null) == + net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS) { + random.setSeed(this.conf.strongholdSeed); + } else { + // Paper end + random.setSeed(this.ringPlacementSeed); + } // Paper + double d0 = random.nextDouble() * 3.141592653589793D * 2.0D; int l = 0; int i1 = 0; for(int j1 = 0; j1 < j; ++j1) { - double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5) * (double) i * 2.5; + double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5D) * (double) i * 2.5D; int k1 = (int) Math.round(Math.cos(d0) * d1); int l1 = (int) Math.round(Math.sin(d0) * d1); - int i2 = SectionPosition.a(k1, 8); - int j2 = SectionPosition.a(l1, 8); + int i2 = SectionPos.sectionToBlockCoord(k1, 8); + int j2 = SectionPos.sectionToBlockCoord(l1, 8); + Objects.requireNonNull(set); - Pair> pair = this.c.a(i2, 0, j2, 112, set::contains, random, this.d()); + Pair> pair = this.biomeSource.findBiomeHorizontal(i2, 0, j2, 112, set::contains, random, + this.climateSampler()); + if(pair != null) { - BlockPosition blockposition = pair.getFirst(); - k1 = SectionPosition.a(blockposition.u()); - l1 = SectionPosition.a(blockposition.w()); + BlockPos blockposition = (BlockPos) pair.getFirst(); + + k1 = SectionPos.blockToSectionCoord(blockposition.getX()); + l1 = SectionPos.blockToSectionCoord(blockposition.getZ()); } - list.add(new ChunkCoordIntPair(k1, l1)); - d0 += 6.283185307179586 / (double) k; + list.add(new ChunkPos(k1, l1)); + d0 += 6.283185307179586D / (double) k; ++l; if(l == k) { ++i1; l = 0; k += 2 * k / (i1 + 1); k = Math.min(k, j - j1); - d0 += random.nextDouble() * Math.PI * 2.0; + d0 += random.nextDouble() * 3.141592653589793D * 2.0D; } } - return list; + return list; } - public int getMinimumY() { - return h(); - } - - @Override //addDebugScreenInfo - public void a(List arg0, BlockPosition arg1) { + @Override + public void addDebugScreenInfo(@NotNull List arg0, @NotNull BlockPos arg1) { } } diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java index 7402c1463..46f4a64c0 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSInjectListener.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.nms.v1_18_R2; -import net.minecraft.server.level.WorldServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkGenerator; import org.bukkit.World; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; @@ -30,21 +30,21 @@ public void onWorldInit(WorldInitEvent event) { INJECTED.add(event.getWorld()); LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName()); CraftWorld craftWorld = (CraftWorld) event.getWorld(); - WorldServer serverWorld = craftWorld.getHandle(); + ServerLevel serverWorld = craftWorld.getHandle(); ConfigPack pack = bukkitChunkGeneratorWrapper.getPack(); - ChunkGenerator vanilla = serverWorld.k().g(); - NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.e(), craftWorld.getSeed()); + ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); + NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), vanilla.getBiomeSource(), craftWorld.getSeed()); NMSChunkGeneratorDelegate custom = new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()); custom.conf = vanilla.conf; // world config from Spigot - serverWorld.k().a.u = custom; + serverWorld.getChunkSource().chunkMap.generator = custom; LOGGER.info("Successfully injected into world."); - serverWorld.k().a.u.i(); // generate stronghold data now + serverWorld.getChunkSource().chunkMap.generator.ensureStructuresGenerated(); // generate stronghold data now INJECT_LOCK.unlock(); } diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java index 97dd66167..73b009fc4 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSWorldProperties.java @@ -26,11 +26,11 @@ public long getSeed() { @Override public int getMaxHeight() { - return height.ag(); + return height.getMaxBuildHeight(); } @Override public int getMinHeight() { - return height.u_(); + return height.getMinBuildHeight(); } } diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java new file mode 100644 index 000000000..785c93bf5 --- /dev/null +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java @@ -0,0 +1,35 @@ +package com.dfsek.terra.bukkit.nms.v1_18_R2; + +import net.minecraft.core.MappedRegistry; +import net.minecraft.world.level.biome.Biome; +import xyz.jpenilla.reflectionremapper.ReflectionRemapper; +import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; +import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter; +import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter; +import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; + + +public class Reflection { + public static final MappedRegistryProxy MAPPED_REGISTRY; + public static final BiomeProxy BIOME; + + static { + ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); + ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper, Reflection.class.getClassLoader()); + + MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); + BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class); + } + + @Proxies + public interface MappedRegistryProxy { + @FieldSetter("frozen") + void setFrozen(MappedRegistry instance, boolean frozen); + } + + @Proxies + public interface BiomeProxy { + @FieldGetter("category") + Biome.BiomeCategory getCategory(Biome instance); + } +} diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java index 0702b25c9..3902b61d3 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Registries.java @@ -1,30 +1,30 @@ package com.dfsek.terra.bukkit.nms.v1_18_R2; -import net.minecraft.core.IRegistry; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.structure.StructureSet; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_18_R2.CraftServer; public class Registries { - private static IRegistry getRegistry(ResourceKey> key) { + private static Registry getRegistry(ResourceKey> key) { CraftServer craftserver = (CraftServer) Bukkit.getServer(); DedicatedServer dedicatedserver = craftserver.getServer(); return dedicatedserver - .aU() // getRegistryManager - .b( // getRegistry - key - ); + .registryAccess() + .registryOrThrow( // getRegistry + key + ); } - public static IRegistry biomeRegistry() { - return getRegistry(IRegistry.aP); + public static Registry biomeRegistry() { + return getRegistry(Registry.BIOME_REGISTRY); } - public static IRegistry structureSet() { - return getRegistry(IRegistry.aM); + public static Registry structureSet() { + return getRegistry(Registry.STRUCTURE_SET_REGISTRY); } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java index f77fbefab..8cc0895b6 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java @@ -110,11 +110,10 @@ public static void registerBiomes(ConfigRegistry configRegistry) { } } - @SuppressWarnings("unchecked, rawtypes") public static Optional> getEntry(Registry registry, ResourceLocation identifier) { - return (Optional) registry.getOptional(identifier) - .flatMap(registry::getResourceKey) - .map(registry::getHolder); + return registry.getOptional(identifier) + .flatMap(registry::getResourceKey) + .map(registry::getOrCreateHolderOrThrow); } private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) From 2c85284cfbd132da8180b24275184081e885854c Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 20:27:14 -0700 Subject: [PATCH 06/17] improve bukkit build --- buildSrc/build.gradle.kts | 5 +++++ platforms/bukkit/nms/v1_18_R2/build.gradle.kts | 6 ++---- platforms/bukkit/nms/v1_19_R1/build.gradle.kts | 6 ++---- settings.gradle.kts | 3 --- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 07713bb5b..21036749f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -16,10 +16,15 @@ repositories { mavenCentral() gradlePluginPortal() maven { url = uri("https://repo.codemc.org/repository/maven-public") } + maven("https://papermc.io/repo/repository/maven-public/") { + name = "PaperMC" + } } dependencies { implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:+") + implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.3.5") + implementation("org.ow2.asm:asm:9.3") implementation("org.ow2.asm:asm-tree:9.3") implementation("com.dfsek.tectonic:common:4.2.0") diff --git a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts b/platforms/bukkit/nms/v1_18_R2/build.gradle.kts index ddf11570f..2fa163cee 100644 --- a/platforms/bukkit/nms/v1_18_R2/build.gradle.kts +++ b/platforms/bukkit/nms/v1_18_R2/build.gradle.kts @@ -1,6 +1,4 @@ -plugins { - id("io.papermc.paperweight.userdev") version "1.3.3" -} +apply(plugin = "io.papermc.paperweight.userdev") repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") @@ -14,6 +12,6 @@ dependencies { tasks { assemble { - dependsOn(reobfJar) + dependsOn("reobfJar") } } \ No newline at end of file diff --git a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts index 5561d17c8..e40d548dc 100644 --- a/platforms/bukkit/nms/v1_19_R1/build.gradle.kts +++ b/platforms/bukkit/nms/v1_19_R1/build.gradle.kts @@ -1,6 +1,4 @@ -plugins { - id("io.papermc.paperweight.userdev") version "1.3.3" -} +apply(plugin = "io.papermc.paperweight.userdev") repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") @@ -14,6 +12,6 @@ dependencies { tasks { assemble { - dependsOn(reobfJar) + dependsOn("reobfJar") } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 16353b28c..7a34493bb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,9 +27,6 @@ pluginManagement { maven("https://maven.fabricmc.net") { name = "Fabric" } - maven("https://papermc.io/repo/repository/maven-public/") { - name = "PaperMC" - } gradlePluginPortal() } } From 5a445feface88fd1d6756c3696f9f46d171cb93a Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 20:47:59 -0700 Subject: [PATCH 07/17] fix bukkit reobf nms shadow --- platforms/bukkit/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 6e0bf4927..d14870df0 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -18,8 +18,8 @@ val purpurURL = "https://api.purpurmc.org/v2/purpur/%version%/latest/download" dependencies { shaded(project(":platforms:bukkit:common")) - shaded(project(":platforms:bukkit:nms:v1_18_R2")) - shaded(project(":platforms:bukkit:nms:v1_19_R1")) + shaded(project(":platforms:bukkit:nms:v1_18_R2", configuration = "reobf")) + shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf")) } val throttleCoreCount = 0 From 55686e270466ae1ab28a0ddbb0134d18bbe90486 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:19:57 -0700 Subject: [PATCH 08/17] shade reflection remapper --- platforms/bukkit/build.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index d14870df0..146321dff 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -16,10 +16,15 @@ val paperBuild = 350 val paperURL = "https://papermc.io/api/v2/projects/paper/versions/%version%/builds/$paperBuild/downloads/paper-%version%-$paperBuild.jar" val purpurURL = "https://api.purpurmc.org/v2/purpur/%version%/latest/download" +repositories { + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") +} + dependencies { shaded(project(":platforms:bukkit:common")) shaded(project(":platforms:bukkit:nms:v1_18_R2", configuration = "reobf")) shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf")) + shaded("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT") } val throttleCoreCount = 0 From 2363ad8c6c62f1d5d2afcee4069f83398fc919ee Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:24:19 -0700 Subject: [PATCH 09/17] fix reflection proxies --- .../dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java | 2 +- .../com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java | 8 ++++---- .../com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java index 544072061..d7a03ef1e 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSBiomeInjector.java @@ -121,7 +121,7 @@ private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bi Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); // Builder - builder.biomeCategory(Reflection.BIOME.getCategory(vanilla)) + builder.biomeCategory(Reflection.BIOME.getBiomeCategory(vanilla)) .precipitation(vanilla.getPrecipitation()) // getPrecipitation .mobSpawnSettings(vanilla.getMobSettings()) .generationSettings(vanilla.getGenerationSettings()) diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java index 785c93bf5..53e9e80f9 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/Reflection.java @@ -21,15 +21,15 @@ public class Reflection { BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class); } - @Proxies + @Proxies(MappedRegistry.class) public interface MappedRegistryProxy { @FieldSetter("frozen") void setFrozen(MappedRegistry instance, boolean frozen); } - @Proxies + @Proxies(Biome.class) public interface BiomeProxy { - @FieldGetter("category") - Biome.BiomeCategory getCategory(Biome instance); + @FieldGetter("biomeCategory") + Biome.BiomeCategory getBiomeCategory(Biome instance); } } diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java index 35beefb41..157157005 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/Reflection.java @@ -17,7 +17,7 @@ public class Reflection { MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class); } - @Proxies + @Proxies(MappedRegistry.class) public interface MappedRegistryProxy { @FieldSetter("frozen") void setFrozen(MappedRegistry instance, boolean frozen); From d333b186b119bd0ff9ba4fc28b985e82e7a3051c Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:31:12 -0700 Subject: [PATCH 10/17] update cloud to 1.70-SNAPSHOT --- buildSrc/src/main/kotlin/Versions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index f466b89ba..05b7f8a64 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -4,7 +4,7 @@ object Versions { const val paralithic = "0.7.0" const val strata = "1.1.1" - const val cloud = "1.6.2" + const val cloud = "1.7.0-SNAPSHOT" const val slf4j = "1.7.36" const val log4j_slf4j_impl = "2.14.1" From fbc1a38a8d77a1424a8f2c84427b5b5235925441 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:33:45 -0700 Subject: [PATCH 11/17] depend on Cloud again in Fabric --- platforms/fabric/build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index e84d53391..962c65a50 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -15,7 +15,7 @@ dependencies { modImplementation("net.fabricmc:fabric-loader:${Versions.Fabric.fabricLoader}") - setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base").forEach { apiModule -> + setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base", "fabric-command-api-v2").forEach { apiModule -> val module = fabricApi.module(apiModule, Versions.Fabric.fabricAPI) modImplementation(module) include(module) @@ -28,8 +28,8 @@ dependencies { "annotationProcessor"("net.fabricmc:sponge-mixin:${Versions.Fabric.mixin}") "annotationProcessor"("net.fabricmc:fabric-loom:${Versions.Fabric.loom}") - //include(modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud)) - //include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) + include(modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud)) + include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud) } loom { From ee88f9e75f0d61ab45057d3094cdebbafa90b776 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:36:29 -0700 Subject: [PATCH 12/17] apply downfall to 1.19 NMS biomes --- .../bukkit/nms/v1_19_R1/NMSBiomeInjector.java | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java index 8cc0895b6..2da3c3f85 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSBiomeInjector.java @@ -1,5 +1,10 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; +import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; +import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; +import com.dfsek.terra.registry.master.ConfigRegistry; + import com.google.common.collect.ImmutableMap; import com.mojang.serialization.Lifecycle; import net.minecraft.core.Holder; @@ -16,18 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; -import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; -import com.dfsek.terra.registry.master.ConfigRegistry; +import java.util.*; public class NMSBiomeInjector { @@ -50,9 +44,10 @@ public static void registerBiomes(ConfigRegistry configRegistry) { Biome platform = createBiome( biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)) // get - ); + ); - ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", createBiomeID(pack, key))); + ResourceKey delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, + new ResourceLocation("terra", createBiomeID(pack, key))); BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform); biomeRegistry.register(delegateKey, platform, Lifecycle.stable()); @@ -65,7 +60,7 @@ public static void registerBiomes(ConfigRegistry configRegistry) { throw new RuntimeException(e); } })); - + Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry) biomeRegistry, true); // freeze registry again :) LOGGER.info("Doing tag garbage...."); @@ -75,7 +70,7 @@ public static void registerBiomes(ConfigRegistry configRegistry) { (map, pair) -> map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())), HashMap::putAll); - + terraBiomeMap .forEach((vb, terraBiomes) -> getEntry(biomeRegistry, vb) @@ -89,7 +84,7 @@ public static void registerBiomes(ConfigRegistry configRegistry) { terra.unwrapKey().orElseThrow().location() + ": " + vanilla.tags().toList()); - + vanilla.tags() .forEach( tag -> collect @@ -101,7 +96,7 @@ public static void registerBiomes(ConfigRegistry configRegistry) { "No such biome: {}", tb))), () -> LOGGER.error("No vanilla biome: {}", vb))); - + biomeRegistry.resetTags(); biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); @@ -121,14 +116,13 @@ private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bi Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); builder - .precipitation(vanilla.getPrecipitation()) + .precipitation(vanilla.getPrecipitation()) + .downfall(vanilla.getDownfall()) .temperature(vanilla.getBaseTemperature()) .mobSpawnSettings(vanilla.getMobSettings()) .generationSettings(vanilla.getGenerationSettings()); - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); @@ -137,11 +131,11 @@ private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bi effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) + .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) + .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); + .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); if(vanillaBiomeProperties.getFoliageColor() == null) { vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); From 170b3d95eaaa26833676ce5ad2cbb8aea706833c Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:57:10 -0700 Subject: [PATCH 13/17] fix vanilla features generating in terra biomes --- .../bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java | 6 ++++++ .../bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java index 12a9d2711..0f8504c44 100644 --- a/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_18_R2/src/main/java/com/dfsek/terra/bukkit/nms/v1_18_R2/NMSChunkGeneratorDelegate.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.NoiseColumn; import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.biome.Climate; @@ -70,6 +71,11 @@ public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNul // no-op } + @Override + public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, @NotNull StructureFeatureManager structureAccessor) { + vanilla.applyBiomeDecoration(world, chunk, structureAccessor); + } + @Override public int getSeaLevel() { return vanilla.getSeaLevel(); diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java index 32a785ec5..cd3cf0ac0 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java @@ -6,6 +6,7 @@ import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.NoiseColumn; import net.minecraft.world.level.StructureManager; +import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; @@ -59,6 +60,11 @@ public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManag // no-op } + @Override + public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, @NotNull StructureManager structureAccessor) { + vanilla.applyBiomeDecoration(world, chunk, structureAccessor); + } + @Override public void spawnOriginalMobs(@NotNull WorldGenRegion region) { vanilla.spawnOriginalMobs(region); From 443b372736fdd5215992b3519e2344fb45ea91b4 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:57:19 -0700 Subject: [PATCH 14/17] reimplement Cloud in Fabric --- .../com/dfsek/terra/fabric/FabricEntryPoint.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricEntryPoint.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricEntryPoint.java index 7974d8884..66348ed53 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricEntryPoint.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricEntryPoint.java @@ -17,7 +17,15 @@ package com.dfsek.terra.fabric; +import cloud.commandframework.execution.CommandExecutionCoordinator; + +import cloud.commandframework.fabric.FabricServerCommandManager; + +import com.dfsek.terra.api.command.CommandSender; +import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent; + import net.fabricmc.api.ModInitializer; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import net.minecraft.world.gen.WorldPresets; @@ -45,7 +53,7 @@ public static void register() { // register the things @Override public void onInitialize() { logger.info("Initializing Terra Fabric mod..."); - /* + FabricServerCommandManager manager = new FabricServerCommandManager<>( CommandExecutionCoordinator.simpleCoordinator(), serverCommandSource -> (CommandSender) serverCommandSource, @@ -56,7 +64,5 @@ public void onInitialize() { manager.brigadierManager().setNativeNumberSuggestions(false); TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager)); - TODO: re-enable when Cloud updates - */ } } From 1d7ddc2844d7858b2ab53af01037e07e12fc82e1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 21:57:47 -0700 Subject: [PATCH 15/17] remove ReloadCommandMixin --- .../fabric/mixin/ReloadCommandMixin.java | 25 ------------------- .../src/main/resources/terra.mixins.json | 1 - 2 files changed, 26 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/ReloadCommandMixin.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/ReloadCommandMixin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/ReloadCommandMixin.java deleted file mode 100644 index 9fcfaae15..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/ReloadCommandMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.dfsek.terra.fabric.mixin; - -import com.dfsek.terra.fabric.FabricEntryPoint; - -import net.minecraft.server.command.ReloadCommand; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import org.checkerframework.checker.units.qual.A; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Collection; - - -@Mixin(ReloadCommand.class) -public class ReloadCommandMixin { - @Inject(method = "tryReloadDataPacks", at = @At("HEAD")) - private static void inject(Collection dataPacks, ServerCommandSource source, CallbackInfo ci) { - source.sendFeedback(Text.literal("Reloading Terra..."), true); - FabricEntryPoint.getPlatform().reload(); - source.sendFeedback(Text.literal("Done."), true); - } -} diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json index 778f06889..9c4e278bc 100644 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -4,7 +4,6 @@ "package": "com.dfsek.terra.fabric.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ReloadCommandMixin", "access.MobSpawnerLogicAccessor", "access.StateAccessor", "access.StructureAccessorAccessor", From e2088bbbb8bceca7ecfff8347b7eefaba18f4fae Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 22:20:27 -0700 Subject: [PATCH 16/17] implement stronghold hack on 1.19 bukkit --- .../v1_19_R1/NMSChunkGeneratorDelegate.java | 127 +++++++++++++++++- 1 file changed, 123 insertions(+), 4 deletions(-) diff --git a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java index cd3cf0ac0..b95a7f53c 100644 --- a/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java +++ b/platforms/bukkit/nms/v1_19_R1/src/main/java/com/dfsek/terra/bukkit/nms/v1_19_R1/NMSChunkGeneratorDelegate.java @@ -1,12 +1,20 @@ package com.dfsek.terra.bukkit.nms.v1_19_R1; +import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.SectionPos; import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.NoiseColumn; import net.minecraft.world.level.StructureManager; import net.minecraft.world.level.WorldGenLevel; +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.chunk.ChunkAccess; @@ -15,20 +23,33 @@ import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.blending.Blender; +import net.minecraft.world.level.levelgen.structure.Structure; +import net.minecraft.world.level.levelgen.structure.StructureSet; +import net.minecraft.world.level.levelgen.structure.StructureSet.StructureSelectionEntry; +import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement; import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import java.util.stream.Stream; import com.dfsek.terra.api.config.ConfigPack; +import com.dfsek.terra.api.util.generic.Lazy; import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.info.WorldProperties; public class NMSChunkGeneratorDelegate extends ChunkGenerator { + private static final Logger LOGGER = LoggerFactory.getLogger(NMSChunkGeneratorDelegate.class); private final com.dfsek.terra.api.world.chunk.generation.ChunkGenerator delegate; private final ChunkGenerator vanilla; @@ -43,7 +64,7 @@ public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBio this.pack = pack; this.seed = seed; } - + @Override protected @NotNull Codec codec() { return ChunkGenerator.CODEC; @@ -56,12 +77,14 @@ public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNul } @Override - public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, @NotNull ChunkAccess chunk) { + public void buildSurface(@NotNull WorldGenRegion region, @NotNull StructureManager structures, @NotNull RandomState noiseConfig, + @NotNull ChunkAccess chunk) { // no-op } @Override - public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, @NotNull StructureManager structureAccessor) { + public void applyBiomeDecoration(@NotNull WorldGenLevel world, @NotNull ChunkAccess chunk, + @NotNull StructureManager structureAccessor) { vanilla.applyBiomeDecoration(world, chunk, structureAccessor); } @@ -76,7 +99,8 @@ public int getGenDepth() { } @Override - public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, @NotNull RandomState noiseConfig, + public @NotNull CompletableFuture fillFromNoise(@NotNull Executor executor, @NotNull Blender blender, + @NotNull RandomState noiseConfig, @NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) { return vanilla.fillFromNoise(executor, blender, noiseConfig, structureAccessor, chunk); } @@ -119,4 +143,99 @@ public int getBaseHeight(int x, int z, @NotNull Types heightmap, @NotNull LevelH public void addDebugScreenInfo(@NotNull List text, @NotNull RandomState noiseConfig, @NotNull BlockPos pos) { } + + private volatile boolean rings = false; + private final Map>> ringPositions = new Object2ObjectArrayMap<>(); + + @Override + public void ensureStructuresGenerated(@NotNull RandomState noiseConfig) { + if(!this.rings) { + super.ensureStructuresGenerated(noiseConfig); + this.populateStrongholdData(noiseConfig); + this.rings = true; + } + + } + + @Override + public List getRingPositionsFor(@NotNull ConcentricRingsStructurePlacement structurePlacement, @NotNull RandomState noiseConfig) { + ensureStructuresGenerated(noiseConfig); + return ringPositions.get(structurePlacement).value(); + } + + private void populateStrongholdData(RandomState noiseConfig) { + LOGGER.info("Generating safe stronghold data. This may take up to a minute."); + Set> set = this.biomeSource.possibleBiomes(); + possibleStructureSets().map(Holder::value).forEach((holder) -> { + boolean match = false; + for(StructureSelectionEntry structureset_a : holder.structures()) { + Structure structure = structureset_a.structure().value(); + Stream> stream = structure.biomes().stream(); + if(stream.anyMatch(set::contains)) { + match = true; + } + } + + if (match) { + if (holder.placement() instanceof ConcentricRingsStructurePlacement concentricringsstructureplacement) { + this.ringPositions.put(concentricringsstructureplacement, Lazy.lazy(() -> this.generateRingPositions(holder, noiseConfig, concentricringsstructureplacement))); + } + } + }); + } + private List generateRingPositions(StructureSet holder, RandomState randomstate, + ConcentricRingsStructurePlacement concentricringsstructureplacement) { // Spigot + if(concentricringsstructureplacement.count() == 0) { + return List.of(); + } + + List list = new ArrayList<>(); + int i = concentricringsstructureplacement.distance(); + int j = concentricringsstructureplacement.count(); + int k = concentricringsstructureplacement.spread(); + HolderSet holderset = concentricringsstructureplacement.preferredBiomes(); + RandomSource randomsource = RandomSource.create(); + + if(this.conf.strongholdSeed != null && this.structureSets.getResourceKey(holder).orElse(null) == + net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS) { + randomsource.setSeed(this.conf.strongholdSeed); + } else { + randomsource.setSeed(randomstate.legacyLevelSeed()); + } + double d0 = randomsource.nextDouble() * 3.141592653589793D * 2.0D; + int l = 0; + int i1 = 0; + + for(int j1 = 0; j1 < j; ++j1) { + double d1 = (double) (4 * i + i * i1 * 6) + (randomsource.nextDouble() - 0.5D) * (double) i * 2.5D; + int k1 = (int) Math.round(Math.cos(d0) * d1); + int l1 = (int) Math.round(Math.sin(d0) * d1); + int i2 = SectionPos.sectionToBlockCoord(k1, 8); + int j2 = SectionPos.sectionToBlockCoord(l1, 8); + + Objects.requireNonNull(holderset); + Pair> pair = this.biomeSource.findBiomeHorizontal(i2, 0, j2, 112, holderset::contains, randomsource, + randomstate.sampler()); + + if(pair != null) { + BlockPos blockposition = pair.getFirst(); + + k1 = SectionPos.blockToSectionCoord(blockposition.getX()); + l1 = SectionPos.blockToSectionCoord(blockposition.getZ()); + } + + list.add(new ChunkPos(k1, l1)); + d0 += 6.283185307179586D / (double) k; + ++l; + if(l == k) { + ++i1; + l = 0; + k += 2 * k / (i1 + 1); + k = Math.min(k, j - j1); + d0 += randomsource.nextDouble() * 3.141592653589793D * 2.0D; + } + } + + return list; + } } From a94c0adeb53de702e762c40ee32ff75d9737d49b Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 12 Jun 2022 22:22:50 -0700 Subject: [PATCH 17/17] bump versions --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 39cee7e68..2938b5688 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ preRelease(true) -versionProjects(":common:api", version("6.1.1")) -versionProjects(":common:implementation", version("6.1.1")) -versionProjects(":platforms", version("6.1.1")) +versionProjects(":common:api", version("6.1.2")) +versionProjects(":common:implementation", version("6.1.2")) +versionProjects(":platforms", version("6.1.2")) allprojects {