Merge remote-tracking branch 'origin/ver/6.6.0' into dev/7.0-2

This commit is contained in:
Zoe Gidiere
2024-10-25 15:21:47 -06:00
45 changed files with 245 additions and 191 deletions
+1 -1
View File
@@ -11,5 +11,5 @@ dependencies {
shadedApi("com.google.guava", "guava", Versions.Libraries.Internal.guava)
shadedApi("org.incendo", "cloud-paper", Versions.Libraries.cloudPaper)
shadedApi("org.incendo", "cloud-paper", Versions.Bukkit.cloud)
}
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry;
@@ -43,7 +42,7 @@ public class AwfulBukkitHacks {
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
vanillaBukkitKey.getKey());
Biome platform = NMSBiomeInjector.createBiome(biome, Objects.requireNonNull(biomeRegistry.get(vanillaMinecraftKey)));
Biome platform = NMSBiomeInjector.createBiome(biome, biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value());
ResourceKey<Biome> delegateKey = ResourceKey.create(
Registries.BIOME,
@@ -70,7 +69,7 @@ public class AwfulBukkitHacks {
.getTags() // streamKeysAndEntries
.collect(HashMap::new,
(map, pair) ->
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
map.put(pair.key(), new ArrayList<>(Reflection.HOLDER_SET.invokeContents(pair).stream().toList())),
HashMap::putAll);
terraBiomeMap
@@ -91,8 +90,8 @@ public class AwfulBukkitHacks {
() -> LOGGER.error("No such biome: {}", tb))),
() -> LOGGER.error("No vanilla biome: {}", vb)));
biomeRegistry.resetTags();
biomeRegistry.bindTags(ImmutableMap.copyOf(collect));
((MappedRegistry<Biome>) biomeRegistry).bindAllTagsToEmpty();
ImmutableMap.copyOf(collect).forEach(biomeRegistry::bindTag);
} catch(SecurityException | IllegalArgumentException exception) {
throw new RuntimeException(exception);
@@ -19,7 +19,7 @@ public class NMSBiomeInjector {
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
return registry.getOptional(identifier)
.flatMap(registry::getResourceKey)
.flatMap(registry::getHolder);
.flatMap(registry::get);
}
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla)
@@ -29,7 +29,7 @@ public class NMSBiomeProvider extends BiomeSource {
protected Stream<Holder<Biome>> collectPossibleBiomes() {
return delegate.stream()
.map(biome -> RegistryFetcher.biomeRegistry()
.getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
.getOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
.get(NMSBiomeInfo.class)
.biomeKey()));
}
@@ -45,7 +45,7 @@ public class NMSBiomeProvider extends BiomeSource {
@Override
public @NotNull Holder<Biome> getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) {
return biomeRegistry.getHolderOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed)
return biomeRegistry.getOrThrow(((BukkitPlatformBiome) delegate.getBiome(x << 2, y << 2, z << 2, seed)
.getPlatformBiome()).getContext()
.get(NMSBiomeInfo.class)
.biomeKey());
@@ -15,7 +15,6 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Beardifier;
import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext;
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;
@@ -59,7 +58,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
@Override
public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world,
@NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk, @NotNull Carving carverStep) {
@NotNull StructureManager structureAccessor, @NotNull ChunkAccess chunk) {
// no-op
}
@@ -41,19 +41,15 @@ public class NMSInjectListener implements Listener {
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
ChunkMap chunkMap = serverWorld.getChunkSource().chunkMap;
WorldGenContext worldGenContext = chunkMap.worldGenContext;
try {
ReflectionUtil.setFinalField(chunkMap, "worldGenContext", new WorldGenContext(
worldGenContext.level(),
new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()),
worldGenContext.structureManager(),
worldGenContext.lightEngine(),
worldGenContext.mainThreadMailBox()
));
} catch(NoSuchFieldException e) {
throw new RuntimeException(e);
}
WorldGenContext worldGenContext = Reflection.CHUNKMAP.getWorldGenContext(chunkMap);
Reflection.CHUNKMAP.setWorldGenContext(chunkMap, new WorldGenContext(
worldGenContext.level(),
new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()),
worldGenContext.structureManager(),
worldGenContext.lightEngine(),
worldGenContext.mainThreadExecutor(),
worldGenContext.unsavedListener()
));
LOGGER.info("Successfully injected into world.");
@@ -26,11 +26,11 @@ public class NMSWorldProperties implements WorldProperties {
@Override
public int getMaxHeight() {
return height.getMaxBuildHeight();
return height.getMaxY();
}
@Override
public int getMinHeight() {
return height.getMinBuildHeight();
return height.getMinY();
}
}
@@ -2,9 +2,12 @@ package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference;
import net.minecraft.core.HolderSet;
import net.minecraft.core.MappedRegistry;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.chunk.status.WorldGenContext;
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory;
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter;
@@ -12,6 +15,8 @@ import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName;
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
import java.util.List;
public class Reflection {
public static final MappedRegistryProxy MAPPED_REGISTRY;
@@ -19,6 +24,9 @@ public class Reflection {
public static final ReferenceProxy REFERENCE;
public static final ChunkMapProxy CHUNKMAP;
public static final HolderSetProxy HOLDER_SET;
static {
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
ReflectionProxyFactory reflectionProxyFactory = ReflectionProxyFactory.create(reflectionRemapper,
@@ -27,6 +35,8 @@ public class Reflection {
MAPPED_REGISTRY = reflectionProxyFactory.reflectionProxy(MappedRegistryProxy.class);
STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class);
REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class);
CHUNKMAP = reflectionProxyFactory.reflectionProxy(ChunkMapProxy.class);
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetProxy.class);
}
@@ -49,4 +59,19 @@ public class Reflection {
@MethodName("bindValue")
<T> void invokeBindValue(Reference<T> instance, T value);
}
@Proxies(ChunkMap.class)
public interface ChunkMapProxy {
@FieldGetter("worldGenContext")
WorldGenContext getWorldGenContext(ChunkMap instance);
@FieldSetter("worldGenContext")
void setWorldGenContext(ChunkMap instance, WorldGenContext worldGenContext);
}
@Proxies(HolderSet.class)
public interface HolderSetProxy {
@MethodName("contents")
<T> List<Holder<T>> invokeContents(HolderSet<T> instance);
}
}
@@ -15,7 +15,9 @@ public class RegistryFetcher {
DedicatedServer dedicatedserver = craftserver.getServer();
return dedicatedserver
.registryAccess()
.registryOrThrow(key);
.get(key)
.orElseThrow()
.value();
}
public static Registry<Biome> biomeRegistry() {