diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 499617156..616cdfb81 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -181,9 +181,9 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type ITEM1_13 = new ItemType1_13(); public static final Type ITEM1_13_2 = new ItemType1_13_2(); public static final Type ITEM1_20_2 = new ItemType1_20_2(); + public static final Type ITEM1_8_SHORT_ARRAY = new ItemShortArrayType1_8(); public static final Type ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13(); public static final Type ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2(); - public static final Type ITEM1_8_ARRAY = new ItemShortArrayType1_8(); public static final Type ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13); public static final Type ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2); public static final Type ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2); @@ -194,7 +194,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { @Deprecated/*(forRemoval=true)*/ public static final Type FLAT_VAR_INT_ITEM = ITEM1_13_2; @Deprecated/*(forRemoval=true)*/ - public static final Type ITEM_ARRAY = ITEM1_8_ARRAY; + public static final Type ITEM_ARRAY = ITEM1_8_SHORT_ARRAY; @Deprecated/*(forRemoval=true)*/ public static final Type FLAT_ITEM_ARRAY = ITEM1_13_SHORT_ARRAY; @Deprecated/*(forRemoval=true)*/ diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java index b0107ca40..bbf06b60d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java @@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_13 extends BaseItemArrayType { - public ItemShortArrayType1_13() { - super("Flat Item Array"); - } - @Override public Item[] read(ByteBuf buffer) throws Exception { int amount = Type.SHORT.readPrimitive(buffer); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java index 16299c8f5..e0a7b48b1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java @@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_13_2 extends BaseItemArrayType { - public ItemShortArrayType1_13_2() { - super("Flat Item Array"); - } - @Override public Item[] read(ByteBuf buffer) throws Exception { int amount = Type.SHORT.readPrimitive(buffer); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java index 346451977..8261d061a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java @@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_8 extends BaseItemArrayType { - public ItemShortArrayType1_8() { - super("Item Array"); - } - @Override public Item[] read(ByteBuf buffer) throws Exception { int amount = Type.SHORT.readPrimitive(buffer); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java index 07cd86ad5..14cdb47d9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java @@ -27,7 +27,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_10To1_9_3_4 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, null, null); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java index 31168fdd5..c1df771a0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java @@ -27,7 +27,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_11_1To1_11 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, null, null); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java index 7cddb6600..63e77e857 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/packets/InventoryPackets.java @@ -29,13 +29,13 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_11To1_10 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, null, null); } @Override public void registerPackets() { registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); - registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_ARRAY); + registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY); registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8); // Plugin message Packet -> Trading diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index 09de3af1a..e6de54866 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -31,13 +31,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_12To1_11_1 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, null, null); } @Override public void registerPackets() { registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); - registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_ARRAY); + registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY); registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8); // Plugin message Packet -> Trading diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java index 7cb527c8c..e9b449522 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java @@ -17,6 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; @@ -28,7 +29,7 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter; public class InventoryPackets extends ItemRewriter { public InventoryPackets(Protocol1_13_1To1_13 protocol) { - super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); + super(protocol, null, null); } @Override @@ -71,7 +72,17 @@ public class InventoryPackets extends ItemRewriter recipeRewriter = new RecipeRewriter<>(protocol); + RecipeRewriter recipeRewriter = new RecipeRewriter(protocol) { + @Override + protected Type itemType() { + return Type.ITEM1_13; + } + + @Override + protected Type itemArrayType() { + return Type.ITEM1_13_ARRAY; + } + }; protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> { int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 0308afdfd..60822d519 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -402,57 +402,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol { - wrapper1.write(Type.VAR_INT, RecipeData.recipes.size()); - for (Map.Entry entry : RecipeData.recipes.entrySet()) { - wrapper1.write(Type.STRING, entry.getKey()); // Id - wrapper1.write(Type.STRING, entry.getValue().getType()); - switch (entry.getValue().getType()) { - case "crafting_shapeless": { - wrapper1.write(Type.STRING, entry.getValue().getGroup()); - wrapper1.write(Type.VAR_INT, entry.getValue().getIngredients().length); - for (Item[] ingredient : entry.getValue().getIngredients()) { - Item[] clone = ingredient.clone(); // Clone because array and item is mutable - for (int i = 0; i < clone.length; i++) { - if (clone[i] == null) continue; - clone[i] = new DataItem(clone[i]); - } - wrapper1.write(Type.ITEM1_13_ARRAY, clone); - } - wrapper1.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); - break; - } - case "crafting_shaped": { - wrapper1.write(Type.VAR_INT, entry.getValue().getWidth()); - wrapper1.write(Type.VAR_INT, entry.getValue().getHeight()); - wrapper1.write(Type.STRING, entry.getValue().getGroup()); - for (Item[] ingredient : entry.getValue().getIngredients()) { - Item[] clone = ingredient.clone(); // Clone because array and item is mutable - for (int i = 0; i < clone.length; i++) { - if (clone[i] == null) continue; - clone[i] = new DataItem(clone[i]); - } - wrapper1.write(Type.ITEM1_13_ARRAY, clone); - } - wrapper1.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); - break; - } - case "smelting": { - wrapper1.write(Type.STRING, entry.getValue().getGroup()); - Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable - for (int i = 0; i < clone.length; i++) { - if (clone[i] == null) continue; - clone[i] = new DataItem(clone[i]); - } - wrapper1.write(Type.ITEM1_13_ARRAY, clone); - wrapper1.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); - wrapper1.write(Type.FLOAT, entry.getValue().getExperience()); - wrapper1.write(Type.VAR_INT, entry.getValue().getCookingTime()); - break; - } - } - } - }).send(Protocol1_13To1_12_2.class); + wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, w -> writeDeclareRecipes(w)).send(Protocol1_13To1_12_2.class); } }); } @@ -843,6 +793,58 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol entry : RecipeData.recipes.entrySet()) { + recipesPacket.write(Type.STRING, entry.getKey()); // Id + recipesPacket.write(Type.STRING, entry.getValue().getType()); + switch (entry.getValue().getType()) { + case "crafting_shapeless": { + recipesPacket.write(Type.STRING, entry.getValue().getGroup()); + recipesPacket.write(Type.VAR_INT, entry.getValue().getIngredients().length); + for (Item[] ingredient : entry.getValue().getIngredients()) { + Item[] clone = ingredient.clone(); // Clone because array and item is mutable + for (int i = 0; i < clone.length; i++) { + if (clone[i] == null) continue; + clone[i] = new DataItem(clone[i]); + } + recipesPacket.write(Type.ITEM1_13_ARRAY, clone); + } + recipesPacket.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); + break; + } + case "crafting_shaped": { + recipesPacket.write(Type.VAR_INT, entry.getValue().getWidth()); + recipesPacket.write(Type.VAR_INT, entry.getValue().getHeight()); + recipesPacket.write(Type.STRING, entry.getValue().getGroup()); + for (Item[] ingredient : entry.getValue().getIngredients()) { + Item[] clone = ingredient.clone(); // Clone because array and item is mutable + for (int i = 0; i < clone.length; i++) { + if (clone[i] == null) continue; + clone[i] = new DataItem(clone[i]); + } + recipesPacket.write(Type.ITEM1_13_ARRAY, clone); + } + recipesPacket.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); + break; + } + case "smelting": { + recipesPacket.write(Type.STRING, entry.getValue().getGroup()); + Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable + for (int i = 0; i < clone.length; i++) { + if (clone[i] == null) continue; + clone[i] = new DataItem(clone[i]); + } + recipesPacket.write(Type.ITEM1_13_ARRAY, clone); + recipesPacket.write(Type.ITEM1_13, new DataItem(entry.getValue().getResult())); + recipesPacket.write(Type.FLOAT, entry.getValue().getExperience()); + recipesPacket.write(Type.VAR_INT, entry.getValue().getCookingTime()); + break; + } + } + } + } + @Override protected void onMappingDataLoaded() { ConnectionData.init(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index fa70ebed4..dfa677b29 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -51,7 +51,7 @@ public class InventoryPackets extends ItemRewriter { - Item[] stacks = wrapper.get(Type.ITEM1_8_ARRAY, 0); + Item[] stacks = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); @@ -166,7 +166,7 @@ public class InventoryPackets { handler(wrapper -> { InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); if (inventoryTracker.getInventory() != null && inventoryTracker.getInventory().equals("minecraft:brewing_stand")) { - Item[] oldStack = wrapper.get(Type.ITEM1_8_ARRAY, 0); + Item[] oldStack = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); Item[] newStack = new Item[oldStack.length + 1]; for (int i = 0; i < newStack.length; i++) { if (i > 4) { @@ -177,7 +177,7 @@ public class InventoryPackets { } } } - wrapper.set(Type.ITEM1_8_ARRAY, 0, newStack); + wrapper.set(Type.ITEM1_8_SHORT_ARRAY, 0, newStack); } }); }