3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 13:52:50 +02:00

Correctly convert between ITEM -> FLAT_ITEM

Dieser Commit ist enthalten in:
Myles 2017-12-18 15:48:25 +00:00
Ursprung bd9096ef6d
Commit 0a37031418
2 geänderte Dateien mit 21 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -17,10 +17,7 @@ public class FlatItemType extends BaseItemType {
} else {
Item item = new Item();
item.setId(id);
item.setAmount(buffer.readByte());
if (id != 0) {
item.setTag(Type.NBT.read(buffer));
}
item.setTag(Type.NBT.read(buffer));
return item;
}
}
@ -32,9 +29,7 @@ public class FlatItemType extends BaseItemType {
} else {
buffer.writeShort(object.getId());
buffer.writeByte(object.getAmount());
if (object.getId() != 0) {
Type.NBT.write(buffer, object.getTag());
}
Type.NBT.write(buffer, object.getTag());
}
}
}

Datei anzeigen

@ -27,7 +27,7 @@ public class InventoryPackets {
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM); // 2 - Slot Value
map(Type.ITEM, Type.FLAT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
@ -44,7 +44,7 @@ public class InventoryPackets {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_ITEM_ARRAY); // 1 - Window Values
map(Type.ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
@ -73,12 +73,22 @@ public class InventoryPackets {
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Input Item
toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Output Item
// Input Item
Item input = wrapper.read(Type.ITEM);
toClient(input);
wrapper.write(Type.ITEM, input);
// Output Item
Item output = wrapper.read(Type.ITEM);
toClient(output);
wrapper.write(Type.ITEM, output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem)
toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Second Item
if (secondItem) {
// Second Item
Item second = wrapper.read(Type.ITEM);
toClient(second);
wrapper.write(Type.ITEM, second);
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
@ -96,7 +106,7 @@ public class InventoryPackets {
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_ITEM); // 2 - Item
map(Type.ITEM, Type.FLAT_ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
@ -122,7 +132,7 @@ public class InventoryPackets {
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_ITEM); // 5 - Clicked Item
map(Type.FLAT_ITEM, Type.ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
@ -140,7 +150,7 @@ public class InventoryPackets {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_ITEM); // 1 - Clicked Item
map(Type.FLAT_ITEM, Type.ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override