Paper/patches/server/0980-API-for-updating-recipes-on-clients.patch
Nassim Jahnke 9df2066642
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
dfe1fb48 PR-906: Add missing MinecraftExperimental annotation to Bundles
825ab30d PR-905: Add missing MapCursor.Type and update documentation
e03d10e6 PR-903: Make BARRIER Waterlogged
1961ead6 PR-898: Use Java Consumer instead of Bukkit Consumer

CraftBukkit Changes:
f71a799f0 Make BARRIER Waterlogged
172f76a45 Upgrade specialsource-maven-plugin
f0702775c SPIGOT-7486: Alternate approach to null profile names
069495671 SPIGOT-7485: Allow air entity items since required for Vanilla logic
5dfd33dc2 SPIGOT-7484: Cancelling PlayerEditBookEvent does not update client's book contents
02d490788 PR-1250: Standardize and centralize Bukkit / Minecraft registry conversion
9024a09b9 PR-1251: Use Java Consumer instead of Bukkit Consumer
6d4b25bf1 Increase diff stability
2023-09-23 12:21:59 +10:00

115 lines
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 21 Aug 2021 17:25:38 -0700
Subject: [PATCH] API for updating recipes on clients
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 723a87701a44e379c80e6def91c5340e37c87ba1..986ab7dd2135b4cb871923b20e3dc83e17e2bae9 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1518,6 +1518,13 @@ public abstract class PlayerList {
}
public void reloadResources() {
+ // Paper start - split this method up into separate methods
+ this.reloadAdvancementData();
+ this.reloadTagData();
+ this.reloadRecipeData();
+ }
+ public void reloadAdvancementData() {
+ // Paper end
// CraftBukkit start
/*Iterator iterator = this.advancements.values().iterator();
@@ -1533,7 +1540,15 @@ public abstract class PlayerList {
}
// CraftBukkit end
+ // Paper start
+ }
+ public void reloadTagData() {
+ // Paper end
this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries)));
+ // Paper start
+ }
+ public void reloadRecipeData() {
+ // Paper end
ClientboundUpdateRecipesPacket packetplayoutrecipeupdate = new ClientboundUpdateRecipesPacket(this.server.getRecipeManager().getRecipes());
Iterator iterator1 = this.players.iterator();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 3c5ae22e97a0dc7307161b6a96140dae2be25995..a3d1d4d259014f55feda56dc97c2cfd48891de12 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1131,6 +1131,18 @@ public final class CraftServer implements Server {
ReloadCommand.reload(console);
}
+ // Paper start
+ @Override
+ public void updateResources() {
+ this.playerList.reloadResources();
+ }
+
+ @Override
+ public void updateRecipes() {
+ this.playerList.reloadRecipeData();
+ }
+ // Paper end
+
private void loadIcon() {
this.icon = new CraftIconCache(null);
try {
@@ -1473,6 +1485,13 @@ public final class CraftServer implements Server {
@Override
public boolean addRecipe(Recipe recipe) {
+ // Paper start
+ return this.addRecipe(recipe, false);
+ }
+
+ @Override
+ public boolean addRecipe(Recipe recipe, boolean resendRecipes) {
+ // Paper end
CraftRecipe toAdd;
if (recipe instanceof CraftRecipe) {
toAdd = (CraftRecipe) recipe;
@@ -1502,6 +1521,11 @@ public final class CraftServer implements Server {
}
}
toAdd.addToCraftingManager();
+ // Paper start
+ if (resendRecipes) {
+ this.playerList.reloadRecipeData();
+ }
+ // Paper end
return true;
}
@@ -1621,10 +1645,23 @@ public final class CraftServer implements Server {
@Override
public boolean removeRecipe(NamespacedKey recipeKey) {
+ // Paper start
+ return this.removeRecipe(recipeKey, false);
+ }
+
+ @Override
+ public boolean removeRecipe(NamespacedKey recipeKey, boolean resendRecipes) {
+ // Paper end
Preconditions.checkArgument(recipeKey != null, "recipeKey == null");
ResourceLocation mcKey = CraftNamespacedKey.toMinecraft(recipeKey);
- return this.getServer().getRecipeManager().removeRecipe(mcKey);
+ // Paper start - resend recipes on successful removal
+ boolean removed = this.getServer().getRecipeManager().removeRecipe(mcKey);
+ if (removed && resendRecipes) {
+ this.playerList.reloadRecipeData();
+ }
+ return removed;
+ // Paper end
}
@Override