mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 16:18:02 +01:00
174 lines
7.7 KiB
Diff
174 lines
7.7 KiB
Diff
--- a/net/minecraft/stats/ServerRecipeBook.java
|
|
+++ b/net/minecraft/stats/ServerRecipeBook.java
|
|
@@ -4,6 +4,7 @@
|
|
import com.mojang.logging.LogUtils;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.function.Consumer;
|
|
@@ -19,27 +20,35 @@
|
|
import net.minecraft.world.item.crafting.RecipeManager;
|
|
import org.slf4j.Logger;
|
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
|
+
|
|
public class ServerRecipeBook extends RecipeBook {
|
|
+
|
|
public static final String RECIPE_BOOK_TAG = "recipeBook";
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
|
|
+ public ServerRecipeBook() {}
|
|
+
|
|
public int addRecipes(Collection<RecipeHolder<?>> recipes, ServerPlayer player) {
|
|
List<ResourceLocation> list = Lists.newArrayList();
|
|
int i = 0;
|
|
+ Iterator iterator = recipes.iterator();
|
|
|
|
- for (RecipeHolder<?> recipeHolder : recipes) {
|
|
- ResourceLocation resourceLocation = recipeHolder.id();
|
|
- if (!this.known.contains(resourceLocation) && !recipeHolder.value().isSpecial()) {
|
|
- this.add(resourceLocation);
|
|
- this.addHighlight(resourceLocation);
|
|
- list.add(resourceLocation);
|
|
- CriteriaTriggers.RECIPE_UNLOCKED.trigger(player, recipeHolder);
|
|
- i++;
|
|
+ while (iterator.hasNext()) {
|
|
+ RecipeHolder<?> recipeholder = (RecipeHolder) iterator.next();
|
|
+ ResourceLocation minecraftkey = recipeholder.id();
|
|
+
|
|
+ if (!this.known.contains(minecraftkey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(player, minecraftkey)) { // CraftBukkit
|
|
+ this.add(minecraftkey);
|
|
+ this.addHighlight(minecraftkey);
|
|
+ list.add(minecraftkey);
|
|
+ CriteriaTriggers.RECIPE_UNLOCKED.trigger(player, recipeholder);
|
|
+ ++i;
|
|
}
|
|
}
|
|
|
|
if (list.size() > 0) {
|
|
- this.sendRecipes(ClientboundRecipePacket.State.ADD, player, list);
|
|
+ this.sendRecipes(ClientboundRecipePacket.Action.ADD, player, list);
|
|
}
|
|
|
|
return i;
|
|
@@ -48,71 +57,86 @@
|
|
public int removeRecipes(Collection<RecipeHolder<?>> recipes, ServerPlayer player) {
|
|
List<ResourceLocation> list = Lists.newArrayList();
|
|
int i = 0;
|
|
+ Iterator iterator = recipes.iterator();
|
|
|
|
- for (RecipeHolder<?> recipeHolder : recipes) {
|
|
- ResourceLocation resourceLocation = recipeHolder.id();
|
|
- if (this.known.contains(resourceLocation)) {
|
|
- this.remove(resourceLocation);
|
|
- list.add(resourceLocation);
|
|
- i++;
|
|
+ while (iterator.hasNext()) {
|
|
+ RecipeHolder<?> recipeholder = (RecipeHolder) iterator.next();
|
|
+ ResourceLocation minecraftkey = recipeholder.id();
|
|
+
|
|
+ if (this.known.contains(minecraftkey)) {
|
|
+ this.remove(minecraftkey);
|
|
+ list.add(minecraftkey);
|
|
+ ++i;
|
|
}
|
|
}
|
|
|
|
- this.sendRecipes(ClientboundRecipePacket.State.REMOVE, player, list);
|
|
+ this.sendRecipes(ClientboundRecipePacket.Action.REMOVE, player, list);
|
|
return i;
|
|
}
|
|
|
|
- private void sendRecipes(ClientboundRecipePacket.State state, ServerPlayer player, List<ResourceLocation> recipes) {
|
|
+ private void sendRecipes(ClientboundRecipePacket.Action state, ServerPlayer player, List<ResourceLocation> recipes) {
|
|
+ if (player.connection == null) return; // SPIGOT-4478 during PlayerLoginEvent
|
|
player.connection.send(new ClientboundRecipePacket(state, recipes, Collections.emptyList(), this.getBookSettings()));
|
|
}
|
|
|
|
public CompoundTag toNbt() {
|
|
- CompoundTag compoundTag = new CompoundTag();
|
|
- this.getBookSettings().write(compoundTag);
|
|
- ListTag list = new ListTag();
|
|
+ CompoundTag nbttagcompound = new CompoundTag();
|
|
|
|
- for (ResourceLocation resourceLocation : this.known) {
|
|
- list.add(StringTag.valueOf(resourceLocation.toString()));
|
|
+ this.getBookSettings().write(nbttagcompound);
|
|
+ ListTag nbttaglist = new ListTag();
|
|
+ Iterator iterator = this.known.iterator();
|
|
+
|
|
+ while (iterator.hasNext()) {
|
|
+ ResourceLocation minecraftkey = (ResourceLocation) iterator.next();
|
|
+
|
|
+ nbttaglist.add(StringTag.valueOf(minecraftkey.toString()));
|
|
}
|
|
|
|
- compoundTag.put("recipes", list);
|
|
- ListTag list1 = new ListTag();
|
|
+ nbttagcompound.put("recipes", nbttaglist);
|
|
+ ListTag nbttaglist1 = new ListTag();
|
|
+ Iterator iterator1 = this.highlight.iterator();
|
|
|
|
- for (ResourceLocation resourceLocation1 : this.highlight) {
|
|
- list1.add(StringTag.valueOf(resourceLocation1.toString()));
|
|
+ while (iterator1.hasNext()) {
|
|
+ ResourceLocation minecraftkey1 = (ResourceLocation) iterator1.next();
|
|
+
|
|
+ nbttaglist1.add(StringTag.valueOf(minecraftkey1.toString()));
|
|
}
|
|
|
|
- compoundTag.put("toBeDisplayed", list1);
|
|
- return compoundTag;
|
|
+ nbttagcompound.put("toBeDisplayed", nbttaglist1);
|
|
+ return nbttagcompound;
|
|
}
|
|
|
|
public void fromNbt(CompoundTag tag, RecipeManager recipeManager) {
|
|
this.setBookSettings(RecipeBookSettings.read(tag));
|
|
- ListTag list = tag.getList("recipes", 8);
|
|
- this.loadRecipes(list, this::add, recipeManager);
|
|
- ListTag list1 = tag.getList("toBeDisplayed", 8);
|
|
- this.loadRecipes(list1, this::addHighlight, recipeManager);
|
|
+ ListTag nbttaglist = tag.getList("recipes", 8);
|
|
+
|
|
+ this.loadRecipes(nbttaglist, this::add, recipeManager);
|
|
+ ListTag nbttaglist1 = tag.getList("toBeDisplayed", 8);
|
|
+
|
|
+ this.loadRecipes(nbttaglist1, this::addHighlight, recipeManager);
|
|
}
|
|
|
|
private void loadRecipes(ListTag tags, Consumer<RecipeHolder<?>> recipeConsumer, RecipeManager recipeManager) {
|
|
- for (int i = 0; i < tags.size(); i++) {
|
|
- String string = tags.getString(i);
|
|
+ for (int i = 0; i < tags.size(); ++i) {
|
|
+ String s = tags.getString(i);
|
|
|
|
try {
|
|
- ResourceLocation resourceLocation = new ResourceLocation(string);
|
|
- Optional<RecipeHolder<?>> optional = recipeManager.byKey(resourceLocation);
|
|
+ ResourceLocation minecraftkey = new ResourceLocation(s);
|
|
+ Optional<RecipeHolder<?>> optional = recipeManager.byKey(minecraftkey);
|
|
+
|
|
if (optional.isEmpty()) {
|
|
- LOGGER.error("Tried to load unrecognized recipe: {} removed now.", resourceLocation);
|
|
+ ServerRecipeBook.LOGGER.error("Tried to load unrecognized recipe: {} removed now.", minecraftkey);
|
|
} else {
|
|
- recipeConsumer.accept(optional.get());
|
|
+ recipeConsumer.accept((RecipeHolder) optional.get());
|
|
}
|
|
- } catch (ResourceLocationException var8) {
|
|
- LOGGER.error("Tried to load improperly formatted recipe: {} removed now.", string);
|
|
+ } catch (ResourceLocationException resourcekeyinvalidexception) {
|
|
+ ServerRecipeBook.LOGGER.error("Tried to load improperly formatted recipe: {} removed now.", s);
|
|
}
|
|
}
|
|
+
|
|
}
|
|
|
|
public void sendInitialRecipeBook(ServerPlayer player) {
|
|
- player.connection.send(new ClientboundRecipePacket(ClientboundRecipePacket.State.INIT, this.known, this.highlight, this.getBookSettings()));
|
|
+ player.connection.send(new ClientboundRecipePacket(ClientboundRecipePacket.Action.INIT, this.known, this.highlight, this.getBookSettings()));
|
|
}
|
|
}
|