Updated Bukkit to support 1.21.3

This commit is contained in:
OakLoaf
2024-10-25 19:36:18 +01:00
parent 32f8907cb1
commit 62756d2784
9 changed files with 32 additions and 17 deletions
+2 -2
View File
@@ -56,8 +56,8 @@ object Versions {
// } // }
object Bukkit { object Bukkit {
const val minecraft = "1.21.1" const val minecraft = "1.21.3"
const val paperBuild = "$minecraft-R0.1-20240917.151311-80" const val paperBuild = "$minecraft-R0.1-20241025.163321-1"
const val paper = paperBuild const val paper = paperBuild
const val paperLib = "1.0.8" const val paperLib = "1.0.8"
const val reflectionRemapper = "0.1.1" const val reflectionRemapper = "0.1.1"
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome; import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.registry.master.ConfigRegistry;
@@ -43,7 +42,7 @@ public class AwfulBukkitHacks {
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey(); NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(), ResourceLocation vanillaMinecraftKey = ResourceLocation.fromNamespaceAndPath(vanillaBukkitKey.getNamespace(),
vanillaBukkitKey.getKey()); 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( ResourceKey<Biome> delegateKey = ResourceKey.create(
Registries.BIOME, Registries.BIOME,
@@ -70,7 +69,7 @@ public class AwfulBukkitHacks {
.getTags() // streamKeysAndEntries .getTags() // streamKeysAndEntries
.collect(HashMap::new, .collect(HashMap::new,
(map, pair) -> (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); HashMap::putAll);
terraBiomeMap terraBiomeMap
@@ -91,8 +90,8 @@ public class AwfulBukkitHacks {
() -> LOGGER.error("No such biome: {}", tb))), () -> LOGGER.error("No such biome: {}", tb))),
() -> LOGGER.error("No vanilla biome: {}", vb))); () -> LOGGER.error("No vanilla biome: {}", vb)));
biomeRegistry.resetTags(); ((MappedRegistry<Biome>) biomeRegistry).bindAllTagsToEmpty();
biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); ImmutableMap.copyOf(collect).forEach(biomeRegistry::bindTag);
} catch(SecurityException | IllegalArgumentException exception) { } catch(SecurityException | IllegalArgumentException exception) {
throw new RuntimeException(exception); throw new RuntimeException(exception);
@@ -19,7 +19,7 @@ public class NMSBiomeInjector {
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) { public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
return registry.getOptional(identifier) return registry.getOptional(identifier)
.flatMap(registry::getResourceKey) .flatMap(registry::getResourceKey)
.flatMap(registry::getHolder); .flatMap(registry::get);
} }
public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla) 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() { protected Stream<Holder<Biome>> collectPossibleBiomes() {
return delegate.stream() return delegate.stream()
.map(biome -> RegistryFetcher.biomeRegistry() .map(biome -> RegistryFetcher.biomeRegistry()
.getHolderOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext() .getOrThrow(((BukkitPlatformBiome) biome.getPlatformBiome()).getContext()
.get(NMSBiomeInfo.class) .get(NMSBiomeInfo.class)
.biomeKey())); .biomeKey()));
} }
@@ -45,7 +45,7 @@ public class NMSBiomeProvider extends BiomeSource {
@Override @Override
public @NotNull Holder<Biome> getNoiseBiome(int x, int y, int z, @NotNull Sampler sampler) { 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() .getPlatformBiome()).getContext()
.get(NMSBiomeInfo.class) .get(NMSBiomeInfo.class)
.biomeKey()); .biomeKey());
@@ -15,7 +15,6 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Beardifier; import net.minecraft.world.level.levelgen.Beardifier;
import net.minecraft.world.level.levelgen.DensityFunction.SinglePointContext; 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.Heightmap.Types;
import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.blending.Blender;
@@ -59,7 +58,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
@Override @Override
public void applyCarvers(@NotNull WorldGenRegion chunkRegion, long seed, @NotNull RandomState noiseConfig, @NotNull BiomeManager world, 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 // no-op
} }
@@ -41,13 +41,14 @@ public class NMSInjectListener implements Listener {
ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator(); ChunkGenerator vanilla = serverWorld.getChunkSource().getGenerator();
NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed()); NMSBiomeProvider provider = new NMSBiomeProvider(pack.getBiomeProvider(), craftWorld.getSeed());
ChunkMap chunkMap = serverWorld.getChunkSource().chunkMap; ChunkMap chunkMap = serverWorld.getChunkSource().chunkMap;
WorldGenContext worldGenContext = chunkMap.worldGenContext; WorldGenContext worldGenContext = Reflection.CHUNKMAP.getWorldGenContext(chunkMap);
Reflection.CHUNKMAP.setWorldGenContext(chunkMap, new WorldGenContext( Reflection.CHUNKMAP.setWorldGenContext(chunkMap, new WorldGenContext(
worldGenContext.level(), worldGenContext.level(),
new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()), new NMSChunkGeneratorDelegate(vanilla, pack, provider, craftWorld.getSeed()),
worldGenContext.structureManager(), worldGenContext.structureManager(),
worldGenContext.lightEngine(), worldGenContext.lightEngine(),
worldGenContext.mainThreadMailBox() worldGenContext.mainThreadExecutor(),
worldGenContext.unsavedListener()
)); ));
LOGGER.info("Successfully injected into world."); LOGGER.info("Successfully injected into world.");
@@ -26,11 +26,11 @@ public class NMSWorldProperties implements WorldProperties {
@Override @Override
public int getMaxHeight() { public int getMaxHeight() {
return height.getMaxBuildHeight(); return height.getMaxY();
} }
@Override @Override
public int getMinHeight() { public int getMinHeight() {
return height.getMinBuildHeight(); return height.getMinY();
} }
} }
@@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit.nms.v1_21;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference; import net.minecraft.core.Holder.Reference;
import net.minecraft.core.HolderSet;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
@@ -14,6 +15,8 @@ import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldSetter;
import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName; import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName;
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies; import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies;
import java.util.List;
public class Reflection { public class Reflection {
public static final MappedRegistryProxy MAPPED_REGISTRY; public static final MappedRegistryProxy MAPPED_REGISTRY;
@@ -22,6 +25,7 @@ public class Reflection {
public static final ReferenceProxy REFERENCE; public static final ReferenceProxy REFERENCE;
public static final ChunkMapProxy CHUNKMAP; public static final ChunkMapProxy CHUNKMAP;
public static final HolderSetProxy HOLDER_SET;
static { static {
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
@@ -32,6 +36,7 @@ public class Reflection {
STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class); STRUCTURE_MANAGER = reflectionProxyFactory.reflectionProxy(StructureManagerProxy.class);
REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class); REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class);
CHUNKMAP = reflectionProxyFactory.reflectionProxy(ChunkMapProxy.class); CHUNKMAP = reflectionProxyFactory.reflectionProxy(ChunkMapProxy.class);
HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetProxy.class);
} }
@@ -57,7 +62,16 @@ public class Reflection {
@Proxies(ChunkMap.class) @Proxies(ChunkMap.class)
public interface ChunkMapProxy { public interface ChunkMapProxy {
@FieldGetter("worldGenContext")
WorldGenContext getWorldGenContext(ChunkMap instance);
@FieldSetter("worldGenContext") @FieldSetter("worldGenContext")
void setWorldGenContext(ChunkMap instance, WorldGenContext 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(); DedicatedServer dedicatedserver = craftserver.getServer();
return dedicatedserver return dedicatedserver
.registryAccess() .registryAccess()
.registryOrThrow(key); .get(key)
.orElseThrow()
.value();
} }
public static Registry<Biome> biomeRegistry() { public static Registry<Biome> biomeRegistry() {