use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaBackwards by ViaVersion.
the class Protocol1_14_4To1_15 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
translatableRewriter.registerChatMessage(ClientboundPackets1_15.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_15.DISCONNECT);
translatableRewriter.registerOpenWindow(ClientboundPackets1_15.OPEN_WINDOW);
translatableRewriter.registerTabList(ClientboundPackets1_15.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_15.TITLE);
translatableRewriter.registerPing();
(blockItemPackets = new BlockItemPackets1_15(this)).register();
entityRewriter.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_15.STOP_SOUND);
// Explosion - manually send an explosion sound
registerClientbound(ClientboundPackets1_15.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.FLOAT);
// y
map(Type.FLOAT);
// z
map(Type.FLOAT);
handler(wrapper -> {
PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_14.SOUND);
// entity.generic.explode
soundPacket.write(Type.VAR_INT, 243);
// blocks category
soundPacket.write(Type.VAR_INT, 4);
// x
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 0)));
// y
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 1)));
// z
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 2)));
// volume
soundPacket.write(Type.FLOAT, 4F);
// pitch - usually semi randomized by the server, but we don't really have to care about that
soundPacket.write(Type.FLOAT, 1F);
soundPacket.send(Protocol1_14_4To1_15.class);
});
}
private int toEffectCoordinate(float coordinate) {
return (int) (coordinate * 8);
}
});
new TagRewriter(this).register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
}
use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaVersion by ViaVersion.
the class EntityPackets method register.
public static void register(Protocol1_16To1_15_2 protocol) {
MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class);
// Spawn lightning -> Spawn entity
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.passthrough(Type.VAR_INT);
byte type = wrapper.read(Type.BYTE);
if (type != 1) {
// Cancel if not lightning/invalid id
wrapper.cancel();
return;
}
wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT);
// uuid
wrapper.write(Type.UUID, UUID.randomUUID());
// entity type
wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId());
// x
wrapper.passthrough(Type.DOUBLE);
// y
wrapper.passthrough(Type.DOUBLE);
// z
wrapper.passthrough(Type.DOUBLE);
// yaw
wrapper.write(Type.BYTE, (byte) 0);
// pitch
wrapper.write(Type.BYTE, (byte) 0);
// data
wrapper.write(Type.INT, 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
// velocity
wrapper.write(Type.SHORT, (short) 0);
});
}
});
metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(DIMENSION_HANDLER);
// Seed
map(Type.LONG);
// Gamemode
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
// Previous gamemode, set to none
wrapper.write(Type.BYTE, (byte) -1);
String levelType = wrapper.read(Type.STRING);
// debug
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, levelType.equals("flat"));
// keep all playerdata
wrapper.write(Type.BOOLEAN, true);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Gamemode
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
// Previous gamemode, set to none
wrapper.write(Type.BYTE, (byte) -1);
// World list - only used for command completion
wrapper.write(Type.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length));
// Dimension registry
wrapper.write(Type.NBT, DIMENSIONS_TAG.clone());
});
// Dimension
handler(DIMENSION_HANDLER);
// Seed
map(Type.LONG);
// Max players
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
// level type
final String type = wrapper.read(Type.STRING);
// View distance
wrapper.passthrough(Type.VAR_INT);
// Reduced debug info
wrapper.passthrough(Type.BOOLEAN);
// Show death screen
wrapper.passthrough(Type.BOOLEAN);
// Debug
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, type.equals("flat"));
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.INT);
int actualSize = size;
for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = "minecraft:" + key;
if (!com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Invalid attribute: " + key);
}
actualSize--;
wrapper.read(Type.DOUBLE);
int modifierSize = wrapper.read(Type.VAR_INT);
for (int j = 0; j < modifierSize; j++) {
wrapper.read(Type.UUID);
wrapper.read(Type.DOUBLE);
wrapper.read(Type.BYTE);
}
continue;
}
}
wrapper.write(Type.STRING, attributeIdentifier);
wrapper.passthrough(Type.DOUBLE);
int modifierSize = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < modifierSize; j++) {
wrapper.passthrough(Type.UUID);
wrapper.passthrough(Type.DOUBLE);
wrapper.passthrough(Type.BYTE);
}
}
if (size != actualSize) {
wrapper.set(Type.INT, 0, actualSize);
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
// Don't send an arm swing if the player has an inventory opened.
if (inventoryTracker.getInventory() != -1) {
wrapper.cancel();
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
// clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing
PacketHandler cursorRemapper = wrapper -> {
PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT);
clearPacket.write(Type.UNSIGNED_BYTE, (short) -1);
clearPacket.write(Type.SHORT, (short) -1);
clearPacket.write(Type.FLAT_VAR_INT_ITEM, null);
clearPacket.send(Protocol1_16To1_15_2.class);
};
protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.VAR_INT);
// Window Type
map(Type.VAR_INT);
// Window Title
map(Type.COMPONENT);
handler(cursorRemapper);
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
int windowId = wrapper.get(Type.VAR_INT, 0);
int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType >= 20) {
// smithing added with id 20
wrapper.set(Type.VAR_INT, 1, ++windowType);
}
inventoryTracker.setInventory((short) windowId);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(cursorRemapper);
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1);
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.WINDOW_PROPERTY, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.UNSIGNED_BYTE);
// Property
map(Type.SHORT);
// Value
map(Type.SHORT);
handler(wrapper -> {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) {
// Enchantment id
short enchantmentId = wrapper.get(Type.SHORT, 1);
if (enchantmentId >= 11) {
// soul_speed added with id 11
wrapper.set(Type.SHORT, 1, ++enchantmentId);
}
}
});
}
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT);
wrapper.write(Type.BYTE, (byte) slot);
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
});
}
});
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1);
});
}
});
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
use of com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15 in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol1_16To1_15_2 protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerClientbound(ClientboundPackets1_15.UPDATE_LIGHT, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.VAR_INT);
// y
map(Type.VAR_INT);
// Take neighbour's light into account as well
handler(wrapper -> wrapper.write(Type.BOOLEAN, true));
}
});
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_15Type());
wrapper.write(new Chunk1_16Type(), chunk);
chunk.setIgnoreOldLightData(chunk.isFullChunk());
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));
}
}
CompoundTag heightMaps = chunk.getHeightMap();
for (Tag heightMapTag : heightMaps.values()) {
LongArrayTag heightMap = (LongArrayTag) heightMapTag;
int[] heightMapData = new int[256];
CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
}
if (chunk.getBlockEntities() == null)
return;
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
handleBlockEntity(blockEntity);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Position position = wrapper.passthrough(Type.POSITION1_14);
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
CompoundTag tag = wrapper.passthrough(Type.NBT);
handleBlockEntity(tag);
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
}
Aggregations