From 9c8593cb14f7fbe7333bf9d9f2fd65a7fc165c80 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 25 Apr 2024 19:54:07 -0700 Subject: [PATCH] compile fixes --- patches/server/Adventure.patch | 6 ++-- .../Flat-bedrock-generator-settings.patch | 6 +++- patches/server/Implement-Mob-Goal-API.patch | 9 ++++-- patches/server/ItemStack-Tooltip-API.patch | 4 ++- .../server/Mob-Spawner-API-Enhancements.patch | 12 ++++++-- patches/server/More-CommandBlock-API.patch | 2 +- patches/server/Paper-dumpitem-command.patch | 3 ++ patches/server/Rewrite-chunk-system.patch | 28 +++++++++++-------- 8 files changed, 47 insertions(+), 23 deletions(-) diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 757a3b4ced..475ecc5959 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -925,7 +925,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + private net.kyori.adventure.chat.ChatType.Bound adventure(ChatType.Bound chatType) { + @Subst("key:value") final String stringKey = Objects.requireNonNull( -+ ChatProcessor.this.server.registryAccess().registryOrThrow(Registries.CHAT_TYPE).getKey(chatType.chatType()), ++ chatType.chatType().unwrapKey().orElseThrow().location(), + () -> "No key for '%s' in CHAT_TYPE registry.".formatted(chatType) + ).toString(); + net.kyori.adventure.chat.@Nullable ChatType adventure = BUILT_IN_CHAT_TYPES.get(stringKey); @@ -934,7 +934,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + return adventure.bind( + PaperAdventure.asAdventure(chatType.name()), -+ PaperAdventure.asAdventure(chatType.targetName()) ++ chatType.targetName().map(PaperAdventure::asAdventure).orElse(null) + ); + } + @@ -3603,7 +3603,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public void name(net.kyori.adventure.text.Component name) { -+ getSnapshot().getCommandBlock().setName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name)); ++ getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name)); + } + // Paper end } diff --git a/patches/server/Flat-bedrock-generator-settings.patch b/patches/server/Flat-bedrock-generator-settings.patch index b02ea581b9..aab963184f 100644 --- a/patches/server/Flat-bedrock-generator-settings.patch +++ b/patches/server/Flat-bedrock-generator-settings.patch @@ -27,6 +27,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +package io.papermc.paper.world.worldgen; + +import com.mojang.serialization.Codec; ++import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; @@ -46,7 +47,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +@DefaultQualifier(NonNull.class) +public record OptionallyFlatBedrockConditionSource(ResourceLocation randomName, VerticalAnchor trueAtAndBelow, VerticalAnchor falseAtAndAbove, boolean isRoof) implements SurfaceRules.ConditionSource { + -+ private static final ResourceKey> CODEC_RESOURCE_KEY = ResourceKey.create(Registries.MATERIAL_CONDITION, new ResourceLocation(ResourceLocation.PAPER_NAMESPACE, "optionally_flat_bedrock_condition_source")); ++ private static final ResourceKey> CODEC_RESOURCE_KEY = ResourceKey.create( ++ Registries.MATERIAL_CONDITION, ++ new ResourceLocation(ResourceLocation.PAPER_NAMESPACE, "optionally_flat_bedrock_condition_source") ++ ); + private static final KeyDispatchDataCodec CODEC = KeyDispatchDataCodec.of(RecordCodecBuilder.mapCodec((instance) -> { + return instance.group( + ResourceLocation.CODEC.fieldOf("random_name").forGetter(OptionallyFlatBedrockConditionSource::randomName), diff --git a/patches/server/Implement-Mob-Goal-API.patch b/patches/server/Implement-Mob-Goal-API.patch index 475bb942a8..90dc34b726 100644 --- a/patches/server/Implement-Mob-Goal-API.patch +++ b/patches/server/Implement-Mob-Goal-API.patch @@ -273,7 +273,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + public static String getUsableName(Class clazz) { -+ String name = MappingEnvironment.reobf() ? ObfHelper.INSTANCE.deobfClassName(clazz.getName()) : clazz.getName(); ++ String name = io.papermc.paper.util.MappingEnvironment.reobf() ? ObfHelper.INSTANCE.deobfClassName(clazz.getName()) : clazz.getName(); + name = name.substring(name.lastIndexOf(".") + 1); + boolean flag = false; + // inner classes @@ -625,7 +625,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public Collection> getRunningGoals(T mob, GoalType type) { + CraftMob craftMob = (CraftMob) mob; + Set> goals = new HashSet<>(); -+ getHandle(craftMob, type).getRunningGoals() ++ getHandle(craftMob, type).getAvailableGoals() ++ .stream().filter(WrappedGoal::isRunning) + .filter(item -> item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type))) + .forEach(item -> { + if (item.getGoal() instanceof PaperCustomGoal) { @@ -646,7 +647,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (internalType == type) { + continue; + } -+ getHandle(craftMob, internalType).getRunningGoals() ++ getHandle(craftMob, internalType).getAvailableGoals() ++ .stream() ++ .filter(WrappedGoal::isRunning) + .filter(item -> !item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type))) + .forEach(item -> { + if (item.getGoal() instanceof PaperCustomGoal) { diff --git a/patches/server/ItemStack-Tooltip-API.patch b/patches/server/ItemStack-Tooltip-API.patch index 37c29b717e..594264b3e9 100644 --- a/patches/server/ItemStack-Tooltip-API.patch +++ b/patches/server/ItemStack-Tooltip-API.patch @@ -20,7 +20,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (tooltipContext.isCreative()) { + flag = flag.asCreative(); + } -+ final java.util.List lines = CraftItemStack.asNMSCopy(itemStack).getTooltipLines(player == null ? null : ((org.bukkit.craftbukkit.entity.CraftPlayer) player).getHandle(), flag); ++ final java.util.List lines = CraftItemStack.asNMSCopy(itemStack).getTooltipLines( ++ net.minecraft.world.item.Item.TooltipContext.of(player == null ? net.minecraft.server.MinecraftServer.getServer().registryAccess() : ((org.bukkit.craftbukkit.entity.CraftPlayer) player).getHandle().level().registryAccess()), ++ player == null ? null : ((org.bukkit.craftbukkit.entity.CraftPlayer) player).getHandle(), flag); + return lines.stream().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).toList(); + } + // Paper end - expose itemstack tooltip lines diff --git a/patches/server/Mob-Spawner-API-Enhancements.patch b/patches/server/Mob-Spawner-API-Enhancements.patch index 18a59b6ec8..d288aca7e1 100644 --- a/patches/server/Mob-Spawner-API-Enhancements.patch +++ b/patches/server/Mob-Spawner-API-Enhancements.patch @@ -96,8 +96,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + net.minecraft.world.item.ItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(itemStack); + net.minecraft.nbt.CompoundTag entity = new net.minecraft.nbt.CompoundTag(); + entity.putString("id", net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString()); -+ entity.put("Item", item.save(new net.minecraft.nbt.CompoundTag())); -+ this.getSnapshot().getSpawner().setNextSpawnData(this.isPlaced() ? this.world.getHandle() : null, this.getPosition(), new net.minecraft.world.level.SpawnData(entity, java.util.Optional.empty())); ++ entity.put("Item", item.save(this.world.getHandle().registryAccess())); ++ this.getSnapshot().getSpawner().setNextSpawnData( ++ this.isPlaced() ? this.world.getHandle() : null, ++ this.getPosition(), ++ new net.minecraft.world.level.SpawnData( ++ entity, ++ java.util.Optional.empty(), ++ Optional.ofNullable(this.getSnapshot().getSpawner().nextSpawnData).flatMap(SpawnData::equipment) ++ ) ++ ); + } + // Paper end } diff --git a/patches/server/More-CommandBlock-API.patch b/patches/server/More-CommandBlock-API.patch index 5645763550..05ca808fa4 100644 --- a/patches/server/More-CommandBlock-API.patch +++ b/patches/server/More-CommandBlock-API.patch @@ -58,7 +58,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 super(world, tileEntity); @@ -0,0 +0,0 @@ public class CraftCommandBlock extends CraftBlockEntityState public void name(net.kyori.adventure.text.Component name) { - getSnapshot().getCommandBlock().setName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name)); + getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name)); } + + @Override diff --git a/patches/server/Paper-dumpitem-command.patch b/patches/server/Paper-dumpitem-command.patch index e81c2453a8..dedec91967 100644 --- a/patches/server/Paper-dumpitem-command.patch +++ b/patches/server/Paper-dumpitem-command.patch @@ -57,6 +57,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + private void doDumpItem(final CommandSender sender) { ++ if (true) throw new UnsupportedOperationException("FIXME"); // TODO ++ /* + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command"); + return; @@ -80,5 +82,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .color(GRAY) + .decorate(ITALIC) + .clickEvent(ClickEvent.copyToClipboard(tag == null ? itemId : (itemId + tag)))); ++ */ + } +} diff --git a/patches/server/Rewrite-chunk-system.patch b/patches/server/Rewrite-chunk-system.patch index d36d3de3dd..2fd02c1c58 100644 --- a/patches/server/Rewrite-chunk-system.patch +++ b/patches/server/Rewrite-chunk-system.patch @@ -8869,15 +8869,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor; +import ca.spottedleaf.concurrentutil.util.ConcurrentUtil; -+import com.mojang.datafixers.util.Either; +import com.mojang.logging.LogUtils; -+import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ChunkMap; ++import net.minecraft.server.level.ChunkResult; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.status.ChunkStatus; +import net.minecraft.world.level.chunk.ProtoChunk; ++import net.minecraft.world.level.chunk.status.WorldGenContext; +import org.slf4j.Logger; +import java.lang.invoke.VarHandle; +import java.util.List; @@ -8931,7 +8931,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + final ServerChunkCache serverChunkCache = this.world.chunkSource; + final ChunkMap chunkMap = serverChunkCache.chunkMap; + -+ final CompletableFuture> completeFuture; ++ final CompletableFuture completeFuture; + + final boolean generation; + boolean completing = false; @@ -8939,6 +8939,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // note: should optimise the case where the chunk does not need to execute the status, because + // schedule() calls this synchronously if it will run through that path + ++ final WorldGenContext ctx = new WorldGenContext( ++ this.world, ++ chunkMap.generator, ++ chunkMap.getWorldGenContext().structureManager(), ++ serverChunkCache.getLightEngine() ++ ); + try { + generation = !chunk.getStatus().isOrAfter(this.toStatus); + if (generation) { @@ -8950,12 +8956,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + this.complete(chunk, null); + return; + } -+ completeFuture = this.toStatus.generate(Runnable::run, this.world, chunkMap.generator, chunkMap.structureTemplateManager, -+ serverChunkCache.getLightEngine(), null, this.neighbours) -+ .whenComplete((final Either either, final Throwable throwable) -> { -+ final ChunkAccess newChunk = (either == null) ? null : either.left().orElse(null); -+ if (newChunk instanceof ProtoChunk) { -+ ((ProtoChunk)newChunk).setStatus(ChunkUpgradeGenericStatusTask.this.toStatus); ++ completeFuture = this.toStatus.generate(ctx, Runnable::run, null, this.neighbours) ++ .whenComplete((final ChunkAccess either, final Throwable throwable) -> { ++ if (either instanceof ProtoChunk proto) { ++ proto.setStatus(ChunkUpgradeGenericStatusTask.this.toStatus); + } + } + ); @@ -8965,7 +8969,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + this.complete(chunk, null); + return; + } -+ completeFuture = this.toStatus.load(this.world, chunkMap.structureTemplateManager, serverChunkCache.getLightEngine(), null, chunk); ++ completeFuture = this.toStatus.load(ctx, null, chunk); + } + } catch (final Throwable throwable) { + if (!completing) { @@ -8996,12 +9000,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + LOGGER.warn("Future status not complete after scheduling: " + this.toStatus.toString() + ", generate: " + generation); + } + -+ final Either either; ++ final ChunkResult either; + final ChunkAccess newChunk; + + try { + either = completeFuture.join(); -+ newChunk = (either == null) ? null : either.left().orElse(null); ++ newChunk = (either == null) ? null : either.orElse(null); + } catch (final Throwable throwable) { + this.complete(null, throwable); + // ensure the chunk system can respond, then die