From 65e8faf29a68d8cbde4bed08a377dd83171c9720 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 2 Jul 2020 09:27:18 +1000 Subject: [PATCH] #682: Add hasDiscoveredRecipe() and getDiscoveredRecipes() By: Parker Hawke --- paper-server/nms-patches/RecipeBook.patch | 11 +++++++++++ .../craftbukkit/entity/CraftHumanEntity.java | 11 +++++++++++ .../bukkit/craftbukkit/entity/CraftPlayer.java | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 paper-server/nms-patches/RecipeBook.patch diff --git a/paper-server/nms-patches/RecipeBook.patch b/paper-server/nms-patches/RecipeBook.patch new file mode 100644 index 0000000000..2034712bcb --- /dev/null +++ b/paper-server/nms-patches/RecipeBook.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/server/RecipeBook.java ++++ b/net/minecraft/server/RecipeBook.java +@@ -6,7 +6,7 @@ + + public class RecipeBook { + +- protected final Set a = Sets.newHashSet(); ++ public final Set a = Sets.newHashSet(); // PAIL + protected final Set b = Sets.newHashSet(); + protected boolean c; + protected boolean d; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index fdebdf85c4..60ef17fdb1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -506,6 +507,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { return getHandle().undiscoverRecipes(bukkitKeysToMinecraftRecipes(recipes)); } + @Override + public boolean hasDiscoveredRecipe(NamespacedKey recipe) { + return false; + } + + @Override + public Set getDiscoveredRecipes() { + return ImmutableSet.of(); + } + private Collection> bukkitKeysToMinecraftRecipes(Collection recipeKeys) { Collection> recipes = new ArrayList<>(); CraftingManager manager = getHandle().world.getMinecraftServer().getCraftingManager(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 35b25a02c0..9f027e1f1c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -77,6 +77,7 @@ import org.bukkit.GameMode; import org.bukkit.Instrument; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Note; import org.bukkit.OfflinePlayer; import org.bukkit.Particle; @@ -106,6 +107,7 @@ import org.bukkit.craftbukkit.map.RenderData; import org.bukkit.craftbukkit.scoreboard.CraftScoreboard; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerRegisterChannelEvent; @@ -757,6 +759,19 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return new Location(getWorld(), bed.getX(), bed.getY(), bed.getZ()); } + @Override + public boolean hasDiscoveredRecipe(NamespacedKey recipe) { + Preconditions.checkArgument(recipe != null, "recipe cannot be null"); + return getHandle().B().b(CraftNamespacedKey.toMinecraft(recipe)); + } + + @Override + public Set getDiscoveredRecipes() { + ImmutableSet.Builder bukkitRecipeKeys = ImmutableSet.builder(); + getHandle().B().a.forEach(key -> bukkitRecipeKeys.add(CraftNamespacedKey.fromMinecraft(key))); + return bukkitRecipeKeys.build(); + } + @Override public void incrementStatistic(Statistic statistic) { CraftStatistic.incrementStatistic(getHandle().getStatisticManager(), statistic);