mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Refactor Ingredient to HolderSet
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
This commit is contained in:
parent
39b50c44a7
commit
eb64c3850c
4 changed files with 20 additions and 105 deletions
|
@ -1000,19 +1000,11 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ingredient readRecipeIngredient(ByteBuf buf) {
|
public Ingredient readRecipeIngredient(ByteBuf buf) {
|
||||||
ItemStack[] options = new ItemStack[this.readVarInt(buf)];
|
return new Ingredient(this.readHolderSet(buf));
|
||||||
for (int i = 0; i < options.length; i++) {
|
|
||||||
options[i] = this.readOptionalItemStack(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Ingredient(options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) {
|
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) {
|
||||||
this.writeVarInt(buf, ingredient.getOptions().length);
|
this.writeHolderSet(buf, ingredient.getValues());
|
||||||
for (ItemStack option : ingredient.getOptions()) {
|
|
||||||
this.writeOptionalItemStack(buf, option);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeDisplay readRecipeDisplay(ByteBuf buf) {
|
public RecipeDisplay readRecipeDisplay(ByteBuf buf) {
|
||||||
|
|
|
@ -2,12 +2,10 @@ package org.geysermc.mcprotocollib.protocol.data.game.recipe;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.HolderSet;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class Ingredient {
|
public class Ingredient {
|
||||||
private final @Nullable ItemStack @NonNull [] options;
|
private final HolderSet values;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,6 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private record SelectableRecipe(Ingredient input, SlotDisplay recipe) {
|
public record SelectableRecipe(Ingredient input, SlotDisplay recipe) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
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.CraftingBookCategory;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
|
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Recipe;
|
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Recipe;
|
||||||
|
@ -11,104 +12,28 @@ import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.ShapedRecipeDat
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.ShapelessRecipeData;
|
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.SmithingTransformRecipeData;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
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.geysermc.mcprotocollib.protocol.packet.PacketTest;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ServerDeclareRecipesTest extends PacketTest {
|
public class ServerDeclareRecipesTest extends PacketTest {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPackets(
|
this.setPackets(
|
||||||
new ClientboundUpdateRecipesPacket(
|
new ClientboundUpdateRecipesPacket(
|
||||||
new Recipe[]{
|
new HashMap<>(){{
|
||||||
new Recipe(
|
put(Key.key("smithing_addition"), new int[]{829, 837, 833, 830, 831, 671, 827, 828, 835, 838});
|
||||||
RecipeType.CRAFTING_SHAPELESS,
|
}},
|
||||||
Key.key("minecraft:recipe1"),
|
new ArrayList<>(){{
|
||||||
new ShapelessRecipeData(
|
add(new ClientboundUpdateRecipesPacket.SelectableRecipe(
|
||||||
"Group1",
|
new Ingredient(new HolderSet(new int[]{6})),
|
||||||
CraftingBookCategory.MISC,
|
new ItemStackSlotDisplay(new ItemStack(2, 662, null))
|
||||||
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)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue