3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Fix 1.13->1.13.1 recipes, rename ITEM1_8_ARRAY

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-10-21 13:22:25 +10:00
Ursprung faedf26b5b
Commit 815e0820da
12 geänderte Dateien mit 80 neuen und 79 gelöschten Zeilen

Datei anzeigen

@ -181,9 +181,9 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<Item> ITEM1_13 = new ItemType1_13(); public static final Type<Item> ITEM1_13 = new ItemType1_13();
public static final Type<Item> ITEM1_13_2 = new ItemType1_13_2(); public static final Type<Item> ITEM1_13_2 = new ItemType1_13_2();
public static final Type<Item> ITEM1_20_2 = new ItemType1_20_2(); public static final Type<Item> ITEM1_20_2 = new ItemType1_20_2();
public static final Type<Item[]> ITEM1_8_SHORT_ARRAY = new ItemShortArrayType1_8();
public static final Type<Item[]> ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13(); public static final Type<Item[]> ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13();
public static final Type<Item[]> ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2(); public static final Type<Item[]> ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2();
public static final Type<Item[]> ITEM1_8_ARRAY = new ItemShortArrayType1_8();
public static final Type<Item[]> ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13); public static final Type<Item[]> ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13);
public static final Type<Item[]> ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2); public static final Type<Item[]> ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2);
public static final Type<Item[]> ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2); public static final Type<Item[]> ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2);
@ -194,7 +194,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
@Deprecated/*(forRemoval=true)*/ @Deprecated/*(forRemoval=true)*/
public static final Type<Item> FLAT_VAR_INT_ITEM = ITEM1_13_2; public static final Type<Item> FLAT_VAR_INT_ITEM = ITEM1_13_2;
@Deprecated/*(forRemoval=true)*/ @Deprecated/*(forRemoval=true)*/
public static final Type<Item[]> ITEM_ARRAY = ITEM1_8_ARRAY; public static final Type<Item[]> ITEM_ARRAY = ITEM1_8_SHORT_ARRAY;
@Deprecated/*(forRemoval=true)*/ @Deprecated/*(forRemoval=true)*/
public static final Type<Item[]> FLAT_ITEM_ARRAY = ITEM1_13_SHORT_ARRAY; public static final Type<Item[]> FLAT_ITEM_ARRAY = ITEM1_13_SHORT_ARRAY;
@Deprecated/*(forRemoval=true)*/ @Deprecated/*(forRemoval=true)*/

Datei anzeigen

