3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-07 16:50:14 +01:00

Item rewriter cleanup

Dieser Commit ist enthalten in:
KennyTV 2019-10-04 13:01:33 +02:00
Ursprung 857ae523cf
Commit c8171b3f43
19 geänderte Dateien mit 197 neuen und 529 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,111 @@
package us.myles.ViaVersion.api.rewriters;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
// If any of these methods become outdated, just create a new rewriter overriding the methods
public class ItemRewriter {
private final Protocol protocol;
private final RewriteFunction toClient;
private final RewriteFunction toServer;
public ItemRewriter(Protocol protocol, RewriteFunction toClient, RewriteFunction toServer) {
this.protocol = protocol;
this.toClient = toClient;
this.toServer = toServer;
}
public void registerWindowItems(Type<Item[]> type, int oldPacketId, int newPacketId) {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(type); // 1 - Window Values
handler(itemArrayHandler(type));
}
});
}
public void registerSetSlot(Type<Item> type, int oldPacketId, int newPacketId) {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(type); // 2 - Slot Value
handler(itemToClientHandler(type));
}
});
}
public void registerEntityEquipment(Type<Item> type, int oldPacketId, int newPacketId) {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(type); // 2 - Item
handler(itemToClientHandler(type));
}
});
}
public void registerCreativeInvAction(Type<Item> type, int oldPacketId, int newPacketId) {
protocol.registerIncoming(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(type); // 1 - Clicked Item
handler(itemToServerHandler(type));
}
});
}
public void registerClickWindow(Type<Item> type, int oldPacketId, int newPacketId) {
protocol.registerIncoming(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(type); // 5 - Clicked Item
handler(itemToServerHandler(type));
}
});
}
// Only sent to the client
public PacketHandler itemArrayHandler(Type<Item[]> type) {
return wrapper -> {
Item[] items = wrapper.get(type, 0);
for (Item item : items) {
toClient.rewrite(item);
}
};
}
public PacketHandler itemToClientHandler(Type<Item> type) {
return wrapper -> toClient.rewrite(wrapper.get(type, 0));
}
public PacketHandler itemToServerHandler(Type<Item> type) {
return wrapper -> toServer.rewrite(wrapper.get(type, 0));
}
@FunctionalInterface
public interface RewriteFunction {
void rewrite(Item item);
}
}

Datei anzeigen

@ -15,11 +15,12 @@ import us.myles.ViaVersion.packets.State;
import java.util.*;
import java.util.logging.Logger;
public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
public abstract class MetadataRewriter {
private final Class<? extends EntityTracker> entityTrackerClass;
private final Protocol protocol;
protected MetadataRewriter(T protocol, Class<? extends EntityTracker> entityTrackerClass) {
super(protocol);
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
this.protocol = protocol;
this.entityTrackerClass = entityTrackerClass;
protocol.put(this);
}
@ -53,7 +54,7 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
}
public void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
@ -146,7 +147,7 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
}
public void registerEntityDestroy(int oldPacketId, int newPacketId) {
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity ids

Datei anzeigen

@ -1,15 +0,0 @@
package us.myles.ViaVersion.api.rewriters;
import us.myles.ViaVersion.api.protocol.Protocol;
public abstract class Rewriter<T extends Protocol> {
protected final T protocol;
protected Rewriter(T protocol) {
this.protocol = protocol;
}
public T getProtocol() {
return protocol;
}
}

Datei anzeigen

@ -18,7 +18,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Protocol1_11To1_10> {
public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
public MetadataRewriter1_11To1_10(Protocol1_11To1_10 protocol) {
super(protocol, EntityTracker1_11.class);

Datei anzeigen

@ -1,73 +1,27 @@
package us.myles.ViaVersion.protocols.protocol1_11to1_10.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter;
import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
public class InventoryPackets {
public static void register(Protocol1_11To1_10 protocol) {
/*
Incoming packets
*/
ItemRewriter itemRewriter = new ItemRewriter(protocol, EntityIdRewriter::toClientItem, EntityIdRewriter::toServerItem);
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.ITEM, 0);
EntityIdRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16);
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x14, 0x14, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
for (Item stack : stacks)
EntityIdRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14);
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3C, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.ITEM, 0);
EntityIdRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3C);
// Plugin message Packet -> Trading
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
@ -100,48 +54,11 @@ public class InventoryPackets {
}
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x07, 0x07, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.ITEM, 0);
EntityIdRewriter.toServerItem(item);
}
});
}
}
);
itemRewriter.registerClickWindow(Type.ITEM, 0x07, 0x07);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.ITEM, 0);
EntityIdRewriter.toServerItem(item);
}
});
}
}
);
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18);
}
}

