use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class EntityTracker1_9 method setSecondHand.
public void setSecondHand(int entityID, Item item) {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_EQUIPMENT, null, user());
wrapper.write(Type.VAR_INT, entityID);
// slot
wrapper.write(Type.VAR_INT, 1);
wrapper.write(Type.ITEM, this.itemInSecondHand = item);
try {
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class Protocol1_9To1_9_1 method registerPackets.
@Override
protected void registerPackets() {
// Currently supports 1.9.1 and 1.9.2
registerClientbound(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Player ID
map(Type.INT);
// 1 - Player Gamemode
map(Type.UNSIGNED_BYTE);
// 1.9.1 PRE 2 Changed this
// 2 - Player Dimension
map(Type.INT, Type.BYTE);
// 3 - World Difficulty
map(Type.UNSIGNED_BYTE);
// 4 - Max Players (Tab)
map(Type.UNSIGNED_BYTE);
// 5 - Level Type
map(Type.STRING);
// 6 - Reduced Debug info
map(Type.BOOLEAN);
}
});
registerClientbound(ClientboundPackets1_9.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound ID
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int sound = wrapper.get(Type.VAR_INT, 0);
if (// Stop the Elytra sound for 1.9 (It's introduced in 1.9.2)
sound == 415)
wrapper.cancel();
else if (// Act like the Elytra sound never existed
sound >= 416)
wrapper.set(Type.VAR_INT, 0, sound - 1);
}
});
}
});
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class CommandBlockProvider method sendPermission.
public void sendPermission(UserConnection user) throws Exception {
if (!isEnabled())
return;
// Entity status
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_STATUS, null, user);
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
// Entity ID
wrapper.write(Type.INT, tracker.getProvidedEntityId());
// Hardcoded op permission level
wrapper.write(Type.BYTE, (byte) 26);
wrapper.scheduleSend(Protocol1_9To1_8.class);
user.get(CommandBlockStorage.class).setPermissions(true);
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class InventoryPackets method register.
public static void register(Protocol protocol) {
protocol.registerClientbound(ClientboundPackets1_13.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Window ID
map(Type.UNSIGNED_BYTE);
// 1 - Slot ID
map(Type.SHORT);
// 2 - Slot Value
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM);
}
});
protocol.registerClientbound(ClientboundPackets1_13.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Window ID
map(Type.UNSIGNED_BYTE);
// 1 - Window Values
map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY);
}
});
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// Channel
map(Type.STRING);
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")) {
// Passthrough Window ID
wrapper.passthrough(Type.INT);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
// Output Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
// Has second item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
if (secondItem) {
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
}
// Trade disabled
wrapper.passthrough(Type.BOOLEAN);
// Number of tools uses
wrapper.passthrough(Type.INT);
// Maximum number of trade uses
wrapper.passthrough(Type.INT);
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Slot ID
map(Type.VAR_INT);
// 2 - Item
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM);
}
});
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int recipesNo = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < recipesNo; i++) {
// Id
wrapper.passthrough(Type.STRING);
String type = wrapper.passthrough(Type.STRING);
if (type.equals("crafting_shapeless")) {
// Group
wrapper.passthrough(Type.STRING);
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} else if (type.equals("crafting_shaped")) {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
// Group
wrapper.passthrough(Type.STRING);
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} else if (type.equals("smelting")) {
// Group
wrapper.passthrough(Type.STRING);
// Ingredient start
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
// Ingredient end
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
// EXP
wrapper.passthrough(Type.FLOAT);
// Cooking time
wrapper.passthrough(Type.VAR_INT);
}
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_13.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Window ID
map(Type.UNSIGNED_BYTE);
// 1 - Slot
map(Type.SHORT);
// 2 - Button
map(Type.BYTE);
// 3 - Action number
map(Type.SHORT);
// 4 - Mode
map(Type.VAR_INT);
// 5 - Clicked Item
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM);
}
});
protocol.registerServerbound(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Slot
map(Type.SHORT);
// 1 - Clicked Item
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM);
}
});
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class Protocol1_13_1To1_13 method registerPackets.
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
WorldPackets.register(this);
registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, String inputValue) {
// 1.13 starts sending slash at start, so we remove it for compatibility
return inputValue.startsWith("/") ? inputValue.substring(1) : inputValue;
}
});
}
});
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.FLAT_ITEM);
map(Type.BOOLEAN);
handler(wrapper -> {
Item item = wrapper.get(Type.FLAT_ITEM, 0);
itemRewriter.handleItemToServer(item);
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT);
if (hand == 1) {
wrapper.cancel();
}
}
});
}
});
registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
// Transaction id
map(Type.VAR_INT);
// Start
map(Type.VAR_INT);
// Length
map(Type.VAR_INT);
// Count
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int start = wrapper.get(Type.VAR_INT, 1);
// Offset by +1 to take into account / at beginning
wrapper.set(Type.VAR_INT, 1, start + 1);
// Passthrough suggestions
int count = wrapper.get(Type.VAR_INT, 3);
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.STRING);
boolean hasTooltip = wrapper.passthrough(Type.BOOLEAN);
if (hasTooltip) {
// JSON Tooltip
wrapper.passthrough(Type.STRING);
}
}
}
});
}
});
registerClientbound(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UUID);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 0) {
wrapper.passthrough(Type.COMPONENT);
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.VAR_INT);
short flags = wrapper.read(Type.BYTE);
if ((flags & 0x02) != 0)
flags |= 0x04;
wrapper.write(Type.UNSIGNED_BYTE, flags);
}
}
});
}
});
new TagRewriter(this).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
}
Aggregations