99 lines
4.8 KiB
Java
99 lines
4.8 KiB
Java
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.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.rewriters.RecipeRewriter;
|
|
import us.myles.ViaVersion.api.type.Type;
|
|
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
|
|
|
|
public class InventoryPackets {
|
|
|
|
public static void register(Protocol1_13_1To1_13 protocol) {
|
|
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
|
|
itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
|
|
itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
|
|
itemRewriter.registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_ITEM);
|
|
|
|
protocol.registerOutgoing(ClientboundPackets1_13.COOLDOWN, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
handler(wrapper -> {
|
|
int itemId = wrapper.read(Type.VAR_INT);
|
|
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewItemId(itemId));
|
|
});
|
|
}
|
|
});
|
|
|
|
protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
map(Type.STRING); // Channel
|
|
handler(new PacketHandler() {
|
|
@Override
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
String channel = wrapper.get(Type.STRING, 0);
|
|
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
|
|
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
|
|
|
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
|
for (int i = 0; i < size; i++) {
|
|
// Input Item
|
|
toClient(wrapper.passthrough(Type.FLAT_ITEM));
|
|
// Output Item
|
|
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM));
|
|
|
|
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
|
|
if (secondItem) {
|
|
// Second Item
|
|
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM));
|
|
}
|
|
|
|
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
|
wrapper.passthrough(Type.INT); // Number of tools uses
|
|
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
|
|
|
|
RecipeRewriter recipeRewriter = new RecipeRewriter1_13_2(protocol, InventoryPackets::toClient);
|
|
protocol.registerOutgoing(ClientboundPackets1_13.DECLARE_RECIPES, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
handler(wrapper -> {
|
|
int size = wrapper.passthrough(Type.VAR_INT);
|
|
for (int i = 0; i < size; i++) {
|
|
// First id, then type
|
|
String id = wrapper.passthrough(Type.STRING);
|
|
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
|
|
recipeRewriter.handle(wrapper, type);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM);
|
|
itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM);
|
|
}
|
|
|
|
public static void toClient(Item item) {
|
|
if (item == null) return;
|
|
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getNewItemId(item.getIdentifier()));
|
|
}
|
|
|
|
public static void toServer(Item item) {
|
|
if (item == null) return;
|
|
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getOldItemId(item.getIdentifier()));
|
|
}
|
|
}
|