1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
--- a/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -3,31 +3,54 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
-import java.util.List;
+import it.unimi.dsi.fastutil.ints.IntList;
+import java.util.Iterator;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.entity.player.StackedContents;
-import net.minecraft.world.inventory.CraftingContainer;
+import net.minecraft.world.inventory.InventoryCrafting;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
+// CraftBukkit start
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
+// CraftBukkit end
-public class ShapelessRecipe implements CraftingRecipe {
+public class ShapelessRecipe implements RecipeCrafting {
+
final String group;
final CraftingBookCategory category;
final ItemStack result;
final NonNullList<Ingredient> ingredients;
- public ShapelessRecipe(String string, CraftingBookCategory craftingBookCategory, ItemStack itemStack, NonNullList<Ingredient> list) {
- this.group = string;
- this.category = craftingBookCategory;
- this.result = itemStack;
- this.ingredients = list;
+ public ShapelessRecipe(String s, CraftingBookCategory craftingbookcategory, ItemStack itemstack, NonNullList<Ingredient> nonnulllist) {
+ this.group = s;
+ this.category = craftingbookcategory;
+ this.result = itemstack;
+ this.ingredients = nonnulllist;
}
+ // CraftBukkit start
+ @SuppressWarnings("unchecked")
@Override
+ public org.bukkit.inventory.ShapelessRecipe toBukkitRecipe(NamespacedKey id) {
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
+ CraftShapelessRecipe recipe = new CraftShapelessRecipe(id, result, this);
+ recipe.setGroup(this.group);
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ for (Ingredient list : this.ingredients) {
+ recipe.addIngredient(CraftRecipe.toBukkit(list));
+ }
+ return recipe;
+ }
+ // CraftBukkit end
+
+ @Override
public RecipeSerializer<?> getSerializer() {
return RecipeSerializer.SHAPELESS_RECIPE;
}
@@ -52,24 +75,23 @@
return this.ingredients;
}
- @Override
- public boolean matches(CraftingContainer inv, Level level) {
- StackedContents stackedContents = new StackedContents();
+ public boolean matches(InventoryCrafting inv, Level level) {
+ StackedContents autorecipestackmanager = new StackedContents();
int i = 0;
- for (int i1 = 0; i1 < inv.getContainerSize(); i1++) {
- ItemStack item = inv.getItem(i1);
- if (!item.isEmpty()) {
- i++;
- stackedContents.accountStack(item, 1);
+ for (int j = 0; j < inv.getContainerSize(); ++j) {
+ ItemStack itemstack = inv.getItem(j);
+
+ if (!itemstack.isEmpty()) {
+ ++i;
+ autorecipestackmanager.accountStack(itemstack, 1);
}
}
- return i == this.ingredients.size() && stackedContents.canCraft(this, null);
+ return i == this.ingredients.size() && autorecipestackmanager.canCraft(this, (IntList) null);
}
- @Override
- public ItemStack assemble(CraftingContainer container, RegistryAccess registryAccess) {
+ public ItemStack assemble(InventoryCrafting container, RegistryAccess registryAccess) {
return this.result.copy();
}
@@ -79,60 +101,64 @@
}
public static class Serializer implements RecipeSerializer<ShapelessRecipe> {
- private static final Codec<ShapelessRecipe> CODEC = RecordCodecBuilder.create(
- instance -> instance.group(
- ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter(shapelessRecipe -> shapelessRecipe.group),
- CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(shapelessRecipe -> shapelessRecipe.category),
- ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter(shapelessRecipe -> shapelessRecipe.result),
- Ingredient.CODEC_NONEMPTY
- .listOf()
- .fieldOf("ingredients")
- .flatXmap(
- list -> {
- Ingredient[] ingredients = list.stream().filter(ingredient -> !ingredient.isEmpty()).toArray(Ingredient[]::new);
- if (ingredients.length == 0) {
- return DataResult.error(() -> "No ingredients for shapeless recipe");
- } else {
- return ingredients.length > 9
- ? DataResult.error(() -> "Too many ingredients for shapeless recipe")
- : DataResult.success(NonNullList.of(Ingredient.EMPTY, ingredients));
- }
- },
- DataResult::success
- )
- .forGetter(shapelessRecipe -> shapelessRecipe.ingredients)
- )
- .apply(instance, ShapelessRecipe::new)
- );
+ private static final Codec<ShapelessRecipe> CODEC = RecordCodecBuilder.create((instance) -> {
+ return instance.group(ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter((shapelessrecipes) -> {
+ return shapelessrecipes.group;
+ }), CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter((shapelessrecipes) -> {
+ return shapelessrecipes.category;
+ }), ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter((shapelessrecipes) -> {
+ return shapelessrecipes.result;
+ }), Ingredient.CODEC_NONEMPTY.listOf().fieldOf("ingredients").flatXmap((list) -> {
+ Ingredient[] arecipeitemstack = (Ingredient[]) list.stream().filter((recipeitemstack) -> {
+ return !recipeitemstack.isEmpty();
+ }).toArray((i) -> {
+ return new Ingredient[i];
+ });
+
+ return arecipeitemstack.length == 0 ? DataResult.error(() -> {
+ return "No ingredients for shapeless recipe";
+ }) : (arecipeitemstack.length > 9 ? DataResult.error(() -> {
+ return "Too many ingredients for shapeless recipe";
+ }) : DataResult.success(NonNullList.of(Ingredient.EMPTY, arecipeitemstack)));
+ }, DataResult::success).forGetter((shapelessrecipes) -> {
+ return shapelessrecipes.ingredients;
+ })).apply(instance, ShapelessRecipe::new);
+ });
+
+ public Serializer() {}
+
@Override
public Codec<ShapelessRecipe> codec() {
- return CODEC;
+ return ShapelessRecipe.Serializer.CODEC;
}
@Override
- public ShapelessRecipe fromNetwork(FriendlyByteBuf friendlyByteBuf) {
- String utf = friendlyByteBuf.readUtf();
- CraftingBookCategory craftingBookCategory = friendlyByteBuf.readEnum(CraftingBookCategory.class);
- int varInt = friendlyByteBuf.readVarInt();
- NonNullList<Ingredient> list = NonNullList.withSize(varInt, Ingredient.EMPTY);
+ public ShapelessRecipe fromNetwork(FriendlyByteBuf packetdataserializer) {
+ String s = packetdataserializer.readUtf();
+ CraftingBookCategory craftingbookcategory = (CraftingBookCategory) packetdataserializer.readEnum(CraftingBookCategory.class);
+ int i = packetdataserializer.readVarInt();
+ NonNullList<Ingredient> nonnulllist = NonNullList.withSize(i, Ingredient.EMPTY);
- for (int i = 0; i < list.size(); i++) {
- list.set(i, Ingredient.fromNetwork(friendlyByteBuf));
+ for (int j = 0; j < nonnulllist.size(); ++j) {
+ nonnulllist.set(j, Ingredient.fromNetwork(packetdataserializer));
}
- ItemStack item = friendlyByteBuf.readItem();
- return new ShapelessRecipe(utf, craftingBookCategory, item, list);
+ ItemStack itemstack = packetdataserializer.readItem();
+
+ return new ShapelessRecipe(s, craftingbookcategory, itemstack, nonnulllist);
}
- @Override
public void toNetwork(FriendlyByteBuf buffer, ShapelessRecipe recipe) {
buffer.writeUtf(recipe.group);
buffer.writeEnum(recipe.category);
buffer.writeVarInt(recipe.ingredients.size());
+ Iterator iterator = recipe.ingredients.iterator();
- for (Ingredient ingredient : recipe.ingredients) {
- ingredient.toNetwork(buffer);
+ while (iterator.hasNext()) {
+ Ingredient recipeitemstack = (Ingredient) iterator.next();
+
+ recipeitemstack.toNetwork(buffer);
}
buffer.writeItem(recipe.result);
|