Skip to content

Commit

Permalink
Refactor Ingredient to HolderSet
Browse files Browse the repository at this point in the history
  • Loading branch information
basaigh committed Oct 13, 2024
1 parent 39b50c4 commit eb64c38
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1000,19 +1000,11 @@ public void writeEntityEvent(ByteBuf buf, EntityEvent event) {
}

public Ingredient readRecipeIngredient(ByteBuf buf) {
ItemStack[] options = new ItemStack[this.readVarInt(buf)];
for (int i = 0; i < options.length; i++) {
options[i] = this.readOptionalItemStack(buf);
}

return new Ingredient(options);
return new Ingredient(this.readHolderSet(buf));
}

public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) {
this.writeVarInt(buf, ingredient.getOptions().length);
for (ItemStack option : ingredient.getOptions()) {
this.writeOptionalItemStack(buf, option);
}
this.writeHolderSet(buf, ingredient.getValues());
}

public RecipeDisplay readRecipeDisplay(ByteBuf buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;

@Data
@AllArgsConstructor
public class Ingredient {
private final @Nullable ItemStack @NonNull [] options;
private final HolderSet values;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
});
}

private record SelectableRecipe(Ingredient input, SlotDisplay recipe) {
public record SelectableRecipe(Ingredient input, SlotDisplay recipe) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.kyori.adventure.key.Key;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Recipe;
Expand All @@ -11,104 +12,28 @@
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.ShapelessRecipeData;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.SmithingTransformRecipeData;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemStackSlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay;
import org.geysermc.mcprotocollib.protocol.packet.PacketTest;
import org.junit.jupiter.api.BeforeEach;

import java.util.ArrayList;
import java.util.HashMap;

public class ServerDeclareRecipesTest extends PacketTest {
@BeforeEach
public void setup() {
this.setPackets(
new ClientboundUpdateRecipesPacket(
new Recipe[]{
new Recipe(
RecipeType.CRAFTING_SHAPELESS,
Key.key("minecraft:recipe1"),
new ShapelessRecipeData(
"Group1",
CraftingBookCategory.MISC,
new Ingredient[]{
new Ingredient(new ItemStack[]{
new ItemStack(0)
})
},
new ItemStack(10)
)
),
new Recipe(
RecipeType.CRAFTING_SHAPED,
Key.key("minecraft:recipe2"),
new ShapedRecipeData(
2,
3,
"Group2",
CraftingBookCategory.BUILDING,
new Ingredient[]{
new Ingredient(new ItemStack[]{
new ItemStack(1)
}),
new Ingredient(new ItemStack[]{
new ItemStack(2)
}),
new Ingredient(new ItemStack[]{
new ItemStack(3)
}),
new Ingredient(new ItemStack[]{
new ItemStack(4)
}),
new Ingredient(new ItemStack[]{
new ItemStack(5)
}),
new Ingredient(new ItemStack[]{
new ItemStack(6)
})
},
new ItemStack(20),
true
)
),
new Recipe(
RecipeType.SMELTING,
Key.key("minecraft:recipe3"),
new CookedRecipeData(
"Group3",
CraftingBookCategory.EQUIPMENT,
new Ingredient(new ItemStack[]{
new ItemStack(7)
}),
new ItemStack(30),
10.5f,
10
)
),
new Recipe(
RecipeType.STONECUTTING,
Key.key("minecraft:recipe4"),
new StoneCuttingRecipeData(
"Group4",
new Ingredient(new ItemStack[]{
new ItemStack(8),
new ItemStack(9)
}),
new ItemStack(40)
)
),
new Recipe(
RecipeType.SMITHING_TRANSFORM,
Key.key("minecraft:recipe5"),
new SmithingTransformRecipeData(
new Ingredient(new ItemStack[]{
new ItemStack(10)
}),
new Ingredient(new ItemStack[]{
new ItemStack(11)
}),
new Ingredient(new ItemStack[]{
new ItemStack(12)
}),
new ItemStack(13)
)
)
}
new HashMap<>(){{
put(Key.key("smithing_addition"), new int[]{829, 837, 833, 830, 831, 671, 827, 828, 835, 838});
}},
new ArrayList<>(){{
add(new ClientboundUpdateRecipesPacket.SelectableRecipe(
new Ingredient(new HolderSet(new int[]{6})),
new ItemStackSlotDisplay(new ItemStack(2, 662, null))
));
}}
)
);
}
Expand Down

0 comments on commit eb64c38

Please sign in to comment.