us.myles.ViaVersion.api.remapper.PacketHandler Java Examples
The following examples show how to use
us.myles.ViaVersion.api.remapper.PacketHandler.
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: LegacyEntityRewriter.java From ViaBackwards with MIT License | 6 votes |
protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) { return wrapper -> { ObjectType type = objectGetter.apply(wrapper.get(Type.BYTE, 0)); if (type == null) { ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0)); return; } EntityData data = getObjectData(type); if (data != null) { wrapper.set(Type.BYTE, 0, (byte) data.getReplacementId()); if (data.getObjectData() != -1) { wrapper.set(Type.INT, 0, data.getObjectData()); } } }; }
Example #2
Source File: LegacyEntityRewriter.java From ViaBackwards with MIT License | 6 votes |
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); EntityType type = getEntityType(wrapper.user(), entityId); MetaStorage storage = new MetaStorage(wrapper.get(metaType, 0)); handleMeta(wrapper.user(), entityId, storage); EntityData entityData = getEntityData(type); if (entityData != null) { wrapper.set(Type.VAR_INT, 1, entityData.getReplacementId()); if (entityData.hasBaseMeta()) { entityData.getDefaultMeta().createMeta(storage); } } // Rewrite Metadata wrapper.set(metaType, 0, storage.getMetaDataList()); }; }
Example #3
Source File: MetadataRewriter.java From ViaVersion with MIT License | 6 votes |
/** * Returns a packethandler to track and rewrite an entity. * * @param metaType type of the metadata list * @return handler for tracking and rewriting entities */ public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); int newType = getNewEntityId(type); if (newType != type) { wrapper.set(Type.VAR_INT, 1, newType); } EntityType entType = getTypeFromId(newType); // Register Type ID wrapper.user().get(entityTrackerClass).addEntity(entityId, entType); if (metaType != null) { handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user()); } }; }
Example #4
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 #5
Source File: ItemRewriter.java From ViaVersion with MIT License | 5 votes |
public PacketHandler itemArrayHandler(Type<Item[]> type) { return wrapper -> { Item[] items = wrapper.get(type, 0); for (Item item : items) { toClient.rewrite(item); } }; }
Example #6
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 5 votes |
protected PacketHandler getDimensionHandler(int index) { return wrapper -> { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); int dimensionId = wrapper.get(Type.INT, index); clientWorld.setEnvironment(dimensionId); }; }
Example #7
Source File: LegacyEntityRewriter.java From ViaBackwards with MIT License | 5 votes |
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) { return wrapper -> { addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType); List<Metadata> metaDataList = handleMeta(wrapper.user(), wrapper.get(Type.VAR_INT, 0), new MetaStorage(wrapper.get(metaType, 0))).getMetaDataList(); wrapper.set(metaType, 0, metaDataList); }; }
Example #8
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 #9
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 #10
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 #11
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 #12
Source File: Protocol1_14_4To1_14_3.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.write(Type.INT, 0); // demand value added in pre5 } } }); } }); }
Example #13
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 #14
Source File: MetadataRewriter.java From ViaVersion with MIT License | 5 votes |
public PacketHandler getTrackerAndRewriter(@Nullable Type<List<Metadata>> metaType, EntityType entityType) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); // Register Type ID wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType); if (metaType != null) { handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user()); } }; }
Example #15
Source File: MetadataRewriter.java From ViaVersion with MIT License | 5 votes |
/** * Returns a packethandler to track an object entity. * * @return handler for tracking and rewriting entities */ public PacketHandler getObjectTracker() { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); byte type = wrapper.get(Type.BYTE, 0); EntityType entType = getObjectTypeFromId(type); // Register Type ID wrapper.user().get(entityTrackerClass).addEntity(entityId, entType); }; }
Example #16
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); } }); } }); }
Example #17
Source File: PlayerPackets1_11.java From ViaBackwards with MIT License | 4 votes |
public void register(Protocol1_10To1_11 protocol) { protocol.registerOutgoing(ClientboundPackets1_9_3.TITLE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int action = wrapper.get(Type.VAR_INT, 0); // Handle the new ActionBar if (action == 2) { // Convert to the old actionbar way PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet JsonElement msg = wrapper.read(Type.COMPONENT); actionbar.write(Type.COMPONENT, msg); actionbar.write(Type.BYTE, (byte) 2); // Above hotbar actionbar.send(Protocol1_10To1_11.class); wrapper.cancel(); // Cancel the title packet return; } if (action > 2) { wrapper.set(Type.VAR_INT, 0, action - 1); // Move everything one position down } } }); } }); protocol.registerOutgoing(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Collected entity id map(Type.VAR_INT); // 1 - Collector entity id handler(wrapper -> wrapper.read(Type.VAR_INT)); // Ignore item pickup count } }); protocol.registerIncoming(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Location map(Type.VAR_INT); // 1 - Face map(Type.VAR_INT); // 2 - Hand map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); } }); }
Example #18
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 4 votes |
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) { return wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType); }
Example #19
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 4 votes |
protected PacketHandler getTrackerHandler() { return getTrackerHandler(Type.VAR_INT, 1); }
Example #20
Source File: EntityRewriterBase.java From ViaBackwards with MIT License | 4 votes |
protected PacketHandler getTrackerHandler(Type intType, int typeIndex) { return wrapper -> { Number id = (Number) wrapper.get(intType, typeIndex); addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getTypeFromId(id.intValue())); }; }
Example #21
Source File: ItemRewriter.java From ViaVersion with MIT License | 4 votes |
public PacketHandler itemToClientHandler(Type<Item> type) { return wrapper -> toClient.rewrite(wrapper.get(type, 0)); }
Example #22
Source File: ItemRewriter.java From ViaVersion with MIT License | 4 votes |
public PacketHandler itemToServerHandler(Type<Item> type) { return wrapper -> toServer.rewrite(wrapper.get(type, 0)); }
Example #23
Source File: LegacyEntityRewriter.java From ViaBackwards with MIT License | 4 votes |
protected PacketHandler getObjectTrackerHandler() { return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0))); }
Example #24
Source File: MetadataRewriter.java From ViaVersion with MIT License | 4 votes |
public PacketHandler getTracker() { return getTrackerAndRewriter(null); }
Example #25
Source File: EntityPackets1_14_1.java From ViaBackwards with MIT License | 4 votes |
@Override protected void registerPackets() { registerExtraTracker(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, Entity1_14Types.EntityType.EXPERIENCE_ORB); registerExtraTracker(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, Entity1_14Types.EntityType.LIGHTNING_BOLT); registerExtraTracker(ClientboundPackets1_14.SPAWN_PAINTING, Entity1_14Types.EntityType.PAINTING); registerExtraTracker(ClientboundPackets1_14.SPAWN_PLAYER, Entity1_14Types.EntityType.PLAYER); registerExtraTracker(ClientboundPackets1_14.JOIN_GAME, Entity1_14Types.EntityType.PLAYER, Type.INT); registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES); protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id map(Type.UUID); // 1 - UUID map(Type.VAR_INT); // 2 - Type handler(getTrackerHandler()); } }); protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_MOB, 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 - Yaw map(Type.BYTE); // 7 - Pitch map(Type.BYTE); // 8 - Head Pitch map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z map(Types1_14.METADATA_LIST); // 12 - Metadata handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); // Register Type ID addTrackedEntity(wrapper, entityId, Entity1_14Types.getTypeFromId(type)); MetaStorage storage = new MetaStorage(wrapper.get(Types1_14.METADATA_LIST, 0)); handleMeta(wrapper.user(), entityId, storage); } }); } }); // Entity Metadata registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST); }
Example #26
Source File: SoundPackets1_11.java From ViaBackwards with MIT License | 4 votes |
@Override protected void registerPackets() { protocol.registerOutgoing(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound name map(Type.VAR_INT); // 1 - Sound Category map(Type.INT); // 2 - x map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume map(Type.FLOAT); // 6 - Pitch } }); protocol.registerOutgoing(ClientboundPackets1_9_3.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound name map(Type.VAR_INT); // 1 - Sound Category map(Type.INT); // 2 - x map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume map(Type.FLOAT); // 6 - Pitch handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int oldId = wrapper.get(Type.VAR_INT, 0); int newId = handleSounds(oldId); if (newId == -1) wrapper.cancel(); else { if (hasPitch(oldId)) wrapper.set(Type.FLOAT, 1, handlePitch(oldId)); wrapper.set(Type.VAR_INT, 0, newId); } } }); } }); }
Example #27
Source File: EntityPackets.java From ViaVersion with MIT License | 4 votes |
public static void register(Protocol1_13_1To1_13 protocol) { MetadataRewriter1_13_1To1_13 metadataRewriter = protocol.get(MetadataRewriter1_13_1To1_13.class); protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id map(Type.UUID); // 1 - UUID map(Type.BYTE); // 2 - 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 // Track Entity handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); byte type = wrapper.get(Type.BYTE, 0); Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true); if (entType != null) { if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) { int data = wrapper.get(Type.INT, 0); wrapper.set(Type.INT, 0, Protocol1_13_1To1_13.getNewBlockStateId(data)); } // Register Type ID wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType); } } }); } }); protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_MOB, 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 - Yaw map(Type.BYTE); // 7 - Pitch map(Type.BYTE); // 8 - Head Pitch map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z map(Types1_13.METADATA_LIST); // 12 - Metadata handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST)); } }); protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID map(Type.UUID); // 1 - Player UUID map(Type.DOUBLE); // 2 - X map(Type.DOUBLE); // 3 - Y map(Type.DOUBLE); // 4 - Z map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 6 - Pitch map(Types1_13.METADATA_LIST); // 7 - Metadata handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER)); } }); metadataRewriter.registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES); metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST); }
Example #28
Source File: ItemPackets1_11_1.java From ViaBackwards with MIT License | 4 votes |
@Override protected void registerPackets() { ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM); itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY); itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM); // Plugin message Packet -> Trading protocol.registerOutgoing(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) { wrapper.passthrough(Type.INT); // Passthrough Window ID int size = wrapper.passthrough(Type.UNSIGNED_BYTE); for (int i = 0; i < size; i++) { wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Input Item wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Output Item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item if (secondItem) { wrapper.write(Type.ITEM, handleItemToClient(wrapper.read(Type.ITEM))); // Second Item } wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Type.INT); // Maximum number of trade uses } } } }); } }); itemRewriter.registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM); itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM); // Handle item metadata protocol.getEntityPackets().registerMetaHandler().handle(e -> { Metadata data = e.getData(); if (data.getMetaType().getType().equals(Type.ITEM)) { // Is Item data.setValue(handleItemToClient((Item) data.getValue())); } return data; }); }
Example #29
Source File: SoundPackets1_10.java From ViaBackwards with MIT License | 4 votes |
@Override protected void registerPackets() { protocol.registerOutgoing(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound name map(Type.VAR_INT); // 1 - Sound Category map(Type.INT); // 2 - x map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume map(Type.FLOAT, toOldPitch); // 6 - Pitch } }); protocol.registerOutgoing(ClientboundPackets1_9_3.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound name map(Type.VAR_INT); // 1 - Sound Category map(Type.INT); // 2 - x map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume map(Type.FLOAT, toOldPitch); // 6 - Pitch handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int oldId = wrapper.get(Type.VAR_INT, 0); int newId = handleSounds(oldId); if (newId == -1) { wrapper.cancel(); return; } if (hasPitch(oldId)) { wrapper.set(Type.UNSIGNED_BYTE, 0, (short) Math.round(handlePitch(oldId) * 63.5F)); } wrapper.set(Type.VAR_INT, 0, newId); } }); } }); }
Example #30
Source File: InventoryPackets1_13_1.java From ViaBackwards with MIT License | 4 votes |
public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets1_13_1::toClient, InventoryPackets1_13_1::toServer); itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets1_13_1::getOldItemId); itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY); itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM); protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { String channel = wrapper.passthrough(Type.STRING); if (channel.equals("minecraft:trader_list")) { wrapper.passthrough(Type.INT); //Passthrough Window ID int size = wrapper.passthrough(Type.UNSIGNED_BYTE); for (int i = 0; i < size; i++) { //Input Item Item input = wrapper.passthrough(Type.FLAT_ITEM); toClient(input); //Output Item Item output = wrapper.passthrough(Type.FLAT_ITEM); toClient(output); boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item if (secondItem) { //Second Item Item second = wrapper.passthrough(Type.FLAT_ITEM); toClient(second); } wrapper.passthrough(Type.BOOLEAN); //Trade disabled wrapper.passthrough(Type.INT); //Number of tools uses wrapper.passthrough(Type.INT); //Maximum number of trade uses } } } }); } }); itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM); itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM); itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM); }