use of com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType in project ViaVersion by ViaVersion.
the class Protocol1_17To1_16_4 method registerPackets.
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
WorldPackets.register(this);
registerClientbound(ClientboundPackets1_16_2.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Tags are now generically written with resource location - 5 different Vanilla types
wrapper.write(Type.VAR_INT, 5);
for (RegistryType type : RegistryType.getValues()) {
// Prefix with resource location
wrapper.write(Type.STRING, type.resourceLocation());
// Id conversion
tagRewriter.handle(wrapper, tagRewriter.getRewriter(type), tagRewriter.getNewTags(type));
// Stop iterating after entity types
if (type == RegistryType.ENTITY) {
break;
}
}
// New Game Event tags type
wrapper.write(Type.STRING, RegistryType.GAME_EVENT.resourceLocation());
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
for (String tag : NEW_GAME_EVENT_TAGS) {
wrapper.write(Type.STRING, tag);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[0]);
}
});
}
});
new StatisticsRewriter(this).register(ClientboundPackets1_16_2.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
registerClientbound(ClientboundPackets1_16_2.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.STRING);
// Required
wrapper.write(Type.BOOLEAN, Via.getConfig().isForcedUse1_17ResourcePack());
// Prompt message
wrapper.write(Type.OPTIONAL_COMPONENT, Via.getConfig().get1_17ResourcePackPrompt());
});
}
});
registerClientbound(ClientboundPackets1_16_2.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BYTE);
// Tracking position removed
wrapper.read(Type.BOOLEAN);
wrapper.passthrough(Type.BOOLEAN);
int size = wrapper.read(Type.VAR_INT);
// Write whether markers exists or not
if (size != 0) {
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.VAR_INT, size);
} else {
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
registerClientbound(ClientboundPackets1_16_2.TITLE, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Title 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.TITLE_TEXT;
break;
case 1:
packetType = ClientboundPackets1_17.TITLE_SUBTITLE;
break;
case 2:
packetType = ClientboundPackets1_17.ACTIONBAR;
break;
case 3:
packetType = ClientboundPackets1_17.TITLE_TIMES;
break;
case 4:
packetType = ClientboundPackets1_17.CLEAR_TITLES;
// Reset times
wrapper.write(Type.BOOLEAN, false);
break;
case 5:
packetType = ClientboundPackets1_17.CLEAR_TITLES;
// Reset times
wrapper.write(Type.BOOLEAN, true);
break;
default:
throw new IllegalArgumentException("Invalid title type received: " + type);
}
wrapper.setId(packetType.getId());
});
}
});
registerClientbound(ClientboundPackets1_16_2.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// X
map(Type.FLOAT);
// Y
map(Type.FLOAT);
// Z
map(Type.FLOAT);
// Strength
map(Type.FLOAT);
handler(wrapper -> {
// Collection length is now a var int
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT));
});
}
});
registerClientbound(ClientboundPackets1_16_2.SPAWN_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
handler(wrapper -> {
// Angle (which Mojang just forgot to write to the buffer, lol)
wrapper.write(Type.FLOAT, 0f);
});
}
});
registerServerbound(ServerboundPackets1_17.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// Locale
map(Type.STRING);
// View distance
map(Type.BYTE);
// Chat mode
map(Type.VAR_INT);
// Chat colors
map(Type.BOOLEAN);
// Chat flags
map(Type.UNSIGNED_BYTE);
// Main hand
map(Type.VAR_INT);
handler(wrapper -> {
// Text filtering
wrapper.read(Type.BOOLEAN);
});
}
});
}
use of com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType 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.api.protocol.packet.ClientboundPacketType 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