#682: Add hasDiscoveredRecipe() and getDiscoveredRecipes()

This commit is contained in:
Parker Hawke 2020-07-02 09:27:18 +10:00 committed by md_5
parent d9bd43b060
commit 8297676c20
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 37 additions and 0 deletions

View File

@ -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<MinecraftKey> a = Sets.newHashSet();
+ public final Set<MinecraftKey> a = Sets.newHashSet(); // PAIL
protected final Set<MinecraftKey> b = Sets.newHashSet();
protected boolean c;
protected boolean d;

View File

@ -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<NamespacedKey> getDiscoveredRecipes() {
return ImmutableSet.of();
}
private Collection<IRecipe<?>> bukkitKeysToMinecraftRecipes(Collection<NamespacedKey> recipeKeys) {
Collection<IRecipe<?>> recipes = new ArrayList<>();
CraftingManager manager = getHandle().world.getMinecraftServer().getCraftingManager();

View File

@ -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<NamespacedKey> getDiscoveredRecipes() {
ImmutableSet.Builder<NamespacedKey> 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);