2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
|
|
|
* Copyright (C) 2016-2021 ViaVersion and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-08-22 18:05:24 +02:00
|
|
|
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets;
|
2018-08-08 21:45:54 +02:00
|
|
|
|
|
|
|
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;
|
2019-10-04 13:01:33 +02:00
|
|
|
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
|
2020-07-15 11:42:59 +02:00
|
|
|
import us.myles.ViaVersion.api.rewriters.RecipeRewriter;
|
2018-08-08 21:45:54 +02:00
|
|
|
import us.myles.ViaVersion.api.type.Type;
|
2020-08-16 16:24:06 +02:00
|
|
|
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
2020-06-05 20:30:09 +02:00
|
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
|
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
2020-07-15 11:42:59 +02:00
|
|
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
|
2018-08-08 21:45:54 +02:00
|
|
|
|
|
|
|
public class InventoryPackets {
|
|
|
|
|
2020-08-16 16:24:06 +02:00
|
|
|
public static void register(Protocol1_13_1To1_13 protocol) {
|
2019-10-04 13:01:33 +02:00
|
|
|
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
|
2020-06-05 23:06:00 +02:00
|
|
|
itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
|
|
|
|
itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
|
2020-07-02 00:18:33 +02:00
|
|
|
itemRewriter.registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_ITEM);
|
2020-09-09 11:25:45 +02:00
|
|
|
itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
|
2020-08-16 16:24:06 +02:00
|
|
|
|
2020-06-05 20:30:09 +02:00
|
|
|
protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
|
2018-08-22 22:05:46 +02:00
|
|
|
@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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-05 23:06:00 +02:00
|
|
|
itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
|
2018-08-08 21:45:54 +02:00
|
|
|
|
2020-07-15 11:42:59 +02:00
|
|
|
RecipeRewriter recipeRewriter = new RecipeRewriter1_13_2(protocol, InventoryPackets::toClient);
|
2020-06-05 20:30:09 +02:00
|
|
|
protocol.registerOutgoing(ClientboundPackets1_13.DECLARE_RECIPES, new PacketRemapper() {
|
2018-08-22 22:05:46 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
2020-07-15 11:42:59 +02:00
|
|
|
handler(wrapper -> {
|
|
|
|
int size = wrapper.passthrough(Type.VAR_INT);
|
|
|
|
for (int i = 0; i < size; i++) {
|
2020-07-19 13:37:41 +02:00
|
|
|
// First id, then type
|
|
|
|
String id = wrapper.passthrough(Type.STRING);
|
2020-07-15 11:42:59 +02:00
|
|
|
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
|
|
|
|
recipeRewriter.handle(wrapper, type);
|
2018-08-22 22:05:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-05 23:06:00 +02:00
|
|
|
itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM);
|
|
|
|
itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM);
|
2020-09-21 09:53:04 +02:00
|
|
|
|
|
|
|
itemRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_ITEM, Type.FLOAT);
|
2018-08-08 21:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void toClient(Item item) {
|
|
|
|
if (item == null) return;
|
2020-08-16 16:24:06 +02:00
|
|
|
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getNewItemId(item.getIdentifier()));
|
2018-08-08 21:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void toServer(Item item) {
|
|
|
|
if (item == null) return;
|
2020-08-16 16:24:06 +02:00
|
|
|
item.setIdentifier(Protocol1_13_1To1_13.MAPPINGS.getOldItemId(item.getIdentifier()));
|
2018-08-08 21:45:54 +02:00
|
|
|
}
|
|
|
|
}
|