Datei anzeigen

@ -12,7 +12,7 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker1
import java.util.List;
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Protocol1_12To1_11_1> {
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter {
public MetadataRewriter1_12To1_11_1(Protocol1_12To1_11_1 protocol) {
super(protocol, EntityTracker1_12.class);

Datei anzeigen

@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter;
@ -12,64 +13,18 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
public class InventoryPackets {
public static void register(Protocol1_12To1_11_1 protocol) {
/*
Outgoing packets
*/
ItemRewriter itemRewriter = new ItemRewriter(protocol, BedRewriter::toClientItem, BedRewriter::toServerItem);
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.ITEM, 0);
BedRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16);
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x14, 0x14, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
for (Item stack : stacks)
BedRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14);
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3E, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.ITEM, 0);
BedRewriter.toClientItem(stack);
}
});
}
});
itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3E);
// Plugin message Packet -> Trading
protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() {
@ -102,9 +57,6 @@ public class InventoryPackets {
}
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x07, 0x08, new PacketRemapper() {
@ -148,21 +100,6 @@ public class InventoryPackets {
);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x18, 0x1b, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.ITEM, 0);
BedRewriter.toServerItem(item);
}
});
}
}
);
itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x1b);
}
}

Datei anzeigen

@ -13,7 +13,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1
import java.util.List;
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Protocol1_13_1To1_13> {
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter {
public MetadataRewriter1_13_1To1_13(Protocol1_13_1To1_13 protocol) {
super(protocol, EntityTracker1_13.class);

Datei anzeigen

@ -5,52 +5,20 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class InventoryPackets {
public static void register(Protocol protocol) {
/*
Outgoing packets
*/
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
}
});
itemRewriter.registerSetSlot(Type.FLAT_ITEM, 0x17, 0x17);
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.FLAT_ITEM_ARRAY, 0);
for (Item stack : stacks)
toClient(stack);
}
});
}
});
itemRewriter.registerWindowItems(Type.FLAT_ITEM_ARRAY, 0x15, 0x15);
// Plugin message
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@ -88,22 +56,7 @@ public class InventoryPackets {
});
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
}
});
itemRewriter.registerEntityEquipment(Type.FLAT_ITEM, 0x42, 0x42);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() {
@ -155,49 +108,11 @@ public class InventoryPackets {
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.FLAT_ITEM, 0);
toServer(item);
}
});
}
}
);
itemRewriter.registerClickWindow(Type.FLAT_ITEM, 0x08, 0x08);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.FLAT_ITEM, 0);
toServer(item);
}
});
}
}
);
itemRewriter.registerCreativeInvAction(Type.FLAT_ITEM, 0x24, 0x24);
}
public static void toClient(Item item) {

Datei anzeigen

@ -10,11 +10,6 @@ import us.myles.ViaVersion.packets.State;
public class InventoryPackets {
public static void register(Protocol protocol) {
/*
Outgoing packets
*/
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override
@ -118,11 +113,6 @@ public class InventoryPackets {
}
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
@Override

Datei anzeigen

@ -19,7 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1
import java.util.List;
import java.util.Map;
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Protocol1_13To1_12_2> {
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) {
super(protocol, EntityTracker1_13.class);

Datei anzeigen

@ -10,9 +10,11 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.SoundSource;
@ -25,14 +27,10 @@ import java.util.Locale;
import java.util.Optional;
public class InventoryPackets {
private static String NBT_TAG_NAME;
private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_13To1_12_2.class.getSimpleName();
public static void register(Protocol protocol) {
NBT_TAG_NAME = "ViaVersion|" + protocol.getClass().getSimpleName();
/*
Outgoing packets
*/
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x16, 0x17, new PacketRemapper() {
@ -42,13 +40,7 @@ public class InventoryPackets {
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM, Type.FLAT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
handler(itemRewriter.itemToClientHandler(Type.FLAT_ITEM));
}
});
@ -59,14 +51,7 @@ public class InventoryPackets {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM_ARRAY, Type.FLAT_ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.FLAT_ITEM_ARRAY, 0);
for (Item stack : stacks)
toClient(stack);
}
});
handler(itemRewriter.itemArrayHandler(Type.FLAT_ITEM_ARRAY));
}
});
@ -77,14 +62,13 @@ public class InventoryPackets {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.SHORT); // Property
map(Type.SHORT); // Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) { // Enchantment id
wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewId(
wrapper.get(Type.SHORT, 1)
));
wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewId(wrapper.get(Type.SHORT, 1)));
}
}
});
@ -202,21 +186,11 @@ public class InventoryPackets {
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM, Type.FLAT_ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_ITEM, 0);
toClient(stack);
}
});
handler(itemRewriter.itemToClientHandler(Type.FLAT_ITEM));
}
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x07, 0x08, new PacketRemapper() {
@Override
@ -228,16 +202,9 @@ public class InventoryPackets {
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_ITEM, Type.ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.ITEM, 0);
toServer(item);
handler(itemRewriter.itemToServerHandler(Type.ITEM));
}
});
}
}
);
// Plugin message
protocol.registerIncoming(State.PLAY, 0x09, 0x0A, new PacketRemapper() {
@ -282,17 +249,10 @@ public class InventoryPackets {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_ITEM, Type.ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.ITEM, 0);
toServer(item);
handler(itemRewriter.itemToServerHandler(Type.ITEM));
}
});
}
}
);
}
// TODO CLEANUP / SMARTER REWRITE SYSTEM
// TODO Rewrite identifiers

