us.myles.ViaVersion.api.remapper.PacketRemapper Java Examples
The following examples show how to use
us.myles.ViaVersion.api.remapper.PacketRemapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetadataRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction itemRewriter) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id map(Type.UUID); // 1 - Entity UUID map(Type.VAR_INT); // 2 - Entity Type map(Type.DOUBLE); // 3 - X map(Type.DOUBLE); // 4 - Y map(Type.DOUBLE); // 5 - Z map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 7 - Yaw map(Type.INT); // 8 - Data handler(getTracker()); handler(wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); EntityType entityType = wrapper.user().get(entityTrackerClass).getEntity(entityId); if (entityType == fallingBlockType) { wrapper.set(Type.INT, 0, itemRewriter.rewrite(wrapper.get(Type.INT, 0))); } }); } }); }
Example #2
Source File: EntityRewriter.java From ViaBackwards with MIT License | 6 votes |
public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction blockStateRewriter) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id map(Type.UUID); // 1 - Entity UUID map(Type.VAR_INT); // 2 - Entity Type map(Type.DOUBLE); // 3 - X map(Type.DOUBLE); // 4 - Y map(Type.DOUBLE); // 5 - Z map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 7 - Yaw map(Type.INT); // 8 - Data handler(wrapper -> { EntityType entityType = setOldEntityId(wrapper); if (entityType == fallingBlockType) { int blockState = wrapper.get(Type.INT, 0); wrapper.set(Type.INT, 0, blockStateRewriter.rewrite(blockState)); } }); } }); }
Example #3
Source File: SoundRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerSound(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Sound Id handler(wrapper -> { int soundId = wrapper.get(Type.VAR_INT, 0); int mappedId = idRewriter.rewrite(soundId); if (mappedId == -1) { wrapper.cancel(); } else if (soundId != mappedId) { wrapper.set(Type.VAR_INT, 0, mappedId); } }); } }); }
Example #4
Source File: BlockRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerEffect(ClientboundPacketType packetType, int playRecordId, int blockBreakId, IdRewriteFunction itemIdRewriteFunction) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id map(positionType); // Location map(Type.INT); // Data handler(wrapper -> { int id = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 1); if (id == playRecordId) { // Play record wrapper.set(Type.INT, 1, itemIdRewriteFunction.rewrite(data)); } else if (id == blockBreakId) { // Block break + block break sound wrapper.set(Type.INT, 1, blockStateRewriter.rewrite(data)); } }); } }); }
Example #5
Source File: ItemRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerEntityEquipmentArray(ClientboundPacketType packetType, Type<Item> type) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID handler(wrapper -> { byte slot; do { slot = wrapper.passthrough(Type.BYTE); // & 0x7F into an extra variable if slot is needed toClient.rewrite(wrapper.passthrough(type)); } while ((slot & 0xFFFFFF80) != 0); }); } }); }
Example #6
Source File: BlockRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerBlockAction(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(positionType); // Location map(Type.UNSIGNED_BYTE); // Action id map(Type.UNSIGNED_BYTE); // Action param map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE handler(wrapper -> { int id = wrapper.get(Type.VAR_INT, 0); int mappedId = blockRewriter.rewrite(id); if (mappedId == -1) { // Block (action) has been removed wrapper.cancel(); return; } wrapper.set(Type.VAR_INT, 0, mappedId); }); } }); }
Example #7
Source File: Protocol1_9To1_8.java From ViaVersion with MIT License | 6 votes |
@Override protected void registerPackets() { new MetadataRewriter1_9To1_8(this); // Disconnect workaround (JSON!) registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Reason } }); // Other Handlers SpawnPackets.register(this); InventoryPackets.register(this); EntityPackets.register(this); PlayerPackets.register(this); WorldPackets.register(this); }
Example #8
Source File: WorldPackets.java From ViaVersion with MIT License | 6 votes |
public static void register(Protocol protocol) { protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID map(Type.BOOLEAN); // 1 - Long Distance map(Type.FLOAT); // 2 - X map(Type.FLOAT); // 3 - Y map(Type.FLOAT); // 4 - Z map(Type.FLOAT); // 5 - Offset X map(Type.FLOAT); // 6 - Offset Y map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int id = wrapper.get(Type.INT, 0); if (id == 27) { wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); } } }); } }); }
Example #9
Source File: TagRewriter.java From ViaVersion with MIT License | 6 votes |
public void register(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { handle(wrapper, blockRewriter, newBlockTags); handle(wrapper, itemRewriter, newItemTags); if (entityRewriter == null && newEntityTags.isEmpty()) return; int fluidTagsSize = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < fluidTagsSize; i++) { wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE); } handle(wrapper, entityRewriter, newEntityTags); }); } }); }
Example #10
Source File: Protocol1_12_2To1_12_1.java From ViaVersion with MIT License | 6 votes |
@Override protected void registerPackets() { registerOutgoing(ClientboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT, Type.LONG); } }); registerIncoming(ServerboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() { @Override public void registerMap() { map(Type.LONG, Type.VAR_INT); } }); }
Example #11
Source File: SoundRewriter.java From ViaBackwards with MIT License | 6 votes |
public void registerNamedSound(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // Sound identifier handler(wrapper -> { String soundId = wrapper.get(Type.STRING, 0); String mappedId = stringIdRewriter.apply(soundId); if (mappedId == null) return; if (!mappedId.isEmpty()) { wrapper.set(Type.STRING, 0, mappedId); } else { wrapper.cancel(); } }); } }); }
Example #12
Source File: MetadataRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerJoinGame(ClientboundPacketType packetType, @Nullable EntityType playerType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID map(Type.UNSIGNED_BYTE); // 1 - Gamemode map(Type.INT); // 2 - Dimension handler(wrapper -> { ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); int dimensionId = wrapper.get(Type.INT, 1); clientChunks.setEnvironment(dimensionId); if (playerType != null) { wrapper.user().get(entityTrackerClass).addEntity(wrapper.get(Type.INT, 0), playerType); } }); } }); }
Example #13
Source File: MetadataRewriter.java From ViaVersion with MIT License | 6 votes |
public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID if (oldMetaType != null) { map(oldMetaType, newMetaType); } else { map(newMetaType); } handler(wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); List<Metadata> metadata = wrapper.get(newMetaType, 0); handleMetadata(entityId, metadata, wrapper.user()); }); } }); }
Example #14
Source File: WorldPackets1_13_2.java From ViaBackwards with MIT License | 5 votes |
public static void register(Protocol1_13_1To1_13_2 protocol) { protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID map(Type.BOOLEAN); // 1 - Long Distance map(Type.FLOAT); // 2 - X map(Type.FLOAT); // 3 - Y map(Type.FLOAT); // 4 - Z map(Type.FLOAT); // 5 - Offset X map(Type.FLOAT); // 6 - Offset Y map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int id = wrapper.get(Type.INT, 0); if (id == 27) { wrapper.write(Type.FLAT_ITEM, wrapper.read(Type.FLAT_VAR_INT_ITEM)); } } }); } }); }
Example #15
Source File: Protocol1_9_4To1_10.java From ViaBackwards with MIT License | 5 votes |
protected void registerPackets() { new SoundPackets1_10(this).register(); (entityPackets = new EntityPackets1_10(this)).register(); (blockItemPackets = new BlockItemPackets1_10(this)).register(); registerIncoming(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Type.NOTHING); // 0 - Hash map(Type.VAR_INT); // 1 - Result } }); }
Example #16
Source File: WorldPackets1_13_1.java From ViaBackwards with MIT License | 5 votes |
public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13To1_13_1::getNewBlockStateId, Protocol1_13To1_13_1::getNewBlockId); protocol.registerOutgoing(ClientboundPackets1_13.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.passthrough(new Chunk1_13Type(clientWorld)); for (ChunkSection section : chunk.getSections()) { if (section != null) { for (int i = 0; i < section.getPaletteSize(); i++) { section.setPaletteEntry(i, Protocol1_13To1_13_1.getNewBlockStateId(section.getPaletteEntry(i))); } } } } }); } }); blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE); blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets1_13_1::getOldItemId); blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets1_13_1::toClient, Type.FLAT_ITEM, Type.FLOAT); }
Example #17
Source File: TranslatableRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerLegacyOpenWindow(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Id map(Type.STRING); // Window Type handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); }
Example #18
Source File: TranslatableRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerOpenWindow(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Id map(Type.VAR_INT); // Window Type handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); }
Example #19
Source File: TranslatableRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerTabList(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { processText(wrapper.passthrough(Type.COMPONENT)); processText(wrapper.passthrough(Type.COMPONENT)); }); } }); }
Example #20
Source File: SoundRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerStopSound(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { byte flags = wrapper.passthrough(Type.BYTE); if ((flags & 0x02) == 0) return; // No sound specified if ((flags & 0x01) != 0) { wrapper.passthrough(Type.VAR_INT); // Source } String soundId = wrapper.read(Type.STRING); String mappedId = stringIdRewriter.apply(soundId); if (mappedId == null) { // No mapping found wrapper.write(Type.STRING, soundId); return; } if (!mappedId.isEmpty()) { wrapper.write(Type.STRING, mappedId); } else { // Cancel if set to empty wrapper.cancel(); } }); } }); }
Example #21
Source File: EntityRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerSpawnTracker(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID map(Type.UUID); // 1 - Entity UUID map(Type.VAR_INT); // 2 - Entity Type handler(wrapper -> setOldEntityId(wrapper)); } }); }
Example #22
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 5 votes |
public void registerRespawn(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); handler(wrapper -> { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); clientWorld.setEnvironment(wrapper.get(Type.INT, 0)); }); } }); }
Example #23
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 5 votes |
public void registerJoinGame(ClientboundPacketType packetType, EntityType playerType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID map(Type.UNSIGNED_BYTE); // 1 - Gamemode map(Type.INT); // 2 - Dimension handler(wrapper -> { ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); clientChunks.setEnvironment(wrapper.get(Type.INT, 1)); getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), playerType); }); } }); }
Example #24
Source File: TranslatableRewriter.java From ViaBackwards with MIT License | 5 votes |
public void registerChatMessage(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT))); } }); }
Example #25
Source File: Protocol1_14_3To1_14_2.java From ViaVersion with MIT License | 5 votes |
@Override protected void registerPackets() { registerOutgoing(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { wrapper.passthrough(Type.VAR_INT); int size = wrapper.passthrough(Type.UNSIGNED_BYTE); for (int i = 0; i < size; i++) { wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); if (wrapper.passthrough(Type.BOOLEAN)) { wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); } wrapper.passthrough(Type.BOOLEAN); wrapper.passthrough(Type.INT); wrapper.passthrough(Type.INT); wrapper.passthrough(Type.INT); wrapper.passthrough(Type.INT); wrapper.passthrough(Type.FLOAT); } wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.VAR_INT); boolean regularVillager = wrapper.passthrough(Type.BOOLEAN); wrapper.write(Type.BOOLEAN, regularVillager); // new boolean added in pre-1 } }); } }); }
Example #26
Source File: MetadataRewriter.java From ViaVersion with MIT License | 5 votes |
public void registerEntityDestroy(ClientboundPacketType packetType) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids handler(wrapper -> { EntityTracker entityTracker = wrapper.user().get(entityTrackerClass); for (int entity : wrapper.get(Type.VAR_INT_ARRAY_PRIMITIVE, 0)) { entityTracker.removeEntity(entity); } }); } }); }
Example #27
Source File: ChatPackets1_12.java From ViaBackwards with MIT License | 5 votes |
@Override protected void registerPackets() { protocol.registerOutgoing(ClientboundPackets1_12.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { JsonElement element = wrapper.passthrough(Type.COMPONENT); componentRewriter.processText(element); }); } }); }
Example #28
Source File: Protocol1_9_1To1_9.java From ViaVersion with MIT License | 5 votes |
@Override protected void registerPackets() { // Currently supports 1.9.1 and 1.9.2 registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Player ID map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode // 1.9.1 PRE 2 Changed this map(Type.BYTE, Type.INT); // 2 - Player Dimension map(Type.UNSIGNED_BYTE); // 3 - World Difficulty map(Type.UNSIGNED_BYTE); // 4 - Max Players (Tab) map(Type.STRING); // 5 - Level Type map(Type.BOOLEAN); // 6 - Reduced Debug info } }); registerOutgoing(ClientboundPackets1_9.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound ID handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int sound = wrapper.get(Type.VAR_INT, 0); if (sound >= 415) // Add 1 to every sound id since there is no Elytra sound on a 1.9 server wrapper.set(Type.VAR_INT, 0, sound + 1); } }); } }); }
Example #29
Source File: ScoreboardPackets.java From ViaRewind with MIT License | 5 votes |
public static void register(Protocol protocol) { /* OUTGOING */ //Display Scoreboard protocol.registerOutgoing(State.PLAY, 0x38, 0x3D); //Scoreboard Objective protocol.registerOutgoing(State.PLAY, 0x3F, 0x3B); //Scoreboard Team protocol.registerOutgoing(State.PLAY, 0x41, 0x3E, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); map(Type.BYTE); handler(new PacketHandler() { @Override public void handle(PacketWrapper packetWrapper) throws Exception { byte mode = packetWrapper.get(Type.BYTE, 0); if (mode == 0 || mode == 2) { packetWrapper.passthrough(Type.STRING); //Display Name packetWrapper.passthrough(Type.STRING); //Prefix packetWrapper.passthrough(Type.STRING); //Suffix packetWrapper.passthrough(Type.BYTE); //Friendly Flags packetWrapper.passthrough(Type.STRING); //Name Tag Visibility packetWrapper.read(Type.STRING); //Skip Collision Rule packetWrapper.passthrough(Type.BYTE); //Friendly Flags } if (mode == 0 || mode == 3 || mode == 4) { packetWrapper.passthrough(Type.STRING_ARRAY); } } }); } }); //Update Score protocol.registerOutgoing(State.PLAY, 0x42, 0x3C); }
Example #30
Source File: Protocol1_9To1_9_1.java From ViaVersion with MIT License | 5 votes |
@Override protected void registerPackets() { // Currently supports 1.9.1 and 1.9.2 registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Player ID map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode // 1.9.1 PRE 2 Changed this map(Type.INT, Type.BYTE); // 2 - Player Dimension map(Type.UNSIGNED_BYTE); // 3 - World Difficulty map(Type.UNSIGNED_BYTE); // 4 - Max Players (Tab) map(Type.STRING); // 5 - Level Type map(Type.BOOLEAN); // 6 - Reduced Debug info } }); registerOutgoing(ClientboundPackets1_9.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound ID handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int sound = wrapper.get(Type.VAR_INT, 0); if (sound == 415) // Stop the Elytra sound for 1.9 (It's introduced in 1.9.2) wrapper.cancel(); else if (sound >= 416) // Act like the Elytra sound never existed wrapper.set(Type.VAR_INT, 0, sound - 1); } }); } }); }