use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17 in project ViaBackwards by ViaVersion.
the class EntityPackets1_17 method registerPackets.
@Override
protected void registerPackets() {
registerTrackerWithData(ClientboundPackets1_17.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
registerSpawnTracker(ClientboundPackets1_17.SPAWN_MOB);
registerTracker(ClientboundPackets1_17.SPAWN_EXPERIENCE_ORB, Entity1_17Types.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_17Types.PAINTING);
registerTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_17Types.PLAYER);
registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_16.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_16_2.DESTROY_ENTITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.read(Type.VAR_INT);
tracker(wrapper.user()).removeEntity(entityId);
// Write into single value array
int[] array = { entityId };
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, array);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Hardcore
map(Type.BOOLEAN);
// Gamemode
map(Type.UNSIGNED_BYTE);
// Previous Gamemode
map(Type.BYTE);
// Worlds
map(Type.STRING_ARRAY);
// Dimension registry
map(Type.NBT);
// Current dimension data
map(Type.NBT);
// World
map(Type.STRING);
handler(wrapper -> {
byte previousGamemode = wrapper.get(Type.BYTE, 0);
if (previousGamemode == -1) {
// "Unset" gamemode removed
wrapper.set(Type.BYTE, 0, (byte) 0);
}
});
handler(getTrackerHandler(Entity1_17Types.PLAYER, Type.INT));
handler(worldDataTrackerHandler(1));
handler(wrapper -> {
CompoundTag registry = wrapper.get(Type.NBT, 0);
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
ListTag biomes = biomeRegistry.get("value");
for (Tag biome : biomes) {
CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
StringTag category = biomeCompound.get("category");
if (category.getValue().equalsIgnoreCase("underground")) {
category.setValue("none");
}
}
CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type");
ListTag dimensions = dimensionRegistry.get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
reduceExtendedHeight(dimensionCompound, false);
}
reduceExtendedHeight(wrapper.get(Type.NBT, 1), true);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// Dimension data
map(Type.NBT);
// World
map(Type.STRING);
handler(worldDataTrackerHandler(0));
handler(wrapper -> reduceExtendedHeight(wrapper.get(Type.NBT, 0), true));
}
});
protocol.registerClientbound(ClientboundPackets1_17.PLAYER_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.BYTE);
map(Type.VAR_INT);
handler(wrapper -> {
// Dismount vehicle ¯\_(ツ)_/¯
wrapper.read(Type.BOOLEAN);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
// Entity id
map(Type.VAR_INT);
handler(wrapper -> {
// Collection length
wrapper.write(Type.INT, wrapper.read(Type.VAR_INT));
});
}
});
// TODO translatables
protocol.mergePacket(ClientboundPackets1_17.COMBAT_ENTER, ClientboundPackets1_16_2.COMBAT_EVENT, 0);
protocol.mergePacket(ClientboundPackets1_17.COMBAT_END, ClientboundPackets1_16_2.COMBAT_EVENT, 1);
protocol.mergePacket(ClientboundPackets1_17.COMBAT_KILL, ClientboundPackets1_16_2.COMBAT_EVENT, 2);
}
use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17 in project ViaVersion by ViaVersion.
the class EntityPackets method registerPackets.
@Override
public void registerPackets() {
registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
registerTracker(ClientboundPackets1_16_2.SPAWN_MOB);
registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_17Types.PLAYER);
registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_16.METADATA_LIST, Types1_17.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_16_2.DESTROY_ENTITIES, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
wrapper.cancel();
EntityTracker entityTracker = wrapper.user().getEntityTracker(Protocol1_17To1_16_4.class);
for (int entityId : entityIds) {
entityTracker.removeEntity(entityId);
// Send individual remove packets
PacketWrapper newPacket = wrapper.create(ClientboundPackets1_17.REMOVE_ENTITY);
newPacket.write(Type.VAR_INT, entityId);
newPacket.send(Protocol1_17To1_16_4.class);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
// Entity id
map(Type.VAR_INT);
handler(wrapper -> {
// Collection length is now a var int
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT));
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.PLAYER_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.BYTE);
map(Type.VAR_INT);
handler(wrapper -> {
// Dismount vehicle
wrapper.write(Type.BOOLEAN, false);
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.COMBAT_EVENT, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Combat packet actions have been split into individual packets (the content hasn't changed)
int type = wrapper.read(Type.VAR_INT);
ClientboundPacketType packetType;
switch(type) {
case 0:
packetType = ClientboundPackets1_17.COMBAT_ENTER;
break;
case 1:
packetType = ClientboundPackets1_17.COMBAT_END;
break;
case 2:
packetType = ClientboundPackets1_17.COMBAT_KILL;
break;
default:
throw new IllegalArgumentException("Invalid combat type received: " + type);
}
wrapper.setId(packetType.getId());
});
}
});
// The parent class of the other entity move packets that is never actually used has finally been removed from the id list
protocol.cancelClientbound(ClientboundPackets1_16_2.ENTITY_MOVEMENT);
}
use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
protocol.registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.UNSIGNED_BYTE);
// Slot
map(Type.SHORT);
// Button
map(Type.BYTE);
// Action id - doesn't matter, as the sent out confirmation packet will be cancelled
handler(wrapper -> wrapper.write(Type.SHORT, (short) 0));
// Action
map(Type.VAR_INT);
handler(wrapper -> {
// Affected items - throw them away!
int length = wrapper.read(Type.VAR_INT);
for (int i = 0; i < length; i++) {
// Slot
wrapper.read(Type.SHORT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
}
// 1.17 clients send the then carried item, but 1.16 expects the clicked one
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 5 || action == 1) {
// Quick craft (= dragging / mouse movement while clicking on an empty slot)
// OR Quick move (= shift click to move a whole stack to the other inventory)
// The server always expects an empty item here
item = null;
} else {
// Use the item sent
handleItemToServer(item);
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.WINDOW_CONFIRMATION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short inventoryId = wrapper.read(Type.UNSIGNED_BYTE);
short confirmationId = wrapper.read(Type.SHORT);
boolean accepted = wrapper.read(Type.BOOLEAN);
if (!accepted) {
// Use the new ping packet to replace the removed acknowledgement, extra bit for fast dismissal
int id = (1 << 30) | (inventoryId << 16) | (confirmationId & 0xFFFF);
wrapper.user().get(InventoryAcknowledgements.class).addId(id);
PacketWrapper pingPacket = wrapper.create(ClientboundPackets1_17.PING);
pingPacket.write(Type.INT, id);
pingPacket.send(Protocol1_17To1_16_4.class);
}
wrapper.cancel();
});
}
});
// New pong packet
protocol.registerServerbound(ServerboundPackets1_17.PONG, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int id = wrapper.read(Type.INT);
// Check extra bit for fast dismissal
if ((id & (1 << 30)) != 0 && wrapper.user().get(InventoryAcknowledgements.class).removeId(id)) {
// Decode our requested inventory acknowledgement
short inventoryId = (short) ((id >> 16) & 0xFF);
short confirmationId = (short) (id & 0xFFFF);
PacketWrapper packet = wrapper.create(ServerboundPackets1_16_2.WINDOW_CONFIRMATION);
packet.write(Type.UNSIGNED_BYTE, inventoryId);
packet.write(Type.SHORT, confirmationId);
// Accept
packet.write(Type.BOOLEAN, true);
packet.sendToServer(Protocol1_17To1_16_4.class);
}
wrapper.cancel();
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17 in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol1_17To1_16_4 protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerClientbound(ClientboundPackets1_16_2.WORLD_BORDER, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Border packet actions have been split into individual packets (the content hasn't changed)
int type = wrapper.read(Type.VAR_INT);
ClientboundPacketType packetType;
switch(type) {
case 0:
packetType = ClientboundPackets1_17.WORLD_BORDER_SIZE;
break;
case 1:
packetType = ClientboundPackets1_17.WORLD_BORDER_LERP_SIZE;
break;
case 2:
packetType = ClientboundPackets1_17.WORLD_BORDER_CENTER;
break;
case 3:
packetType = ClientboundPackets1_17.WORLD_BORDER_INIT;
break;
case 4:
packetType = ClientboundPackets1_17.WORLD_BORDER_WARNING_DELAY;
break;
case 5:
packetType = ClientboundPackets1_17.WORLD_BORDER_WARNING_DISTANCE;
break;
default:
throw new IllegalArgumentException("Invalid world border type received: " + type);
}
wrapper.setId(packetType.getId());
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.UPDATE_LIGHT, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.VAR_INT);
// y
map(Type.VAR_INT);
// trust edges
map(Type.BOOLEAN);
handler(wrapper -> {
int skyLightMask = wrapper.read(Type.VAR_INT);
int blockLightMask = wrapper.read(Type.VAR_INT);
// Now all written as a representation of BitSets
// Sky light mask
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, toBitSetLongArray(skyLightMask));
// Block light mask
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, toBitSetLongArray(blockLightMask));
// Empty sky light mask
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, toBitSetLongArray(wrapper.read(Type.VAR_INT)));
// Empty block light mask
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, toBitSetLongArray(wrapper.read(Type.VAR_INT)));
writeLightArrays(wrapper, skyLightMask);
writeLightArrays(wrapper, blockLightMask);
});
}
private void writeLightArrays(PacketWrapper wrapper, int bitMask) throws Exception {
List<byte[]> light = new ArrayList<>();
for (int i = 0; i < 18; i++) {
if (isSet(bitMask, i)) {
light.add(wrapper.read(Type.BYTE_ARRAY_PRIMITIVE));
}
}
// Now needs the length of the bytearray-array
wrapper.write(Type.VAR_INT, light.size());
for (byte[] bytes : light) {
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, bytes);
}
}
private long[] toBitSetLongArray(int bitmask) {
return new long[] { bitmask };
}
private boolean isSet(int mask, int i) {
return (mask & (1 << i)) != 0;
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
if (!chunk.isFullChunk()) {
// All chunks are full chunk packets now (1.16 already stopped sending non-full chunks)
// Construct multi block change packets instead
// Height map updates are lost (unless we want to fully cache and resend entire chunks)
// Block entities are always empty for non-full chunks in Vanilla
writeMultiBlockChangePacket(wrapper, chunk);
wrapper.cancel();
return;
}
// Normal full chunk writing
wrapper.write(new Chunk1_17Type(chunk.getSections().length), chunk);
// 1.17 uses a bitset for the mask
chunk.setChunkMask(BitSet.valueOf(new long[] { chunk.getBitmask() }));
for (int s = 0; s < chunk.getSections().length; s++) {
ChunkSection section = chunk.getSections()[s];
if (section == null)
continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old));
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Hardcore
map(Type.BOOLEAN);
// Gamemode
map(Type.UNSIGNED_BYTE);
// Previous Gamemode
map(Type.BYTE);
// World List
map(Type.STRING_ARRAY);
// Registry
map(Type.NBT);
// Current dimension
map(Type.NBT);
handler(wrapper -> {
// Add new dimension fields
CompoundTag dimensionRegistry = wrapper.get(Type.NBT, 0).get("minecraft:dimension_type");
ListTag dimensions = dimensionRegistry.get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
addNewDimensionData(dimensionCompound);
}
CompoundTag currentDimensionTag = wrapper.get(Type.NBT, 1);
addNewDimensionData(currentDimensionTag);
UserConnection user = wrapper.user();
user.getEntityTracker(Protocol1_17To1_16_4.class).addEntity(wrapper.get(Type.INT, 0), Entity1_17Types.PLAYER);
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
CompoundTag dimensionData = wrapper.passthrough(Type.NBT);
addNewDimensionData(dimensionData);
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
}
Aggregations