Datei anzeigen

@ -10,7 +10,7 @@ import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1
import java.util.List;
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Protocol1_14_1To1_14> {
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter {
public MetadataRewriter1_14_1To1_14(Protocol1_14_1To1_14 protocol) {
super(protocol, EntityTracker1_14_1.class);

Datei anzeigen

@ -19,7 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1
import java.util.List;
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Protocol1_14To1_13_2> {
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
super(protocol, EntityTracker1_14.class);

Datei anzeigen

@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
@ -21,14 +22,11 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
public class InventoryPackets {
private static String NBT_TAG_NAME;
private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_14To1_13_2.class.getSimpleName();
private static final Set<String> REMOVED_RECIPE_TYPES = Sets.newHashSet("crafting_special_banneraddpattern", "crafting_special_repairitem");
public static void register(Protocol protocol) {
NBT_TAG_NAME = "ViaVersion|" + protocol.getClass().getSimpleName();
/*
Outgoing packets
*/
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
// Open Inventory
protocol.registerOutgoing(State.PLAY, 0x14, -1, new PacketRemapper() {
@ -105,38 +103,10 @@ public class InventoryPackets {
});
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x15, 0x14, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0);
for (Item stack : stacks) toClient(stack);
}
});
}
});
itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x15, 0x14);
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x17, 0x16);
// Plugin message
protocol.registerOutgoing(State.PLAY, 0x19, 0x18, new PacketRemapper() {
@ -192,21 +162,7 @@ public class InventoryPackets {
});
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x46, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_VAR_INT_ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x42, 0x46);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x54, 0x5A, new PacketRemapper() {
@ -259,29 +215,8 @@ public class InventoryPackets {
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x08, 0x09);
// Select trade
protocol.registerIncoming(State.PLAY, 0x1F, 0x21, new PacketRemapper() {
@ -307,20 +242,7 @@ public class InventoryPackets {
});
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x24, 0x26, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x24, 0x26);
}

Datei anzeigen

@ -14,7 +14,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1
import java.util.List;
public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter<Protocol1_15To1_14_4> {
public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter {
public MetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) {
super(protocol, EntityTracker1_15.class);

Datei anzeigen

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
@ -13,22 +14,10 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
public class InventoryPackets {
public static void register(Protocol protocol) {
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x14, 0x15, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0);
for (Item stack : stacks) toClient(stack);
}
});
}
});
// Window items packet
itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x14, 0x15);
// Trade list packet
protocol.registerOutgoing(State.PLAY, 0x27, 0x28, new PacketRemapper() {
@ -70,38 +59,10 @@ public class InventoryPackets {
});
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x16, 0x17, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x16, 0x17);
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x46, 0x47, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_VAR_INT_ITEM); // 2 - Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x46, 0x47);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x5A, 0x5B, new PacketRemapper() {
@ -171,40 +132,10 @@ public class InventoryPackets {
});
// Click window packet
protocol.registerIncoming(State.PLAY, 0x09, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x26, 0x26, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
});
itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x26);
}
public static void toClient(Item item) {

Datei anzeigen

@ -19,7 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Protocol1_9To1_8> {
public class MetadataRewriter1_9To1_8 extends MetadataRewriter {
public MetadataRewriter1_9To1_8(Protocol1_9To1_8 protocol) {
super(protocol, EntityTracker1_9.class);

Datei anzeigen

@ -14,6 +14,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
public class InventoryPackets {
public static void register(Protocol protocol) {
// Window Property Packet
protocol.registerOutgoing(State.PLAY, 0x31, 0x15, new PacketRemapper() {
@ -334,7 +335,5 @@ public class InventoryPackets {
protocol.registerIncoming(State.PLAY, 0x0F, 0x05); // Confirm Transaction Packet
protocol.registerIncoming(State.PLAY, 0x11, 0x06); // Enchant Item Packet
}
}