@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_13 extends BaseItemArrayType { public class ItemShortArrayType1_13 extends BaseItemArrayType {
public ItemShortArrayType1_13() {
super("Flat Item Array");
}
@Override @Override
public Item[] read(ByteBuf buffer) throws Exception { public Item[] read(ByteBuf buffer) throws Exception {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Type.SHORT.readPrimitive(buffer);

Datei anzeigen

@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_13_2 extends BaseItemArrayType { public class ItemShortArrayType1_13_2 extends BaseItemArrayType {
public ItemShortArrayType1_13_2() {
super("Flat Item Array");
}
@Override @Override
public Item[] read(ByteBuf buffer) throws Exception { public Item[] read(ByteBuf buffer) throws Exception {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Type.SHORT.readPrimitive(buffer);

Datei anzeigen

@ -28,10 +28,6 @@ import io.netty.buffer.ByteBuf;
public class ItemShortArrayType1_8 extends BaseItemArrayType { public class ItemShortArrayType1_8 extends BaseItemArrayType {
public ItemShortArrayType1_8() {
super("Item Array");
}
@Override @Override
public Item[] read(ByteBuf buffer) throws Exception { public Item[] read(ByteBuf buffer) throws Exception {
int amount = Type.SHORT.readPrimitive(buffer); int amount = Type.SHORT.readPrimitive(buffer);

Datei anzeigen

@ -27,7 +27,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_10To1_9_3_4> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_10To1_9_3_4> {
public InventoryPackets(Protocol1_10To1_9_3_4 protocol) { public InventoryPackets(Protocol1_10To1_9_3_4 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override

Datei anzeigen

@ -27,7 +27,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11_1To1_11> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11_1To1_11> {
public InventoryPackets(Protocol1_11_1To1_11 protocol) { public InventoryPackets(Protocol1_11_1To1_11 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override

Datei anzeigen

@ -29,13 +29,13 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_10> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_10> {
public InventoryPackets(Protocol1_11To1_10 protocol) { public InventoryPackets(Protocol1_11To1_10 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override
public void registerPackets() { public void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); 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); registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
// Plugin message Packet -> Trading // Plugin message Packet -> Trading

Datei anzeigen

@ -31,13 +31,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_12, Protocol1_12To1_11_1> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_12, Protocol1_12To1_11_1> {
public InventoryPackets(Protocol1_12To1_11_1 protocol) { public InventoryPackets(Protocol1_12To1_11_1 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override
public void registerPackets() { public void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8); 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); registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
// Plugin message Packet -> Trading // Plugin message Packet -> Trading

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets; 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.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; 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<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> {
public InventoryPackets(Protocol1_13_1To1_13 protocol) { public InventoryPackets(Protocol1_13_1To1_13 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override
@ -71,7 +72,17 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.ITEM1_13); registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.ITEM1_13);
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<>(protocol); RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<ClientboundPackets1_13>(protocol) {
@Override
protected Type<Item> itemType() {
return Type.ITEM1_13;
}
@Override
protected Type<Item[]> itemArrayType() {
return Type.ITEM1_13_ARRAY;
}
};
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT); int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {

Datei anzeigen

@ -402,57 +402,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
wrapper.write(Type.STRING_ARRAY, stringIds); wrapper.write(Type.STRING_ARRAY, stringIds);
} }
if (action == 0) { if (action == 0) {
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, wrapper1 -> { wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, w -> writeDeclareRecipes(w)).send(Protocol1_13To1_12_2.class);
wrapper1.write(Type.VAR_INT, RecipeData.recipes.size());
for (Map.Entry<String, RecipeData.Recipe> 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);
} }
}); });
} }
@ -843,6 +793,58 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
}); });
} }
private void writeDeclareRecipes(PacketWrapper recipesPacket) {
recipesPacket.write(Type.VAR_INT, RecipeData.recipes.size());
for (Map.Entry<String, RecipeData.Recipe> 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 @Override
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
ConnectionData.init(); ConnectionData.init();

Datei anzeigen

@ -51,7 +51,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_13To1_12_2.class.getSimpleName(); private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_13To1_12_2.class.getSimpleName();
public InventoryPackets(Protocol1_13To1_12_2 protocol) { public InventoryPackets(Protocol1_13To1_12_2 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY); super(protocol, null, null);
} }
@Override @Override
@ -70,7 +70,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_8_ARRAY, Type.ITEM1_13_SHORT_ARRAY); // 1 - Window Values map(Type.ITEM1_8_SHORT_ARRAY, Type.ITEM1_13_SHORT_ARRAY); // 1 - Window Values
handler(itemArrayToClientHandler(Type.ITEM1_13_SHORT_ARRAY)); handler(itemArrayToClientHandler(Type.ITEM1_13_SHORT_ARRAY));
} }

Datei anzeigen

@ -134,10 +134,10 @@ public class InventoryPackets {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_8_ARRAY); // 1 - Window Values map(Type.ITEM1_8_SHORT_ARRAY); // 1 - Window Values
handler(wrapper -> { handler(wrapper -> {
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); Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
@ -166,7 +166,7 @@ public class InventoryPackets {
handler(wrapper -> { handler(wrapper -> {
InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class); InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
if (inventoryTracker.getInventory() != null && inventoryTracker.getInventory().equals("minecraft:brewing_stand")) { 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]; Item[] newStack = new Item[oldStack.length + 1];
for (int i = 0; i < newStack.length; i++) { for (int i = 0; i < newStack.length; i++) {
if (i > 4) { 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);
} }
}); });
} }