use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13 in project ViaBackwards by ViaVersion.
the class PlayerPackets1_14 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_14.SERVER_DIFFICULTY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE);
// Locked
map(Type.BOOLEAN, Type.NOTHING);
handler(wrapper -> {
byte difficulty = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
wrapper.user().get(DifficultyStorage.class).setDifficulty(difficulty);
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.OPEN_SIGN_EDITOR, new // c
PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
// Action
map(Type.VAR_INT);
// Position
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 0);
if (type == 0) {
wrapper.passthrough(Type.STRING);
} else if (type == 1) {
// Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Crafting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Blast furnace/smoker data
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.read(Type.POSITION);
int face = wrapper.read(Type.VAR_INT);
int hand = wrapper.read(Type.VAR_INT);
float x = wrapper.read(Type.FLOAT);
float y = wrapper.read(Type.FLOAT);
float z = wrapper.read(Type.FLOAT);
wrapper.write(Type.VAR_INT, hand);
wrapper.write(Type.POSITION1_14, position);
wrapper.write(Type.VAR_INT, face);
wrapper.write(Type.FLOAT, x);
wrapper.write(Type.FLOAT, y);
wrapper.write(Type.FLOAT, z);
// Inside block
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_14 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
protocol.registerClientbound(ClientboundPackets1_14.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int windowId = wrapper.read(Type.VAR_INT);
wrapper.write(Type.UNSIGNED_BYTE, (short) windowId);
int type = wrapper.read(Type.VAR_INT);
String stringType = null;
String containerTitle = null;
int slotSize = 0;
if (type < 6) {
if (type == 2)
containerTitle = "Barrel";
stringType = "minecraft:container";
slotSize = (type + 1) * 9;
} else {
switch(type) {
case 11:
stringType = "minecraft:crafting_table";
break;
// blast furnace
case 9:
// smoker
case 20:
// furnace
case 13:
case // grindstone
14:
if (type == 9)
containerTitle = "Blast Furnace";
else if (type == 20)
containerTitle = "Smoker";
else if (type == 14)
containerTitle = "Grindstone";
stringType = "minecraft:furnace";
slotSize = 3;
break;
case 6:
stringType = "minecraft:dropper";
slotSize = 9;
break;
case 12:
stringType = "minecraft:enchanting_table";
break;
case 10:
stringType = "minecraft:brewing_stand";
slotSize = 5;
break;
case 18:
stringType = "minecraft:villager";
break;
case 8:
stringType = "minecraft:beacon";
slotSize = 1;
break;
// cartography_table
case 21:
case 7:
if (type == 21)
containerTitle = "Cartography Table";
stringType = "minecraft:anvil";
break;
case 15:
stringType = "minecraft:hopper";
slotSize = 5;
break;
case 19:
stringType = "minecraft:shulker_box";
slotSize = 27;
break;
}
}
if (stringType == null) {
ViaBackwards.getPlatform().getLogger().warning("Can't open inventory for 1.13 player! Type: " + type);
wrapper.cancel();
return;
}
wrapper.write(Type.STRING, stringType);
JsonElement title = wrapper.read(Type.COMPONENT);
if (containerTitle != null) {
// Don't rewrite renamed, only translatable titles
JsonObject object;
if (title.isJsonObject() && (object = title.getAsJsonObject()).has("translate")) {
// Don't rewrite other 9x3 translatable containers
if (type != 2 || object.getAsJsonPrimitive("translate").getAsString().equals("container.barrel")) {
title = ChatRewriter.legacyTextToJson(containerTitle);
}
}
}
wrapper.write(Type.COMPONENT, title);
wrapper.write(Type.UNSIGNED_BYTE, (short) slotSize);
}
});
}
});
// Horse window -> Open Window
protocol.registerClientbound(ClientboundPackets1_14.OPEN_HORSE_WINDOW, ClientboundPackets1_13.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Window id
wrapper.passthrough(Type.UNSIGNED_BYTE);
// Type
wrapper.write(Type.STRING, "EntityHorse");
JsonObject object = new JsonObject();
object.addProperty("translate", "minecraft.horse");
// Title
wrapper.write(Type.COMPONENT, object);
// Number of slots
wrapper.write(Type.UNSIGNED_BYTE, wrapper.read(Type.VAR_INT).shortValue());
// Entity id
wrapper.passthrough(Type.INT);
}
});
}
});
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
// Trade List -> Plugin Message
protocol.registerClientbound(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "minecraft:trader_list");
int windowId = wrapper.read(Type.VAR_INT);
wrapper.write(Type.INT, windowId);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
Item input = wrapper.read(Type.FLAT_VAR_INT_ITEM);
input = handleItemToClient(input);
wrapper.write(Type.FLAT_VAR_INT_ITEM, input);
// Output Item
Item output = wrapper.read(Type.FLAT_VAR_INT_ITEM);
output = handleItemToClient(output);
wrapper.write(Type.FLAT_VAR_INT_ITEM, output);
// Has second item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
if (secondItem) {
// Second Item
Item second = wrapper.read(Type.FLAT_VAR_INT_ITEM);
second = handleItemToClient(second);
wrapper.write(Type.FLAT_VAR_INT_ITEM, second);
}
// Trade disabled
wrapper.passthrough(Type.BOOLEAN);
// Number of tools uses
wrapper.passthrough(Type.INT);
// Maximum number of trade uses
wrapper.passthrough(Type.INT);
wrapper.read(Type.INT);
wrapper.read(Type.INT);
wrapper.read(Type.FLOAT);
}
wrapper.read(Type.VAR_INT);
wrapper.read(Type.VAR_INT);
wrapper.read(Type.BOOLEAN);
}
});
}
});
// Open Book -> Plugin Message
protocol.registerClientbound(ClientboundPackets1_14.OPEN_BOOK, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "minecraft:book_open");
wrapper.passthrough(Type.VAR_INT);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.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_VAR_INT_ITEM);
handler(itemToClientHandler(Type.FLAT_VAR_INT_ITEM));
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = wrapper.user().getEntityTracker(Protocol1_13_2To1_14.class).entityType(entityId);
if (entityType == null)
return;
if (entityType.isOrHasParent(Entity1_14Types.ABSTRACT_HORSE)) {
wrapper.setId(0x3F);
wrapper.resetReader();
wrapper.passthrough(Type.VAR_INT);
wrapper.read(Type.VAR_INT);
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
int armorType = item == null || item.identifier() == 0 ? 0 : item.identifier() - 726;
if (armorType < 0 || armorType > 3) {
ViaBackwards.getPlatform().getLogger().warning("Received invalid horse armor: " + item);
wrapper.cancel();
return;
}
List<Metadata> metadataList = new ArrayList<>();
metadataList.add(new Metadata(16, Types1_13_2.META_TYPES.varIntType, armorType));
wrapper.write(Types1_13.METADATA_LIST, metadataList);
}
}
});
}
});
RecipeRewriter recipeHandler = new RecipeRewriter1_13_2(protocol);
protocol.registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
private final Set<String> removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting");
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int size = wrapper.passthrough(Type.VAR_INT);
int deleted = 0;
for (int i = 0; i < size; i++) {
String type = wrapper.read(Type.STRING);
// Recipe Identifier
String id = wrapper.read(Type.STRING);
type = type.replace("minecraft:", "");
if (removedTypes.contains(type)) {
switch(type) {
case "blasting":
case "smoking":
case "campfire_cooking":
// Group
wrapper.read(Type.STRING);
// Ingredients
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
// EXP
wrapper.read(Type.FLOAT);
// Cooking time
wrapper.read(Type.VAR_INT);
break;
case "stonecutting":
// Group?
wrapper.read(Type.STRING);
// Ingredients
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
// Result
wrapper.read(Type.FLAT_VAR_INT_ITEM);
break;
}
deleted++;
continue;
}
wrapper.write(Type.STRING, id);
wrapper.write(Type.STRING, type);
// Handle the rest of the types
recipeHandler.handle(wrapper, type);
}
wrapper.set(Type.VAR_INT, 0, size - deleted);
}
});
}
});
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_BREAK_ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION1_14, Type.POSITION);
map(Type.BYTE);
}
});
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
// Location
map(Type.POSITION1_14, Type.POSITION);
// Action id
map(Type.UNSIGNED_BYTE);
// Action param
map(Type.UNSIGNED_BYTE);
// Block id - /!\ NOT BLOCK STATE
map(Type.VAR_INT);
handler(wrapper -> {
int mappedId = protocol.getMappingData().getNewBlockId(wrapper.get(Type.VAR_INT, 0));
if (mappedId == -1) {
wrapper.cancel();
return;
}
wrapper.set(Type.VAR_INT, 0, mappedId);
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(id));
}
});
}
});
blockRewriter.registerMultiBlockChange(ClientboundPackets1_14.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_14.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// X
map(Type.FLOAT);
// Y
map(Type.FLOAT);
// Z
map(Type.FLOAT);
// Radius
map(Type.FLOAT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int i = 0; i < 3; i++) {
float coord = wrapper.get(Type.FLOAT, i);
if (coord < 0f) {
coord = (float) Math.floor(coord);
wrapper.set(Type.FLOAT, i, coord);
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.read(new Chunk1_14Type());
wrapper.write(new Chunk1_13Type(clientWorld), chunk);
ChunkLightStorage.ChunkLight chunkLight = wrapper.user().get(ChunkLightStorage.class).getStoredLight(chunk.getX(), chunk.getZ());
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
ChunkSectionLight sectionLight = new ChunkSectionLightImpl();
section.setLight(sectionLight);
if (chunkLight == null) {
sectionLight.setBlockLight(ChunkLightStorage.FULL_LIGHT);
if (clientWorld.getEnvironment() == Environment.NORMAL) {
sectionLight.setSkyLight(ChunkLightStorage.FULL_LIGHT);
}
} else {
byte[] blockLight = chunkLight.getBlockLight()[i];
sectionLight.setBlockLight(blockLight != null ? blockLight : ChunkLightStorage.FULL_LIGHT);
if (clientWorld.getEnvironment() == Environment.NORMAL) {
byte[] skyLight = chunkLight.getSkyLight()[i];
sectionLight.setSkyLight(skyLight != null ? skyLight : ChunkLightStorage.FULL_LIGHT);
}
}
if (Via.getConfig().isNonFullBlockLightFix() && section.getNonAirBlocksCount() != 0 && sectionLight.hasBlockLight()) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int id = section.getFlatBlock(x, y, z);
if (Protocol1_14To1_13_2.MAPPINGS.getNonFullBlocks().contains(id)) {
sectionLight.getBlockLightNibbleArray().set(x, y, z, 0);
}
}
}
}
}
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId);
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.UNLOAD_CHUNK, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int x = wrapper.passthrough(Type.INT);
int z = wrapper.passthrough(Type.INT);
wrapper.user().get(ChunkLightStorage.class).unloadChunk(x, z);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect Id
map(Type.INT);
// Location
map(Type.POSITION1_14, Type.POSITION);
// Data
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
} else if (id == 2001) {
// Block break + block break sound
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
}
}
});
}
});
registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.FLOAT);
protocol.registerClientbound(ClientboundPackets1_14.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.BYTE);
map(Type.BOOLEAN);
// Locked
map(Type.BOOLEAN, Type.NOTHING);
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12_1.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.ITEM, Type.FLAT_ITEM);
handler(itemToClientHandler(Type.FLAT_ITEM));
}
});
protocol.registerClientbound(ClientboundPackets1_12_1.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Window ID
map(Type.UNSIGNED_BYTE);
// 1 - Window Values
map(Type.ITEM_ARRAY, Type.FLAT_ITEM_ARRAY);
handler(itemArrayHandler(Type.FLAT_ITEM_ARRAY));
}
});
protocol.registerClientbound(ClientboundPackets1_12_1.WINDOW_PROPERTY, new PacketRemapper() {
@Override
public void registerMap() {
// Window id
map(Type.UNSIGNED_BYTE);
// Property
map(Type.SHORT);
// Value
map(Type.SHORT);
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) protocol.getMappingData().getEnchantmentMappings().getNewId(wrapper.get(Type.SHORT, 1)));
}
}
});
}
});
// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Channel
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.get(Type.STRING, 0);
// Handle stopsound change
if (channel.equalsIgnoreCase("MC|StopSound")) {
String originalSource = wrapper.read(Type.STRING);
String originalSound = wrapper.read(Type.STRING);
// Reset the packet
wrapper.clearPacket();
wrapper.setId(0x4C);
byte flags = 0;
// Placeholder
wrapper.write(Type.BYTE, flags);
if (!originalSource.isEmpty()) {
flags |= 1;
Optional<SoundSource> finalSource = SoundSource.findBySource(originalSource);
if (!finalSource.isPresent()) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master");
}
finalSource = Optional.of(SoundSource.MASTER);
}
wrapper.write(Type.VAR_INT, finalSource.get().getId());
}
if (!originalSound.isEmpty()) {
flags |= 2;
wrapper.write(Type.STRING, originalSound);
}
// Update flags
wrapper.set(Type.BYTE, 0, flags);
return;
} else if (channel.equalsIgnoreCase("MC|TrList")) {
channel = "minecraft: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
Item input = wrapper.read(Type.ITEM);
handleItemToClient(input);
wrapper.write(Type.FLAT_ITEM, input);
// Output Item
Item output = wrapper.read(Type.ITEM);
handleItemToClient(output);
wrapper.write(Type.FLAT_ITEM, output);
// Has second item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
if (secondItem) {
// Second Item
Item second = wrapper.read(Type.ITEM);
handleItemToClient(second);
wrapper.write(Type.FLAT_ITEM, second);
}
// Trade disabled
wrapper.passthrough(Type.BOOLEAN);
// Number of tools uses
wrapper.passthrough(Type.INT);
// Maximum number of trade uses
wrapper.passthrough(Type.INT);
}
} else {
String old = channel;
channel = getNewPluginChannelId(channel);
if (channel == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring outgoing plugin message with channel: " + old);
}
wrapper.cancel();
return;
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> rewrittenChannels = new ArrayList<>();
for (int i = 0; i < channels.length; i++) {
String rewritten = getNewPluginChannelId(channels[i]);
if (rewritten != null) {
rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring plugin channel in outgoing REGISTER: " + channels[i]);
}
}
if (!rewrittenChannels.isEmpty()) {
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} else {
wrapper.cancel();
return;
}
}
}
wrapper.set(Type.STRING, 0, channel);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_12_1.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.ITEM, Type.FLAT_ITEM);
handler(itemToClientHandler(Type.FLAT_ITEM));
}
});
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_ITEM, Type.ITEM);
handler(itemToServerHandler(Type.ITEM));
}
});
protocol.registerServerbound(ServerboundPackets1_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);
String old = channel;
channel = getOldPluginChannelId(channel);
if (channel == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring incoming plugin message with channel: " + old);
}
wrapper.cancel();
return;
} else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> rewrittenChannels = new ArrayList<>();
for (int i = 0; i < channels.length; i++) {
String rewritten = getOldPluginChannelId(channels[i]);
if (rewritten != null) {
rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring plugin channel in incoming REGISTER: " + channels[i]);
}
}
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
}
wrapper.set(Type.STRING, 0, channel);
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Slot
map(Type.SHORT);
// 1 - Clicked Item
map(Type.FLAT_ITEM, Type.ITEM);
handler(itemToServerHandler(Type.ITEM));
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13 in project ViaVersion by ViaVersion.
the class Protocol1_13To1_12_2 method registerPackets.
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
WorldPackets.register(this);
registerClientbound(State.LOGIN, 0x0, 0x0, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
}
});
registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String response = wrapper.get(Type.STRING, 0);
try {
JsonObject json = GsonUtil.getGson().fromJson(response, JsonObject.class);
if (json.has("favicon")) {
json.addProperty("favicon", json.get("favicon").getAsString().replace("\n", ""));
}
wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json));
} catch (JsonParseException e) {
e.printStackTrace();
}
}
});
}
});
// New packet 0x04 - Login Plugin Message
// Statistics
registerClientbound(ClientboundPackets1_12_1.STATISTICS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int size = wrapper.read(Type.VAR_INT);
List<StatisticData> remappedStats = new ArrayList<>();
for (int i = 0; i < size; i++) {
String name = wrapper.read(Type.STRING);
String[] split = name.split("\\.");
int categoryId = 0;
int newId = -1;
int value = wrapper.read(Type.VAR_INT);
if (split.length == 2) {
// Custom types
categoryId = 8;
Integer newIdRaw = StatisticMappings.CUSTOM_STATS.get(name);
if (newIdRaw != null) {
newId = newIdRaw;
} else {
Via.getPlatform().getLogger().warning("Could not find 1.13 -> 1.12.2 statistic mapping for " + name);
}
} else if (split.length > 2) {
String category = split[1];
// TODO convert string ids (blocks, items, entities)
switch(category) {
case "mineBlock":
categoryId = 0;
break;
case "craftItem":
categoryId = 1;
break;
case "useItem":
categoryId = 2;
break;
case "breakItem":
categoryId = 3;
break;
case "pickup":
categoryId = 4;
break;
case "drop":
categoryId = 5;
break;
case "killEntity":
categoryId = 6;
break;
case "entityKilledBy":
categoryId = 7;
break;
}
}
if (newId != -1)
remappedStats.add(new StatisticData(categoryId, newId, value));
}
// size
wrapper.write(Type.VAR_INT, remappedStats.size());
for (StatisticData stat : remappedStats) {
// category id
wrapper.write(Type.VAR_INT, stat.getCategoryId());
// statistics id
wrapper.write(Type.VAR_INT, stat.getNewId());
// value
wrapper.write(Type.VAR_INT, stat.getValue());
}
}
});
}
});
componentRewriter.registerBossBar(ClientboundPackets1_12_1.BOSSBAR);
componentRewriter.registerComponentPacket(ClientboundPackets1_12_1.CHAT_MESSAGE);
registerClientbound(ClientboundPackets1_12_1.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId());
String input = wrapper.user().get(TabCompleteTracker.class).getInput();
// Start & End
int index;
int length;
// If no input or new word (then it's the start)
if (input.endsWith(" ") || input.isEmpty()) {
index = input.length();
length = 0;
} else {
// Otherwise find the last space (+1 as we include it)
int lastSpace = input.lastIndexOf(' ') + 1;
index = lastSpace;
length = input.length() - lastSpace;
}
// Write index + length
wrapper.write(Type.VAR_INT, index);
wrapper.write(Type.VAR_INT, length);
int count = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < count; i++) {
String suggestion = wrapper.read(Type.STRING);
// If we're at the start then handle removing slash
if (suggestion.startsWith("/") && index == 0) {
suggestion = suggestion.substring(1);
}
wrapper.write(Type.STRING, suggestion);
wrapper.write(Type.BOOLEAN, false);
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Id
map(Type.UNSIGNED_BYTE);
// Window type
map(Type.STRING);
// Title
handler(wrapper -> componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
}
});
registerClientbound(ClientboundPackets1_12_1.COOLDOWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int item = wrapper.read(Type.VAR_INT);
int ticks = wrapper.read(Type.VAR_INT);
wrapper.cancel();
if (item == 383) {
// Spawn egg
for (int i = 0; i < 44; i++) {
Integer newItem = getMappingData().getItemMappings().get(item << 16 | i);
if (newItem != null) {
PacketWrapper packet = wrapper.create(ClientboundPackets1_13.COOLDOWN);
packet.write(Type.VAR_INT, newItem);
packet.write(Type.VAR_INT, ticks);
packet.send(Protocol1_13To1_12_2.class);
} else {
break;
}
}
} else {
for (int i = 0; i < 16; i++) {
int newItem = getMappingData().getItemMappings().get(item << 4 | i);
if (newItem != -1) {
PacketWrapper packet = wrapper.create(ClientboundPackets1_13.COOLDOWN);
packet.write(Type.VAR_INT, newItem);
packet.write(Type.VAR_INT, ticks);
packet.send(Protocol1_13To1_12_2.class);
} else {
break;
}
}
}
}
});
}
});
componentRewriter.registerComponentPacket(ClientboundPackets1_12_1.DISCONNECT);
registerClientbound(ClientboundPackets1_12_1.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect Id
map(Type.INT);
// Location
map(Type.POSITION);
// Data
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, getMappingData().getItemMappings().get(data << 4));
} else if (id == 2001) {
// Block break + block break sound
int blockId = data & 0xFFF;
int blockData = data >> 12;
wrapper.set(Type.INT, 1, WorldPackets.toNewId(blockId << 4 | blockData));
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Store the player
int entityId = wrapper.get(Type.INT, 0);
wrapper.user().getEntityTracker(Protocol1_13To1_12_2.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER);
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
handler(SEND_DECLARE_COMMANDS_AND_TAGS);
}
});
registerClientbound(ClientboundPackets1_12_1.CRAFT_RECIPE_RESPONSE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE);
handler(wrapper -> wrapper.write(Type.STRING, "viaversion:legacy/" + wrapper.read(Type.VAR_INT)));
}
});
componentRewriter.registerCombatEvent(ClientboundPackets1_12_1.COMBAT_EVENT);
registerClientbound(ClientboundPackets1_12_1.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Map id
map(Type.VAR_INT);
// 1 - Scale
map(Type.BYTE);
// 2 - Tracking Position
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int iconCount = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < iconCount; i++) {
byte directionAndType = wrapper.read(Type.BYTE);
int type = (directionAndType & 0xF0) >> 4;
wrapper.write(Type.VAR_INT, type);
// Icon X
wrapper.passthrough(Type.BYTE);
// Icon Z
wrapper.passthrough(Type.BYTE);
byte direction = (byte) (directionAndType & 0x0F);
wrapper.write(Type.BYTE, direction);
// Display Name
wrapper.write(Type.OPTIONAL_COMPONENT, null);
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.UNLOCK_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
// action
map(Type.VAR_INT);
// crafting book open
map(Type.BOOLEAN);
// crafting filter active
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// smelting book open
wrapper.write(Type.BOOLEAN, false);
// smelting filter active
wrapper.write(Type.BOOLEAN, false);
}
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
for (int i = 0; i < (action == 0 ? 2 : 1); i++) {
int[] ids = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
String[] stringIds = new String[ids.length];
for (int j = 0; j < ids.length; j++) {
stringIds[j] = "viaversion:legacy/" + ids[j];
}
wrapper.write(Type.STRING_ARRAY, stringIds);
}
if (action == 0) {
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new // Declare recipes
PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, RecipeData.recipes.size());
for (Map.Entry<String, RecipeData.Recipe> entry : RecipeData.recipes.entrySet()) {
// Id
wrapper.write(Type.STRING, entry.getKey());
wrapper.write(Type.STRING, entry.getValue().getType());
switch(entry.getValue().getType()) {
case "crafting_shapeless":
{
wrapper.write(Type.STRING, entry.getValue().getGroup());
wrapper.write(Type.VAR_INT, entry.getValue().getIngredients().length);
for (Item[] ingredient : entry.getValue().getIngredients()) {
// Clone because array and item is mutable
Item[] clone = ingredient.clone();
for (int i = 0; i < clone.length; i++) {
if (clone[i] == null)
continue;
clone[i] = new DataItem(clone[i]);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
}
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
break;
}
case "crafting_shaped":
{
wrapper.write(Type.VAR_INT, entry.getValue().getWidth());
wrapper.write(Type.VAR_INT, entry.getValue().getHeight());
wrapper.write(Type.STRING, entry.getValue().getGroup());
for (Item[] ingredient : entry.getValue().getIngredients()) {
// Clone because array and item is mutable
Item[] clone = ingredient.clone();
for (int i = 0; i < clone.length; i++) {
if (clone[i] == null)
continue;
clone[i] = new DataItem(clone[i]);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
}
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
break;
}
case "smelting":
{
wrapper.write(Type.STRING, entry.getValue().getGroup());
// Clone because array and item is mutable
Item[] clone = entry.getValue().getIngredient().clone();
for (int i = 0; i < clone.length; i++) {
if (clone[i] == null)
continue;
clone[i] = new DataItem(clone[i]);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
wrapper.write(Type.FLOAT, entry.getValue().getExperience());
wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime());
break;
}
}
}
}
}).send(Protocol1_13To1_12_2.class);
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.clearBlockStorage(wrapper.user());
}
}
});
handler(SEND_DECLARE_COMMANDS_AND_TAGS);
}
});
registerClientbound(ClientboundPackets1_12_1.SCOREBOARD_OBJECTIVE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Objective name
map(Type.STRING);
// 1 - Mode
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
byte mode = wrapper.get(Type.BYTE, 0);
// On create or update
if (mode == 0 || mode == 2) {
// Value
String value = wrapper.read(Type.STRING);
wrapper.write(Type.COMPONENT, ChatRewriter.legacyTextToJson(value));
String type = wrapper.read(Type.STRING);
// integer or hearts
wrapper.write(Type.VAR_INT, type.equals("integer") ? 0 : 1);
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.TEAMS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Team Name
map(Type.STRING);
// 1 - Mode
map(Type.BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
byte action = wrapper.get(Type.BYTE, 0);
if (action == 0 || action == 2) {
// Display Name
String displayName = wrapper.read(Type.STRING);
wrapper.write(Type.COMPONENT, ChatRewriter.legacyTextToJson(displayName));
// Prefix moved
String prefix = wrapper.read(Type.STRING);
// Suffix moved
String suffix = wrapper.read(Type.STRING);
// Flags
wrapper.passthrough(Type.BYTE);
// Name Tag Visibility
wrapper.passthrough(Type.STRING);
// Collision rule
wrapper.passthrough(Type.STRING);
// Handle new colors
int colour = wrapper.read(Type.BYTE).intValue();
if (colour == -1) {
// -1 changed to 21
colour = 21;
}
if (Via.getConfig().is1_13TeamColourFix()) {
char lastColorChar = getLastColorChar(prefix);
colour = ChatColorUtil.getColorOrdinal(lastColorChar);
suffix = ChatColorUtil.COLOR_CHAR + Character.toString(lastColorChar) + suffix;
}
wrapper.write(Type.VAR_INT, colour);
// Prefix
wrapper.write(Type.COMPONENT, ChatRewriter.legacyTextToJson(prefix));
// Suffix
wrapper.write(Type.COMPONENT, ChatRewriter.legacyTextToJson(suffix));
}
if (action == 0 || action == 3 || action == 4) {
// Entities
String[] names = wrapper.read(Type.STRING_ARRAY);
for (int i = 0; i < names.length; i++) {
names[i] = rewriteTeamMemberName(names[i]);
}
wrapper.write(Type.STRING_ARRAY, names);
}
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.UPDATE_SCORE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Display Name
String displayName = wrapper.read(Type.STRING);
displayName = rewriteTeamMemberName(displayName);
wrapper.write(Type.STRING, displayName);
byte action = wrapper.read(Type.BYTE);
wrapper.write(Type.BYTE, action);
// Objective Name
wrapper.passthrough(Type.STRING);
if (action != 1) {
// Value
wrapper.passthrough(Type.VAR_INT);
}
}
});
}
});
componentRewriter.registerTitle(ClientboundPackets1_12_1.TITLE);
// New 0x4C - Stop Sound
new SoundRewriter(this).registerSound(ClientboundPackets1_12_1.SOUND);
registerClientbound(ClientboundPackets1_12_1.TAB_LIST, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
}
});
}
});
registerClientbound(ClientboundPackets1_12_1.ADVANCEMENTS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Reset/clear
wrapper.passthrough(Type.BOOLEAN);
// Mapping size
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
// Identifier
wrapper.passthrough(Type.STRING);
// Parent
if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING);
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
// Title
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
// Description
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
Item icon = wrapper.read(Type.ITEM);
itemRewriter.handleItemToClient(icon);
// Translate item to flat item
wrapper.write(Type.FLAT_ITEM, icon);
// Frame type
wrapper.passthrough(Type.VAR_INT);
// Flags
int flags = wrapper.passthrough(Type.INT);
if ((flags & 1) != 0) {
// Background texture
wrapper.passthrough(Type.STRING);
}
// X
wrapper.passthrough(Type.FLOAT);
// Y
wrapper.passthrough(Type.FLOAT);
}
// Criteria
wrapper.passthrough(Type.STRING_ARRAY);
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
// String array
wrapper.passthrough(Type.STRING_ARRAY);
}
}
}
});
}
});
// Incoming packets
// New packet 0x02 - Login Plugin Message
cancelServerbound(State.LOGIN, 0x02);
// New 0x01 - Query Block NBT
cancelServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT);
// Tab-Complete
registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Disable auto-complete if configured
if (Via.getConfig().isDisable1_13AutoComplete()) {
wrapper.cancel();
}
int tid = wrapper.read(Type.VAR_INT);
// Save transaction id
wrapper.user().get(TabCompleteTracker.class).setTransactionId(tid);
}
});
// Prepend /
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, String inputValue) {
wrapper.user().get(TabCompleteTracker.class).setInput(inputValue);
return "/" + inputValue;
}
});
// Fake the end of the packet
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null);
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) {
TabCompleteTracker tracker = wrapper.user().get(TabCompleteTracker.class);
wrapper.cancel();
tracker.setTimeToSend(System.currentTimeMillis() + Via.getConfig().get1_13TabCompleteDelay() * 50L);
tracker.setLastTabComplete(wrapper.get(Type.STRING, 0));
}
}
});
}
});
// New 0x0A - Edit book -> Plugin Message
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.read(Type.FLAT_ITEM);
boolean isSigning = wrapper.read(Type.BOOLEAN);
itemRewriter.handleItemToServer(item);
// Channel
wrapper.write(Type.STRING, isSigning ? "MC|BSign" : "MC|BEdit");
wrapper.write(Type.ITEM, item);
}
});
}
});
// New 0x0C - Query Entity NBT
cancelServerbound(ServerboundPackets1_13.ENTITY_NBT_REQUEST);
// New 0x15 - Pick Item -> Plugin Message
registerServerbound(ServerboundPackets1_13.PICK_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Channel
wrapper.write(Type.STRING, "MC|PickItem");
}
});
}
});
registerServerbound(ServerboundPackets1_13.CRAFT_RECIPE_REQUEST, new PacketRemapper() {
@Override
public void registerMap() {
// Window id
map(Type.BYTE);
handler(wrapper -> {
String s = wrapper.read(Type.STRING);
Integer id;
if (s.length() < 19 || (id = Ints.tryParse(s.substring(18))) == null) {
wrapper.cancel();
return;
}
wrapper.write(Type.VAR_INT, id);
});
}
});
registerServerbound(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Type
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 0);
if (type == 0) {
String s = wrapper.read(Type.STRING);
Integer id;
// Custom recipes
if (s.length() < 19 || (id = Ints.tryParse(s.substring(18))) == null) {
wrapper.cancel();
return;
}
wrapper.write(Type.INT, id);
}
if (type == 1) {
// Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Crafting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Book Open | IGNORE NEW 1.13 FIELD
wrapper.read(Type.BOOLEAN);
// Smelting Recipe Filter Active | IGNORE NEW 1.13 FIELD
wrapper.read(Type.BOOLEAN);
}
}
});
}
});
// New 0x1C - Name Item -> Plugin Message
registerServerbound(ServerboundPackets1_13.RENAME_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Channel
wrapper.write(Type.STRING, "MC|ItemName");
});
}
});
// New 0x1F - Select Trade -> Plugin Message
registerServerbound(ServerboundPackets1_13.SELECT_TRADE, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Channel
wrapper.write(Type.STRING, "MC|TrSel");
});
// Slot
map(Type.VAR_INT, Type.INT);
}
});
// New 0x20 - Set Beacon Effect -> Plugin Message
registerServerbound(ServerboundPackets1_13.SET_BEACON_EFFECT, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Channel
wrapper.write(Type.STRING, "MC|Beacon");
});
// Primary Effect
map(Type.VAR_INT, Type.INT);
// Secondary Effect
map(Type.VAR_INT, Type.INT);
}
});
// New 0x22 - Update Command Block -> Plugin Message
registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> wrapper.write(Type.STRING, "MC|AutoCmd"));
handler(POS_TO_3_INT);
// Command
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int mode = wrapper.read(Type.VAR_INT);
byte flags = wrapper.read(Type.BYTE);
String stringMode = mode == 0 ? "SEQUENCE" : mode == 1 ? "AUTO" : "REDSTONE";
// Track output
wrapper.write(Type.BOOLEAN, (flags & 0x1) != 0);
wrapper.write(Type.STRING, stringMode);
// Is conditional
wrapper.write(Type.BOOLEAN, (flags & 0x2) != 0);
// Automatic
wrapper.write(Type.BOOLEAN, (flags & 0x4) != 0);
}
});
}
});
// New 0x23 - Update Command Block Minecart -> Plugin Message
registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|AdvCmd");
// Type 1 for Entity
wrapper.write(Type.BYTE, (byte) 1);
}
});
// Entity Id
map(Type.VAR_INT, Type.INT);
}
});
// 0x1B -> 0x24 in InventoryPackets
// New 0x25 - Update Structure Block -> Message Channel
registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Channel
wrapper.write(Type.STRING, "MC|Struct");
});
handler(POS_TO_3_INT);
map(Type.VAR_INT, new // Action
ValueTransformer<Integer, Byte>(// Action
Type.BYTE) {
@Override
public Byte transform(PacketWrapper wrapper, Integer action) throws Exception {
return (byte) (action + 1);
}
});
// Action
map(Type.VAR_INT, new ValueTransformer<Integer, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, Integer mode) throws Exception {
return mode == 0 ? "SAVE" : mode == 1 ? "LOAD" : mode == 2 ? "CORNER" : "DATA";
}
});
// Name
map(Type.STRING);
// Offset X
map(Type.BYTE, Type.INT);
// Offset Y
map(Type.BYTE, Type.INT);
// Offset Z
map(Type.BYTE, Type.INT);
// Size X
map(Type.BYTE, Type.INT);
// Size Y
map(Type.BYTE, Type.INT);
// Size Z
map(Type.BYTE, Type.INT);
map(Type.VAR_INT, new // Mirror
ValueTransformer<Integer, String>(// Mirror
Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, Integer mirror) throws Exception {
return mirror == 0 ? "NONE" : mirror == 1 ? "LEFT_RIGHT" : "FRONT_BACK";
}
});
map(Type.VAR_INT, new // Rotation
ValueTransformer<Integer, String>(// Rotation
Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, Integer rotation) throws Exception {
return rotation == 0 ? "NONE" : rotation == 1 ? "CLOCKWISE_90" : rotation == 2 ? "CLOCKWISE_180" : "COUNTERCLOCKWISE_90";
}
});
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
float integrity = wrapper.read(Type.FLOAT);
long seed = wrapper.read(Type.VAR_LONG);
byte flags = wrapper.read(Type.BYTE);
// Ignore Entities
wrapper.write(Type.BOOLEAN, (flags & 0x1) != 0);
// Show air
wrapper.write(Type.BOOLEAN, (flags & 0x2) != 0);
// Show bounding box
wrapper.write(Type.BOOLEAN, (flags & 0x4) != 0);
wrapper.write(Type.FLOAT, integrity);
wrapper.write(Type.VAR_LONG, seed);
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY);
registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.FLAT_ITEM);
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
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
handleItemToClient(wrapper.passthrough(Type.FLAT_ITEM));
// Output Item
handleItemToClient(wrapper.passthrough(Type.FLAT_ITEM));
// Has second item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
if (secondItem) {
// Second Item
handleItemToClient(wrapper.passthrough(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);
}
}
}
});
}
});
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
RecipeRewriter recipeRewriter = new RecipeRewriter1_13_2(protocol);
protocol.registerClientbound(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);
}
});
}
});
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLAT_ITEM, Type.FLOAT);
}
Aggregations