From 2ab3bcbdd864d59d72ee3cdc88bb98ef57bc26aa Mon Sep 17 00:00:00 2001 From: Brendan Grieve Date: Fri, 8 May 2020 20:31:13 +0800 Subject: [PATCH 01/70] Copy v361 to protocol v363 for MCEE support --- bedrock/bedrock-v363/pom.xml | 22 + .../protocol/bedrock/v363/BedrockUtils.java | 1050 +++++++++++++++++ .../protocol/bedrock/v363/Bedrock_v363.java | 158 +++ .../AddBehaviorTreeSerializer_v363.java | 23 + .../serializer/AddEntitySerializer_v363.java | 40 + .../AddItemEntitySerializer_v363.java | 36 + .../AddPaintingSerializer_v363.java | 34 + .../serializer/AddPlayerSerializer_v363.java | 48 + .../AdventureSettingsSerializer_v363.java | 96 ++ .../serializer/AnimateSerializer_v363.java | 47 + .../AnvilDamageSerializer_v363.java | 26 + ...utomationClientConnectSerializer_v363.java | 24 + .../AvailableCommandsSerializer_v363.java | 299 +++++ ...lableEntityIdentifiersSerializer_v363.java | 37 + .../BiomeDefinitionListSerializer_v363.java | 37 + .../BlockEntityDataSerializer_v363.java | 40 + .../serializer/BlockEventSerializer_v363.java | 28 + .../BlockPickRequestSerializer_v363.java | 27 + .../serializer/BookEditSerializer_v363.java | 77 ++ .../serializer/BossEventSerializer_v363.java | 77 ++ .../serializer/CameraSerializer_v363.java | 25 + .../ChangeDimensionSerializer_v363.java | 28 + .../ChunkRadiusUpdatedSerializer_v363.java | 23 + .../ClientCacheBlobStatusSerializer_v363.java | 43 + ...lientCacheMissResponseSerializer_v363.java | 39 + .../ClientCacheStatusSerializer_v363.java | 22 + ...lientToServerHandshakeSerializer_v363.java | 22 + ...ClientboundMapItemDataSerializer_v363.java | 154 +++ .../CommandBlockUpdateSerializer_v363.java | 56 + .../CommandOutputSerializer_v363.java | 40 + .../CommandRequestSerializer_v363.java | 27 + .../CompletedUsingItemSerializer_v363.java | 28 + .../ContainerCloseSerializer_v363.java | 22 + .../ContainerOpenSerializer_v363.java | 31 + .../ContainerSetDataSerializer_v363.java | 27 + .../CraftingDataSerializer_v363.java | 137 +++ .../CraftingEventSerializer_v363.java | 37 + .../serializer/DisconnectSerializer_v363.java | 30 + .../EducationSettingsSerializer_v363.java | 26 + .../v363/serializer/EmoteSerializer_v363.java | 29 + .../EntityEventSerializer_v363.java | 88 ++ .../serializer/EntityFallSerializer_v363.java | 28 + .../EntityPickRequestSerializer_v363.java | 25 + .../v363/serializer/EventSerializer_v363.java | 264 +++++ .../serializer/ExplodeSerializer_v363.java | 31 + .../GameRulesChangedSerializer_v363.java | 34 + .../GuiDataPickItemSerializer_v363.java | 28 + .../serializer/HurtArmorSerializer_v363.java | 24 + .../serializer/InteractSerializer_v363.java | 36 + .../InventoryContentSerializer_v363.java | 38 + .../InventorySlotSerializer_v363.java | 28 + .../InventoryTransactionSerializer_v363.java | 85 ++ .../ItemFrameDropItemSerializer_v363.java | 24 + .../serializer/LabTableSerializer_v363.java | 28 + .../LecternUpdateSerializer_v363.java | 29 + .../serializer/LevelChunkSerializer_v363.java | 52 + .../LevelEventGenericSerializer_v363.java | 40 + .../serializer/LevelEventSerializer_v363.java | 170 +++ .../LevelSoundEvent1Serializer_v363.java | 292 +++++ .../LevelSoundEvent2Serializer_v363.java | 36 + .../LevelSoundEvent3Serializer_v363.java | 37 + .../v363/serializer/LoginSerializer_v363.java | 38 + .../MapCreateLockedCopySerializer_v363.java | 25 + .../MapInfoRequestSerializer_v363.java | 24 + .../MobArmorEquipmentSerializer_v363.java | 33 + .../serializer/MobEffectSerializer_v363.java | 34 + .../MobEquipmentSerializer_v363.java | 32 + .../ModalFormRequestSerializer_v363.java | 27 + .../ModalFormResponseSerializer_v363.java | 27 + .../MoveEntityAbsoluteSerializer_v363.java | 42 + .../MoveEntityDeltaSerializer_v363.java | 84 ++ .../serializer/MovePlayerSerializer_v363.java | 46 + .../MultiplayerSettingsSerializer_v363.java | 27 + ...rkChunkPublisherUpdateSerializer_v363.java | 26 + .../NetworkSettingsSerializer_v363.java | 23 + .../NetworkStackLatencySerializer_v363.java | 25 + .../serializer/NpcRequestSerializer_v363.java | 33 + ...ScreenTextureAnimationSerializer_v363.java | 22 + .../PacketHeaderSerializer_v363.java | 31 + .../PhotoTransferSerializer_v363.java | 33 + .../serializer/PlaySoundSerializer_v363.java | 30 + .../serializer/PlayStatusSerializer_v363.java | 25 + .../PlayerActionSerializer_v363.java | 33 + .../PlayerAuthInputSerializer_v363.java | 52 + .../PlayerHotbarSerializer_v363.java | 27 + .../PlayerInputSerializer_v363.java | 28 + .../serializer/PlayerListSerializer_v363.java | 70 ++ .../serializer/PlayerSkinSerializer_v363.java | 46 + .../PurchaseReceiptSerializer_v363.java | 24 + .../RemoveEntitySerializer_v363.java | 24 + .../RemoveObjectiveSerializer_v363.java | 24 + .../RequestChunkRadiusSerializer_v363.java | 24 + .../ResourcePackChunkDataSerializer_v363.java | 40 + ...sourcePackChunkRequestSerializer_v363.java | 32 + ...urcePackClientResponseSerializer_v363.java | 42 + .../ResourcePackDataInfoSerializer_v363.java | 58 + .../ResourcePackStackSerializer_v363.java | 30 + .../ResourcePacksInfoSerializer_v363.java | 29 + .../serializer/RespawnSerializer_v363.java | 24 + .../serializer/RiderJumpSerializer_v363.java | 24 + .../ScriptCustomEventSerializer_v363.java | 27 + .../ServerSettingsRequestSerializer_v363.java | 23 + ...ServerSettingsResponseSerializer_v363.java | 27 + ...erverToClientHandshakeSerializer_v363.java | 26 + .../SetCommandsEnabledSerializer_v363.java | 23 + .../SetDefaultGameTypeSerializer_v363.java | 24 + .../SetDifficultySerializer_v363.java | 24 + .../SetDisplayObjectiveSerializer_v363.java | 33 + .../SetEntityDataSerializer_v363.java | 27 + .../SetEntityLinkSerializer_v363.java | 24 + .../SetEntityMotionSerializer_v363.java | 27 + .../serializer/SetHealthSerializer_v363.java | 24 + .../SetLastHurtBySerializer_v363.java | 24 + ...calPlayerAsInitializedSerializer_v363.java | 24 + .../SetPlayerGameTypeSerializer_v363.java | 24 + .../serializer/SetScoreSerializer_v363.java | 73 ++ .../SetScoreboardIdentitySerializer_v363.java | 46 + .../SetSpawnPositionSerializer_v363.java | 29 + .../serializer/SetTimeSerializer_v363.java | 24 + .../serializer/SetTitleSerializer_v363.java | 33 + .../SettingsCommandSerializer_v363.java | 26 + .../ShowCreditsSerializer_v363.java | 26 + .../ShowProfileSerializer_v363.java | 24 + .../ShowStoreOfferSerializer_v363.java | 26 + .../SimpleEventSerializer_v363.java | 23 + .../SpawnExperienceOrbSerializer_v363.java | 27 + .../SpawnParticleEffectSerializer_v363.java | 30 + .../serializer/StartGameSerializer_v363.java | 159 +++ .../serializer/StopSoundSerializer_v363.java | 26 + .../StructureBlockUpdateSerializer_v363.java | 28 + ...plateDataExportRequestSerializer_v363.java | 29 + ...lateDataExportResponseSerializer_v363.java | 58 + .../SubClientLoginSerializer_v363.java | 32 + .../TakeItemEntitySerializer_v363.java | 26 + .../v363/serializer/TextSerializer_v363.java | 68 ++ .../serializer/TransferSerializer_v363.java | 26 + .../UpdateAttributesSerializer_v363.java | 27 + .../UpdateBlockPropertiesSerializer_v363.java | 37 + .../UpdateBlockSerializer_v363.java | 45 + .../UpdateBlockSyncedSerializer_v363.java | 49 + .../UpdateEquipSerializer_v363.java | 47 + .../UpdateSoftEnumSerializer_v363.java | 25 + .../UpdateTradeSerializer_v363.java | 59 + .../VideoStreamConnectSerializer_v363.java | 31 + bedrock/pom.xml | 1 + 145 files changed, 7348 insertions(+) create mode 100644 bedrock/bedrock-v363/pom.xml create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java diff --git a/bedrock/bedrock-v363/pom.xml b/bedrock/bedrock-v363/pom.xml new file mode 100644 index 000000000..ec1c5685f --- /dev/null +++ b/bedrock/bedrock-v363/pom.xml @@ -0,0 +1,22 @@ + + + + bedrock-parent + com.nukkitx.protocol + 2.5.6 + + 4.0.0 + + bedrock-v363 + + + + com.nukkitx.protocol + bedrock-common + ${project.version} + compile + + + \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java new file mode 100644 index 000000000..d1dca9463 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java @@ -0,0 +1,1050 @@ +package com.nukkitx.protocol.bedrock.v363; + +import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.nbt.CompoundTagBuilder; +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.nbt.tag.Tag; +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.*; +import com.nukkitx.protocol.bedrock.packet.ResourcePackStackPacket; +import com.nukkitx.protocol.bedrock.packet.ResourcePacksInfoPacket; +import com.nukkitx.protocol.bedrock.v363.serializer.GameRulesChangedSerializer_v363; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import io.netty.util.AsciiString; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.experimental.UtilityClass; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static com.nukkitx.protocol.bedrock.data.EntityData.*; + +@UtilityClass +public final class BedrockUtils { + private static final InternalLogger log = InternalLoggerFactory.getInstance(BedrockUtils.class); + private static final Int2ObjectBiMap METADATAS = new Int2ObjectBiMap<>(); + private static final Int2ObjectBiMap METADATA_FLAGS = new Int2ObjectBiMap<>(); + private static final Int2ObjectBiMap METADATA_TYPES = new Int2ObjectBiMap<>(9); + + static { + METADATAS.put(0, FLAGS); + METADATAS.put(1, HEALTH); + METADATAS.put(2, VARIANT); + METADATAS.put(3, COLOR); + METADATAS.put(4, NAMETAG); + METADATAS.put(5, OWNER_EID); + METADATAS.put(6, TARGET_EID); + METADATAS.put(7, AIR); + METADATAS.put(8, POTION_COLOR); + METADATAS.put(9, POTION_AMBIENT); + METADATAS.put(10, JUMP_DURATION); + METADATAS.put(11, HURT_TIME); + METADATAS.put(12, HURT_DIRECTION); + METADATAS.put(13, PADDLE_TIME_LEFT); + METADATAS.put(14, PADDLE_TIME_RIGHT); + METADATAS.put(15, EXPERIENCE_VALUE); + METADATAS.put(16, DISPLAY_ITEM); + METADATAS.put(17, DISPLAY_OFFSET); + METADATAS.put(18, HAS_DISPLAY); + METADATAS.put(22, CHARGED); + METADATAS.put(23, ENDERMAN_HELD_ITEM_ID); + METADATAS.put(24, ENTITY_AGE); + //METADATAS.put(25, WITCH_UNKNOWN); + METADATAS.put(26, CAN_START_SLEEP); + METADATAS.put(27, PLAYER_INDEX); + METADATAS.put(28, BED_RESPAWN_POS); + METADATAS.put(29, FIREBALL_POWER_X); + METADATAS.put(30, FIREBALL_POWER_Y); + METADATAS.put(31, FIREBALL_POWER_Z); + METADATAS.put(36, POTION_AUX_VALUE); + METADATAS.put(37, LEAD_HOLDER_EID); + METADATAS.put(38, SCALE); + METADATAS.put(39, HAS_NPC_COMPONENT); + METADATAS.put(40, NPC_SKIN_ID); + METADATAS.put(41, URL_TAG); + METADATAS.put(42, MAX_AIR); + METADATAS.put(43, MARK_VARIANT); + METADATAS.put(44, CONTAINER_TYPE); + METADATAS.put(45, CONTAINER_BASE_SIZE); + METADATAS.put(46, CONTAINER_EXTRA_SLOTS_PER_STRENGTH); + + METADATAS.put(47, BLOCK_TARGET); + METADATAS.put(48, WITHER_INVULNERABLE_TICKS); + METADATAS.put(49, WITHER_TARGET_1); + METADATAS.put(50, WITHER_TARGET_2); + METADATAS.put(51, WITHER_TARGET_3); + + METADATAS.put(53, BOUNDING_BOX_WIDTH); + METADATAS.put(54, BOUNDING_BOX_HEIGHT); + METADATAS.put(55, FUSE_LENGTH); + METADATAS.put(56, RIDER_SEAT_POSITION); + METADATAS.put(57, RIDER_ROTATION_LOCKED); + METADATAS.put(58, RIDER_MAX_ROTATION); + METADATAS.put(59, RIDER_MIN_ROTATION); + METADATAS.put(60, AREA_EFFECT_CLOUD_RADIUS); + METADATAS.put(61, AREA_EFFECT_CLOUD_WAITING); + METADATAS.put(62, AREA_EFFECT_CLOUD_PARTICLE_ID); + + METADATAS.put(64, SHULKER_ATTACH_FACE); + + METADATAS.put(66, SHULKER_ATTACH_POS); + METADATAS.put(67, TRADING_PLAYER_EID); + + METADATAS.put(69, COMMAND_BLOCK_ENABLED); // Unsure + METADATAS.put(70, COMMAND_BLOCK_COMMAND); + METADATAS.put(71, COMMAND_BLOCK_LAST_OUTPUT); + METADATAS.put(72, COMMAND_BLOCK_TRACK_OUTPUT); + METADATAS.put(73, CONTROLLING_RIDER_SEAT_NUMBER); + METADATAS.put(74, STRENGTH); + METADATAS.put(75, MAX_STRENGTH); + METADATAS.put(76, EVOKER_SPELL_COLOR); + METADATAS.put(77, LIMITED_LIFE); + METADATAS.put(78, ARMOR_STAND_POSE_INDEX); + METADATAS.put(79, ENDER_CRYSTAL_TIME_OFFSET); + METADATAS.put(80, ALWAYS_SHOW_NAMETAG); + METADATAS.put(81, COLOR_2); + METADATAS.put(83, SCORE_TAG); + METADATAS.put(84, BALLOON_ATTACHED_ENTITY); + METADATAS.put(85, PUFFERFISH_SIZE); + METADATAS.put(86, BOAT_BUBBLE_TIME); + METADATAS.put(87, AGENT_ID); + + + METADATAS.put(90, EAT_COUNTER); + METADATAS.put(91, FLAGS_2); + + + METADATAS.put(94, AREA_EFFECT_CLOUD_DURATION); + METADATAS.put(95, AREA_EFFECT_CLOUD_SPAWN_TIME); + METADATAS.put(96, AREA_EFFECT_CLOUD_RADIUS_PER_TICK); + METADATAS.put(97, AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP); + METADATAS.put(98, AREA_EFFECT_CLOUD_PICKUP_COUNT); + METADATAS.put(99, INTERACTIVE_TAG); + METADATAS.put(100, TRADE_TIER); + METADATAS.put(101, MAX_TRADE_TIER); + METADATAS.put(102, TRADE_XP); + METADATAS.put(103, SKIN_ID); + + + METADATA_FLAGS.put(0, EntityFlag.ON_FIRE); + METADATA_FLAGS.put(1, EntityFlag.SNEAKING); + METADATA_FLAGS.put(2, EntityFlag.RIDING); + METADATA_FLAGS.put(3, EntityFlag.SPRINTING); + METADATA_FLAGS.put(4, EntityFlag.USING_ITEM); + METADATA_FLAGS.put(5, EntityFlag.INVISIBLE); + METADATA_FLAGS.put(6, EntityFlag.TEMPTED); + METADATA_FLAGS.put(7, EntityFlag.IN_LOVE); + METADATA_FLAGS.put(8, EntityFlag.SADDLED); + METADATA_FLAGS.put(9, EntityFlag.POWERED); + METADATA_FLAGS.put(10, EntityFlag.IGNITED); + METADATA_FLAGS.put(11, EntityFlag.BABY); + METADATA_FLAGS.put(12, EntityFlag.CONVERTING); + METADATA_FLAGS.put(13, EntityFlag.CRITICAL); + METADATA_FLAGS.put(14, EntityFlag.CAN_SHOW_NAME); + METADATA_FLAGS.put(15, EntityFlag.ALWAYS_SHOW_NAME); + METADATA_FLAGS.put(16, EntityFlag.NO_AI); + METADATA_FLAGS.put(17, EntityFlag.SILENT); + METADATA_FLAGS.put(18, EntityFlag.WALL_CLIMBING); + METADATA_FLAGS.put(19, EntityFlag.CAN_CLIMB); + METADATA_FLAGS.put(20, EntityFlag.CAN_SWIM); + METADATA_FLAGS.put(21, EntityFlag.CAN_FLY); + METADATA_FLAGS.put(22, EntityFlag.CAN_WALK); + METADATA_FLAGS.put(23, EntityFlag.RESTING); + METADATA_FLAGS.put(24, EntityFlag.SITTING); + METADATA_FLAGS.put(25, EntityFlag.ANGRY); + METADATA_FLAGS.put(26, EntityFlag.INTERESTED); + METADATA_FLAGS.put(27, EntityFlag.CHARGED); + METADATA_FLAGS.put(28, EntityFlag.TAMED); + METADATA_FLAGS.put(29, EntityFlag.ORPHANED); + METADATA_FLAGS.put(30, EntityFlag.LEASHED); + METADATA_FLAGS.put(31, EntityFlag.SHEARED); + METADATA_FLAGS.put(32, EntityFlag.GLIDING); + METADATA_FLAGS.put(33, EntityFlag.ELDER); + METADATA_FLAGS.put(34, EntityFlag.MOVING); + METADATA_FLAGS.put(35, EntityFlag.BREATHING); + METADATA_FLAGS.put(36, EntityFlag.CHESTED); + METADATA_FLAGS.put(37, EntityFlag.STACKABLE); + METADATA_FLAGS.put(38, EntityFlag.SHOW_BOTTOM); + METADATA_FLAGS.put(39, EntityFlag.STANDING); + METADATA_FLAGS.put(40, EntityFlag.SHAKING); + METADATA_FLAGS.put(41, EntityFlag.IDLING); + METADATA_FLAGS.put(42, EntityFlag.CASTING); + METADATA_FLAGS.put(43, EntityFlag.CHARGING); + METADATA_FLAGS.put(44, EntityFlag.WASD_CONTROLLED); + METADATA_FLAGS.put(45, EntityFlag.CAN_POWER_JUMP); + METADATA_FLAGS.put(46, EntityFlag.LINGERING); + METADATA_FLAGS.put(47, EntityFlag.HAS_COLLISION); + METADATA_FLAGS.put(48, EntityFlag.HAS_GRAVITY); + METADATA_FLAGS.put(49, EntityFlag.FIRE_IMMUNE); + METADATA_FLAGS.put(50, EntityFlag.DANCING); + METADATA_FLAGS.put(51, EntityFlag.ENCHANTED); + METADATA_FLAGS.put(52, EntityFlag.RETURN_TRIDENT); + METADATA_FLAGS.put(53, EntityFlag.CONTAINER_IS_PRIVATE); + METADATA_FLAGS.put(55, EntityFlag.DAMAGE_NEARBY_MOBS); + METADATA_FLAGS.put(56, EntityFlag.SWIMMING); + METADATA_FLAGS.put(57, EntityFlag.BRIBED); + METADATA_FLAGS.put(58, EntityFlag.IS_PREGNANT); + METADATA_FLAGS.put(59, EntityFlag.LAYING_EGG); + METADATA_FLAGS.put(60, EntityFlag.RIDER_CAN_PICK); + METADATA_FLAGS.put(61, EntityFlag.TRANSITION_SITTING); + METADATA_FLAGS.put(62, EntityFlag.EATING); + METADATA_FLAGS.put(63, EntityFlag.LAYING_DOWN); + METADATA_FLAGS.put(64, EntityFlag.SNEEZING); + METADATA_FLAGS.put(65, EntityFlag.TRUSTING); + METADATA_FLAGS.put(66, EntityFlag.ROLLING); + METADATA_FLAGS.put(67, EntityFlag.SCARED); + METADATA_FLAGS.put(68, EntityFlag.IN_SCAFFOLDING); + METADATA_FLAGS.put(69, EntityFlag.OVER_SCAFFOLDING); + METADATA_FLAGS.put(70, EntityFlag.FALL_THROUGH_SCAFFOLDING); + METADATA_FLAGS.put(71, EntityFlag.BLOCKING); + METADATA_FLAGS.put(72, EntityFlag.DISABLE_BLOCKING); + + + METADATA_FLAGS.put(75, EntityFlag.SLEEPING); + + METADATA_FLAGS.put(77, EntityFlag.TRADE_INTEREST); + METADATA_FLAGS.put(78, EntityFlag.DOOR_BREAKER); + METADATA_FLAGS.put(79, EntityFlag.BREAKING_OBSTRUCTION); + METADATA_FLAGS.put(80, EntityFlag.DOOR_OPENER); + METADATA_FLAGS.put(81, EntityFlag.ILLAGER_CAPTAIN); + METADATA_FLAGS.put(82, EntityFlag.STUNNED); + METADATA_FLAGS.put(83, EntityFlag.ROARING); + METADATA_FLAGS.put(84, EntityFlag.DELAYED_ATTACKING); + METADATA_FLAGS.put(85, EntityFlag.AVOIDING_MOBS); + + METADATA_TYPES.put(7, Type.FLAGS); + METADATA_TYPES.put(0, Type.BYTE); + METADATA_TYPES.put(1, Type.SHORT); + METADATA_TYPES.put(2, Type.INT); + METADATA_TYPES.put(3, Type.FLOAT); + METADATA_TYPES.put(4, Type.STRING); + METADATA_TYPES.put(5, Type.NBT); + METADATA_TYPES.put(6, Type.VECTOR3I); + METADATA_TYPES.put(7, Type.LONG); + METADATA_TYPES.put(8, Type.VECTOR3F); + } + + public static byte[] readByteArray(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + byte[] bytes = new byte[VarInts.readUnsignedInt(buffer)]; + buffer.readBytes(bytes); + return bytes; + } + + public static void writeByteArray(ByteBuf buffer, byte[] bytes) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(bytes, "bytes"); + VarInts.writeUnsignedInt(buffer, bytes.length); + buffer.writeBytes(bytes); + } + + public static String readString(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + return new String(readByteArray(buffer), StandardCharsets.UTF_8); + } + + public static void writeString(ByteBuf buffer, String string) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(string, "string"); + writeByteArray(buffer, string.getBytes(StandardCharsets.UTF_8)); + } + + public static AsciiString readLEAsciiString(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + int length = buffer.readIntLE(); + byte[] bytes = new byte[length]; + buffer.readBytes(bytes); + return new AsciiString(bytes); + } + + public static void writeLEAsciiString(ByteBuf buffer, AsciiString string) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(string, "string"); + buffer.writeIntLE(string.length()); + buffer.writeBytes(string.toByteArray()); + } + + public static AsciiString readVarIntAsciiString(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + int length = VarInts.readUnsignedInt(buffer); + byte[] bytes = new byte[length]; + buffer.readBytes(bytes); + return new AsciiString(bytes); + } + + public static void writeVarIntAsciiString(ByteBuf buffer, AsciiString string) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(string, "string"); + VarInts.writeUnsignedInt(buffer, string.length()); + buffer.writeBytes(string.toByteArray()); + } + + public static UUID readUuid(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + return new UUID(buffer.readLongLE(), buffer.readLongLE()); + } + + public static void writeUuid(ByteBuf buffer, UUID uuid) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(uuid, "uuid"); + buffer.writeLongLE(uuid.getMostSignificantBits()); + buffer.writeLongLE(uuid.getLeastSignificantBits()); + } + + public static Vector3f readVector3f(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + float x = buffer.readFloatLE(); + float y = buffer.readFloatLE(); + float z = buffer.readFloatLE(); + return Vector3f.from(x, y, z); + } + + public static void writeVector3f(ByteBuf buffer, Vector3f vector3f) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(vector3f, "vector3f"); + buffer.writeFloatLE(vector3f.getX()); + buffer.writeFloatLE(vector3f.getY()); + buffer.writeFloatLE(vector3f.getZ()); + } + + public static Vector2f readVector2f(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + float x = buffer.readFloatLE(); + float y = buffer.readFloatLE(); + return Vector2f.from(x, y); + } + + public static void writeVector2f(ByteBuf buffer, Vector2f vector2f) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(vector2f, "vector2f"); + buffer.writeFloatLE(vector2f.getX()); + buffer.writeFloatLE(vector2f.getY()); + } + + + public static Vector3i readVector3i(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + int x = VarInts.readInt(buffer); + int y = VarInts.readInt(buffer); + int z = VarInts.readInt(buffer); + + return Vector3i.from(x, y, z); + } + + public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(vector3i, "vector3i"); + VarInts.writeInt(buffer, vector3i.getX()); + VarInts.writeInt(buffer, vector3i.getY()); + VarInts.writeInt(buffer, vector3i.getZ()); + } + + public static Vector3i readBlockPosition(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + int x = VarInts.readInt(buffer); + int y = VarInts.readUnsignedInt(buffer); + int z = VarInts.readInt(buffer); + + return Vector3i.from(x, y, z); + } + + public static void writeBlockPosition(ByteBuf buffer, Vector3i blockPosition) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(blockPosition, "blockPosition"); + VarInts.writeInt(buffer, blockPosition.getX()); + VarInts.writeUnsignedInt(buffer, blockPosition.getY()); + VarInts.writeInt(buffer, blockPosition.getZ()); + } + + public static Vector3f readByteRotation(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + float pitch = readByteAngle(buffer); + float yaw = readByteAngle(buffer); + float roll = readByteAngle(buffer); + return Vector3f.from(pitch, yaw, roll); + } + + public static void writeByteRotation(ByteBuf buffer, Vector3f rotation) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(rotation, "rotation"); + writeByteAngle(buffer, rotation.getX()); + writeByteAngle(buffer, rotation.getY()); + writeByteAngle(buffer, rotation.getZ()); + } + + public static float readByteAngle(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + return buffer.readByte() * (360f / 256f); + } + + public static void writeByteAngle(ByteBuf buffer, float angle) { + Preconditions.checkNotNull(buffer, "buffer"); + buffer.writeByte((byte) (angle / (360f / 256f))); + } + + public static Attribute readEntityAttribute(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + String name = BedrockUtils.readString(buffer); + float min = buffer.readFloatLE(); + float max = buffer.readFloatLE(); + float val = buffer.readFloatLE(); + + return new Attribute(name, min, max, val, max); + } + + public static void writeEntityAttribute(ByteBuf buffer, Attribute attribute) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(attribute, "attribute"); + + BedrockUtils.writeString(buffer, attribute.getName()); + buffer.writeFloatLE(attribute.getMinimum()); + buffer.writeFloatLE(attribute.getMaximum()); + buffer.writeFloatLE(attribute.getValue()); + } + + public static Attribute readPlayerAttribute(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + float min = buffer.readFloatLE(); + float max = buffer.readFloatLE(); + float val = buffer.readFloatLE(); + float def = buffer.readFloatLE(); + String name = BedrockUtils.readString(buffer); + + return new Attribute(name, min, max, val, def); + } + + public static void writePlayerAttribute(ByteBuf buffer, Attribute attribute) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(attribute, "attribute"); + + buffer.writeFloatLE(attribute.getMinimum()); + buffer.writeFloatLE(attribute.getMaximum()); + buffer.writeFloatLE(attribute.getValue()); + buffer.writeFloatLE(attribute.getDefaultValue()); + BedrockUtils.writeString(buffer, attribute.getName()); + } + + public static EntityLink readEntityLink(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + long from = VarInts.readLong(buffer); + long to = VarInts.readLong(buffer); + int type = buffer.readUnsignedByte(); + boolean immediate = buffer.readBoolean(); + + return new EntityLink(from, to, EntityLink.Type.values()[type], immediate); + } + + public static void writeEntityLink(ByteBuf buffer, EntityLink entityLink) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(entityLink, "entityLink"); + + VarInts.writeLong(buffer, entityLink.getFrom()); + VarInts.writeLong(buffer, entityLink.getTo()); + buffer.writeByte(entityLink.getType().ordinal()); + buffer.writeBoolean(entityLink.isImmediate()); + } + + public static ItemData readItemData(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + int id = VarInts.readInt(buffer); + if (id == 0) { + // We don't need to read anything extra. + return ItemData.AIR; + } + int aux = VarInts.readInt(buffer); + short damage = (short) (aux >> 8); + if (damage == Short.MAX_VALUE) damage = -1; + int count = aux & 0xff; + int nbtSize = buffer.readShortLE(); + + CompoundTag compoundTag = null; + if (nbtSize > 0) { + try (NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(buffer.readSlice(nbtSize)))) { + Tag tag = reader.readTag(); + if (tag instanceof CompoundTag) { + compoundTag = (CompoundTag) tag; + } + } catch (IllegalArgumentException ignored) { + } catch (IOException e) { + throw new IllegalStateException("Unable to load NBT data", e); + } + } else if (nbtSize == -1) { + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + int nbtTagCount = VarInts.readUnsignedInt(buffer); + if (nbtTagCount == 1) { + Tag tag = reader.readTag(); + if (tag instanceof CompoundTag) { + compoundTag = (CompoundTag) tag; + } + } else { + throw new AssertionError("Expected 1 tag but got " + nbtTagCount); + } + } catch (IllegalArgumentException ignored) { + } catch (IOException e) { + throw new IllegalStateException("Unable to load NBT data", e); + } + } + + String[] canPlace = new String[VarInts.readInt(buffer)]; + for (int i = 0; i < canPlace.length; i++) { + canPlace[i] = readString(buffer); + } + + String[] canBreak = new String[VarInts.readInt(buffer)]; + for (int i = 0; i < canBreak.length; i++) { + canBreak[i] = readString(buffer); + } + + long blockingTicks = 0; + if (id == 513) { // TODO: 20/03/2019 We shouldn't be hardcoding this but it's what Microjang have made us do + blockingTicks = VarInts.readLong(buffer); + } + + return ItemData.of(id, damage, count, compoundTag, canPlace, canBreak, blockingTicks); + } + + public static void writeItemData(ByteBuf buffer, ItemData item) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(item, "item"); + + // Write id + int id = item.getId(); + if (id == 0) { + // We don't need to write anything extra. + buffer.writeByte(0); + return; + } + VarInts.writeInt(buffer, id); + + // Write damage and count + short damage = item.getDamage(); + if (damage == -1) damage = Short.MAX_VALUE; + VarInts.writeInt(buffer, (damage << 8) | (item.getCount() & 0xff)); + + if (item.getTag() != null) { + buffer.writeShort(-1); + VarInts.writeUnsignedInt(buffer, 1); // Hardcoded in current version + + try (NBTOutputStream stream = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + stream.write(item.getTag()); + } catch (IOException e) { + // This shouldn't happen (as this is backed by a Netty ByteBuf), but okay... + throw new IllegalStateException("Unable to save NBT data", e); + } + } else { + buffer.writeShortLE(0); + } + + String[] canPlace = item.getCanPlace(); + VarInts.writeInt(buffer, canPlace.length); + for (String aCanPlace : canPlace) { + BedrockUtils.writeString(buffer, aCanPlace); + } + + String[] canBreak = item.getCanBreak(); + VarInts.writeInt(buffer, canBreak.length); + for (String aCanBreak : canBreak) { + BedrockUtils.writeString(buffer, aCanBreak); + } + + if (id == 513) { // TODO: 20/03/2019 We shouldn't be hardcoding this but it's what Microjang have made us do + VarInts.writeLong(buffer, item.getBlockingTicks()); + } + } + + public static ItemData readRecipeIngredient(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + int id = VarInts.readInt(buffer); + int auxValue = 0; + int stackSize = 0; + + if (id != 0) { + auxValue = VarInts.readInt(buffer); + if (auxValue == 0x7fff) auxValue = -1; + stackSize = VarInts.readInt(buffer); + } + + return ItemData.of(id, (short) auxValue, stackSize); + } + + public static void writeRecipeIngredient(ByteBuf buffer, ItemData itemData) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(itemData, "itemData"); + + int id = itemData.getId(); + VarInts.writeInt(buffer, id); + + if (id != 0) { + int damage = itemData.getDamage(); + if (damage == -1) damage = 0x7fff; + VarInts.writeInt(buffer, damage); + VarInts.writeInt(buffer, itemData.getCount()); + } + } + + public static CommandOriginData readCommandOriginData(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + CommandOriginData.Origin origin = CommandOriginData.Origin.values()[VarInts.readUnsignedInt(buffer)]; + UUID uuid = readUuid(buffer); + String requestId = readString(buffer); + long varLong = -1; + if (origin == CommandOriginData.Origin.DEV_CONSOLE || origin == CommandOriginData.Origin.TEST) { + varLong = VarInts.readLong(buffer); + } + return new CommandOriginData(origin, uuid, requestId, varLong); + } + + public static void writeCommandOriginData(ByteBuf buffer, CommandOriginData originData) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(originData, "commandOriginData"); + VarInts.writeUnsignedInt(buffer, originData.getOrigin().ordinal()); + writeUuid(buffer, originData.getUuid()); + writeString(buffer, originData.getRequestId()); + if (originData.getOrigin() == CommandOriginData.Origin.DEV_CONSOLE || originData.getOrigin() == CommandOriginData.Origin.TEST) { + VarInts.writeLong(buffer, originData.getEvent()); + } + } + + public static CommandOutputMessage readCommandOutputMessage(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + boolean internal = buffer.readBoolean(); + String messageId = readString(buffer); + String[] parameters = new String[VarInts.readUnsignedInt(buffer)]; + for (int i = 0; i < parameters.length; i++) { + parameters[i] = BedrockUtils.readString(buffer); + } + return new CommandOutputMessage(internal, messageId, parameters); + } + + public static void writeCommandOutputMessage(ByteBuf buffer, CommandOutputMessage outputMessage) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(outputMessage, "outputMessage"); + buffer.writeBoolean(outputMessage.isInternal()); + writeString(buffer, outputMessage.getMessageId()); + writeArray(buffer, outputMessage.getParameters(), BedrockUtils::writeString); + } + + public static List readPacksInfoEntries(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + List entries = new ObjectArrayList<>(); + int length = buffer.readUnsignedShortLE(); + for (int i = 0; i < length; i++) { + String packId = readString(buffer); + String packVersion = readString(buffer); + long packSize = buffer.readLongLE(); + String encryptionKey = readString(buffer); + String subpackName = readString(buffer); + String contentId = readString(buffer); + boolean unknownBool = buffer.readBoolean(); + entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, unknownBool)); + } + return entries; + } + + public static void writePacksInfoEntries(ByteBuf buffer, Collection packInfoEntries) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(packInfoEntries, "packInfoEntries"); + buffer.writeShortLE(packInfoEntries.size()); + for (ResourcePacksInfoPacket.Entry packInfoEntry : packInfoEntries) { + writeString(buffer, packInfoEntry.getPackId().toString()); + writeString(buffer, packInfoEntry.getPackVersion()); + buffer.writeLongLE(packInfoEntry.getPackSize()); + writeString(buffer, packInfoEntry.getEncryptionKey()); + writeString(buffer, packInfoEntry.getSubpackName()); + writeString(buffer, packInfoEntry.getContentId()); + buffer.writeBoolean(packInfoEntry.isScripting()); + } + } + + public static ResourcePackStackPacket.Entry readPackInstanceEntry(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + String packId = readString(buffer); + String packVersion = readString(buffer); + String subpackName = readString(buffer); + return new ResourcePackStackPacket.Entry(packId, packVersion, subpackName); + } + + public static void writePackInstanceEntry(ByteBuf buffer, ResourcePackStackPacket.Entry packInstanceEntry) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(packInstanceEntry, "packInstanceEntry"); + + writeString(buffer, packInstanceEntry.getPackId().toString()); + writeString(buffer, packInstanceEntry.getPackVersion()); + writeString(buffer, packInstanceEntry.getSubpackName()); + } + + public static void readArray(ByteBuf buffer, Collection array, Function function) { + int length = VarInts.readUnsignedInt(buffer); + + + for (int i = 0; i < length; i++) { + array.add(function.apply(buffer)); + } + } + + public static void writeArray(ByteBuf buffer, Collection array, BiConsumer biConsumer) { + VarInts.writeUnsignedInt(buffer, array.size()); + for (T val : array) { + biConsumer.accept(buffer, val); + } + } + + public static void writeArray(ByteBuf buffer, T[] array, BiConsumer biConsumer) { + VarInts.writeUnsignedInt(buffer, array.length); + for (T val : array) { + biConsumer.accept(buffer, val); + } + } + + public static InventoryActionData readInventoryAction(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + InventorySource source = readInventorySource(buffer); + + int slot = VarInts.readUnsignedInt(buffer); + ItemData fromItem = readItemData(buffer); + ItemData toItem = readItemData(buffer); + + return new InventoryActionData(source, slot, fromItem, toItem); + } + + public static void writeInventoryAction(ByteBuf buffer, InventoryActionData action) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(action, "action"); + + writeInventorySource(buffer, action.getSource()); + + VarInts.writeUnsignedInt(buffer, action.getSlot()); + writeItemData(buffer, action.getFromItem()); + writeItemData(buffer, action.getToItem()); + } + + public static InventorySource readInventorySource(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + InventorySource.Type type = InventorySource.Type.byId(VarInts.readUnsignedInt(buffer)); + + switch (type) { + case CONTAINER: + int containerId = VarInts.readInt(buffer); + return InventorySource.fromContainerWindowId(containerId); + case GLOBAL: + return InventorySource.fromGlobalInventory(); + case WORLD_INTERACTION: + InventorySource.Flag flag = InventorySource.Flag.values()[VarInts.readUnsignedInt(buffer)]; + return InventorySource.fromWorldInteraction(flag); + case CREATIVE: + return InventorySource.fromCreativeInventory(); + case UNTRACKED_INTERACTION_UI: + containerId = VarInts.readInt(buffer); + return InventorySource.fromUntrackedInteractionUI(containerId); + case NON_IMPLEMENTED_TODO: + containerId = VarInts.readInt(buffer); + return InventorySource.fromNonImplementedTodo(containerId); + default: + return InventorySource.fromInvalid(); + } + } + + public static void writeInventorySource(ByteBuf buffer, InventorySource inventorySource) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(inventorySource, "inventorySource"); + + VarInts.writeUnsignedInt(buffer, inventorySource.getType().id()); + + switch (inventorySource.getType()) { + case CONTAINER: + case UNTRACKED_INTERACTION_UI: + case NON_IMPLEMENTED_TODO: + VarInts.writeInt(buffer, inventorySource.getContainerId()); + break; + case WORLD_INTERACTION: + VarInts.writeUnsignedInt(buffer, inventorySource.getFlag().ordinal()); + break; + } + } + + public static GameRuleData readGameRule(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + String name = BedrockUtils.readString(buffer); + int type = VarInts.readUnsignedInt(buffer); + + switch (type) { + case 1: + return new GameRuleData<>(name, buffer.readBoolean()); + case 2: + return new GameRuleData<>(name, VarInts.readUnsignedInt(buffer)); + case 3: + return new GameRuleData<>(name, buffer.readFloatLE()); + } + throw new IllegalStateException("Invalid gamerule type received"); + } + + public static void writeGameRule(ByteBuf buffer, GameRuleData gameRule) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(gameRule, "gameRule"); + + Object value = gameRule.getValue(); + int type = GameRulesChangedSerializer_v363.RULE_TYPES.get(value.getClass()); + + BedrockUtils.writeString(buffer, gameRule.getName()); + VarInts.writeUnsignedInt(buffer, type); + + switch (type) { + case 1: + buffer.writeBoolean((boolean) value); + break; + case 2: + VarInts.writeUnsignedInt(buffer, (int) value); + break; + case 3: + buffer.writeFloatLE((float) value); + break; + } + } + + public static void readEntityData(ByteBuf buffer, EntityDataMap metadataDictionary) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(metadataDictionary, "metadataDictionary"); + + int length = VarInts.readUnsignedInt(buffer); + + for (int i = 0; i < length; i++) { + int metadataInt = VarInts.readUnsignedInt(buffer); + EntityData entityData = METADATAS.get(metadataInt); + EntityData.Type type = METADATA_TYPES.get(VarInts.readUnsignedInt(buffer)); + if (entityData != null && entityData.isFlags()) { + if (type != Type.LONG) { + throw new IllegalArgumentException("Expected long value for flags, got " + type.name()); + } + type = Type.FLAGS; + } + + Object object; + switch (type) { + case BYTE: + object = buffer.readByte(); + break; + case SHORT: + object = buffer.readShortLE(); + break; + case INT: + object = VarInts.readInt(buffer); + break; + case FLOAT: + object = buffer.readFloatLE(); + break; + case STRING: + object = BedrockUtils.readString(buffer); + break; + case NBT: + CompoundTag tag; + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + tag = (CompoundTag) reader.readTag(); + } catch (IOException e) { + throw new IllegalStateException("Error whilst decoding NBT entity data"); + } + object = tag; + log.debug("TAG \n{}", tag); + break; + case VECTOR3I: + object = BedrockUtils.readVector3i(buffer); + break; + case FLAGS: + int index = entityData == FLAGS_2 ? 1 : 0; + metadataDictionary.getOrCreateFlags().set(VarInts.readLong(buffer), index, METADATA_FLAGS); + continue; + case LONG: + object = VarInts.readLong(buffer); + break; + case VECTOR3F: + object = BedrockUtils.readVector3f(buffer); + break; + default: + throw new IllegalArgumentException("Unknown entity data type received"); + } + if (entityData != null) { + metadataDictionary.put(entityData, object); + } else { + log.debug("Unknown entity data: {} type {} value {}", metadataInt, type, object); + } + } + } + + public static void writeEntityData(ByteBuf buffer, EntityDataMap metadataDictionary) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(metadataDictionary, "metadataDictionary"); + + VarInts.writeUnsignedInt(buffer, metadataDictionary.size()); + + for (Map.Entry entry : metadataDictionary.entrySet()) { + int index = buffer.writerIndex(); + VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey())); + Object object = entry.getValue(); + EntityData.Type type = EntityData.Type.from(object); + VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type)); + + switch (type) { + case BYTE: + buffer.writeByte((byte) object); + break; + case SHORT: + buffer.writeShortLE((short) object); + break; + case INT: + VarInts.writeInt(buffer, (int) object); + break; + case FLOAT: + buffer.writeFloatLE((float) object); + break; + case STRING: + BedrockUtils.writeString(buffer, (String) object); + break; + case NBT: + CompoundTag tag; + if (object instanceof CompoundTag) { + tag = (CompoundTag) object; + } else { + ItemData item = (ItemData) object; + tag = item.getTag(); + if (tag == null) { + tag = CompoundTagBuilder.builder().buildRootTag(); + } + } + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(tag); + } catch (IOException e) { + throw new IllegalStateException("Error whilst decoding NBT entity data"); + } + break; + case VECTOR3I: + BedrockUtils.writeVector3i(buffer, (Vector3i) object); + break; + case FLAGS: + int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0; + object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS); + case LONG: + VarInts.writeLong(buffer, (long) object); + break; + case VECTOR3F: + BedrockUtils.writeVector3f(buffer, (Vector3f) object); + break; + default: + buffer.writerIndex(index); + break; + } + } + } + + public static CommandEnumData readCommandEnumData(ByteBuf buffer, boolean soft) { + Preconditions.checkNotNull(buffer, "buffer"); + + String name = BedrockUtils.readString(buffer); + + String[] values = new String[VarInts.readUnsignedInt(buffer)]; + for (int i = 0; i < values.length; i++) { + values[i] = BedrockUtils.readString(buffer); + } + return new CommandEnumData(name, values, soft); + } + + public static void writeCommandEnumData(ByteBuf buffer, CommandEnumData enumData) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(enumData, "enumData"); + + BedrockUtils.writeString(buffer, enumData.getName()); + + String[] values = enumData.getValues(); + VarInts.writeUnsignedInt(buffer, values.length); + for (String value : values) { + BedrockUtils.writeString(buffer, value); + } + } + + public static StructureSettings readStructureSettings(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + String paletteName = BedrockUtils.readString(buffer); + boolean ignoreEntities = buffer.readBoolean(); + boolean ignoreBlocks = buffer.readBoolean(); + Vector3i structureSize = BedrockUtils.readBlockPosition(buffer); + Vector3i structureOffset = BedrockUtils.readBlockPosition(buffer); + long lastTouchedByEntityId = VarInts.readLong(buffer); + byte rotation = buffer.readByte(); + byte mirror = buffer.readByte(); + float integrityValue = buffer.readFloatLE(); + int integritySeed = VarInts.readUnsignedInt(buffer); + + return new StructureSettings(paletteName, ignoreEntities, ignoreBlocks, structureSize, structureOffset, + lastTouchedByEntityId, rotation, mirror, integrityValue, integritySeed); + } + + public static void writeStructureSettings(ByteBuf buffer, StructureSettings structureSettings) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(structureSettings, "structureSettings"); + + BedrockUtils.writeString(buffer, structureSettings.getPaletteName()); + buffer.writeBoolean(structureSettings.isIgnoreEntities()); + buffer.writeBoolean(structureSettings.isIgnoreBlocks()); + BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureSize()); + BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureOffset()); + VarInts.writeLong(buffer, structureSettings.getLastTouchedByEntityId()); + buffer.writeByte(structureSettings.getRotation()); + buffer.writeByte(structureSettings.getMirror()); + buffer.writeFloatLE(structureSettings.getIntegrityValue()); + VarInts.writeUnsignedInt(buffer, structureSettings.getIntegritySeed()); + } + + public static StructureEditorData readStructureEditorData(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + String name = BedrockUtils.readString(buffer); + String structureDataField = BedrockUtils.readString(buffer); + boolean includePlayers = buffer.readBoolean(); + boolean showBoundingBox = buffer.readBoolean(); + int structureBlockType = VarInts.readInt(buffer); + StructureSettings settings = BedrockUtils.readStructureSettings(buffer); + + return new StructureEditorData(name, structureDataField, includePlayers, showBoundingBox, structureBlockType, + settings); + } + + public static void writeStructureEditorData(ByteBuf buffer, StructureEditorData structureEditorData) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(structureEditorData, "structureEditorData"); + + BedrockUtils.writeString(buffer, structureEditorData.getName()); + BedrockUtils.writeString(buffer, structureEditorData.getStructureDataField()); + buffer.writeBoolean(structureEditorData.isIncludePlayers()); + buffer.writeBoolean(structureEditorData.isShowBoundingBox()); + VarInts.writeInt(buffer, structureEditorData.getStructureBlockType()); + BedrockUtils.writeStructureSettings(buffer, structureEditorData.getStructureSettings()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java new file mode 100644 index 000000000..cfd99aaf3 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -0,0 +1,158 @@ +package com.nukkitx.protocol.bedrock.v363; + +import com.nukkitx.protocol.bedrock.BedrockPacketCodec; +import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.protocol.bedrock.v363.serializer.*; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class Bedrock_v363 { + public static BedrockPacketCodec V363_CODEC = BedrockPacketCodec.builder() + .protocolVersion(363) + .minecraftVersion("1.12.60") + .headerSerializer(PacketHeaderSerializer_v363.INSTANCE) + .registerPacket(LoginPacket.class, LoginSerializer_v363.INSTANCE, 1) + .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v363.INSTANCE, 2) + .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v363.INSTANCE, 3) + .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v363.INSTANCE, 4) + .registerPacket(DisconnectPacket.class, DisconnectSerializer_v363.INSTANCE, 5) + .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v363.INSTANCE, 6) + .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v363.INSTANCE, 7) + .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v363.INSTANCE, 8) + .registerPacket(TextPacket.class, TextSerializer_v363.INSTANCE, 9) + .registerPacket(SetTimePacket.class, SetTimeSerializer_v363.INSTANCE, 10) + .registerPacket(StartGamePacket.class, StartGameSerializer_v363.INSTANCE, 11) + .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v363.INSTANCE, 12) + .registerPacket(AddEntityPacket.class, AddEntitySerializer_v363.INSTANCE, 13) + .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v363.INSTANCE, 14) + .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v363.INSTANCE, 15) + .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v363.INSTANCE, 17) + .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v363.INSTANCE, 18) + .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v363.INSTANCE, 19) + .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v363.INSTANCE, 20) + .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v363.INSTANCE, 21) + .registerPacket(AddPaintingPacket.class, AddPaintingSerializer_v363.INSTANCE, 22) + .registerPacket(ExplodePacket.class, ExplodeSerializer_v363.INSTANCE, 23) + .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v363.INSTANCE, 24) + .registerPacket(LevelEventPacket.class, LevelEventSerializer_v363.INSTANCE, 25) + .registerPacket(BlockEventPacket.class, BlockEventSerializer_v363.INSTANCE, 26) + .registerPacket(EntityEventPacket.class, EntityEventSerializer_v363.INSTANCE, 27) + .registerPacket(MobEffectPacket.class, MobEffectSerializer_v363.INSTANCE, 28) + .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v363.INSTANCE, 29) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v363.INSTANCE, 30) + .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v363.INSTANCE, 31) + .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v363.INSTANCE, 32) + .registerPacket(InteractPacket.class, InteractSerializer_v363.INSTANCE, 33) + .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v363.INSTANCE, 34) + .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v363.INSTANCE, 35) + .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v363.INSTANCE, 36) + .registerPacket(EntityFallPacket.class, EntityFallSerializer_v363.INSTANCE, 37) + .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v363.INSTANCE, 38) + .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v363.INSTANCE, 39) + .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v363.INSTANCE, 40) + .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v363.INSTANCE, 41) + .registerPacket(SetHealthPacket.class, SetHealthSerializer_v363.INSTANCE, 42) + .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v363.INSTANCE, 43) + .registerPacket(AnimatePacket.class, AnimateSerializer_v363.INSTANCE, 44) + .registerPacket(RespawnPacket.class, RespawnSerializer_v363.INSTANCE, 45) + .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v363.INSTANCE, 46) + .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v363.INSTANCE, 47) + .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v363.INSTANCE, 48) + .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v363.INSTANCE, 49) + .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v363.INSTANCE, 50) + .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v363.INSTANCE, 51) + .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v363.INSTANCE, 52) + .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v363.INSTANCE, 53) + .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v363.INSTANCE, 54) + .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v363.INSTANCE, 55) + .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v363.INSTANCE, 56) + .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v363.INSTANCE, 57) + .registerPacket(LevelChunkPacket.class, LevelChunkSerializer_v363.INSTANCE, 58) + .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v363.INSTANCE, 59) + .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v363.INSTANCE, 60) + .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v363.INSTANCE, 61) + .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v363.INSTANCE, 62) + .registerPacket(PlayerListPacket.class, PlayerListSerializer_v363.INSTANCE, 63) + .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v363.INSTANCE, 64) + .registerPacket(EventPacket.class, EventSerializer_v363.INSTANCE, 65) + .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v363.INSTANCE, 66) + .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v363.INSTANCE, 67) + .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v363.INSTANCE, 68) + .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v363.INSTANCE, 69) + .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v363.INSTANCE, 70) + .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v363.INSTANCE, 71) + .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v363.INSTANCE, 72) + .registerPacket(CameraPacket.class, CameraSerializer_v363.INSTANCE, 73) + .registerPacket(BossEventPacket.class, BossEventSerializer_v363.INSTANCE, 74) + .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v363.INSTANCE, 75) + .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v363.INSTANCE, 76) + .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v363.INSTANCE, 77) + .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v363.INSTANCE, 78) + .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v363.INSTANCE, 79) + .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v363.INSTANCE, 80) + .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v363.INSTANCE, 81) + .registerPacket(ResourcePackDataInfoPacket.class, ResourcePackDataInfoSerializer_v363.INSTANCE, 82) + .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v363.INSTANCE, 83) + .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v363.INSTANCE, 84) + .registerPacket(TransferPacket.class, TransferSerializer_v363.INSTANCE, 85) + .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v363.INSTANCE, 86) + .registerPacket(StopSoundPacket.class, StopSoundSerializer_v363.INSTANCE, 87) + .registerPacket(SetTitlePacket.class, SetTitleSerializer_v363.INSTANCE, 88) + .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v363.INSTANCE, 89) + .registerPacket(StructureBlockUpdatePacket.class, StructureBlockUpdateSerializer_v363.INSTANCE, 90) + .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v363.INSTANCE, 91) + .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v363.INSTANCE, 92) + .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v363.INSTANCE, 93) + .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v363.INSTANCE, 94) + .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v363.INSTANCE, 95) + .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v363.INSTANCE, 96) + .registerPacket(BookEditPacket.class, BookEditSerializer_v363.INSTANCE, 97) + .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v363.INSTANCE, 98) + .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v363.INSTANCE, 99) + .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v363.INSTANCE, 100) + .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v363.INSTANCE, 101) + .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v363.INSTANCE, 102) + .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v363.INSTANCE, 103) + .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v363.INSTANCE, 104) + .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v363.INSTANCE, 105) + .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v363.INSTANCE, 106) + .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v363.INSTANCE, 107) + .registerPacket(SetScorePacket.class, SetScoreSerializer_v363.INSTANCE, 108) + .registerPacket(LabTablePacket.class, LabTableSerializer_v363.INSTANCE, 109) + .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v363.INSTANCE, 110) + .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v363.INSTANCE, 111) + .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v363.INSTANCE, 112) + .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v363.INSTANCE, 113) + .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v363.INSTANCE, 114) + .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v363.INSTANCE, 115) + .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v363.INSTANCE, 117) + .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v363.INSTANCE, 118) + .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v363.INSTANCE, 119) + .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v363.INSTANCE, 120) + .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v363.INSTANCE, 121) + .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v363.INSTANCE, 122) + .registerPacket(LevelSoundEventPacket.class, LevelSoundEvent3Serializer_v363.INSTANCE, 123) + .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v363.INSTANCE, 124) + .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v363.INSTANCE, 125) + .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v363.INSTANCE, 126) + // AddEntityPacket 127 + // RemoveEntityPacket 128 + .registerPacket(ClientCacheStatusPacket.class, ClientCacheStatusSerializer_v363.INSTANCE, 129) + .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v363.INSTANCE, 130) + .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v363.INSTANCE, 131) + .registerPacket(StructureTemplateDataExportRequestPacket.class, StructureTemplateDataExportRequestSerializer_v363.INSTANCE, 132) + .registerPacket(StructureTemplateDataExportResponsePacket.class, StructureTemplateDataExportResponseSerializer_v363.INSTANCE, 133) + .registerPacket(UpdateBlockPropertiesPacket.class, UpdateBlockPropertiesSerializer_v363.INSTANCE, 134) + .registerPacket(ClientCacheBlobStatusPacket.class, ClientCacheBlobStatusSerializer_v363.INSTANCE, 135) + .registerPacket(ClientCacheMissResponsePacket.class, ClientCacheMissResponseSerializer_v363.INSTANCE, 136) + + .registerPacket(EducationSettingsPacket.class, EducationSettingsSerializer_v363.INSTANCE, 137) + .registerPacket(EmotePacket.class, EmoteSerializer_v363.INSTANCE, 138) + .registerPacket(MultiplayerSettingsPacket.class, MultiplayerSettingsSerializer_v363.INSTANCE, 139) + .registerPacket(SettingsCommandPacket.class, SettingsCommandSerializer_v363.INSTANCE, 140) + .registerPacket(AnvilDamagePacket.class, AnvilDamageSerializer_v363.INSTANCE, 141) + .registerPacket(CompletedUsingItemPacket.class, CompletedUsingItemSerializer_v363.INSTANCE, 142) + .registerPacket(NetworkSettingsPacket.class, NetworkSettingsSerializer_v363.INSTANCE, 143) + .registerPacket(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v363.INSTANCE, 144) + .build(); +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java new file mode 100644 index 000000000..5866bc936 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.AddBehaviorTreePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddBehaviorTreeSerializer_v363 implements PacketSerializer { + public static final AddBehaviorTreeSerializer_v363 INSTANCE = new AddBehaviorTreeSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AddBehaviorTreePacket packet) { + BedrockUtils.writeString(buffer, packet.getBehaviorTreeJson()); + } + + @Override + public void deserialize(ByteBuf buffer, AddBehaviorTreePacket packet) { + packet.setBehaviorTreeJson(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java new file mode 100644 index 000000000..c9f6d3d2d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java @@ -0,0 +1,40 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddEntitySerializer_v363 implements PacketSerializer { + public static final AddEntitySerializer_v363 INSTANCE = new AddEntitySerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AddEntityPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeString(buffer, packet.getIdentifier()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeVector3f(buffer, packet.getMotion()); + BedrockUtils.writeVector3f(buffer, packet.getRotation()); + BedrockUtils.writeArray(buffer, packet.getAttributes(), BedrockUtils::writeEntityAttribute); + BedrockUtils.writeEntityData(buffer, packet.getMetadata()); + BedrockUtils.writeArray(buffer, packet.getEntityLinks(), BedrockUtils::writeEntityLink); + } + + @Override + public void deserialize(ByteBuf buffer, AddEntityPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setIdentifier(BedrockUtils.readString(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setMotion(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readVector3f(buffer)); + BedrockUtils.readArray(buffer, packet.getAttributes(), BedrockUtils::readEntityAttribute); + BedrockUtils.readEntityData(buffer, packet.getMetadata()); + BedrockUtils.readArray(buffer, packet.getEntityLinks(), BedrockUtils::readEntityLink); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java new file mode 100644 index 000000000..a67d8593e --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java @@ -0,0 +1,36 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.AddItemEntityPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddItemEntitySerializer_v363 implements PacketSerializer { + public static final AddItemEntitySerializer_v363 INSTANCE = new AddItemEntitySerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AddItemEntityPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeItemData(buffer, packet.getItemInHand()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeVector3f(buffer, packet.getMotion()); + BedrockUtils.writeEntityData(buffer, packet.getMetadata()); + buffer.writeBoolean(packet.isFromFishing()); + } + + @Override + public void deserialize(ByteBuf buffer, AddItemEntityPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setItemInHand(BedrockUtils.readItemData(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setMotion(BedrockUtils.readVector3f(buffer)); + BedrockUtils.readEntityData(buffer, packet.getMetadata()); + packet.setFromFishing(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java new file mode 100644 index 000000000..31a5da475 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java @@ -0,0 +1,34 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.network.VarInts.readInt; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddPaintingSerializer_v363 implements PacketSerializer { + public static final AddPaintingSerializer_v363 INSTANCE = new AddPaintingSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AddPaintingPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getDirection()); + BedrockUtils.writeString(buffer, packet.getName()); + } + + @Override + public void deserialize(ByteBuf buffer, AddPaintingPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setDirection(readInt(buffer)); + packet.setName(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java new file mode 100644 index 000000000..483bf51b0 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java @@ -0,0 +1,48 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddPlayerSerializer_v363 implements PacketSerializer { + public static final AddPlayerSerializer_v363 INSTANCE = new AddPlayerSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AddPlayerPacket packet) { + BedrockUtils.writeUuid(buffer, packet.getUuid()); + BedrockUtils.writeString(buffer, packet.getUsername()); + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeString(buffer, packet.getPlatformChatId()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeVector3f(buffer, packet.getMotion()); + BedrockUtils.writeVector3f(buffer, packet.getRotation()); + BedrockUtils.writeItemData(buffer, packet.getHand()); + BedrockUtils.writeEntityData(buffer, packet.getMetadata()); + AdventureSettingsSerializer_v363.INSTANCE.serialize(buffer, packet.getAdventureSettings()); + BedrockUtils.writeArray(buffer, packet.getEntityLinks(), BedrockUtils::writeEntityLink); + BedrockUtils.writeString(buffer, packet.getDeviceId()); + } + + @Override + public void deserialize(ByteBuf buffer, AddPlayerPacket packet) { + packet.setUuid(BedrockUtils.readUuid(buffer)); + packet.setUsername(BedrockUtils.readString(buffer)); + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setPlatformChatId(BedrockUtils.readString(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setMotion(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readVector3f(buffer)); + packet.setHand(BedrockUtils.readItemData(buffer)); + BedrockUtils.readEntityData(buffer, packet.getMetadata()); + AdventureSettingsSerializer_v363.INSTANCE.deserialize(buffer, packet.getAdventureSettings()); + BedrockUtils.readArray(buffer, packet.getEntityLinks(), BedrockUtils::readEntityLink); + packet.setDeviceId(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java new file mode 100644 index 000000000..26931445e --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java @@ -0,0 +1,96 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.CommandPermission; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Set; + +import static com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket.Flag.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AdventureSettingsSerializer_v363 implements PacketSerializer { + public static final AdventureSettingsSerializer_v363 INSTANCE = new AdventureSettingsSerializer_v363(); + + private static final CommandPermission[] COMMAND_PERMISSIONS = CommandPermission.values(); + private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); + + private static final AdventureSettingsPacket.Flag[] FLAGS_1 = {IMMUTABLE_WORLD, NO_PVP, NO_PVM, null, NO_MVP, AUTO_JUMP, MAY_FLY, NO_CLIP, WORLD_BUILDER, FLYING, MUTE}; + private static final AdventureSettingsPacket.Flag[] FLAGS_2 = {MINE, DOORS_AND_SWITCHES, OPEN_CONTAINERS, ATTACK_PLAYERS, ATTACK_MOBS, OP, null, TELEPORT, BUILD, SET_DEFAULT}; + + private static final Object2IntMap FLAGS_TO_BIT_1 = new Object2IntOpenHashMap<>(); + private static final Object2IntMap FLAGS_TO_BIT_2 = new Object2IntOpenHashMap<>(); + + static { + FLAGS_TO_BIT_1.put(IMMUTABLE_WORLD, 0x1); + FLAGS_TO_BIT_1.put(NO_PVP, 0x2); + FLAGS_TO_BIT_1.put(NO_PVM, 0x4); + FLAGS_TO_BIT_1.put(NO_MVP, 0x10); + FLAGS_TO_BIT_1.put(AUTO_JUMP, 0x20); + FLAGS_TO_BIT_1.put(MAY_FLY, 0x40); + FLAGS_TO_BIT_1.put(NO_CLIP, 0x80); + FLAGS_TO_BIT_1.put(WORLD_BUILDER, 0x100); + FLAGS_TO_BIT_1.put(FLYING, 0x200); + FLAGS_TO_BIT_1.put(MUTE, 0x400); + + FLAGS_TO_BIT_2.put(MINE, 0x1); + FLAGS_TO_BIT_2.put(DOORS_AND_SWITCHES, 0x2); + FLAGS_TO_BIT_2.put(OPEN_CONTAINERS, 0x04); + FLAGS_TO_BIT_2.put(ATTACK_PLAYERS, 0x8); + FLAGS_TO_BIT_2.put(ATTACK_MOBS, 0x10); + FLAGS_TO_BIT_2.put(OP, 0x20); + FLAGS_TO_BIT_2.put(TELEPORT, 0x80); + FLAGS_TO_BIT_2.put(BUILD, 0x100); + FLAGS_TO_BIT_2.put(SET_DEFAULT, 0x200); + } + + + @Override + public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) { + int flags1 = 0; + int flags2 = 0; + for (AdventureSettingsPacket.Flag flag : packet.getFlags()) { + if (FLAGS_TO_BIT_1.containsKey(flag)) { + flags1 |= FLAGS_TO_BIT_1.get(flag); + } else if (FLAGS_TO_BIT_2.containsKey(flag)) { + flags2 |= FLAGS_TO_BIT_2.get(flag); + } + } + VarInts.writeUnsignedInt(buffer, flags1); + VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal()); + VarInts.writeUnsignedInt(buffer, flags2); + VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal()); + VarInts.writeUnsignedInt(buffer, 0); // Useless + buffer.writeLongLE(packet.getUniqueEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) { + int flags1 = VarInts.readUnsignedInt(buffer); + packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]); + int flags2 = VarInts.readUnsignedInt(buffer); + packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]); + VarInts.readUnsignedInt(buffer); // useless + packet.setUniqueEntityId(buffer.readLongLE()); + + Set flags = packet.getFlags(); + for (int i = 0; i < FLAGS_1.length; i++) { + if ((flags1 & (1 << i)) != 0) { + flags.add(FLAGS_1[i]); + } + } + + for (int i = 0; i < FLAGS_2.length; i++) { + if ((flags2 & (1 << i)) != 0) { + flags.add(FLAGS_2[i]); + } + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java new file mode 100644 index 000000000..8f6200817 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java @@ -0,0 +1,47 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.AnimatePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.AnimatePacket.Action; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AnimateSerializer_v363 implements PacketSerializer { + public static final AnimateSerializer_v363 INSTANCE = new AnimateSerializer_v363(); + private static final Int2ObjectBiMap types = new Int2ObjectBiMap<>(); + + static { + types.put(0, Action.NO_ACTION); + types.put(1, Action.SWING_ARM); + types.put(3, Action.WAKE_UP); + types.put(4, Action.CRITICAL_HIT); + types.put(5, Action.MAGIC_CRITICAL_HIT); + types.put(128, Action.ROW_RIGHT); + types.put(129, Action.ROW_LEFT); + } + + @Override + public void serialize(ByteBuf buffer, AnimatePacket packet) { + Action action = packet.getAction(); + VarInts.writeInt(buffer, types.get(action)); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) { + buffer.writeFloatLE(packet.getRowingTime()); + } + } + + @Override + public void deserialize(ByteBuf buffer, AnimatePacket packet) { + Action action = types.get(VarInts.readInt(buffer)); + packet.setAction(action); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + if (action == AnimatePacket.Action.ROW_LEFT || action == AnimatePacket.Action.ROW_RIGHT) { + packet.setRowingTime(buffer.readFloatLE()); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java new file mode 100644 index 000000000..411fcb5ba --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.AnvilDamagePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class AnvilDamageSerializer_v363 implements PacketSerializer { + + public static final AnvilDamageSerializer_v363 INSTANCE = new AnvilDamageSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AnvilDamagePacket packet) { + buffer.writeByte(packet.getDamage()); + BedrockUtils.writeBlockPosition(buffer, packet.getPosition()); + } + + @Override + public void deserialize(ByteBuf buffer, AnvilDamagePacket packet) { + packet.setDamage(buffer.readByte()); + packet.setPosition(BedrockUtils.readBlockPosition(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java new file mode 100644 index 000000000..f6ef11349 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.AutomationClientConnectPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AutomationClientConnectSerializer_v363 implements PacketSerializer { + public static final AutomationClientConnectSerializer_v363 INSTANCE = new AutomationClientConnectSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, AutomationClientConnectPacket packet) { + BedrockUtils.writeString(buffer, packet.getAddress()); + } + + @Override + public void deserialize(ByteBuf buffer, AutomationClientConnectPacket packet) { + packet.setAddress(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java new file mode 100644 index 000000000..093e7221f --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java @@ -0,0 +1,299 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.CommandData; +import com.nukkitx.protocol.bedrock.data.CommandEnumData; +import com.nukkitx.protocol.bedrock.data.CommandParamData; +import com.nukkitx.protocol.bedrock.data.CommandParamType; +import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.ObjIntConsumer; +import java.util.function.ToIntFunction; + +import static com.nukkitx.protocol.bedrock.data.CommandParamData.Type.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AvailableCommandsSerializer_v363 implements PacketSerializer { + private static final InternalLogger log = InternalLoggerFactory.getInstance(AvailableCommandsSerializer_v363.class); + public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); + private static final ObjIntConsumer WRITE_BYTE = ByteBuf::writeByte; + private static final ObjIntConsumer WRITE_SHORT = ByteBuf::writeShortLE; + private static final ObjIntConsumer WRITE_INT = ByteBuf::writeIntLE; + private static final ToIntFunction READ_BYTE = ByteBuf::readUnsignedByte; + private static final ToIntFunction READ_SHORT = ByteBuf::readUnsignedShortLE; + private static final ToIntFunction READ_INT = ByteBuf::readIntLE; + private static final Int2ObjectBiMap PARAM_TYPES = new Int2ObjectBiMap<>(); + + static { + PARAM_TYPES.put(1, INT); + PARAM_TYPES.put(2, FLOAT); + PARAM_TYPES.put(3, VALUE); + PARAM_TYPES.put(4, WILDCARD_INT); + PARAM_TYPES.put(5, OPERATOR); + PARAM_TYPES.put(6, TARGET); + PARAM_TYPES.put(7, WILDCARD_TARGET); + PARAM_TYPES.put(14, FILE_PATH); + PARAM_TYPES.put(18, INT_RANGE); + PARAM_TYPES.put(27, STRING); + PARAM_TYPES.put(29, POSITION); + PARAM_TYPES.put(32, MESSAGE); + PARAM_TYPES.put(34, TEXT); + PARAM_TYPES.put(37, JSON); + PARAM_TYPES.put(44, COMMAND); + } + + @Override + public void serialize(ByteBuf buffer, AvailableCommandsPacket packet) { + Set enumValuesSet = new ObjectOpenHashSet<>(); + Set postfixSet = new ObjectOpenHashSet<>(); + Set enumsSet = new ObjectOpenHashSet<>(); + Set softEnumsSet = new ObjectOpenHashSet<>(); + + // Get all enum values + for (CommandData data : packet.getCommands()) { + if (data.getAliases() != null) { + Collections.addAll(enumValuesSet, data.getAliases().getValues()); + enumsSet.add(data.getAliases()); + } + + for (CommandParamData[] overload : data.getOverloads()) { + for (CommandParamData parameter : overload) { + CommandEnumData commandEnumData = parameter.getEnumData(); + if (commandEnumData != null) { + if (commandEnumData.isSoft()) { + softEnumsSet.add(commandEnumData); + } else { + Collections.addAll(enumValuesSet, commandEnumData.getValues()); + enumsSet.add(commandEnumData); + } + } + + String postfix = parameter.getPostfix(); + if (postfix != null) { + postfixSet.add(postfix); + } + } + } + } + + List enumValues = new ObjectArrayList<>(enumValuesSet); + List postFixes = new ObjectArrayList<>(postfixSet); + List enums = new ObjectArrayList<>(enumsSet); + List softEnums = new ObjectArrayList<>(softEnumsSet); + + // Determine width of enum index + ObjIntConsumer indexWriter; + int valuesSize = enumValues.size(); + if (valuesSize < 0x100) { + indexWriter = WRITE_BYTE; + } else if (valuesSize < 0x10000) { + indexWriter = WRITE_SHORT; + } else { + indexWriter = WRITE_INT; + } + + BedrockUtils.writeArray(buffer, enumValues, BedrockUtils::writeString); + BedrockUtils.writeArray(buffer, postFixes, BedrockUtils::writeString); + + // Write enums + BedrockUtils.writeArray(buffer, enums, (buf, commandEnum) -> { + BedrockUtils.writeString(buf, commandEnum.getName()); + + VarInts.writeUnsignedInt(buffer, commandEnum.getValues().length); + for (String value : commandEnum.getValues()) { + int index = enumValues.indexOf(value); + Preconditions.checkArgument(index > -1, "Invalid enum value detected"); + indexWriter.accept(buf, index); + } + }); + + // Write command data + BedrockUtils.writeArray(buffer, packet.getCommands(), (buf, commandData) -> { + BedrockUtils.writeString(buf, commandData.getName()); + BedrockUtils.writeString(buf, commandData.getDescription()); + byte flags = 0; + if (commandData.getFlags() != null) { + for (CommandData.Flag flag : commandData.getFlags()) { + flags |= 1 << flag.ordinal(); + } + } + buf.writeByte(flags); + buf.writeByte(commandData.getPermission()); + + CommandEnumData aliases = commandData.getAliases(); + buf.writeIntLE(enums.indexOf(aliases)); + + CommandParamData[][] overloads = commandData.getOverloads(); + VarInts.writeUnsignedInt(buf, overloads.length); + for (CommandParamData[] overload : overloads) { + VarInts.writeUnsignedInt(buf, overload.length); + for (CommandParamData param : overload) { + BedrockUtils.writeString(buf, param.getName()); + + int index; + boolean postfix = false; + boolean enumData = false; + boolean softEnum = false; + if (param.getPostfix() != null) { + postfix = true; + index = postFixes.indexOf(param.getPostfix()); + } else if (param.getEnumData() != null) { + if (param.getEnumData().isSoft()) { + softEnum = true; + index = softEnums.indexOf(param.getEnumData()); + } else { + enumData = true; + index = enums.indexOf(param.getEnumData()); + } + } else if (param.getType() != null) { + index = PARAM_TYPES.get(param.getType()); + } else { + throw new IllegalStateException("No param type specified"); + } + + CommandParamType type = new CommandParamType(index, enumData, softEnum, postfix); + + buf.writeIntLE(type.serialize()); + buf.writeBoolean(param.isOptional()); + byte options = 0; + if (param.getOptions() != null) { + for (CommandParamData.Option opt : param.getOptions()) { + options |= 1 << opt.ordinal(); + } + } + buf.writeByte(options); + } + } + }); + + BedrockUtils.writeArray(buffer, softEnums, BedrockUtils::writeCommandEnumData); + } + + @Override + public void deserialize(ByteBuf buffer, AvailableCommandsPacket packet) { + List enumValues = new ObjectArrayList<>(); + List postFixes = new ObjectArrayList<>(); + List enums = new ObjectArrayList<>(); + List commands = new ObjectArrayList<>(); + List softEnums = new ObjectArrayList<>(); + + BedrockUtils.readArray(buffer, enumValues, BedrockUtils::readString); + BedrockUtils.readArray(buffer, postFixes, BedrockUtils::readString); + + // Determine width of enum index + ToIntFunction indexReader; + int valuesSize = enumValues.size(); + if (valuesSize < 0x100) { + indexReader = READ_BYTE; + } else if (valuesSize < 0x10000) { + indexReader = READ_SHORT; + } else { + indexReader = READ_INT; + } + + BedrockUtils.readArray(buffer, enums, buf -> { + String name = BedrockUtils.readString(buf); + + int length = VarInts.readUnsignedInt(buffer); + String[] values = new String[length]; + for (int i = 0; i < length; i++) { + values[i] = enumValues.get(indexReader.applyAsInt(buf)); + } + return new CommandEnumData(name, values, false); + }); + + BedrockUtils.readArray(buffer, commands, buf -> { + String name = BedrockUtils.readString(buf); + String description = BedrockUtils.readString(buf); + byte flags = buf.readByte(); + byte permissions = buf.readByte(); + int aliasesIndex = buf.readIntLE(); + + CommandParamData.Builder[][] overloads = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)][]; + for (int i = 0; i < overloads.length; i++) { + overloads[i] = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)]; + for (int i2 = 0; i2 < overloads[i].length; i2++) { + String parameterName = BedrockUtils.readString(buf); + + CommandParamType type = CommandParamType.deserialize(buf.readIntLE()); + + boolean optional = buf.readBoolean(); + byte unknownByte = buf.readByte(); + + overloads[i][i2] = new CommandParamData.Builder(parameterName, type, optional, unknownByte); + } + } + return new CommandData.Builder(name, description, flags, permissions, aliasesIndex, overloads); + }); + + BedrockUtils.readArray(buffer, softEnums, buf -> BedrockUtils.readCommandEnumData(buffer, true)); + + // Generate command data + + for (CommandData.Builder command : commands) { + byte flagsByte = command.getFlags(); + List flags = new ObjectArrayList<>(); + for (int i = 0; i < 8; i++) { + if (((flagsByte >>> i) & 0xf) != 0) { + flags.add(CommandData.Flag.values()[i]); + } + } + int aliasesIndex = command.getAliases(); + CommandEnumData aliases = aliasesIndex == -1 ? null : enums.get(aliasesIndex); + + CommandParamData.Builder[][] overloadBuilders = command.getOverloads(); + CommandParamData[][] overloads = new CommandParamData[overloadBuilders.length][]; + for (int i = 0; i < overloadBuilders.length; i++) { + overloads[i] = new CommandParamData[overloadBuilders[i].length]; + for (int i2 = 0; i2 < overloadBuilders[i].length; i2++) { + String name = overloadBuilders[i][i2].getName(); + CommandParamType type = overloadBuilders[i][i2].getType(); + boolean optional = overloadBuilders[i][i2].isOptional(); + byte optionsByte = overloadBuilders[i][i2].getOptions(); + List options = new ObjectArrayList<>(); + for (int oi = 0; oi < 8; oi++) { + if (((optionsByte >>> oi) & 0xf) != 0) { + options.add(CommandParamData.Option.values()[oi]); + } + } + + String postfix = null; + CommandEnumData enumData = null; + CommandParamData.Type paramType = null; + if (type.isPostfix()) { + postfix = postFixes.get(type.getValue()); + } else { + if (type.isCommandEnum()) { + enumData = enums.get(type.getValue()); + } else if (type.isSoftEnum()) { + enumData = softEnums.get(type.getValue()); + } else { + paramType = PARAM_TYPES.get(type.getValue()); + if (paramType == null) { + log.debug("Unknown parameter type {} from {} in {}", type.getValue(), name, command.getName()); + } + } + } + overloads[i][i2] = new CommandParamData(name, optional, enumData, paramType, postfix, options); + } + } + + packet.getCommands().add(new CommandData(command.getName(), command.getDescription(), + flags, command.getPermission(), aliases, overloads)); + } + } +} \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java new file mode 100644 index 000000000..866848067 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java @@ -0,0 +1,37 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.protocol.bedrock.packet.AvailableEntityIdentifiersPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AvailableEntityIdentifiersSerializer_v363 implements PacketSerializer { + public static final AvailableEntityIdentifiersSerializer_v363 INSTANCE = new AvailableEntityIdentifiersSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) { + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) { + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setTag(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java new file mode 100644 index 000000000..b504324a4 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java @@ -0,0 +1,37 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BiomeDefinitionListSerializer_v363 implements PacketSerializer { + public static final BiomeDefinitionListSerializer_v363 INSTANCE = new BiomeDefinitionListSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, BiomeDefinitionListPacket packet) { + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) { + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setTag(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java new file mode 100644 index 000000000..1108b4703 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java @@ -0,0 +1,40 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BlockEntityDataSerializer_v363 implements PacketSerializer { + public static final BlockEntityDataSerializer_v363 INSTANCE = new BlockEntityDataSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, BlockEntityDataPacket packet) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getData()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setData(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java new file mode 100644 index 000000000..6f0ce8554 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.BlockEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BlockEventSerializer_v363 implements PacketSerializer { + public static final BlockEventSerializer_v363 INSTANCE = new BlockEventSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, BlockEventPacket packet) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeInt(buffer, packet.getEventType()); + VarInts.writeInt(buffer, packet.getEventData()); + } + + @Override + public void deserialize(ByteBuf buffer, BlockEventPacket packet) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setEventType(VarInts.readInt(buffer)); + packet.setEventData(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java new file mode 100644 index 000000000..3ce69ef16 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.BlockPickRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BlockPickRequestSerializer_v363 implements PacketSerializer { + public static final BlockPickRequestSerializer_v363 INSTANCE = new BlockPickRequestSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, BlockPickRequestPacket packet) { + BedrockUtils.writeVector3i(buffer, packet.getBlockPosition()); + buffer.writeBoolean(packet.isAddUserData()); + buffer.writeByte(packet.getHotbarSlot()); + } + + @Override + public void deserialize(ByteBuf buffer, BlockPickRequestPacket packet) { + packet.setBlockPosition(BedrockUtils.readVector3i(buffer)); + packet.setAddUserData(buffer.readBoolean()); + packet.setHotbarSlot(buffer.readUnsignedByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java new file mode 100644 index 000000000..3a5bce023 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java @@ -0,0 +1,77 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.BookEditPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.BookEditPacket.Action; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BookEditSerializer_v363 implements PacketSerializer { + public static final BookEditSerializer_v363 INSTANCE = new BookEditSerializer_v363(); + private static final Int2ObjectBiMap types = new Int2ObjectBiMap<>(); + + static { + types.put(0, Action.REPLACE_PAGE); + types.put(1, Action.ADD_PAGE); + types.put(2, Action.DELETE_PAGE); + types.put(3, Action.SWAP_PAGES); + types.put(4, Action.SIGN_BOOK); + } + + @Override + public void serialize(ByteBuf buffer, BookEditPacket packet) { + buffer.writeByte(packet.getAction().ordinal()); + buffer.writeByte(packet.getInventorySlot()); + switch (packet.getAction()) { + case REPLACE_PAGE: + case ADD_PAGE: + buffer.writeByte(packet.getPageNumber()); + BedrockUtils.writeString(buffer, packet.getText()); + BedrockUtils.writeString(buffer, packet.getPhotoName()); + break; + case DELETE_PAGE: + buffer.writeByte(packet.getPageNumber()); + break; + case SWAP_PAGES: + buffer.writeByte(packet.getPageNumber()); + buffer.writeByte(packet.getSecondaryPageNumber()); + break; + case SIGN_BOOK: + BedrockUtils.writeString(buffer, packet.getTitle()); + BedrockUtils.writeString(buffer, packet.getAuthor()); + BedrockUtils.writeString(buffer, packet.getXuid()); + break; + } + } + + @Override + public void deserialize(ByteBuf buffer, BookEditPacket packet) { + packet.setAction(types.get(buffer.readUnsignedByte())); + packet.setInventorySlot(buffer.readUnsignedByte()); + switch (packet.getAction()) { + case REPLACE_PAGE: + case ADD_PAGE: + packet.setPageNumber(buffer.readUnsignedByte()); + packet.setText(BedrockUtils.readString(buffer)); + packet.setPhotoName(BedrockUtils.readString(buffer)); + break; + case DELETE_PAGE: + packet.setPageNumber(buffer.readUnsignedByte()); + break; + case SWAP_PAGES: + packet.setPageNumber(buffer.readUnsignedByte()); + packet.setSecondaryPageNumber(buffer.readUnsignedByte()); + break; + case SIGN_BOOK: + packet.setTitle(BedrockUtils.readString(buffer)); + packet.setAuthor(BedrockUtils.readString(buffer)); + packet.setXuid(BedrockUtils.readString(buffer)); + break; + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java new file mode 100644 index 000000000..3fe88d22b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java @@ -0,0 +1,77 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.BossEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class BossEventSerializer_v363 implements PacketSerializer { + public static final BossEventSerializer_v363 INSTANCE = new BossEventSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, BossEventPacket packet) { + VarInts.writeLong(buffer, packet.getBossUniqueEntityId()); + VarInts.writeUnsignedInt(buffer, packet.getAction().ordinal()); + + switch (packet.getAction()) { + case REGISTER_PLAYER: + case UNREGISTER_PLAYER: + VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); + break; + case SHOW: + BedrockUtils.writeString(buffer, packet.getTitle()); + buffer.writeFloatLE(packet.getHealthPercentage()); + // fall through + case DARKEN_SKY: + buffer.writeShortLE(packet.getDarkenSky()); + // fall through + case OVERLAY: + VarInts.writeUnsignedInt(buffer, packet.getColor()); + VarInts.writeUnsignedInt(buffer, packet.getOverlay()); + break; + case HEALTH_PERCENTAGE: + buffer.writeFloatLE(packet.getHealthPercentage()); + break; + case TITLE: + BedrockUtils.writeString(buffer, packet.getTitle()); + break; + default: + throw new RuntimeException("BossEvent transactionType was unknown!"); + } + } + + @Override + public void deserialize(ByteBuf buffer, BossEventPacket packet) { + packet.setBossUniqueEntityId(VarInts.readInt(buffer)); + BossEventPacket.Action action = BossEventPacket.Action.values()[VarInts.readUnsignedInt(buffer)]; + packet.setAction(action); + + switch (action) { + case REGISTER_PLAYER: + case UNREGISTER_PLAYER: + packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); + break; + case SHOW: + packet.setTitle(BedrockUtils.readString(buffer)); + packet.setHealthPercentage(buffer.readFloatLE()); + // fall through + case DARKEN_SKY: + packet.setDarkenSky(buffer.readUnsignedShortLE()); + // fall through + case OVERLAY: + packet.setColor(VarInts.readUnsignedInt(buffer)); + packet.setOverlay(VarInts.readUnsignedInt(buffer)); + break; + case HEALTH_PERCENTAGE: + packet.setHealthPercentage(buffer.readFloatLE()); + break; + case TITLE: + packet.setTitle(BedrockUtils.readString(buffer)); + break; + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java new file mode 100644 index 000000000..de7ffff14 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.CameraPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CameraSerializer_v363 implements PacketSerializer { + public static final CameraSerializer_v363 INSTANCE = new CameraSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, CameraPacket packet) { + VarInts.writeLong(buffer, packet.getCameraUniqueEntityId()); + VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, CameraPacket packet) { + packet.setCameraUniqueEntityId(VarInts.readLong(buffer)); + packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java new file mode 100644 index 000000000..cacd8dde9 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ChangeDimensionPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ChangeDimensionSerializer_v363 implements PacketSerializer { + public static final ChangeDimensionSerializer_v363 INSTANCE = new ChangeDimensionSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ChangeDimensionPacket packet) { + VarInts.writeInt(buffer, packet.getDimension()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + buffer.writeBoolean(packet.isRespawn()); + } + + @Override + public void deserialize(ByteBuf buffer, ChangeDimensionPacket packet) { + packet.setDimension(VarInts.readInt(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setRespawn(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java new file mode 100644 index 000000000..66d536caf --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ChunkRadiusUpdatedPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ChunkRadiusUpdatedSerializer_v363 implements PacketSerializer { + public static final ChunkRadiusUpdatedSerializer_v363 INSTANCE = new ChunkRadiusUpdatedSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ChunkRadiusUpdatedPacket packet) { + VarInts.writeInt(buffer, packet.getRadius()); + } + + @Override + public void deserialize(ByteBuf buffer, ChunkRadiusUpdatedPacket packet) { + packet.setRadius(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java new file mode 100644 index 000000000..ef692724e --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java @@ -0,0 +1,43 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ClientCacheBlobStatusPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.longs.LongList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.function.LongConsumer; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ClientCacheBlobStatusSerializer_v363 implements PacketSerializer { + public static final ClientCacheBlobStatusSerializer_v363 INSTANCE = new ClientCacheBlobStatusSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) { + LongList acks = packet.getAcks(); + LongList nacks = packet.getNaks(); + VarInts.writeUnsignedInt(buffer, acks.size()); + VarInts.writeUnsignedInt(buffer, nacks.size()); + + acks.forEach((LongConsumer) buffer::writeLongLE); + nacks.forEach((LongConsumer) buffer::writeLongLE); + } + + @Override + public void deserialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) { + int acksLength = VarInts.readUnsignedInt(buffer); + int naksLength = VarInts.readUnsignedInt(buffer); + + LongList acks = packet.getAcks(); + for (int i = 0; i < acksLength; i++) { + acks.add(buffer.readLongLE()); + } + + LongList naks = packet.getNaks(); + for (int i = 0; i < naksLength; i++) { + naks.add(buffer.readLongLE()); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java new file mode 100644 index 000000000..af5acdb52 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java @@ -0,0 +1,39 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ClientCacheMissResponsePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ClientCacheMissResponseSerializer_v363 implements PacketSerializer { + public static final ClientCacheMissResponseSerializer_v363 INSTANCE = new ClientCacheMissResponseSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { + Long2ObjectMap blobs = packet.getBlobs(); + VarInts.writeUnsignedInt(buffer, blobs.size()); + + blobs.forEach((id, blob) -> { + buffer.writeLongLE(id); + BedrockUtils.writeByteArray(buffer, blob); + }); + } + + @Override + public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { + Long2ObjectMap blobs = packet.getBlobs(); + + int length = VarInts.readUnsignedInt(buffer); + + for (int i = 0; i < length; i++) { + long id = buffer.readLongLE(); + byte[] blob = BedrockUtils.readByteArray(buffer); + blobs.put(id, blob); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java new file mode 100644 index 000000000..2fb0359c9 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java @@ -0,0 +1,22 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ClientCacheStatusPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ClientCacheStatusSerializer_v363 implements PacketSerializer { + public static final ClientCacheStatusSerializer_v363 INSTANCE = new ClientCacheStatusSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ClientCacheStatusPacket packet) { + buffer.writeBoolean(packet.isSupported()); + } + + @Override + public void deserialize(ByteBuf buffer, ClientCacheStatusPacket packet) { + packet.setSupported(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java new file mode 100644 index 000000000..9eefe1019 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java @@ -0,0 +1,22 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ClientToServerHandshakePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ClientToServerHandshakeSerializer_v363 implements PacketSerializer { + public static final ClientToServerHandshakeSerializer_v363 INSTANCE = new ClientToServerHandshakeSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ClientToServerHandshakePacket packet) { + // No payload + } + + @Override + public void deserialize(ByteBuf buffer, ClientToServerHandshakePacket packet) { + // No payload + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java new file mode 100644 index 000000000..e2d8e1d0f --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java @@ -0,0 +1,154 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.MapDecoration; +import com.nukkitx.protocol.bedrock.data.MapTrackedObject; +import com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.longs.LongList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ClientboundMapItemDataSerializer_v363 implements PacketSerializer { + public static final ClientboundMapItemDataSerializer_v363 INSTANCE = new ClientboundMapItemDataSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ClientboundMapItemDataPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueMapId()); + + int type = 0; + int[] colors = packet.getColors(); + if (colors != null && colors.length > 0) { + type |= 0x2; + } + List decorations = packet.getDecorations(); + List trackedObjects = packet.getTrackedObjects(); + if (!decorations.isEmpty() && !trackedObjects.isEmpty()) { + type |= 0x4; + } + LongList trackedEntityIds = packet.getTrackedEntityIds(); + if (!trackedEntityIds.isEmpty()) { + type |= 0x8; + } + + VarInts.writeUnsignedInt(buffer, type); + buffer.writeByte(packet.getDimensionId()); + buffer.writeBoolean(packet.isLocked()); + + if ((type & 0x8) != 0) { + VarInts.writeUnsignedInt(buffer, trackedEntityIds.size()); + for (long trackedEntityId : trackedEntityIds) { + VarInts.writeLong(buffer, trackedEntityId); + } + } + + if ((type & 0xe) != 0) { + buffer.writeByte(packet.getScale()); + } + + if ((type & 0x4) != 0) { + VarInts.writeUnsignedInt(buffer, trackedObjects.size()); + for (MapTrackedObject object : trackedObjects) { + switch (object.getType()) { + case BLOCK: + buffer.writeIntLE(object.getType().ordinal()); + BedrockUtils.writeBlockPosition(buffer, object.getPosition()); + break; + case ENTITY: + buffer.writeIntLE(object.getType().ordinal()); + VarInts.writeLong(buffer, object.getEntityId()); + break; + } + } + + VarInts.writeUnsignedInt(buffer, decorations.size()); + for (MapDecoration decoration : decorations) { + buffer.writeByte(decoration.getImage()); + buffer.writeByte(decoration.getRotation()); + buffer.writeByte(decoration.getXOffset()); + buffer.writeByte(decoration.getYOffset()); + BedrockUtils.writeString(buffer, decoration.getLabel()); + VarInts.writeUnsignedInt(buffer, decoration.getColor()); + } + } + + if ((type & 0x2) != 0) { + VarInts.writeInt(buffer, packet.getWidth()); + VarInts.writeInt(buffer, packet.getHeight()); + VarInts.writeInt(buffer, packet.getXOffset()); + VarInts.writeInt(buffer, packet.getYOffset()); + + VarInts.writeUnsignedInt(buffer, colors.length); + for (int color : colors) { + VarInts.writeUnsignedInt(buffer, color); + } + } + } + + @Override + public void deserialize(ByteBuf buffer, ClientboundMapItemDataPacket packet) { + packet.setUniqueMapId(VarInts.readLong(buffer)); + int type = VarInts.readUnsignedInt(buffer); + packet.setDimensionId(buffer.readUnsignedByte()); + packet.setLocked(buffer.readBoolean()); + + if ((type & 0x8) != 0) { + LongList trackedEntityIds = packet.getTrackedEntityIds(); + int length = VarInts.readUnsignedInt(buffer); + for (int i = 0; i < length; i++) { + trackedEntityIds.add(VarInts.readLong(buffer)); + } + } + + if ((type & 0xe) != 0) { + packet.setScale(buffer.readUnsignedByte()); + } + + if ((type & 0x4) != 0) { + List trackedObjects = packet.getTrackedObjects(); + int length = VarInts.readUnsignedInt(buffer); + for (int i = 0; i < length; i++) { + MapTrackedObject.Type objectType = MapTrackedObject.Type.values()[buffer.readIntLE()]; + switch (objectType) { + case BLOCK: + trackedObjects.add(new MapTrackedObject(BedrockUtils.readBlockPosition(buffer))); + break; + case ENTITY: + trackedObjects.add(new MapTrackedObject(VarInts.readLong(buffer))); + break; + } + } + + List decorations = packet.getDecorations(); + length = VarInts.readUnsignedInt(buffer); + for (int i = 0; i < length; i++) { + int image = buffer.readUnsignedByte(); + int rotation = buffer.readUnsignedByte(); + int xOffset = buffer.readUnsignedByte(); + int yOffset = buffer.readUnsignedByte(); + String label = BedrockUtils.readString(buffer); + int color = VarInts.readUnsignedInt(buffer); + decorations.add(new MapDecoration(image, rotation, xOffset, yOffset, label, color)); + } + } + + if ((type & 0x2) != 0) { + packet.setWidth(VarInts.readInt(buffer)); + packet.setHeight(VarInts.readInt(buffer)); + packet.setXOffset(VarInts.readInt(buffer)); + packet.setYOffset(VarInts.readInt(buffer)); + + int length = VarInts.readUnsignedInt(buffer); + int[] colors = new int[length]; + for (int i = 0; i < length; i++) { + colors[i] = VarInts.readUnsignedInt(buffer); + } + packet.setColors(colors); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java new file mode 100644 index 000000000..3a238866d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java @@ -0,0 +1,56 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.CommandBlockUpdatePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CommandBlockUpdateSerializer_v363 implements PacketSerializer { + public static final CommandBlockUpdateSerializer_v363 INSTANCE = new CommandBlockUpdateSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, CommandBlockUpdatePacket packet) { + buffer.writeBoolean(packet.isBlock()); + + if (packet.isBlock()) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeUnsignedInt(buffer, packet.getCommandBlockMode()); + buffer.writeBoolean(packet.isRedstoneMode()); + buffer.writeBoolean(packet.isConditional()); + } else { + VarInts.writeUnsignedLong(buffer, packet.getMinecartRuntimeEntityId()); + } + + BedrockUtils.writeString(buffer, packet.getCommand()); + BedrockUtils.writeString(buffer, packet.getLastOutput()); + BedrockUtils.writeString(buffer, packet.getName()); + buffer.writeBoolean(packet.isOutputTracked()); + buffer.writeIntLE((int) packet.getTickDelay()); + buffer.writeBoolean(packet.isExecutingOnFirstTick()); + } + + @Override + public void deserialize(ByteBuf buffer, CommandBlockUpdatePacket packet) { + packet.setBlock(buffer.readBoolean()); + + if (packet.isBlock()) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setCommandBlockMode(VarInts.readUnsignedInt(buffer)); + packet.setRedstoneMode(buffer.readBoolean()); + packet.setConditional(buffer.readBoolean()); + } else { + packet.setMinecartRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + } + + packet.setCommand(BedrockUtils.readString(buffer)); + packet.setLastOutput(BedrockUtils.readString(buffer)); + packet.setName(BedrockUtils.readString(buffer)); + packet.setOutputTracked(buffer.readBoolean()); + packet.setTickDelay(buffer.readUnsignedIntLE()); + packet.setExecutingOnFirstTick(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java new file mode 100644 index 000000000..6ab3b9f04 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java @@ -0,0 +1,40 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.CommandOutputPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CommandOutputSerializer_v363 implements PacketSerializer { + public static final CommandOutputSerializer_v363 INSTANCE = new CommandOutputSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, CommandOutputPacket packet) { + BedrockUtils.writeCommandOriginData(buffer, packet.getCommandOriginData()); + buffer.writeByte(packet.getOutputType()); + VarInts.writeUnsignedInt(buffer, packet.getSuccessCount()); + + BedrockUtils.writeArray(buffer, packet.getMessages(), BedrockUtils::writeCommandOutputMessage); + + if (packet.getOutputType() == 4) { + BedrockUtils.writeString(buffer, packet.getData()); + } + } + + @Override + public void deserialize(ByteBuf buffer, CommandOutputPacket packet) { + packet.setCommandOriginData(BedrockUtils.readCommandOriginData(buffer)); + packet.setOutputType(buffer.readUnsignedByte()); + packet.setSuccessCount(VarInts.readUnsignedInt(buffer)); + + BedrockUtils.readArray(buffer, packet.getMessages(), BedrockUtils::readCommandOutputMessage); + + if (packet.getOutputType() == 4) { + packet.setData(BedrockUtils.readString(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java new file mode 100644 index 000000000..58cba8c77 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CommandRequestSerializer_v363 implements PacketSerializer { + public static final CommandRequestSerializer_v363 INSTANCE = new CommandRequestSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, CommandRequestPacket packet) { + BedrockUtils.writeString(buffer, packet.getCommand()); + BedrockUtils.writeCommandOriginData(buffer, packet.getCommandOriginData()); + buffer.writeBoolean(packet.isInternal()); + } + + @Override + public void deserialize(ByteBuf buffer, CommandRequestPacket packet) { + packet.setCommand(BedrockUtils.readString(buffer)); + packet.setCommandOriginData(BedrockUtils.readCommandOriginData(buffer)); + packet.setInternal(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java new file mode 100644 index 000000000..4f0019816 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.data.ItemAction; +import com.nukkitx.protocol.bedrock.packet.CompletedUsingItemPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class CompletedUsingItemSerializer_v363 implements PacketSerializer { + + public static final CompletedUsingItemSerializer_v363 INSTANCE = new CompletedUsingItemSerializer_v363(); + + private static final ItemAction[] VALUES = ItemAction.values(); + + @Override + public void serialize(ByteBuf buffer, CompletedUsingItemPacket packet) { + buffer.writeShortLE(packet.getItemId()); + buffer.writeIntLE(packet.getAction().ordinal() - 1); // Enum starts at -1 + } + + @Override + public void deserialize(ByteBuf buffer, CompletedUsingItemPacket packet) { + packet.setItemId(buffer.readUnsignedShortLE()); + packet.setAction(VALUES[buffer.readIntLE() + 1]); // Enum starts at -1 + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java new file mode 100644 index 000000000..9654802de --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java @@ -0,0 +1,22 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ContainerCloseSerializer_v363 implements PacketSerializer { + public static final ContainerCloseSerializer_v363 INSTANCE = new ContainerCloseSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ContainerClosePacket packet) { + buffer.writeByte(packet.getWindowId()); + } + + @Override + public void deserialize(ByteBuf buffer, ContainerClosePacket packet) { + packet.setWindowId(buffer.readByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java new file mode 100644 index 000000000..60389e541 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java @@ -0,0 +1,31 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ContainerOpenSerializer_v363 implements PacketSerializer { + public static final ContainerOpenSerializer_v363 INSTANCE = new ContainerOpenSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ContainerOpenPacket packet) { + buffer.writeByte(packet.getWindowId()); + buffer.writeByte(packet.getType()); + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, ContainerOpenPacket packet) { + packet.setWindowId(buffer.readByte()); + packet.setType(buffer.readByte()); + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setUniqueEntityId(VarInts.readLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java new file mode 100644 index 000000000..055ac3488 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ContainerSetDataPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ContainerSetDataSerializer_v363 implements PacketSerializer { + public static final ContainerSetDataSerializer_v363 INSTANCE = new ContainerSetDataSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ContainerSetDataPacket packet) { + buffer.writeByte(packet.getWindowId()); + VarInts.writeInt(buffer, packet.getProperty()); + VarInts.writeInt(buffer, packet.getValue()); + } + + @Override + public void deserialize(ByteBuf buffer, ContainerSetDataPacket packet) { + packet.setWindowId(buffer.readByte()); + packet.setProperty(VarInts.readInt(buffer)); + packet.setValue(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java new file mode 100644 index 000000000..4a0b3f240 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java @@ -0,0 +1,137 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.CraftingData; +import com.nukkitx.protocol.bedrock.data.CraftingType; +import com.nukkitx.protocol.bedrock.data.ItemData; +import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CraftingDataSerializer_v363 implements PacketSerializer { + public static final CraftingDataSerializer_v363 INSTANCE = new CraftingDataSerializer_v363(); + + private static final InternalLogger log = InternalLoggerFactory.getInstance(CraftingDataSerializer_v363.class); + + @Override + public void serialize(ByteBuf buffer, CraftingDataPacket packet) { + BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { + VarInts.writeInt(buf, craftingData.getType().ordinal()); + switch (craftingData.getType()) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + BedrockUtils.writeString(buf, craftingData.getRecipeId()); + BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeRecipeIngredient); + BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); + BedrockUtils.writeUuid(buf, craftingData.getUuid()); + BedrockUtils.writeString(buf, craftingData.getCraftingTag()); + VarInts.writeInt(buf, craftingData.getPriority()); + break; + case SHAPED: + case SHAPED_CHEMISTRY: + BedrockUtils.writeString(buf, craftingData.getRecipeId()); + VarInts.writeInt(buf, craftingData.getWidth()); + VarInts.writeInt(buf, craftingData.getHeight()); + int count = craftingData.getWidth() * craftingData.getHeight(); + ItemData[] inputs = craftingData.getInputs(); + for (int i = 0; i < count; i++) { + BedrockUtils.writeRecipeIngredient(buf, inputs[i]); + } + BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); + BedrockUtils.writeUuid(buf, craftingData.getUuid()); + BedrockUtils.writeString(buf, craftingData.getCraftingTag()); + VarInts.writeInt(buf, craftingData.getPriority()); + break; + case FURNACE: + case FURNACE_DATA: + VarInts.writeInt(buf, craftingData.getInputId()); + if (craftingData.getType() == CraftingType.FURNACE_DATA) { + VarInts.writeInt(buf, craftingData.getInputDamage()); + } + BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); + BedrockUtils.writeString(buf, craftingData.getCraftingTag()); + break; + case MULTI: + BedrockUtils.writeUuid(buf, craftingData.getUuid()); + break; + } + }); + buffer.writeBoolean(packet.isCleanRecipes()); + } + + @Override + public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { + BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { + int typeInt = VarInts.readInt(buf); + CraftingType type = CraftingType.byId(typeInt); + if (type == null) { + throw new IllegalArgumentException("Unknown crafting type: " + typeInt); + } + + switch (type) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + String recipeId = BedrockUtils.readString(buf); + int inputCount = VarInts.readUnsignedInt(buf); + ItemData[] inputs = new ItemData[inputCount]; + for (int i = 0; i < inputCount; i++) { + inputs[i] = BedrockUtils.readRecipeIngredient(buf); + } + int outputCount = VarInts.readUnsignedInt(buf); + ItemData[] outputs = new ItemData[outputCount]; + for (int i = 0; i < outputCount; i++) { + outputs[i] = BedrockUtils.readItemData(buf); + } + UUID uuid = BedrockUtils.readUuid(buf); + String craftingTag = BedrockUtils.readString(buf); + int priority = VarInts.readInt(buf); + return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, + outputs, uuid, craftingTag, priority); + case SHAPED: + case SHAPED_CHEMISTRY: + recipeId = BedrockUtils.readString(buf); + int width = VarInts.readInt(buf); + int height = VarInts.readInt(buf); + inputCount = width * height; + inputs = new ItemData[inputCount]; + for (int i = 0; i < inputCount; i++) { + inputs[i] = BedrockUtils.readRecipeIngredient(buf); + } + outputCount = VarInts.readUnsignedInt(buf); + outputs = new ItemData[outputCount]; + for (int i = 0; i < outputCount; i++) { + outputs[i] = BedrockUtils.readItemData(buf); + } + uuid = BedrockUtils.readUuid(buf); + craftingTag = BedrockUtils.readString(buf); + priority = VarInts.readInt(buf); + return new CraftingData(type, recipeId, width, height, -1, -1, inputs, outputs, + uuid, craftingTag, priority); + case FURNACE: + case FURNACE_DATA: + int inputId = VarInts.readInt(buf); + int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; + ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; + craftingTag = BedrockUtils.readString(buf); + return new CraftingData(type, null, -1, -1, inputId, inputDamage, null, + output, null, craftingTag, -1); + case MULTI: + uuid = BedrockUtils.readUuid(buf); + return CraftingData.fromMulti(uuid); + default: + throw new IllegalArgumentException("Unhandled crafting data type: " + type); + } + }); + packet.setCleanRecipes(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java new file mode 100644 index 000000000..1dc0d5c6f --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java @@ -0,0 +1,37 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.CraftingEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CraftingEventSerializer_v363 implements PacketSerializer { + public static final CraftingEventSerializer_v363 INSTANCE = new CraftingEventSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, CraftingEventPacket packet) { + buffer.writeByte(packet.getWindowId()); + VarInts.writeInt(buffer, packet.getType()); + BedrockUtils.writeUuid(buffer, packet.getUuid()); + + BedrockUtils.writeArray(buffer, packet.getInputs(), BedrockUtils::writeItemData); + + BedrockUtils.writeArray(buffer, packet.getOutputs(), BedrockUtils::writeItemData); + } + + @Override + public void deserialize(ByteBuf buffer, CraftingEventPacket packet) { + packet.setWindowId(buffer.readByte()); + packet.setType(VarInts.readInt(buffer)); + packet.setUuid(BedrockUtils.readUuid(buffer)); + + BedrockUtils.readArray(buffer, packet.getInputs(), BedrockUtils::readItemData); + + BedrockUtils.readArray(buffer, packet.getOutputs(), BedrockUtils::readItemData); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java new file mode 100644 index 000000000..365ed9a7c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java @@ -0,0 +1,30 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.DisconnectPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class DisconnectSerializer_v363 implements PacketSerializer { + public static final DisconnectSerializer_v363 INSTANCE = new DisconnectSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, DisconnectPacket packet) { + buffer.writeBoolean(packet.isDisconnectScreenHidden()); + if (!packet.isDisconnectScreenHidden()) { + BedrockUtils.writeString(buffer, packet.getKickMessage()); + } + } + + @Override + public void deserialize(ByteBuf buffer, DisconnectPacket packet) { + packet.setDisconnectScreenHidden(buffer.readBoolean()); + if (!packet.isDisconnectScreenHidden()) { + packet.setKickMessage(BedrockUtils.readString(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java new file mode 100644 index 000000000..80afb9ba3 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.EducationSettingsPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class EducationSettingsSerializer_v363 implements PacketSerializer { + + public static final EducationSettingsSerializer_v363 INSTANCE = new EducationSettingsSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, EducationSettingsPacket packet) { + BedrockUtils.writeString(buffer, packet.getSettings()); + buffer.writeBoolean(packet.isUnknown0()); + } + + @Override + public void deserialize(ByteBuf buffer, EducationSettingsPacket packet) { + packet.setSettings(BedrockUtils.readString(buffer)); + packet.setUnknown0(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java new file mode 100644 index 000000000..4acb1a82d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java @@ -0,0 +1,29 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.EmotePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class EmoteSerializer_v363 implements PacketSerializer { + + public static final EmoteSerializer_v363 INSTANCE = new EmoteSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, EmotePacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeString(buffer, packet.getEmoteId()); + buffer.writeByte(packet.getFlags()); + } + + @Override + public void deserialize(ByteBuf buffer, EmotePacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setEmoteId(BedrockUtils.readString(buffer)); + packet.setFlags(buffer.readByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java new file mode 100644 index 000000000..ba2ccfa7a --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java @@ -0,0 +1,88 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.EntityEventType; +import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.data.EntityEventType.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EntityEventSerializer_v363 implements PacketSerializer { + public static final EntityEventSerializer_v363 INSTANCE = new EntityEventSerializer_v363(); + private static final Int2ObjectBiMap events = new Int2ObjectBiMap<>(); + private static final InternalLogger log = InternalLoggerFactory.getInstance(EntityEventSerializer_v363.class); + + static { + events.put(2, HURT_ANIMATION); + events.put(3, DEATH_ANIMATION); + events.put(4, ARM_SWING); + events.put(6, TAME_FAIL); + events.put(7, TAME_SUCCESS); + events.put(8, SHAKE_WET); + events.put(9, USE_ITEM); + events.put(10, EAT_BLOCK_ANIMATION); + events.put(11, FISH_HOOK_BUBBLE); + events.put(12, FISH_HOOK_POSITION); + events.put(13, FISH_HOOK_HOOK); + events.put(14, FISH_HOOK_LURED); + events.put(15, SQUID_INK_CLOUD); + events.put(16, ZOMBIE_VILLAGER_CURE); + events.put(18, RESPAWN); + events.put(19, IRON_GOLEM_OFFER_FLOWER); + events.put(20, IRON_GOLEM_WITHDRAW_FLOWER); + events.put(21, LOVE_PARTICLES); + events.put(22, VILLAGER_HURT); + events.put(23, VILLAGER_STOP_TRADING); + events.put(24, WITCH_SPELL_PARTICLES); + events.put(25, FIREWORK_PARTICLES); + events.put(27, SILVERFISH_MERGE_WITH_STONE); + events.put(28, GUARDIAN_ATTACK_ANIMATION); + events.put(29, WITCH_DRINK_POTION); + events.put(30, WITCH_THROW_POTION); + events.put(31, MINECART_TNT_PRIME_FUSE); + events.put(34, PLAYER_ADD_XP_LEVELS); + events.put(35, ELDER_GUARDIAN_CURSE); + events.put(36, AGENT_ARM_SWING); + events.put(37, ENDER_DRAGON_DEATH); + events.put(38, DUST_PARTICLES); + events.put(39, ARROW_SHAKE); + events.put(57, EATING_ITEM); + events.put(60, BABY_ANIMAL_FEED); + events.put(61, DEATH_SMOKE_CLOUD); + events.put(62, COMPLETE_TRADE); + events.put(63, REMOVE_LEASH); + events.put(64, CARAVAN); + events.put(65, CONSUME_TOTEM); + events.put(66, CHECK_TREASURE_HUNTER_ACHIEVEMENT); + events.put(67, ENTITY_SPAWN); + events.put(68, DRAGON_FLAMING); + events.put(69, MERGE_ITEMS); + events.put(71, BALLOON_POP); + events.put(72, FIND_TREASURE_BRIBE); + } + + @Override + public void serialize(ByteBuf buffer, EntityEventPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + buffer.writeByte(events.get(packet.getType())); + VarInts.writeInt(buffer, packet.getData()); + } + + @Override + public void deserialize(ByteBuf buffer, EntityEventPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + int event = buffer.readUnsignedByte(); + packet.setType(events.get(event)); + packet.setData(VarInts.readInt(buffer)); + if (packet.getType() == null) { + log.debug("Unknown EntityEvent {} in packet {}", event, packet); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java new file mode 100644 index 000000000..b1e65e754 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.EntityFallPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EntityFallSerializer_v363 implements PacketSerializer { + public static final EntityFallSerializer_v363 INSTANCE = new EntityFallSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, EntityFallPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + buffer.writeFloatLE(packet.getFallDistance()); + buffer.writeBoolean(packet.isInVoid()); + } + + @Override + public void deserialize(ByteBuf buffer, EntityFallPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setFallDistance(buffer.readFloatLE()); + packet.setInVoid(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java new file mode 100644 index 000000000..21768e929 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.EntityPickRequestPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EntityPickRequestSerializer_v363 implements PacketSerializer { + public static final EntityPickRequestSerializer_v363 INSTANCE = new EntityPickRequestSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, EntityPickRequestPacket packet) { + buffer.writeLongLE(packet.getRuntimeEntityId()); + buffer.writeByte(packet.getHotbarSlot()); + } + + @Override + public void deserialize(ByteBuf buffer, EntityPickRequestPacket packet) { + packet.setRuntimeEntityId(buffer.readLongLE()); + packet.setHotbarSlot(buffer.readUnsignedByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java new file mode 100644 index 000000000..edc891103 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java @@ -0,0 +1,264 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.event.*; +import com.nukkitx.protocol.bedrock.packet.EventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Arrays; +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EventSerializer_v363 implements PacketSerializer { + public static final EventSerializer_v363 INSTANCE = new EventSerializer_v363(); + + private static final EventDataType[] VALUES = EventDataType.values(); + + @Override + public void serialize(ByteBuf buffer, EventPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + EventData eventData = packet.getEventData(); + VarInts.writeInt(buffer, eventData.getType().ordinal()); + buffer.writeByte(packet.getUnknown0()); + + switch (eventData.getType()) { + case ACHIEVEMENT_AWARDED: + VarInts.writeInt(buffer, ((AchievementAwardedEventData) eventData).getAchievementId()); + break; + case ENTITY_INTERACT: + EntityInteractEventData entityInteractEventData = (EntityInteractEventData) eventData; + VarInts.writeInt(buffer, entityInteractEventData.getInteractionType()); + VarInts.writeInt(buffer, entityInteractEventData.getLegacyEntityTypeId()); + VarInts.writeInt(buffer, entityInteractEventData.getVariant()); + buffer.writeByte(entityInteractEventData.getPaletteColor()); + break; + case PORTAL_BUILT: + VarInts.writeInt(buffer, ((PortalBuiltEventData) eventData).getDimensionId()); + break; + case PORTAL_USED: + PortalUsedEventData portalUsedEventData = (PortalUsedEventData) eventData; + VarInts.writeInt(buffer, portalUsedEventData.getFromDimensionId()); + VarInts.writeInt(buffer, portalUsedEventData.getToDimensionId()); + break; + case MOB_KILLED: + MobKilledEventData mobKilledEventData = (MobKilledEventData) eventData; + VarInts.writeLong(buffer, mobKilledEventData.getKillerUniqueEntityId()); + VarInts.writeLong(buffer, mobKilledEventData.getVictimUniqueEntityId()); + VarInts.writeInt(buffer, mobKilledEventData.getEntityDamageCause()); + VarInts.writeInt(buffer, mobKilledEventData.getVillagerTradeTier()); + BedrockUtils.writeString(buffer, mobKilledEventData.getVillagerDisplayName()); + break; + case CAULDRON_USED: + CauldronUsedEventData cauldronUsedEventData = (CauldronUsedEventData) eventData; + VarInts.writeUnsignedInt(buffer, cauldronUsedEventData.getPotionId()); + VarInts.writeInt(buffer, cauldronUsedEventData.getColor()); + VarInts.writeInt(buffer, cauldronUsedEventData.getFillLevel()); + break; + case PLAYER_DIED: + PlayerDiedEventData playerDiedEventData = (PlayerDiedEventData) eventData; + VarInts.writeInt(buffer, playerDiedEventData.getUnknown0()); + VarInts.writeInt(buffer, playerDiedEventData.getUnknown1()); + VarInts.writeInt(buffer, playerDiedEventData.getEntityDamageCause()); + buffer.writeBoolean(playerDiedEventData.isInRaid()); + break; + case BOSS_KILLED: + BossKilledEventData bossKilledEventData = (BossKilledEventData) eventData; + VarInts.writeLong(buffer, bossKilledEventData.getBossUniqueEntityId()); + VarInts.writeInt(buffer, bossKilledEventData.getPlayerPartySize()); + VarInts.writeInt(buffer, bossKilledEventData.getLegacyEntityTypeId()); + break; + case AGENT_COMMAND: + AgentCommandEventData agentCommandEventData = (AgentCommandEventData) eventData; + VarInts.writeInt(buffer, agentCommandEventData.getAgentResult()); + VarInts.writeInt(buffer, agentCommandEventData.getDataValue()); + BedrockUtils.writeString(buffer, agentCommandEventData.getCommand()); + BedrockUtils.writeString(buffer, agentCommandEventData.getDataKey()); + BedrockUtils.writeString(buffer, agentCommandEventData.getOutput()); + break; + case PATTERN_REMOVED: + PatternRemovedEventData patternRemovedEventData = (PatternRemovedEventData) eventData; + VarInts.writeInt(buffer, patternRemovedEventData.getItemId()); + VarInts.writeInt(buffer, patternRemovedEventData.getAuxValue()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternsSize()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternIndex()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternColor()); + break; + case SLASH_COMMAND_EXECUTED: + SlashCommandExecutedEventData slashCommandExecutedEventData = (SlashCommandExecutedEventData) eventData; + VarInts.writeInt(buffer, slashCommandExecutedEventData.getSuccessCount()); + List outputMessages = slashCommandExecutedEventData.getOutputMessages(); + VarInts.writeInt(buffer, outputMessages.size()); + BedrockUtils.writeString(buffer, slashCommandExecutedEventData.getCommandName()); + BedrockUtils.writeString(buffer, String.join(";", outputMessages)); + break; + case FISH_BUCKETED: + FishBucketedEventData fishBucketedEventData = (FishBucketedEventData) eventData; + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown0()); + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown1()); + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown2()); + buffer.writeBoolean(fishBucketedEventData.isUnknown3()); + break; + case MOB_BORN: + MobBornEventData mobBornEventData = (MobBornEventData) eventData; + VarInts.writeInt(buffer, mobBornEventData.getLegacyEntityTypeId()); + VarInts.writeInt(buffer, mobBornEventData.getVariant()); + buffer.writeByte(mobBornEventData.getColor()); + break; + case PET_DIED: + PetDiedEventData petDiedEventData = (PetDiedEventData) eventData; + buffer.writeBoolean(petDiedEventData.isUnknown0()); + VarInts.writeLong(buffer, petDiedEventData.getKillerUniqueEntityId()); + VarInts.writeLong(buffer, petDiedEventData.getPetUniqueEntityId()); + VarInts.writeInt(buffer, petDiedEventData.getEntityDamageCause()); + VarInts.writeInt(buffer, petDiedEventData.getUnknown1()); + break; + case CAULDRON_BLOCK_USED: + CauldronBlockUsedEventData cauldronBlockUsedEventData = (CauldronBlockUsedEventData) eventData; + VarInts.writeInt(buffer, cauldronBlockUsedEventData.getBlockInteractionType()); + VarInts.writeInt(buffer, cauldronBlockUsedEventData.getUnknown0()); + break; + case COMPOSTER_BLOCK_USED: + ComposterBlockUsedEventData composterBlockUsedEventData = (ComposterBlockUsedEventData) eventData; + VarInts.writeInt(buffer, composterBlockUsedEventData.getBlockInteractionType()); + VarInts.writeInt(buffer, composterBlockUsedEventData.getUnknown0()); + break; + case BELL_BLOCK_USED: + VarInts.writeInt(buffer, ((BellBlockUsedEventData) eventData).getUnknown0()); + break; + case AGENT_CREATED: + // No extra data + break; + } + } + + @Override + public void deserialize(ByteBuf buffer, EventPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + + int eventId = VarInts.readInt(buffer); + Preconditions.checkElementIndex(eventId, VALUES.length, "EventDataType"); + EventDataType type = VALUES[eventId]; + + packet.setUnknown0(buffer.readByte()); + + EventData data; + + switch (type) { + case ACHIEVEMENT_AWARDED: + data = new AchievementAwardedEventData(VarInts.readInt(buffer)); + break; + case ENTITY_INTERACT: + int interactionType = VarInts.readInt(buffer); + int legacyEntityTypeId = VarInts.readInt(buffer); + int variant = VarInts.readInt(buffer); + int paletteColor = buffer.readUnsignedByte(); + data = new EntityInteractEventData(interactionType, legacyEntityTypeId, variant, paletteColor); + break; + case PORTAL_BUILT: + data = new PortalBuiltEventData(VarInts.readInt(buffer)); + break; + case PORTAL_USED: + int fromDimensionId = VarInts.readInt(buffer); + int toDimensionId = VarInts.readInt(buffer); + data = new PortalUsedEventData(fromDimensionId, toDimensionId); + break; + case MOB_KILLED: + long killerUniqueEntityId = VarInts.readLong(buffer); + long victimUniqueEntityId = VarInts.readLong(buffer); + int entityDamageCause = VarInts.readInt(buffer); + int villagerTradeTier = VarInts.readInt(buffer); + String villagerDisplayName = BedrockUtils.readString(buffer); + data = new MobKilledEventData(killerUniqueEntityId, victimUniqueEntityId, entityDamageCause, + villagerTradeTier, villagerDisplayName); + break; + case CAULDRON_USED: + int potionId = VarInts.readInt(buffer); + int color = VarInts.readInt(buffer); + int fillLevel = VarInts.readInt(buffer); + data = new CauldronUsedEventData(potionId, color, fillLevel); + break; + case PLAYER_DIED: + int unknown0 = VarInts.readInt(buffer); + int unknown1 = VarInts.readInt(buffer); + entityDamageCause = VarInts.readInt(buffer); + boolean inRaid = buffer.readBoolean(); + data = new PlayerDiedEventData(unknown0, unknown1, entityDamageCause, inRaid); + break; + case BOSS_KILLED: + long bossUniqueEntityId = VarInts.readLong(buffer); + int playerPartySize = VarInts.readInt(buffer); + legacyEntityTypeId = VarInts.readInt(buffer); + data = new BossKilledEventData(bossUniqueEntityId, playerPartySize, legacyEntityTypeId); + break; + case AGENT_COMMAND: + int agentResult = VarInts.readInt(buffer); + int dataValue = VarInts.readInt(buffer); + String command = BedrockUtils.readString(buffer); + String dataKey = BedrockUtils.readString(buffer); + String output = BedrockUtils.readString(buffer); + data = new AgentCommandEventData(agentResult, command, dataKey, dataValue, output); + break; + case AGENT_CREATED: + data = AgentCreatedEventData.INSTANCE; + break; + case PATTERN_REMOVED: + int itemId = VarInts.readInt(buffer); + int auxValue = VarInts.readInt(buffer); + int patternsSize = VarInts.readInt(buffer); + int patternIndex = VarInts.readInt(buffer); + int patternColor = VarInts.readInt(buffer); + data = new PatternRemovedEventData(itemId, auxValue, patternsSize, patternIndex, patternColor); + break; + case SLASH_COMMAND_EXECUTED: + int successCount = VarInts.readInt(buffer); + VarInts.readInt(buffer); + String commandName = BedrockUtils.readString(buffer); + List outputMessages = Arrays.asList(BedrockUtils.readString(buffer).split(";")); + data = new SlashCommandExecutedEventData(commandName, successCount, outputMessages); + break; + case FISH_BUCKETED: + unknown0 = VarInts.readInt(buffer); + unknown1 = VarInts.readInt(buffer); + int unknown2 = VarInts.readInt(buffer); + boolean unknown3 = buffer.readBoolean(); + data = new FishBucketedEventData(unknown0, unknown1, unknown2, unknown3); + break; + case MOB_BORN: + legacyEntityTypeId = VarInts.readInt(buffer); + variant = VarInts.readInt(buffer); + color = buffer.readUnsignedByte(); + data = new MobBornEventData(legacyEntityTypeId, variant, color); + break; + case PET_DIED: + boolean unknownBool = buffer.readBoolean(); + killerUniqueEntityId = VarInts.readLong(buffer); + long petUniqueEntityId = VarInts.readLong(buffer); + entityDamageCause = VarInts.readInt(buffer); + unknown1 = VarInts.readInt(buffer); + data = new PetDiedEventData(unknownBool, killerUniqueEntityId, petUniqueEntityId, entityDamageCause, + unknown1); + break; + case CAULDRON_BLOCK_USED: + int blockInterationType = VarInts.readInt(buffer); + unknown0 = VarInts.readInt(buffer); + data = new CauldronBlockUsedEventData(blockInterationType, unknown0); + break; + case COMPOSTER_BLOCK_USED: + blockInterationType = VarInts.readInt(buffer); + unknown0 = VarInts.readInt(buffer); + data = new ComposterBlockUsedEventData(blockInterationType, unknown0); + break; + case BELL_BLOCK_USED: + data = new BellBlockUsedEventData(VarInts.readInt(buffer)); + break; + default: + throw new IllegalArgumentException("Unknown EventDataType"); + } + packet.setEventData(data); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java new file mode 100644 index 000000000..86e0e1ee5 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java @@ -0,0 +1,31 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ExplodePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ExplodeSerializer_v363 implements PacketSerializer { + public static final ExplodeSerializer_v363 INSTANCE = new ExplodeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ExplodePacket packet) { + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, (int) (packet.getRadius() * 32)); + + BedrockUtils.writeArray(buffer, packet.getRecords(), BedrockUtils::writeVector3i); + } + + @Override + public void deserialize(ByteBuf buffer, ExplodePacket packet) { + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setRadius(VarInts.readInt(buffer) / 32f); + + BedrockUtils.readArray(buffer, packet.getRecords(), BedrockUtils::readVector3i); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java new file mode 100644 index 000000000..7866dc8c0 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java @@ -0,0 +1,34 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class GameRulesChangedSerializer_v363 implements PacketSerializer { + public static final GameRulesChangedSerializer_v363 INSTANCE = new GameRulesChangedSerializer_v363(); + + public static final Object2IntMap> RULE_TYPES = new Object2IntOpenHashMap<>(3, 0.5f); + + static { + RULE_TYPES.defaultReturnValue(-1); + RULE_TYPES.put(Boolean.class, 1); + RULE_TYPES.put(Integer.class, 2); + RULE_TYPES.put(Float.class, 3); + } + + @Override + public void serialize(ByteBuf buffer, GameRulesChangedPacket packet) { + BedrockUtils.writeArray(buffer, packet.getGameRules(), BedrockUtils::writeGameRule); + } + + @Override + public void deserialize(ByteBuf buffer, GameRulesChangedPacket packet) { + BedrockUtils.readArray(buffer, packet.getGameRules(), BedrockUtils::readGameRule); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java new file mode 100644 index 000000000..5be1666e4 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.GuiDataPickItemPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class GuiDataPickItemSerializer_v363 implements PacketSerializer { + public static final GuiDataPickItemSerializer_v363 INSTANCE = new GuiDataPickItemSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, GuiDataPickItemPacket packet) { + BedrockUtils.writeString(buffer, packet.getDescription()); + BedrockUtils.writeString(buffer, packet.getItemEffects()); + buffer.writeIntLE(packet.getHotbarSlot()); + } + + @Override + public void deserialize(ByteBuf buffer, GuiDataPickItemPacket packet) { + packet.setDescription(BedrockUtils.readString(buffer)); + packet.setItemEffects(BedrockUtils.readString(buffer)); + packet.setHotbarSlot(buffer.readIntLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java new file mode 100644 index 000000000..f3cf70f1c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.HurtArmorPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class HurtArmorSerializer_v363 implements PacketSerializer { + public static final HurtArmorSerializer_v363 INSTANCE = new HurtArmorSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, HurtArmorPacket packet) { + VarInts.writeInt(buffer, packet.getHealth()); + } + + @Override + public void deserialize(ByteBuf buffer, HurtArmorPacket packet) { + packet.setHealth(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java new file mode 100644 index 000000000..15c9de8b7 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java @@ -0,0 +1,36 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.InteractPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class InteractSerializer_v363 implements PacketSerializer { + public static final InteractSerializer_v363 INSTANCE = new InteractSerializer_v363(); + + private static final InteractPacket.Action[] ACTIONS = InteractPacket.Action.values(); + + @Override + public void serialize(ByteBuf buffer, InteractPacket packet) { + buffer.writeByte(packet.getAction().ordinal()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + + if (packet.getAction() == InteractPacket.Action.MOUSEOVER || packet.getAction() == InteractPacket.Action.NPC_OPEN) { + BedrockUtils.writeVector3f(buffer, packet.getMousePosition()); + } + } + + @Override + public void deserialize(ByteBuf buffer, InteractPacket packet) { + packet.setAction(ACTIONS[buffer.readUnsignedByte()]); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + + if (packet.getAction() == InteractPacket.Action.MOUSEOVER || packet.getAction() == InteractPacket.Action.NPC_OPEN) { + packet.setMousePosition(BedrockUtils.readVector3f(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java new file mode 100644 index 000000000..70b66c2d2 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java @@ -0,0 +1,38 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.ItemData; +import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class InventoryContentSerializer_v363 implements PacketSerializer { + public static final InventoryContentSerializer_v363 INSTANCE = new InventoryContentSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, InventoryContentPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getContainerId()); + + ItemData[] contents = packet.getContents(); + VarInts.writeUnsignedInt(buffer, contents.length); + for (ItemData content : contents) { + BedrockUtils.writeItemData(buffer, content); + } + } + + @Override + public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { + packet.setContainerId(VarInts.readUnsignedInt(buffer)); + + ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; + for (int i = 0; i < contents.length; i++) { + contents[i] = BedrockUtils.readItemData(buffer); + } + packet.setContents(contents); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java new file mode 100644 index 000000000..4c8941e3a --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class InventorySlotSerializer_v363 implements PacketSerializer { + public static final InventorySlotSerializer_v363 INSTANCE = new InventorySlotSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, InventorySlotPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getContainerId()); + VarInts.writeUnsignedInt(buffer, packet.getSlot()); + BedrockUtils.writeItemData(buffer, packet.getItem()); + } + + @Override + public void deserialize(ByteBuf buffer, InventorySlotPacket packet) { + packet.setContainerId(VarInts.readUnsignedInt(buffer)); + packet.setSlot(VarInts.readUnsignedInt(buffer)); + packet.setItem(BedrockUtils.readItemData(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java new file mode 100644 index 000000000..f34daa7a9 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java @@ -0,0 +1,85 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket.Type; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class InventoryTransactionSerializer_v363 implements PacketSerializer { + public static final InventoryTransactionSerializer_v363 INSTANCE = new InventoryTransactionSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, InventoryTransactionPacket packet) { + Type transactionType = packet.getTransactionType(); + VarInts.writeUnsignedInt(buffer, transactionType.ordinal()); + + BedrockUtils.writeArray(buffer, packet.getActions(), BedrockUtils::writeInventoryAction); + + switch (transactionType) { + case ITEM_USE: + VarInts.writeUnsignedInt(buffer, packet.getActionType()); + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeInt(buffer, packet.getFace()); + VarInts.writeInt(buffer, packet.getHotbarSlot()); + BedrockUtils.writeItemData(buffer, packet.getItemInHand()); + BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); + BedrockUtils.writeVector3f(buffer, packet.getClickPosition()); + VarInts.writeUnsignedInt(buffer, packet.getBlockRuntimeId()); + break; + case ITEM_USE_ON_ENTITY: + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeUnsignedInt(buffer, packet.getActionType()); + VarInts.writeInt(buffer, packet.getHotbarSlot()); + BedrockUtils.writeItemData(buffer, packet.getItemInHand()); + BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); + BedrockUtils.writeVector3f(buffer, packet.getClickPosition()); + break; + case ITEM_RELEASE: + VarInts.writeUnsignedInt(buffer, packet.getActionType()); + VarInts.writeInt(buffer, packet.getHotbarSlot()); + BedrockUtils.writeItemData(buffer, packet.getItemInHand()); + BedrockUtils.writeVector3f(buffer, packet.getHeadPosition()); + } + } + + @Override + public void deserialize(ByteBuf buffer, InventoryTransactionPacket packet) { + Type transactionType = Type.values()[VarInts.readUnsignedInt(buffer)]; + packet.setTransactionType(transactionType); + + BedrockUtils.readArray(buffer, packet.getActions(), BedrockUtils::readInventoryAction); + + switch (transactionType) { + case ITEM_USE: + packet.setActionType(VarInts.readUnsignedInt(buffer)); + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setFace(VarInts.readInt(buffer)); + packet.setHotbarSlot(VarInts.readInt(buffer)); + packet.setItemInHand(BedrockUtils.readItemData(buffer)); + packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); + packet.setClickPosition(BedrockUtils.readVector3f(buffer)); + packet.setBlockRuntimeId(VarInts.readUnsignedInt(buffer)); + break; + case ITEM_USE_ON_ENTITY: + packet.setRuntimeEntityId(VarInts.readUnsignedInt(buffer)); + packet.setActionType(VarInts.readUnsignedInt(buffer)); + packet.setHotbarSlot(VarInts.readInt(buffer)); + packet.setItemInHand(BedrockUtils.readItemData(buffer)); + packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); + packet.setClickPosition(BedrockUtils.readVector3f(buffer)); + break; + case ITEM_RELEASE: + packet.setActionType(VarInts.readUnsignedInt(buffer)); + packet.setHotbarSlot(VarInts.readInt(buffer)); + packet.setItemInHand(BedrockUtils.readItemData(buffer)); + packet.setHeadPosition(BedrockUtils.readVector3f(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java new file mode 100644 index 000000000..f4e889587 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ItemFrameDropItemPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ItemFrameDropItemSerializer_v363 implements PacketSerializer { + public static final ItemFrameDropItemSerializer_v363 INSTANCE = new ItemFrameDropItemSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ItemFrameDropItemPacket packet) { + BedrockUtils.writeVector3i(buffer, packet.getBlockPosition()); + } + + @Override + public void deserialize(ByteBuf buffer, ItemFrameDropItemPacket packet) { + packet.setBlockPosition(BedrockUtils.readVector3i(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java new file mode 100644 index 000000000..d2dabaf90 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.LabTablePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LabTableSerializer_v363 implements PacketSerializer { + public static final LabTableSerializer_v363 INSTANCE = new LabTableSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, LabTablePacket packet) { + buffer.writeByte(packet.getUnknownByte0()); + BedrockUtils.writeVector3i(buffer, packet.getBlockEntityPosition()); + buffer.writeByte(packet.getReactionType()); + } + + @Override + public void deserialize(ByteBuf buffer, LabTablePacket packet) { + packet.setUnknownByte0(buffer.readByte()); + packet.setBlockEntityPosition(BedrockUtils.readVector3i(buffer)); + packet.setReactionType(buffer.readByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java new file mode 100644 index 000000000..754a36bf1 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java @@ -0,0 +1,29 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.LecternUpdatePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LecternUpdateSerializer_v363 implements PacketSerializer { + public static final LecternUpdateSerializer_v363 INSTANCE = new LecternUpdateSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, LecternUpdatePacket packet) { + buffer.writeByte(packet.getPage()); + buffer.writeByte(packet.getTotalPages()); + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + buffer.writeBoolean(packet.isDroppingBook()); + } + + @Override + public void deserialize(ByteBuf buffer, LecternUpdatePacket packet) { + packet.setPage(buffer.readUnsignedByte()); + packet.setTotalPages(buffer.readUnsignedByte()); + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setDroppingBook(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java new file mode 100644 index 000000000..6d3a305c6 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java @@ -0,0 +1,52 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.longs.LongList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelChunkSerializer_v363 implements PacketSerializer { + public static final LevelChunkSerializer_v363 INSTANCE = new LevelChunkSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, LevelChunkPacket packet) { + VarInts.writeInt(buffer, packet.getChunkX()); + VarInts.writeInt(buffer, packet.getChunkZ()); + VarInts.writeUnsignedInt(buffer, packet.getSubChunksLength()); + buffer.writeBoolean(packet.isCachingEnabled()); + if (packet.isCachingEnabled()) { + LongList blobIds = packet.getBlobIds(); + VarInts.writeUnsignedInt(buffer, blobIds.size()); + + for (long blobId : blobIds) { + buffer.writeLongLE(blobId); + } + } + + BedrockUtils.writeByteArray(buffer, packet.getData()); + } + + @Override + public void deserialize(ByteBuf buffer, LevelChunkPacket packet) { + packet.setChunkX(VarInts.readInt(buffer)); + packet.setChunkZ(VarInts.readInt(buffer)); + packet.setSubChunksLength(VarInts.readUnsignedInt(buffer)); + packet.setCachingEnabled(buffer.readBoolean()); + + if (packet.isCachingEnabled()) { + LongList blobIds = packet.getBlobIds(); + int length = VarInts.readUnsignedInt(buffer); + + for (int i = 0; i < length; i++) { + blobIds.add(buffer.readLongLE()); + } + } + packet.setData(BedrockUtils.readByteArray(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java new file mode 100644 index 000000000..1f4a64ff7 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java @@ -0,0 +1,40 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.LevelEventGenericPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelEventGenericSerializer_v363 implements PacketSerializer { + public static final LevelEventGenericSerializer_v363 INSTANCE = new LevelEventGenericSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, LevelEventGenericPacket packet) { + VarInts.writeInt(buffer, packet.getEventId()); + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, LevelEventGenericPacket packet) { + packet.setEventId(VarInts.readInt(buffer)); + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setTag(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java new file mode 100644 index 000000000..481a02c19 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java @@ -0,0 +1,170 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.LevelEventType; +import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.data.LevelEventType.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelEventSerializer_v363 implements PacketSerializer { + public static final LevelEventSerializer_v363 INSTANCE = new LevelEventSerializer_v363(); + + private static final InternalLogger log = InternalLoggerFactory.getInstance(LevelEventSerializer_v363.class); + private static final Int2ObjectBiMap events = new Int2ObjectBiMap<>(); + + static { + events.put(1000, SOUND_CLICK); + events.put(1001, SOUND_CLICK_FAIL); + events.put(1002, SOUND_SHOOT); + events.put(1003, SOUND_DOOR); + events.put(1004, SOUND_FIZZ); + events.put(1005, SOUND_IGNITE); + events.put(1007, SOUND_GHAST); + events.put(1008, SOUND_GHAST_SHOOT); + events.put(1009, SOUND_BLAZE_SHOOT); + events.put(1010, SOUND_DOOR_BUMP); + events.put(1012, SOUND_DOOR_CRASH); + events.put(1018, SOUND_ENDERMAN_TELEPORT); + events.put(1020, SOUND_ANVIL_BREAK); + events.put(1021, SOUND_ANVIL_USE); + events.put(1022, SOUND_ANVIL_FALL); + events.put(1030, SOUND_POP); + events.put(1032, SOUND_PORTAL); + events.put(1040, SOUND_ITEMFRAME_ADD_ITEM); + events.put(1041, SOUND_ITEMFRAME_REMOVE); + events.put(1042, SOUND_ITEMFRAME_PLACE); + events.put(1043, SOUND_ITEMFRAME_REMOVE_ITEM); + events.put(1044, SOUND_ITEMFRAME_ROTATE_ITEM); + events.put(1050, SOUND_CAMERA); + events.put(1051, SOUND_ORB); + events.put(1052, SOUND_TOTEM); + events.put(1060, SOUND_ARMOR_STAND_BREAK); + events.put(1061, SOUND_ARMOR_STAND_HIT); + events.put(1062, SOUND_ARMOR_STAND_FALL); + events.put(1063, SOUND_ARMOR_STAND_PLACE); + events.put(2000, SHOOT); + events.put(2001, DESTROY); + events.put(2002, SPLASH); + events.put(2003, EYE_DESPAWN); + events.put(2004, ENTITY_SPAWN); + events.put(2005, BONEMEAL); + events.put(2006, GUARDIAN_CURSE); + events.put(2008, BLOCK_FORCE_FIELD); + events.put(2009, PROJECTILE_HIT); + events.put(2010, DRAGON_EGG_TELEPORT); + events.put(2013, ENDERMAN_TELEPORT); + events.put(2014, PUNCH_BLOCK); + events.put(2015, WATER_SPLASH); + events.put(3001, START_RAIN); + events.put(3002, START_THUNDER); + events.put(3003, STOP_RAIN); + events.put(3004, STOP_THUNDER); + events.put(3005, PAUSE_GAME); + events.put(3500, REDSTONE_TRIGGER); + events.put(3501, CAULDRON_EXPLODE); + events.put(3502, CAULDRON_DYE_ARMOR); + events.put(3503, CAULDRON_CLEAN_ARMOR); + events.put(3504, CAULDRON_FILL_POTION); + events.put(3505, CAULDRON_TAKE_POTION); + events.put(3506, CAULDRON_FILL_WATER); + events.put(3507, CAULDRON_TAKE_WATER); + events.put(3508, CAULDRON_ADD_DYE); + events.put(3509, CAULDRON_CLEAN_BANNER); + events.put(3600, BLOCK_START_BREAK); + events.put(3601, BLOCK_STOP_BREAK); + events.put(3602, BLOCK_CONTINUE_BREAK); + events.put(4000, SET_DATA); + events.put(9800, PLAYERS_SLEEPING); + + // Particles + events.put((1 | 0x4000), PARTICLE_BUBBLE); + // 2 same as 1 + events.put((3 | 0x4000), PARTICLE_CRITICAL); + events.put((4 | 0x4000), PARTICLE_BLOCK_FORCE_FIELD); + events.put((5 | 0x4000), PARTICLE_SMOKE); + events.put((6 | 0x4000), PARTICLE_EXPLODE); + events.put((7 | 0x4000), PARTICLE_EVAPORATION); + events.put((8 | 0x4000), PARTICLE_FLAME); + events.put((9 | 0x4000), PARTICLE_LAVA); + events.put((10 | 0x4000), PARTICLE_LARGE_SMOKE); + events.put((11 | 0x4000), PARTICLE_REDSTONE); + events.put((12 | 0x4000), PARTICLE_RISING_RED_DUST); + // 62 same as 12 + events.put((13 | 0x4000), PARTICLE_ITEM_BREAK); + events.put((14 | 0x4000), PARTICLE_SNOWBALL_POOF); + events.put((15 | 0x4000), PARTICLE_HUGE_EXPLODE); + // 60 same as 15 + events.put((16 | 0x4000), PARTICLE_HUGE_EXPLODE_SEED); + events.put((17 | 0x4000), PARTICLE_MOB_FLAME); + events.put((18 | 0x4000), PARTICLE_HEART); + events.put((19 | 0x4000), PARTICLE_TERRAIN); + events.put((20 | 0x4000), PARTICLE_TOWN_AURA); + // 61 same as 20 + events.put((21 | 0x4000), PARTICLE_PORTAL); + // 22 same as 21 + events.put((23 | 0x4000), PARTICLE_SPLASH); + // 24 same as 23 + events.put((25 | 0x4000), PARTICLE_WATER_WAKE); + events.put((26 | 0x4000), PARTICLE_DRIP_WATER); + events.put((27 | 0x4000), PARTICLE_DRIP_LAVA); + events.put((28 | 0x4000), PARTICLE_FALLING_DUST); + events.put((29 | 0x4000), PARTICLE_MOB_SPELL); + events.put((30 | 0x4000), PARTICLE_MOB_SPELL_AMBIENT); + events.put((31 | 0x4000), PARTICLE_MOB_SPELL_INSTANTANEOUS); + events.put((32 | 0x4000), PARTICLE_INK); + events.put((33 | 0x4000), PARTICLE_SLIME); + events.put((34 | 0x4000), PARTICLE_RAIN_SPLASH); + events.put((35 | 0x4000), PARTICLE_VILLAGER_ANGRY); + // 59 same as 35 + events.put((36 | 0x4000), PARTICLE_VILLAGER_HAPPY); + events.put((37 | 0x4000), PARTICLE_ENCHANTMENT_TABLE); + events.put((38 | 0x4000), PARTICLE_TRACKING_EMITTER); + events.put((39 | 0x4000), PARTICLE_NOTE); + events.put((40 | 0x4000), PARTICLE_WITCH_SPELL); + events.put((41 | 0x4000), PARTICLE_CARROT); + // 42 unknown + events.put((43 | 0x4000), PARTICLE_END_ROD); + // 58 same as 43 + events.put((44 | 0x4000), PARTICLE_DRAGONS_BREATH); + events.put((45 | 0x4000), PARTICLE_SPIT); + events.put((46 | 0x4000), PARTICLE_TOTEM); + events.put((47 | 0x4000), PARTICLE_FOOD); + events.put((48 | 0x4000), PARTICLE_FIREWORKS_STARTER); + events.put((49 | 0x4000), PARTICLE_FIREWORKS_SPARK); + events.put((50 | 0x4000), PARTICLE_FIREWORKS_OVERLAY); + events.put((51 | 0x4000), PARTICLE_BALLOON_GAS); + events.put((52 | 0x4000), PARTICLE_COLORED_FLAME); + events.put((53 | 0x4000), PARTICLE_SPARKLER); + events.put((54 | 0x4000), PARTICLE_CONDUIT); + events.put((55 | 0x4000), PARTICLE_BUBBLE_COLUMN_UP); + events.put((56 | 0x4000), PARTICLE_BUBBLE_COLUMN_DOWN); + events.put((57 | 0x4000), PARTICLE_SNEEZE); + } + + @Override + public void serialize(ByteBuf buffer, LevelEventPacket packet) { + VarInts.writeInt(buffer, events.get(packet.getType())); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getData()); + } + + @Override + public void deserialize(ByteBuf buffer, LevelEventPacket packet) { + int eventId = VarInts.readInt(buffer); + packet.setType(events.get(eventId)); + if (packet.getType() == null) { + log.debug("Unknown Level Event {} received", eventId); + } + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setData(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java new file mode 100644 index 000000000..d611a90bf --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java @@ -0,0 +1,292 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.SoundEvent; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent1Packet; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.data.SoundEvent.*; + + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelSoundEvent1Serializer_v363 implements PacketSerializer { + public static final LevelSoundEvent1Serializer_v363 INSTANCE = new LevelSoundEvent1Serializer_v363(); + + static final Int2ObjectBiMap SOUNDS = new Int2ObjectBiMap<>(2, 0.5F, 255, UNDEFINED); + + static { + SOUNDS.put(0, ITEM_USE_ON); + SOUNDS.put(1, HIT); + SOUNDS.put(2, STEP); + SOUNDS.put(3, FLY); + SOUNDS.put(4, JUMP); + SOUNDS.put(5, BREAK); + SOUNDS.put(6, PLACE); + SOUNDS.put(7, HEAVY_STEP); + SOUNDS.put(8, GALLOP); + SOUNDS.put(9, FALL); + SOUNDS.put(10, AMBIENT); + SOUNDS.put(11, AMBIENT_BABY); + SOUNDS.put(12, AMBIENT_IN_WATER); + SOUNDS.put(13, BREATHE); + SOUNDS.put(14, DEATH); + SOUNDS.put(15, DEATH_IN_WATER); + SOUNDS.put(16, DEATH_TO_ZOMBIE); + SOUNDS.put(17, HURT); + SOUNDS.put(18, HURT_IN_WATER); + SOUNDS.put(19, MAD); + SOUNDS.put(20, BOOST); + SOUNDS.put(21, BOW); + SOUNDS.put(22, SQUISH_BIG); + SOUNDS.put(23, SQUISH_SMALL); + SOUNDS.put(24, FALL_BIG); + SOUNDS.put(25, FALL_SMALL); + SOUNDS.put(26, SPLASH); + SOUNDS.put(27, FIZZ); + SOUNDS.put(28, FLAP); + SOUNDS.put(29, SWIM); + SOUNDS.put(30, DRINK); + SOUNDS.put(31, EAT); + SOUNDS.put(32, TAKEOFF); + SOUNDS.put(33, SHAKE); + SOUNDS.put(34, PLOP); + SOUNDS.put(35, LAND); + SOUNDS.put(36, SADDLE); + SOUNDS.put(37, ARMOR); + SOUNDS.put(38, MOB_ARMOR_STAND_PLACE); + SOUNDS.put(39, ADD_CHEST); + SOUNDS.put(40, THROW); + SOUNDS.put(41, ATTACK); + SOUNDS.put(42, ATTACK_NODAMAGE); + SOUNDS.put(43, ATTACK_STRONG); + SOUNDS.put(44, WARN); + SOUNDS.put(45, SHEAR); + SOUNDS.put(46, MILK); + SOUNDS.put(47, THUNDER); + SOUNDS.put(48, EXPLODE); + SOUNDS.put(49, FIRE); + SOUNDS.put(50, IGNITE); + SOUNDS.put(51, FUSE); + SOUNDS.put(52, STARE); + SOUNDS.put(53, SPAWN); + SOUNDS.put(54, SHOOT); + SOUNDS.put(55, BREAK_BLOCK); + SOUNDS.put(56, LAUNCH); + SOUNDS.put(57, BLAST); + SOUNDS.put(58, LARGE_BLAST); + SOUNDS.put(59, TWINKLE); + SOUNDS.put(60, REMEDY); + SOUNDS.put(61, UNFECT); + SOUNDS.put(62, LEVELUP); + SOUNDS.put(63, BOW_HIT); + SOUNDS.put(64, BULLET_HIT); + SOUNDS.put(65, EXTINGUISH_FIRE); + SOUNDS.put(66, ITEM_FIZZ); + SOUNDS.put(67, CHEST_OPEN); + SOUNDS.put(68, CHEST_CLOSED); + SOUNDS.put(69, SHULKERBOX_OPEN); + SOUNDS.put(70, SHULKERBOX_CLOSED); + SOUNDS.put(71, ENDERCHEST_OPEN); + SOUNDS.put(72, ENDERCHEST_CLOSED); + SOUNDS.put(73, POWER_ON); + SOUNDS.put(74, POWER_OFF); + SOUNDS.put(75, ATTACH); + SOUNDS.put(76, DETACH); + SOUNDS.put(77, DENY); + SOUNDS.put(78, TRIPOD); + SOUNDS.put(79, POP); + SOUNDS.put(80, DROP_SLOT); + SOUNDS.put(81, NOTE); + SOUNDS.put(82, THORNS); + SOUNDS.put(83, PISTON_IN); + SOUNDS.put(84, PISTON_OUT); + SOUNDS.put(85, PORTAL); + SOUNDS.put(86, WATER); + SOUNDS.put(87, LAVA_POP); + SOUNDS.put(88, LAVA); + SOUNDS.put(89, BURP); + SOUNDS.put(90, BUCKET_FILL_WATER); + SOUNDS.put(91, BUCKET_FILL_LAVA); + SOUNDS.put(92, BUCKET_EMPTY_WATER); + SOUNDS.put(93, BUCKET_EMPTY_LAVA); + SOUNDS.put(94, ARMOR_EQUIP_CHAIN); + SOUNDS.put(95, ARMOR_EQUIP_DIAMOND); + SOUNDS.put(96, ARMOR_EQUIP_GENERIC); + SOUNDS.put(97, ARMOR_EQUIP_GOLD); + SOUNDS.put(98, ARMOR_EQUIP_IRON); + SOUNDS.put(99, ARMOR_EQUIP_LEATHER); + SOUNDS.put(100, ARMOR_EQUIP_ELYTRA); + SOUNDS.put(101, RECORD_13); + SOUNDS.put(102, RECORD_CAT); + SOUNDS.put(103, RECORD_BLOCKS); + SOUNDS.put(104, RECORD_CHIRP); + SOUNDS.put(105, RECORD_FAR); + SOUNDS.put(106, RECORD_MALL); + SOUNDS.put(107, RECORD_MELLOHI); + SOUNDS.put(108, RECORD_STAL); + SOUNDS.put(109, RECORD_STRAD); + SOUNDS.put(110, RECORD_WARD); + SOUNDS.put(111, RECORD_11); + SOUNDS.put(112, RECORD_WAIT); + SOUNDS.put(113, STOP_RECORD); //Not really a sound + SOUNDS.put(114, FLOP); + SOUNDS.put(115, ELDERGUARDIAN_CURSE); + SOUNDS.put(116, MOB_WARNING); + SOUNDS.put(117, MOB_WARNING_BABY); + SOUNDS.put(118, TELEPORT); + SOUNDS.put(119, SHULKER_OPEN); + SOUNDS.put(120, SHULKER_CLOSE); + SOUNDS.put(121, HAGGLE); + SOUNDS.put(122, HAGGLE_YES); + SOUNDS.put(123, HAGGLE_NO); + SOUNDS.put(124, HAGGLE_IDLE); + SOUNDS.put(125, CHORUSGROW); + SOUNDS.put(126, CHORUSDEATH); + SOUNDS.put(127, GLASS); + SOUNDS.put(128, POTION_BREWED); + SOUNDS.put(129, CAST_SPELL); + SOUNDS.put(130, PREPARE_ATTACK); + SOUNDS.put(131, PREPARE_SUMMON); + SOUNDS.put(132, PREPARE_WOLOLO); + SOUNDS.put(133, FANG); + SOUNDS.put(134, CHARGE); + SOUNDS.put(135, CAMERA_TAKE_PICTURE); + SOUNDS.put(136, LEASHKNOT_PLACE); + SOUNDS.put(137, LEASHKNOT_BREAK); + SOUNDS.put(138, GROWL); + SOUNDS.put(139, WHINE); + SOUNDS.put(140, PANT); + SOUNDS.put(141, PURR); + SOUNDS.put(142, PURREOW); + SOUNDS.put(143, DEATH_MIN_VOLUME); + SOUNDS.put(144, DEATH_MID_VOLUME); + SOUNDS.put(145, IMITATE_BLAZE); + SOUNDS.put(146, IMITATE_CAVE_SPIDER); + SOUNDS.put(147, IMITATE_CREEPER); + SOUNDS.put(148, IMITATE_ELDER_GUARDIAN); + SOUNDS.put(149, IMITATE_ENDER_DRAGON); + SOUNDS.put(150, IMITATE_ENDERMAN); + SOUNDS.put(152, IMITATE_EVOCATION_ILLAGER); + SOUNDS.put(153, IMITATE_GHAST); + SOUNDS.put(154, IMITATE_HUSK); + SOUNDS.put(155, IMITATE_ILLUSION_ILLAGER); + SOUNDS.put(156, IMITATE_MAGMA_CUBE); + SOUNDS.put(157, IMITATE_POLAR_BEAR); + SOUNDS.put(158, IMITATE_SHULKER); + SOUNDS.put(159, IMITATE_SILVERFISH); + SOUNDS.put(160, IMITATE_SKELETON); + SOUNDS.put(161, IMITATE_SLIME); + SOUNDS.put(162, IMITATE_SPIDER); + SOUNDS.put(163, IMITATE_STRAY); + SOUNDS.put(164, IMITATE_VEX); + SOUNDS.put(165, IMITATE_VINDICATION_ILLAGER); + SOUNDS.put(166, IMITATE_WITCH); + SOUNDS.put(167, IMITATE_WITHER); + SOUNDS.put(168, IMITATE_WITHER_SKELETON); + SOUNDS.put(169, IMITATE_WOLF); + SOUNDS.put(170, IMITATE_ZOMBIE); + SOUNDS.put(171, IMITATE_ZOMBIE_PIGMAN); + SOUNDS.put(172, IMITATE_ZOMBIE_VILLAGER); + SOUNDS.put(173, BLOCK_END_PORTAL_FRAME_FILL); + SOUNDS.put(174, BLOCK_END_PORTAL_SPAWN); + SOUNDS.put(175, RANDOM_ANVIL_USE); + SOUNDS.put(176, BOTTLE_DRAGONBREATH); + SOUNDS.put(177, PORTAL_TRAVEL); + SOUNDS.put(178, ITEM_TRIDENT_HIT); + SOUNDS.put(179, ITEM_TRIDENT_RETURN); + SOUNDS.put(180, ITEM_TRIDENT_RIPTIDE_1); + SOUNDS.put(181, ITEM_TRIDENT_RIPTIDE_2); + SOUNDS.put(182, ITEM_TRIDENT_RIPTIDE_3); + SOUNDS.put(183, ITEM_TRIDENT_THROW); + SOUNDS.put(184, ITEM_TRIDENT_THUNDER); + SOUNDS.put(185, ITEM_TRIDENT_HIT_GROUND); + SOUNDS.put(186, DEFAULT); + SOUNDS.put(188, ELEMENT_CONSTRUCTOR_OPEN); + SOUNDS.put(189, ICE_BOMB_HIT); + SOUNDS.put(190, BALLOON_POP); + SOUNDS.put(191, LT_REACTION_ICE_BOMB); + SOUNDS.put(192, LT_REACTION_BLEACH); + SOUNDS.put(193, LT_REACTION_E_PASTE); + SOUNDS.put(194, LT_REACTION_E_PASTE2); + SOUNDS.put(199, LT_REACTION_FERTILIZER); + SOUNDS.put(200, LT_REACTION_FIREBALL); + SOUNDS.put(201, LT_REACTION_MG_SALT); + SOUNDS.put(202, LT_REACTION_MISC_FIRE); + SOUNDS.put(203, LT_REACTION_FIRE); + SOUNDS.put(204, LT_REACTION_MISC_EXPLOSION); + SOUNDS.put(205, LT_REACTION_MISC_MYSTICAL); + SOUNDS.put(206, LT_REACTION_MISC_MYSTICAL2); + SOUNDS.put(207, LT_REACTION_PRODUCT); + SOUNDS.put(208, SPARKLER_USE); + SOUNDS.put(209, GLOWSTICK_USE); + SOUNDS.put(210, SPARKLER_ACTIVE); + SOUNDS.put(211, CONVERT_TO_DROWNED); + SOUNDS.put(212, BUCKET_FILL_FISH); + SOUNDS.put(213, BUCKET_EMPTY_FISH); + SOUNDS.put(214, BUBBLE_UP); + SOUNDS.put(215, BUBBLE_DOWN); + SOUNDS.put(216, BUBBLE_POP); + SOUNDS.put(217, BUBBLE_UP_INSIDE); + SOUNDS.put(218, BUBBLE_DOWN_INSIDE); + SOUNDS.put(219, HURT_BABY); + SOUNDS.put(220, DEATH_BABY); + SOUNDS.put(221, STEP_BABY); + SOUNDS.put(223, BORN); + SOUNDS.put(224, BLOCK_TURTLE_EGG_BREAK); + SOUNDS.put(225, BLOCK_TURTLE_EGG_CRACK); + SOUNDS.put(226, BLOCK_TURTLE_EGG_HATCH); + SOUNDS.put(228, BLOCK_TURTLE_EGG_ATTACK); + SOUNDS.put(229, BEACON_ACTIVATE); + SOUNDS.put(230, BEACON_AMBIENT); + SOUNDS.put(231, BEACON_DEACTIVATE); + SOUNDS.put(232, BEACON_POWER); + SOUNDS.put(233, CONDUIT_ACTIVATE); + SOUNDS.put(234, CONDUIT_AMBIENT); + SOUNDS.put(235, CONDUIT_ATTACK); + SOUNDS.put(236, CONDUIT_DEACTIVATE); + SOUNDS.put(237, CONDUIT_SHORT); + SOUNDS.put(238, SWOOP); + SOUNDS.put(239, BLOCK_BAMBOO_SAPLING_PLACE); + SOUNDS.put(240, PRE_SNEEZE); + SOUNDS.put(241, SNEEZE); + SOUNDS.put(242, AMBIENT_TAME); + SOUNDS.put(243, SCARED); + SOUNDS.put(244, BLOCK_SCAFFOLDING_CLIMB); + SOUNDS.put(245, CROSSBOW_LOADING_START); + SOUNDS.put(246, CROSSBOW_LOADING_MIDDLE); + SOUNDS.put(247, CROSSBOW_LOADING_END); + SOUNDS.put(248, CROSSBOW_SHOOT); + SOUNDS.put(249, CROSSBOW_QUICK_CHARGE_START); + SOUNDS.put(250, CROSSBOW_QUICK_CHARGE_MIDDLE); + SOUNDS.put(251, CROSSBOW_QUICK_CHARGE_END); + SOUNDS.put(252, AMBIENT_AGGRESSIVE); + SOUNDS.put(253, AMBIENT_WORRIED); + SOUNDS.put(254, CANT_BREED); + SOUNDS.put(255, UNDEFINED); + } + + @Override + public void serialize(ByteBuf buffer, LevelSoundEvent1Packet packet) { + VarInts.writeInt(buffer, SOUNDS.get(packet.getSound())); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getExtraData()); + VarInts.writeInt(buffer, packet.getPitch()); + buffer.writeBoolean(packet.isBabySound()); + buffer.writeBoolean(packet.isRelativeVolumeDisabled()); + } + + @Override + public void deserialize(ByteBuf buffer, LevelSoundEvent1Packet packet) { + packet.setSound(SOUNDS.get(VarInts.readInt(buffer))); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setExtraData(VarInts.readInt(buffer)); + packet.setPitch(VarInts.readInt(buffer)); + packet.setBabySound(buffer.readBoolean()); + packet.setRelativeVolumeDisabled(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java new file mode 100644 index 000000000..0e044866b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java @@ -0,0 +1,36 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.v363.serializer.LevelSoundEvent1Serializer_v363.SOUNDS; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelSoundEvent2Serializer_v363 implements PacketSerializer { + public static final LevelSoundEvent2Serializer_v363 INSTANCE = new LevelSoundEvent2Serializer_v363(); + + @Override + public void serialize(ByteBuf buffer, LevelSoundEvent2Packet packet) { + buffer.writeByte(SOUNDS.get(packet.getSound())); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getExtraData()); + BedrockUtils.writeString(buffer, packet.getIdentifier()); + buffer.writeBoolean(packet.isBabySound()); + buffer.writeBoolean(packet.isRelativeVolumeDisabled()); + } + + @Override + public void deserialize(ByteBuf buffer, LevelSoundEvent2Packet packet) { + packet.setSound(SOUNDS.get(buffer.readUnsignedByte())); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setExtraData(VarInts.readInt(buffer)); + packet.setIdentifier(BedrockUtils.readString(buffer)); + packet.setBabySound(buffer.readBoolean()); + packet.setRelativeVolumeDisabled(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java new file mode 100644 index 000000000..6f76a1b4d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java @@ -0,0 +1,37 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.v363.serializer.LevelSoundEvent1Serializer_v363.SOUNDS; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LevelSoundEvent3Serializer_v363 implements PacketSerializer { + public static final LevelSoundEvent3Serializer_v363 INSTANCE = new LevelSoundEvent3Serializer_v363(); + + @Override + public void serialize(ByteBuf buffer, LevelSoundEventPacket packet) { + VarInts.writeUnsignedInt(buffer, SOUNDS.get(packet.getSound())); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getExtraData()); + BedrockUtils.writeString(buffer, packet.getIdentifier()); + buffer.writeBoolean(packet.isBabySound()); + buffer.writeBoolean(packet.isRelativeVolumeDisabled()); + } + + @Override + public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) { + packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer))); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setExtraData(VarInts.readInt(buffer)); + packet.setIdentifier(BedrockUtils.readString(buffer)); + packet.setBabySound(buffer.readBoolean()); + packet.setRelativeVolumeDisabled(buffer.readBoolean()); + } +} + diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java new file mode 100644 index 000000000..d76beaf4d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java @@ -0,0 +1,38 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.LoginPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.util.AsciiString; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class LoginSerializer_v363 implements PacketSerializer { + public static final LoginSerializer_v363 INSTANCE = new LoginSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, LoginPacket packet) { + buffer.writeInt(packet.getProtocolVersion()); + + AsciiString chainData = packet.getChainData(); + AsciiString skinData = packet.getSkinData(); + + VarInts.writeUnsignedInt(buffer, chainData.length() + skinData.length() + 8); + + BedrockUtils.writeLEAsciiString(buffer, chainData); + BedrockUtils.writeLEAsciiString(buffer, skinData); + } + + @Override + public void deserialize(ByteBuf buffer, LoginPacket packet) { + packet.setProtocolVersion(buffer.readInt()); + + ByteBuf jwt = buffer.readSlice(VarInts.readUnsignedInt(buffer)); // Get the JWT. + packet.setChainData(BedrockUtils.readLEAsciiString(jwt)); + packet.setSkinData(BedrockUtils.readLEAsciiString(jwt)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java new file mode 100644 index 000000000..244c7a4ab --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MapCreateLockedCopyPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MapCreateLockedCopySerializer_v363 implements PacketSerializer { + public static final MapCreateLockedCopySerializer_v363 INSTANCE = new MapCreateLockedCopySerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, MapCreateLockedCopyPacket packet) { + VarInts.writeLong(buffer, packet.getOriginalMapId()); + VarInts.writeLong(buffer, packet.getNewMapId()); + } + + @Override + public void deserialize(ByteBuf buffer, MapCreateLockedCopyPacket packet) { + packet.setOriginalMapId(VarInts.readLong(buffer)); + packet.setNewMapId(VarInts.readLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java new file mode 100644 index 000000000..d293dd5c4 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MapInfoRequestSerializer_v363 implements PacketSerializer { + public static final MapInfoRequestSerializer_v363 INSTANCE = new MapInfoRequestSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, MapInfoRequestPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueMapId()); + } + + @Override + public void deserialize(ByteBuf buffer, MapInfoRequestPacket packet) { + packet.setUniqueMapId(VarInts.readLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java new file mode 100644 index 000000000..463e5fa10 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MobArmorEquipmentSerializer_v363 implements PacketSerializer { + public static final MobArmorEquipmentSerializer_v363 INSTANCE = new MobArmorEquipmentSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, MobArmorEquipmentPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeItemData(buffer, packet.getHelmet()); + BedrockUtils.writeItemData(buffer, packet.getChestplate()); + BedrockUtils.writeItemData(buffer, packet.getLeggings()); + BedrockUtils.writeItemData(buffer, packet.getBoots()); + } + + @Override + public void deserialize(ByteBuf buffer, MobArmorEquipmentPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setHelmet(BedrockUtils.readItemData(buffer)); + packet.setChestplate(BedrockUtils.readItemData(buffer)); + packet.setLeggings(BedrockUtils.readItemData(buffer)); + packet.setBoots(BedrockUtils.readItemData(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java new file mode 100644 index 000000000..481ae22de --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java @@ -0,0 +1,34 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MobEffectSerializer_v363 implements PacketSerializer { + public static final MobEffectSerializer_v363 INSTANCE = new MobEffectSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, MobEffectPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + buffer.writeByte(packet.getEvent().ordinal()); + VarInts.writeInt(buffer, packet.getEffectId()); + VarInts.writeInt(buffer, packet.getAmplifier()); + buffer.writeBoolean(packet.isParticles()); + VarInts.writeInt(buffer, packet.getDuration()); + } + + @Override + public void deserialize(ByteBuf buffer, MobEffectPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setEvent(MobEffectPacket.Event.values()[buffer.readUnsignedByte()]); + packet.setEffectId(VarInts.readInt(buffer)); + packet.setAmplifier(VarInts.readInt(buffer)); + packet.setParticles(buffer.readBoolean()); + packet.setDuration(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java new file mode 100644 index 000000000..5ff83ce6b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java @@ -0,0 +1,32 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MobEquipmentSerializer_v363 implements PacketSerializer { + public static final MobEquipmentSerializer_v363 INSTANCE = new MobEquipmentSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, MobEquipmentPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeItemData(buffer, packet.getItem()); + buffer.writeByte(packet.getInventorySlot()); + buffer.writeByte(packet.getHotbarSlot()); + buffer.writeByte(packet.getContainerId()); + } + + @Override + public void deserialize(ByteBuf buffer, MobEquipmentPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setItem(BedrockUtils.readItemData(buffer)); + packet.setInventorySlot(buffer.readUnsignedByte()); + packet.setHotbarSlot(buffer.readUnsignedByte()); + packet.setContainerId(buffer.readByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java new file mode 100644 index 000000000..72a19b485 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ModalFormRequestSerializer_v363 implements PacketSerializer { + public static final ModalFormRequestSerializer_v363 INSTANCE = new ModalFormRequestSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ModalFormRequestPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getFormId()); + BedrockUtils.writeString(buffer, packet.getFormData()); + } + + @Override + public void deserialize(ByteBuf buffer, ModalFormRequestPacket packet) { + packet.setFormId(VarInts.readUnsignedInt(buffer)); + packet.setFormData(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java new file mode 100644 index 000000000..81607d764 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ModalFormResponsePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ModalFormResponseSerializer_v363 implements PacketSerializer { + public static final ModalFormResponseSerializer_v363 INSTANCE = new ModalFormResponseSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ModalFormResponsePacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getFormId()); + BedrockUtils.writeString(buffer, packet.getFormData()); + } + + @Override + public void deserialize(ByteBuf buffer, ModalFormResponsePacket packet) { + packet.setFormId(VarInts.readUnsignedInt(buffer)); + packet.setFormData(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java new file mode 100644 index 000000000..1af179e15 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java @@ -0,0 +1,42 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MoveEntityAbsoluteSerializer_v363 implements PacketSerializer { + public static final MoveEntityAbsoluteSerializer_v363 INSTANCE = new MoveEntityAbsoluteSerializer_v363(); + + private static final int FLAG_ON_GROUND = 0x1; + private static final int FLAG_TELEPORTED = 0x2; + + @Override + public void serialize(ByteBuf buffer, MoveEntityAbsolutePacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + int flags = 0; + if (packet.isOnGround()) { + flags |= FLAG_ON_GROUND; + } + if (packet.isTeleported()) { + flags |= FLAG_TELEPORTED; + } + buffer.writeByte(flags); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeByteRotation(buffer, packet.getRotation()); + } + + @Override + public void deserialize(ByteBuf buffer, MoveEntityAbsolutePacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + int flags = buffer.readUnsignedByte(); + packet.setOnGround((flags & FLAG_ON_GROUND) != 0); + packet.setTeleported((flags & FLAG_TELEPORTED) != 0); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readByteRotation(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java new file mode 100644 index 000000000..b879b81ac --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java @@ -0,0 +1,84 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MoveEntityDeltaPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MoveEntityDeltaSerializer_v363 implements PacketSerializer { + public static final MoveEntityDeltaSerializer_v363 INSTANCE = new MoveEntityDeltaSerializer_v363(); + + private static final int HAS_X = 0x01; + private static final int HAS_Y = 0x02; + private static final int HAS_Z = 0x4; + private static final int HAS_PITCH = 0x8; + private static final int HAS_YAW = 0x10; + private static final int HAS_ROLL = 0x20; + + @Override + public void serialize(ByteBuf buffer, MoveEntityDeltaPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + byte flags = 0; + Vector3i movementDelta = packet.getMovementDelta(); + Vector3f rotationDelta = packet.getRotationDelta(); + flags |= movementDelta.getX() != 0 ? HAS_X : 0; + flags |= movementDelta.getY() != 0 ? HAS_Y : 0; + flags |= movementDelta.getZ() != 0 ? HAS_Z : 0; + flags |= rotationDelta.getX() != 0 ? HAS_PITCH : 0; + flags |= rotationDelta.getY() != 0 ? HAS_YAW : 0; + flags |= rotationDelta.getZ() != 0 ? HAS_ROLL : 0; + buffer.writeByte(flags); + if ((flags & HAS_X) != 0) { + VarInts.writeInt(buffer, movementDelta.getX()); + } + if ((flags & HAS_Y) != 0) { + VarInts.writeInt(buffer, movementDelta.getY()); + } + if ((flags & HAS_Z) != 0) { + VarInts.writeInt(buffer, movementDelta.getZ()); + } + if ((flags & HAS_PITCH) != 0) { + BedrockUtils.writeByteAngle(buffer, rotationDelta.getX()); + } + if ((flags & HAS_YAW) != 0) { + BedrockUtils.writeByteAngle(buffer, rotationDelta.getY()); + } + if ((flags & HAS_ROLL) != 0) { + BedrockUtils.writeByteAngle(buffer, rotationDelta.getZ()); + } + } + + @Override + public void deserialize(ByteBuf buffer, MoveEntityDeltaPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + byte flags = buffer.readByte(); + int x = 0, y = 0, z = 0; + float pitch = 0, yaw = 0, roll = 0; + if ((flags & HAS_X) != 0) { + x = VarInts.readInt(buffer); + } + if ((flags & HAS_Y) != 0) { + y = VarInts.readInt(buffer); + } + if ((flags & HAS_Z) != 0) { + z = VarInts.readInt(buffer); + } + if ((flags & HAS_PITCH) != 0) { + pitch = BedrockUtils.readByteAngle(buffer); + } + if ((flags & HAS_YAW) != 0) { + yaw = BedrockUtils.readByteAngle(buffer); + } + if ((flags & HAS_ROLL) != 0) { + roll = BedrockUtils.readByteAngle(buffer); + } + packet.setMovementDelta(Vector3i.from(x, y, z)); + packet.setRotationDelta(Vector3f.from(pitch, yaw, roll)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java new file mode 100644 index 000000000..d89be426c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java @@ -0,0 +1,46 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.MovePlayerPacket.Mode; +import static com.nukkitx.protocol.bedrock.packet.MovePlayerPacket.TeleportationCause; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class MovePlayerSerializer_v363 implements PacketSerializer { + public static final MovePlayerSerializer_v363 INSTANCE = new MovePlayerSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, MovePlayerPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeVector3f(buffer, packet.getRotation()); + buffer.writeByte(packet.getMode().ordinal()); + buffer.writeBoolean(packet.isOnGround()); + VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); + if (packet.getMode() == Mode.TELEPORT) { + buffer.writeIntLE(packet.getTeleportationCause().ordinal()); + buffer.writeIntLE(packet.getEntityType()); + } + } + + @Override + public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readVector3f(buffer)); + packet.setMode(Mode.values()[buffer.readByte()]); + packet.setOnGround(buffer.readBoolean()); + packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + if (packet.getMode() == Mode.TELEPORT) { + packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); + packet.setEntityType(buffer.readIntLE()); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java new file mode 100644 index 000000000..05434b5f9 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.MultiplayerMode; +import com.nukkitx.protocol.bedrock.packet.MultiplayerSettingsPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class MultiplayerSettingsSerializer_v363 implements PacketSerializer { + + public static final MultiplayerSettingsSerializer_v363 INSTANCE = new MultiplayerSettingsSerializer_v363(); + + private static final MultiplayerMode[] VALUES = MultiplayerMode.values(); + + @Override + public void serialize(ByteBuf buffer, MultiplayerSettingsPacket packet) { + VarInts.writeInt(buffer, packet.getMode().ordinal()); + } + + @Override + public void deserialize(ByteBuf buffer, MultiplayerSettingsPacket packet) { + packet.setMode(VALUES[VarInts.readInt(buffer)]); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java new file mode 100644 index 000000000..286c9ae07 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NetworkChunkPublisherUpdateSerializer_v363 implements PacketSerializer { + public static final NetworkChunkPublisherUpdateSerializer_v363 INSTANCE = new NetworkChunkPublisherUpdateSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, NetworkChunkPublisherUpdatePacket packet) { + BedrockUtils.writeVector3i(buffer, packet.getPosition()); + VarInts.writeUnsignedInt(buffer, packet.getRadius()); + } + + @Override + public void deserialize(ByteBuf buffer, NetworkChunkPublisherUpdatePacket packet) { + packet.setPosition(BedrockUtils.readVector3i(buffer)); + packet.setRadius(VarInts.readUnsignedInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java new file mode 100644 index 000000000..87e946296 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.NetworkSettingsPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class NetworkSettingsSerializer_v363 implements PacketSerializer { + + public static final NetworkSettingsSerializer_v363 INSTANCE = new NetworkSettingsSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, NetworkSettingsPacket packet) { + buffer.writeShortLE(packet.getCompressionThresholdByteSize()); + } + + @Override + public void deserialize(ByteBuf buffer, NetworkSettingsPacket packet) { + packet.setCompressionThresholdByteSize(buffer.readUnsignedShortLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java new file mode 100644 index 000000000..496a1ff0e --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NetworkStackLatencySerializer_v363 implements PacketSerializer { + public static final NetworkStackLatencySerializer_v363 INSTANCE = new NetworkStackLatencySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, NetworkStackLatencyPacket packet) { + buffer.writeLongLE(packet.getTimestamp()); + buffer.writeBoolean(packet.isSendBack()); + } + + @Override + public void deserialize(ByteBuf buffer, NetworkStackLatencyPacket packet) { + packet.setTimestamp(buffer.readLongLE()); + packet.setSendBack(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java new file mode 100644 index 000000000..f31a0017b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.NpcRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.NpcRequestPacket.Type; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NpcRequestSerializer_v363 implements PacketSerializer { + public static final NpcRequestSerializer_v363 INSTANCE = new NpcRequestSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, NpcRequestPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + buffer.writeByte(packet.getRequestType().ordinal()); + BedrockUtils.writeString(buffer, packet.getCommand()); + buffer.writeByte(packet.getActionType()); + } + + @Override + public void deserialize(ByteBuf buffer, NpcRequestPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setRequestType(Type.values()[buffer.readUnsignedByte()]); + packet.setCommand(BedrockUtils.readString(buffer)); + packet.setActionType(buffer.readUnsignedByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java new file mode 100644 index 000000000..98a6a037a --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java @@ -0,0 +1,22 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.OnScreenTextureAnimationPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class OnScreenTextureAnimationSerializer_v363 implements PacketSerializer { + public static final OnScreenTextureAnimationSerializer_v363 INSTANCE = new OnScreenTextureAnimationSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, OnScreenTextureAnimationPacket packet) { + buffer.writeIntLE((int) packet.getEffectId()); + } + + @Override + public void deserialize(ByteBuf buffer, OnScreenTextureAnimationPacket packet) { + packet.setEffectId(buffer.readUnsignedIntLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java new file mode 100644 index 000000000..8374ca447 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java @@ -0,0 +1,31 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.PacketHeader; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PacketHeaderSerializer_v363 implements PacketSerializer { + public static final PacketHeaderSerializer_v363 INSTANCE = new PacketHeaderSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PacketHeader packet) { + int header = 0; + header |= (packet.getPacketId() & 0x3ff); + header |= (packet.getSenderId() & 3) << 10; + header |= (packet.getClientId() & 3) << 12; + VarInts.writeUnsignedInt(buffer, header); + } + + @Override + public void deserialize(ByteBuf buffer, PacketHeader packet) { + int header = VarInts.readUnsignedInt(buffer); + packet.setPacketId(header & 0x3ff); + packet.setSenderId((header >>> 10) & 3); + packet.setClientId((header >>> 12) & 3); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java new file mode 100644 index 000000000..61892a14b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.PhotoTransferPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PhotoTransferSerializer_v363 implements PacketSerializer { + public static final PhotoTransferSerializer_v363 INSTANCE = new PhotoTransferSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PhotoTransferPacket packet) { + BedrockUtils.writeString(buffer, packet.getName()); + byte[] data = packet.getData(); + VarInts.writeUnsignedInt(buffer, data.length); + buffer.writeBytes(data); + BedrockUtils.writeString(buffer, packet.getBookId()); + } + + @Override + public void deserialize(ByteBuf buffer, PhotoTransferPacket packet) { + packet.setName(BedrockUtils.readString(buffer)); + byte[] data = new byte[VarInts.readUnsignedInt(buffer)]; + buffer.readBytes(data); + packet.setData(data); + packet.setBookId(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java new file mode 100644 index 000000000..5565ea2d0 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java @@ -0,0 +1,30 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.PlaySoundPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlaySoundSerializer_v363 implements PacketSerializer { + public static final PlaySoundSerializer_v363 INSTANCE = new PlaySoundSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlaySoundPacket packet) { + BedrockUtils.writeString(buffer, packet.getSound()); + BedrockUtils.writeBlockPosition(buffer, packet.getPosition().mul(8).toInt()); + buffer.writeFloatLE(packet.getVolume()); + buffer.writeFloatLE(packet.getPitch()); + } + + @Override + public void deserialize(ByteBuf buffer, PlaySoundPacket packet) { + packet.setSound(BedrockUtils.readString(buffer)); + packet.setPosition(BedrockUtils.readBlockPosition(buffer).toFloat().div(8)); + packet.setVolume(buffer.readFloatLE()); + packet.setPitch(buffer.readFloatLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java new file mode 100644 index 000000000..d59177226 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.PlayStatusPacket.Status; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayStatusSerializer_v363 implements PacketSerializer { + public static final PlayStatusSerializer_v363 INSTANCE = new PlayStatusSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayStatusPacket packet) { + buffer.writeInt(packet.getStatus().ordinal()); + } + + @Override + public void deserialize(ByteBuf buffer, PlayStatusPacket packet) { + packet.setStatus(Status.values()[buffer.readInt()]); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java new file mode 100644 index 000000000..fe0f1fca5 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.PlayerActionPacket.Action; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerActionSerializer_v363 implements PacketSerializer { + public static final PlayerActionSerializer_v363 INSTANCE = new PlayerActionSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayerActionPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeInt(buffer, packet.getAction().ordinal()); + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeInt(buffer, packet.getFace()); + } + + @Override + public void deserialize(ByteBuf buffer, PlayerActionPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setAction(Action.values()[VarInts.readInt(buffer)]); + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setFace(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java new file mode 100644 index 000000000..44d083154 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java @@ -0,0 +1,52 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.PlayerAuthInputPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerAuthInputSerializer_v363 implements PacketSerializer { + + public static final PlayerAuthInputSerializer_v363 INSTANCE = new PlayerAuthInputSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, PlayerAuthInputPacket packet) { + Vector3f rotation = packet.getRotation(); + buffer.writeFloatLE(rotation.getX()); + buffer.writeFloatLE(rotation.getY()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + buffer.writeFloatLE(packet.getMotion().getX()); + buffer.writeFloatLE(packet.getMotion().getY()); + buffer.writeFloatLE(rotation.getZ()); + VarInts.writeUnsignedLong(buffer, packet.getInputData()); + VarInts.writeUnsignedInt(buffer, packet.getInputMode()); + VarInts.writeUnsignedInt(buffer, packet.getPlayMode()); + + if (packet.getPlayMode() == 4) { // VR MODE + BedrockUtils.writeVector3f(buffer, packet.getVrGazeDirection()); + } + } + + @Override + public void deserialize(ByteBuf buffer, PlayerAuthInputPacket packet) { + float x = buffer.readFloatLE(); + float y = buffer.readFloatLE(); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setMotion(Vector2f.from(buffer.readFloatLE(), buffer.readFloatLE())); + float z = buffer.readFloatLE(); + packet.setRotation(Vector3f.from(x, y, z)); + packet.setInputData(VarInts.readUnsignedLong(buffer)); + packet.setInputMode(VarInts.readUnsignedInt(buffer)); + packet.setPlayMode(VarInts.readUnsignedInt(buffer)); + + if (packet.getPlayMode() == 4) { + packet.setVrGazeDirection(BedrockUtils.readVector3f(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java new file mode 100644 index 000000000..2e0e0c148 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerHotbarSerializer_v363 implements PacketSerializer { + public static final PlayerHotbarSerializer_v363 INSTANCE = new PlayerHotbarSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, PlayerHotbarPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getSelectedHotbarSlot()); + buffer.writeByte(packet.getContainerId()); + buffer.writeBoolean(packet.isSelectHotbarSlot()); + } + + @Override + public void deserialize(ByteBuf buffer, PlayerHotbarPacket packet) { + packet.setSelectedHotbarSlot(VarInts.readUnsignedInt(buffer)); + packet.setContainerId(buffer.readUnsignedByte()); + packet.setSelectHotbarSlot(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java new file mode 100644 index 000000000..717a3f996 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.PlayerInputPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerInputSerializer_v363 implements PacketSerializer { + public static final PlayerInputSerializer_v363 INSTANCE = new PlayerInputSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayerInputPacket packet) { + BedrockUtils.writeVector2f(buffer, packet.getInputMotion()); + buffer.writeBoolean(packet.isJumping()); + buffer.writeBoolean(packet.isSneaking()); + } + + @Override + public void deserialize(ByteBuf buffer, PlayerInputPacket packet) { + packet.setInputMotion(BedrockUtils.readVector2f(buffer)); + packet.setJumping(buffer.readBoolean()); + packet.setSneaking(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java new file mode 100644 index 000000000..78258a2fc --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java @@ -0,0 +1,70 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.ImageData; +import com.nukkitx.protocol.bedrock.data.SerializedSkin; +import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Action; +import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Entry; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerListSerializer_v363 implements PacketSerializer { + public static final PlayerListSerializer_v363 INSTANCE = new PlayerListSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayerListPacket packet) { + buffer.writeByte(packet.getAction().ordinal()); + VarInts.writeUnsignedInt(buffer, packet.getEntries().size()); + + for (Entry entry : packet.getEntries()) { + BedrockUtils.writeUuid(buffer, entry.getUuid()); + + if (packet.getAction() == Action.ADD) { + VarInts.writeLong(buffer, entry.getEntityId()); + BedrockUtils.writeString(buffer, entry.getName()); + SerializedSkin skin = entry.getSkin(); + BedrockUtils.writeString(buffer, skin.getSkinId()); + skin.getSkinData().checkLegacySkinSize(); + BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); + skin.getCapeData().checkLegacyCapeSize(); + BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); + BedrockUtils.writeString(buffer, skin.getGeometryName()); + BedrockUtils.writeString(buffer, skin.getGeometryData()); + BedrockUtils.writeString(buffer, entry.getXuid()); + BedrockUtils.writeString(buffer, entry.getPlatformChatId()); + } + } + } + + @Override + public void deserialize(ByteBuf buffer, PlayerListPacket packet) { + Action action = Action.values()[buffer.readUnsignedByte()]; + packet.setAction(action); + int length = VarInts.readUnsignedInt(buffer); + + for (int i = 0; i < length; i++) { + Entry entry = new Entry(BedrockUtils.readUuid(buffer)); + + if (action == Action.ADD) { + entry.setEntityId(VarInts.readLong(buffer)); + entry.setName(BedrockUtils.readString(buffer)); + String skinId = BedrockUtils.readString(buffer); + ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); + ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); + String geometryName = BedrockUtils.readString(buffer); + String geometryData = BedrockUtils.readString(buffer); + entry.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, false)); + entry.setXuid(BedrockUtils.readString(buffer)); + entry.setPlatformChatId(BedrockUtils.readString(buffer)); + } + packet.getEntries().add(entry); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java new file mode 100644 index 000000000..a5f07467c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java @@ -0,0 +1,46 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.data.ImageData; +import com.nukkitx.protocol.bedrock.data.SerializedSkin; +import com.nukkitx.protocol.bedrock.packet.PlayerSkinPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerSkinSerializer_v363 implements PacketSerializer { + public static final PlayerSkinSerializer_v363 INSTANCE = new PlayerSkinSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayerSkinPacket packet) { + BedrockUtils.writeUuid(buffer, packet.getUuid()); + SerializedSkin skin = packet.getSkin(); + BedrockUtils.writeString(buffer, skin.getSkinId()); + BedrockUtils.writeString(buffer, packet.getNewSkinName()); + BedrockUtils.writeString(buffer, packet.getOldSkinName()); + skin.getSkinData().checkLegacySkinSize(); + BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); + skin.getCapeData().checkLegacyCapeSize(); + BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); + BedrockUtils.writeString(buffer, skin.getGeometryName()); + BedrockUtils.writeString(buffer, skin.getGeometryData()); + buffer.writeBoolean(skin.isPremium()); + } + + @Override + public void deserialize(ByteBuf buffer, PlayerSkinPacket packet) { + packet.setUuid(BedrockUtils.readUuid(buffer)); + String skinId = BedrockUtils.readString(buffer); + packet.setNewSkinName(BedrockUtils.readString(buffer)); + packet.setOldSkinName(BedrockUtils.readString(buffer)); + ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); + ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); + String geometryName = BedrockUtils.readString(buffer); + String geometryData = BedrockUtils.readString(buffer); + boolean premium = buffer.readBoolean(); + packet.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, premium)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java new file mode 100644 index 000000000..eca51b511 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.PurchaseReceiptPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PurchaseReceiptSerializer_v363 implements PacketSerializer { + public static final PurchaseReceiptSerializer_v363 INSTANCE = new PurchaseReceiptSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PurchaseReceiptPacket packet) { + BedrockUtils.writeArray(buffer, packet.getReceipts(), BedrockUtils::writeString); + } + + @Override + public void deserialize(ByteBuf buffer, PurchaseReceiptPacket packet) { + BedrockUtils.readArray(buffer, packet.getReceipts(), BedrockUtils::readString); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java new file mode 100644 index 000000000..d85606aa1 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RemoveEntitySerializer_v363 implements PacketSerializer { + public static final RemoveEntitySerializer_v363 INSTANCE = new RemoveEntitySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, RemoveEntityPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, RemoveEntityPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java new file mode 100644 index 000000000..34c1e4c29 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RemoveObjectiveSerializer_v363 implements PacketSerializer { + public static final RemoveObjectiveSerializer_v363 INSTANCE = new RemoveObjectiveSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, RemoveObjectivePacket packet) { + BedrockUtils.writeString(buffer, packet.getObjectiveId()); + } + + @Override + public void deserialize(ByteBuf buffer, RemoveObjectivePacket packet) { + packet.setObjectiveId(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java new file mode 100644 index 000000000..a2d0f0309 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.RequestChunkRadiusPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RequestChunkRadiusSerializer_v363 implements PacketSerializer { + public static final RequestChunkRadiusSerializer_v363 INSTANCE = new RequestChunkRadiusSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, RequestChunkRadiusPacket packet) { + VarInts.writeInt(buffer, packet.getRadius()); + } + + @Override + public void deserialize(ByteBuf buffer, RequestChunkRadiusPacket packet) { + packet.setRadius(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java new file mode 100644 index 000000000..6d87dca98 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java @@ -0,0 +1,40 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePackChunkDataPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePackChunkDataSerializer_v363 implements PacketSerializer { + public static final ResourcePackChunkDataSerializer_v363 INSTANCE = new ResourcePackChunkDataSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ResourcePackChunkDataPacket packet) { + String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); + BedrockUtils.writeString(buffer, packInfo); + buffer.writeIntLE(packet.getChunkIndex()); + buffer.writeLongLE(packet.getProgress()); + byte[] data = packet.getData(); + buffer.writeIntLE(data.length); + buffer.writeBytes(data); + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePackChunkDataPacket packet) { + String[] packInfo = BedrockUtils.readString(buffer).split("_"); + packet.setPackId(UUID.fromString(packInfo[0])); + if (packInfo.length > 1) { + packet.setPackVersion(packInfo[1]); + } + packet.setChunkIndex(buffer.readIntLE()); + packet.setProgress(buffer.readLongLE()); + byte[] data = new byte[buffer.readIntLE()]; + buffer.readBytes(data); + packet.setData(data); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java new file mode 100644 index 000000000..ec6926ffd --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java @@ -0,0 +1,32 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePackChunkRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePackChunkRequestSerializer_v363 implements PacketSerializer { + public static final ResourcePackChunkRequestSerializer_v363 INSTANCE = new ResourcePackChunkRequestSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ResourcePackChunkRequestPacket packet) { + String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); + BedrockUtils.writeString(buffer, packInfo); + buffer.writeIntLE(packet.getChunkIndex()); + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePackChunkRequestPacket packet) { + String[] packInfo = BedrockUtils.readString(buffer).split("_"); + packet.setPackId(UUID.fromString(packInfo[0])); + if (packInfo.length > 1) { + packet.setPackVersion(packInfo[1]); + } + packet.setChunkIndex(buffer.readIntLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java new file mode 100644 index 000000000..565068159 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java @@ -0,0 +1,42 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePackClientResponsePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; + +import static com.nukkitx.protocol.bedrock.packet.ResourcePackClientResponsePacket.Status; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePackClientResponseSerializer_v363 implements PacketSerializer { + public static final ResourcePackClientResponseSerializer_v363 INSTANCE = new ResourcePackClientResponseSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ResourcePackClientResponsePacket packet) { + buffer.writeByte(packet.getStatus().ordinal()); + + List packIds = packet.getPackIds(); + buffer.writeShortLE(packIds.size()); + + for (String packId : packIds) { + BedrockUtils.writeString(buffer, packId); + } + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePackClientResponsePacket packet) { + Status status = Status.values()[buffer.readByte()]; + packet.setStatus(status); + + List packIds = packet.getPackIds(); + int packIdsCount = buffer.readShortLE(); + for (int i = 0; i < packIdsCount; i++) { + packIds.add(BedrockUtils.readString(buffer)); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java new file mode 100644 index 000000000..2d9d71a74 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java @@ -0,0 +1,58 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePackDataInfoPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +import static com.nukkitx.protocol.bedrock.packet.ResourcePackDataInfoPacket.Type.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePackDataInfoSerializer_v363 implements PacketSerializer { + public static final ResourcePackDataInfoSerializer_v363 INSTANCE = new ResourcePackDataInfoSerializer_v363(); + + public static final Int2ObjectBiMap TYPES = new Int2ObjectBiMap<>(INVALID); + + static { + TYPES.put(0, INVALID); + TYPES.put(1, RESOURCE); + TYPES.put(2, BEHAVIOR); + TYPES.put(3, WORLD_TEMPLATE); + TYPES.put(4, ADDON); + TYPES.put(5, SKINS); + TYPES.put(6, CACHED); + TYPES.put(7, COPY_PROTECTED); + } + + @Override + public void serialize(ByteBuf buffer, ResourcePackDataInfoPacket packet) { + String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); + BedrockUtils.writeString(buffer, packInfo); + buffer.writeIntLE((int) packet.getMaxChunkSize()); + buffer.writeIntLE((int) packet.getChunkCount()); + buffer.writeLongLE(packet.getCompressedPackSize()); + BedrockUtils.writeByteArray(buffer, packet.getHash()); + buffer.writeBoolean(packet.isPremium()); + buffer.writeByte(TYPES.get(packet.getType())); + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePackDataInfoPacket packet) { + String[] packInfo = BedrockUtils.readString(buffer).split("_"); + packet.setPackId(UUID.fromString(packInfo[0])); + if (packInfo.length > 1) { + packet.setPackVersion(packInfo[1]); + } + packet.setMaxChunkSize(buffer.readUnsignedIntLE()); + packet.setChunkCount(buffer.readUnsignedIntLE()); + packet.setCompressedPackSize(buffer.readLongLE()); + packet.setHash(BedrockUtils.readByteArray(buffer)); + packet.setPremium(buffer.readBoolean()); + packet.setType(TYPES.get(buffer.readUnsignedByte())); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java new file mode 100644 index 000000000..f05fbb649 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java @@ -0,0 +1,30 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePackStackPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePackStackSerializer_v363 implements PacketSerializer { + public static final ResourcePackStackSerializer_v363 INSTANCE = new ResourcePackStackSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ResourcePackStackPacket packet) { + buffer.writeBoolean(packet.isForcedToAccept()); + BedrockUtils.writeArray(buffer, packet.getBehaviorPacks(), BedrockUtils::writePackInstanceEntry); + BedrockUtils.writeArray(buffer, packet.getResourcePacks(), BedrockUtils::writePackInstanceEntry); + buffer.writeBoolean(packet.isExperimental()); + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePackStackPacket packet) { + packet.setForcedToAccept(buffer.readBoolean()); + BedrockUtils.readArray(buffer, packet.getBehaviorPacks(), BedrockUtils::readPackInstanceEntry); + BedrockUtils.readArray(buffer, packet.getResourcePacks(), BedrockUtils::readPackInstanceEntry); + packet.setExperimental(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java new file mode 100644 index 000000000..0dfa02b14 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java @@ -0,0 +1,29 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ResourcePacksInfoPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ResourcePacksInfoSerializer_v363 implements PacketSerializer { + public static final ResourcePacksInfoSerializer_v363 INSTANCE = new ResourcePacksInfoSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, ResourcePacksInfoPacket packet) { + buffer.writeBoolean(packet.isForcedToAccept()); + buffer.writeBoolean(packet.isScriptingEnabled()); + BedrockUtils.writePacksInfoEntries(buffer, packet.getBehaviorPackInfos()); + BedrockUtils.writePacksInfoEntries(buffer, packet.getResourcePackInfos()); + } + + @Override + public void deserialize(ByteBuf buffer, ResourcePacksInfoPacket packet) { + packet.setForcedToAccept(buffer.readBoolean()); + packet.setScriptingEnabled(buffer.readBoolean()); + packet.getBehaviorPackInfos().addAll(BedrockUtils.readPacksInfoEntries(buffer)); + packet.getResourcePackInfos().addAll(BedrockUtils.readPacksInfoEntries(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java new file mode 100644 index 000000000..20f1f1017 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.RespawnPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RespawnSerializer_v363 implements PacketSerializer { + public static final RespawnSerializer_v363 INSTANCE = new RespawnSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, RespawnPacket packet) { + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + } + + @Override + public void deserialize(ByteBuf buffer, RespawnPacket packet) { + packet.setPosition(BedrockUtils.readVector3f(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java new file mode 100644 index 000000000..784dae19a --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.RiderJumpPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RiderJumpSerializer_v363 implements PacketSerializer { + public static final RiderJumpSerializer_v363 INSTANCE = new RiderJumpSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, RiderJumpPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getJumpStrength()); + } + + @Override + public void deserialize(ByteBuf buffer, RiderJumpPacket packet) { + packet.setJumpStrength(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java new file mode 100644 index 000000000..b0a754afe --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ScriptCustomEventPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ScriptCustomEventSerializer_v363 implements PacketSerializer { + public static final ScriptCustomEventSerializer_v363 INSTANCE = new ScriptCustomEventSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ScriptCustomEventPacket packet) { + BedrockUtils.writeString(buffer, packet.getEventName()); + BedrockUtils.writeString(buffer, packet.getData()); + } + + @Override + public void deserialize(ByteBuf buffer, ScriptCustomEventPacket packet) { + packet.setEventName(BedrockUtils.readString(buffer)); + packet.setData(BedrockUtils.readString(buffer)); + } +} + diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java new file mode 100644 index 000000000..0acfb0894 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ServerSettingsRequestSerializer_v363 implements PacketSerializer { + public static final ServerSettingsRequestSerializer_v363 INSTANCE = new ServerSettingsRequestSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ServerSettingsRequestPacket packet) { + // No payload + } + + @Override + public void deserialize(ByteBuf buffer, ServerSettingsRequestPacket packet) { + // No payload + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java new file mode 100644 index 000000000..73f60105d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ServerSettingsResponseSerializer_v363 implements PacketSerializer { + public static final ServerSettingsResponseSerializer_v363 INSTANCE = new ServerSettingsResponseSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ServerSettingsResponsePacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getFormId()); + BedrockUtils.writeString(buffer, packet.getFormData()); + } + + @Override + public void deserialize(ByteBuf buffer, ServerSettingsResponsePacket packet) { + packet.setFormId(VarInts.readUnsignedInt(buffer)); + packet.setFormData(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java new file mode 100644 index 000000000..d9ff66501 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.annotation.NoEncryption; +import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoEncryption // This is sent in plain text to complete the Diffie Hellman key exchange. +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ServerToClientHandshakeSerializer_v363 implements PacketSerializer { + public static final ServerToClientHandshakeSerializer_v363 INSTANCE = new ServerToClientHandshakeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ServerToClientHandshakePacket packet) { + BedrockUtils.writeString(buffer, packet.getJwt()); + } + + @Override + public void deserialize(ByteBuf buffer, ServerToClientHandshakePacket packet) { + packet.setJwt(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java new file mode 100644 index 000000000..b06cf1121 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.SetCommandsEnabledPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetCommandsEnabledSerializer_v363 implements PacketSerializer { + public static final SetCommandsEnabledSerializer_v363 INSTANCE = new SetCommandsEnabledSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetCommandsEnabledPacket packet) { + buffer.writeBoolean(packet.isCommandsEnabled()); + } + + @Override + public void deserialize(ByteBuf buffer, SetCommandsEnabledPacket packet) { + packet.setCommandsEnabled(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java new file mode 100644 index 000000000..86404cf1c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetDefaultGameTypePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetDefaultGameTypeSerializer_v363 implements PacketSerializer { + public static final SetDefaultGameTypeSerializer_v363 INSTANCE = new SetDefaultGameTypeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetDefaultGameTypePacket packet) { + VarInts.writeInt(buffer, packet.getGamemode()); + } + + @Override + public void deserialize(ByteBuf buffer, SetDefaultGameTypePacket packet) { + packet.setGamemode(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java new file mode 100644 index 000000000..d7dc3c25d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetDifficultySerializer_v363 implements PacketSerializer { + public static final SetDifficultySerializer_v363 INSTANCE = new SetDifficultySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetDifficultyPacket packet) { + VarInts.writeInt(buffer, packet.getDifficulty()); + } + + @Override + public void deserialize(ByteBuf buffer, SetDifficultyPacket packet) { + packet.setDifficulty(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java new file mode 100644 index 000000000..c9fd21040 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetDisplayObjectiveSerializer_v363 implements PacketSerializer { + public static final SetDisplayObjectiveSerializer_v363 INSTANCE = new SetDisplayObjectiveSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetDisplayObjectivePacket packet) { + BedrockUtils.writeString(buffer, packet.getDisplaySlot()); + BedrockUtils.writeString(buffer, packet.getObjectiveId()); + BedrockUtils.writeString(buffer, packet.getDisplayName()); + BedrockUtils.writeString(buffer, packet.getCriteria()); + VarInts.writeInt(buffer, packet.getSortOrder()); + } + + @Override + public void deserialize(ByteBuf buffer, SetDisplayObjectivePacket packet) { + packet.setDisplaySlot(BedrockUtils.readString(buffer)); + packet.setObjectiveId(BedrockUtils.readString(buffer)); + packet.setDisplayName(BedrockUtils.readString(buffer)); + packet.setCriteria(BedrockUtils.readString(buffer)); + packet.setSortOrder(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java new file mode 100644 index 000000000..24792b970 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetEntityDataSerializer_v363 implements PacketSerializer { + public static final SetEntityDataSerializer_v363 INSTANCE = new SetEntityDataSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetEntityDataPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeEntityData(buffer, packet.getMetadata()); + } + + @Override + public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + BedrockUtils.readEntityData(buffer, packet.getMetadata()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java new file mode 100644 index 000000000..19671c51d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetEntityLinkSerializer_v363 implements PacketSerializer { + public static final SetEntityLinkSerializer_v363 INSTANCE = new SetEntityLinkSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetEntityLinkPacket packet) { + BedrockUtils.writeEntityLink(buffer, packet.getEntityLink()); + } + + @Override + public void deserialize(ByteBuf buffer, SetEntityLinkPacket packet) { + packet.setEntityLink(BedrockUtils.readEntityLink(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java new file mode 100644 index 000000000..988a704d6 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetEntityMotionSerializer_v363 implements PacketSerializer { + public static final SetEntityMotionSerializer_v363 INSTANCE = new SetEntityMotionSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetEntityMotionPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeVector3f(buffer, packet.getMotion()); + } + + @Override + public void deserialize(ByteBuf buffer, SetEntityMotionPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setMotion(BedrockUtils.readVector3f(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java new file mode 100644 index 000000000..6d9c69d28 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetHealthPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetHealthSerializer_v363 implements PacketSerializer { + public static final SetHealthSerializer_v363 INSTANCE = new SetHealthSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetHealthPacket packet) { + VarInts.writeInt(buffer, packet.getHealth()); + } + + @Override + public void deserialize(ByteBuf buffer, SetHealthPacket packet) { + packet.setHealth(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java new file mode 100644 index 000000000..ced4e4b7a --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetLastHurtByPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetLastHurtBySerializer_v363 implements PacketSerializer { + public static final SetLastHurtBySerializer_v363 INSTANCE = new SetLastHurtBySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetLastHurtByPacket packet) { + VarInts.writeInt(buffer, packet.getEntityTypeId()); + } + + @Override + public void deserialize(ByteBuf buffer, SetLastHurtByPacket packet) { + packet.setEntityTypeId(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java new file mode 100644 index 000000000..dcf9654f5 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetLocalPlayerAsInitializedSerializer_v363 implements PacketSerializer { + public static final SetLocalPlayerAsInitializedSerializer_v363 INSTANCE = new SetLocalPlayerAsInitializedSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetLocalPlayerAsInitializedPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, SetLocalPlayerAsInitializedPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java new file mode 100644 index 000000000..a7f2b00b1 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetPlayerGameTypeSerializer_v363 implements PacketSerializer { + public static final SetPlayerGameTypeSerializer_v363 INSTANCE = new SetPlayerGameTypeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) { + VarInts.writeInt(buffer, packet.getGamemode()); + } + + @Override + public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) { + packet.setGamemode(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java new file mode 100644 index 000000000..b9bccafee --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java @@ -0,0 +1,73 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.ScoreInfo; +import com.nukkitx.protocol.bedrock.packet.SetScorePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.SetScorePacket.Action; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetScoreSerializer_v363 implements PacketSerializer { + public static final SetScoreSerializer_v363 INSTANCE = new SetScoreSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetScorePacket packet) { + Action action = packet.getAction(); + buffer.writeByte(action.ordinal()); + + BedrockUtils.writeArray(buffer, packet.getInfos(), (buf, scoreInfo) -> { + VarInts.writeLong(buf, scoreInfo.getScoreboardId()); + BedrockUtils.writeString(buf, scoreInfo.getObjectiveId()); + buf.writeIntLE(scoreInfo.getScore()); + if (action == Action.SET) { + buf.writeByte(scoreInfo.getType().ordinal()); + switch (scoreInfo.getType()) { + case ENTITY: + case PLAYER: + VarInts.writeLong(buf, scoreInfo.getEntityId()); + break; + case FAKE: + BedrockUtils.writeString(buf, scoreInfo.getName()); + break; + default: + throw new IllegalArgumentException("Invalid score info received"); + } + } + }); + } + + @Override + public void deserialize(ByteBuf buffer, SetScorePacket packet) { + Action action = Action.values()[buffer.readUnsignedByte()]; + packet.setAction(action); + + BedrockUtils.readArray(buffer, packet.getInfos(), buf -> { + long scoreboardId = VarInts.readLong(buf); + String objectiveId = BedrockUtils.readString(buf); + int score = buf.readIntLE(); + if (action == Action.SET) { + ScoreInfo.ScorerType type = ScoreInfo.ScorerType.values()[buf.readUnsignedByte()]; + switch (type) { + case ENTITY: + case PLAYER: + long entityId = VarInts.readLong(buf); + return new ScoreInfo(scoreboardId, objectiveId, score, type, entityId); + case FAKE: + String name = BedrockUtils.readString(buf); + return new ScoreInfo(scoreboardId, objectiveId, score, name); + default: + throw new IllegalArgumentException("Invalid score info received"); + } + } else { + return new ScoreInfo(scoreboardId, objectiveId, score); + } + }); + } + +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java new file mode 100644 index 000000000..e8fbbadc3 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java @@ -0,0 +1,46 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +import static com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket.Action; +import static com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket.Entry; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetScoreboardIdentitySerializer_v363 implements PacketSerializer { + public static final SetScoreboardIdentitySerializer_v363 INSTANCE = new SetScoreboardIdentitySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetScoreboardIdentityPacket packet) { + SetScoreboardIdentityPacket.Action action = packet.getAction(); + buffer.writeByte(action.ordinal()); + BedrockUtils.writeArray(buffer, packet.getEntries(), (buf, entry) -> { + VarInts.writeLong(buffer, entry.getScoreboardId()); + if (action == SetScoreboardIdentityPacket.Action.ADD) { + BedrockUtils.writeUuid(buffer, entry.getUuid()); + } + }); + } + + @Override + public void deserialize(ByteBuf buffer, SetScoreboardIdentityPacket packet) { + Action action = Action.values()[buffer.readUnsignedByte()]; + packet.setAction(action); + BedrockUtils.readArray(buffer, packet.getEntries(), buf -> { + long scoreboardId = VarInts.readLong(buffer); + UUID uuid = null; + if (action == Action.ADD) { + uuid = BedrockUtils.readUuid(buffer); + } + return new Entry(scoreboardId, uuid); + }); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java new file mode 100644 index 000000000..c5ba67d25 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java @@ -0,0 +1,29 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetSpawnPositionPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetSpawnPositionSerializer_v363 implements PacketSerializer { + public static final SetSpawnPositionSerializer_v363 INSTANCE = new SetSpawnPositionSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetSpawnPositionPacket packet) { + VarInts.writeInt(buffer, packet.getSpawnType().ordinal()); + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + buffer.writeBoolean(packet.isSpawnForced()); + } + + @Override + public void deserialize(ByteBuf buffer, SetSpawnPositionPacket packet) { + packet.setSpawnType(SetSpawnPositionPacket.Type.values()[VarInts.readInt(buffer)]); + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setSpawnForced(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java new file mode 100644 index 000000000..30df04e1c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetTimePacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetTimeSerializer_v363 implements PacketSerializer { + public static final SetTimeSerializer_v363 INSTANCE = new SetTimeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetTimePacket packet) { + VarInts.writeInt(buffer, packet.getTime()); + } + + @Override + public void deserialize(ByteBuf buffer, SetTimePacket packet) { + packet.setTime(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java new file mode 100644 index 000000000..e071ace7c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java @@ -0,0 +1,33 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SetTitlePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SetTitleSerializer_v363 implements PacketSerializer { + public static final SetTitleSerializer_v363 INSTANCE = new SetTitleSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SetTitlePacket packet) { + VarInts.writeInt(buffer, packet.getType().ordinal()); + BedrockUtils.writeString(buffer, packet.getText()); + VarInts.writeInt(buffer, packet.getFadeInTime()); + VarInts.writeInt(buffer, packet.getStayTime()); + VarInts.writeInt(buffer, packet.getFadeOutTime()); + } + + @Override + public void deserialize(ByteBuf buffer, SetTitlePacket packet) { + packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]); + packet.setText(BedrockUtils.readString(buffer)); + packet.setFadeInTime(VarInts.readInt(buffer)); + packet.setStayTime(VarInts.readInt(buffer)); + packet.setFadeOutTime(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java new file mode 100644 index 000000000..263222270 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.SettingsCommandPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class SettingsCommandSerializer_v363 implements PacketSerializer { + + public static final SettingsCommandSerializer_v363 INSTANCE = new SettingsCommandSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, SettingsCommandPacket packet) { + BedrockUtils.writeString(buffer, packet.getCommand()); + buffer.writeBoolean(packet.isSuppressingOutput()); + } + + @Override + public void deserialize(ByteBuf buffer, SettingsCommandPacket packet) { + packet.setCommand(BedrockUtils.readString(buffer)); + packet.setSuppressingOutput(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java new file mode 100644 index 000000000..34ea8e21d --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ShowCreditsSerializer_v363 implements PacketSerializer { + public static final ShowCreditsSerializer_v363 INSTANCE = new ShowCreditsSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ShowCreditsPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeInt(buffer, packet.getStatus().ordinal()); + } + + @Override + public void deserialize(ByteBuf buffer, ShowCreditsPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setStatus(ShowCreditsPacket.Status.values()[VarInts.readInt(buffer)]); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java new file mode 100644 index 000000000..1842a4f01 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ShowProfilePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ShowProfileSerializer_v363 implements PacketSerializer { + public static final ShowProfileSerializer_v363 INSTANCE = new ShowProfileSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ShowProfilePacket packet) { + BedrockUtils.writeString(buffer, packet.getXuid()); + } + + @Override + public void deserialize(ByteBuf buffer, ShowProfilePacket packet) { + packet.setXuid(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java new file mode 100644 index 000000000..3ad433a2c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.ShowStoreOfferPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ShowStoreOfferSerializer_v363 implements PacketSerializer { + public static final ShowStoreOfferSerializer_v363 INSTANCE = new ShowStoreOfferSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, ShowStoreOfferPacket packet) { + BedrockUtils.writeString(buffer, packet.getOfferId()); + buffer.writeBoolean(packet.isShownToAll()); + } + + @Override + public void deserialize(ByteBuf buffer, ShowStoreOfferPacket packet) { + packet.setOfferId(BedrockUtils.readString(buffer)); + packet.setShownToAll(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java new file mode 100644 index 000000000..e1b9d1278 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java @@ -0,0 +1,23 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.SimpleEventPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SimpleEventSerializer_v363 implements PacketSerializer { + public static final SimpleEventSerializer_v363 INSTANCE = new SimpleEventSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SimpleEventPacket packet) { + buffer.writeShortLE(packet.getEvent()); + } + + @Override + public void deserialize(ByteBuf buffer, SimpleEventPacket packet) { + packet.setEvent(buffer.readShortLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java new file mode 100644 index 000000000..65e7c26d3 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SpawnExperienceOrbSerializer_v363 implements PacketSerializer { + public static final SpawnExperienceOrbSerializer_v363 INSTANCE = new SpawnExperienceOrbSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SpawnExperienceOrbPacket packet) { + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getAmount()); + } + + @Override + public void deserialize(ByteBuf buffer, SpawnExperienceOrbPacket packet) { + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setAmount(VarInts.readInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java new file mode 100644 index 000000000..b570c0d62 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java @@ -0,0 +1,30 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SpawnParticleEffectPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SpawnParticleEffectSerializer_v363 implements PacketSerializer { + public static final SpawnParticleEffectSerializer_v363 INSTANCE = new SpawnParticleEffectSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, SpawnParticleEffectPacket packet) { + buffer.writeByte(packet.getDimensionId()); + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + BedrockUtils.writeVector3f(buffer, packet.getPosition()); + BedrockUtils.writeString(buffer, packet.getIdentifier()); + } + + @Override + public void deserialize(ByteBuf buffer, SpawnParticleEffectPacket packet) { + packet.setDimensionId(buffer.readUnsignedByte()); + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setPosition(BedrockUtils.readVector3f(buffer)); + packet.setIdentifier(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java new file mode 100644 index 000000000..6224aacf9 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -0,0 +1,159 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.CompoundTagBuilder; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.nbt.tag.ListTag; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.GamePublishSetting; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.packet.StartGamePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StartGameSerializer_v363 implements PacketSerializer { + public static final StartGameSerializer_v363 INSTANCE = new StartGameSerializer_v363(); + + private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); + + @Override + public void serialize(ByteBuf buffer, StartGamePacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeInt(buffer, packet.getPlayerGamemode()); + BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); + BedrockUtils.writeVector2f(buffer, packet.getRotation()); + // Level settings start + VarInts.writeInt(buffer, packet.getSeed()); + VarInts.writeInt(buffer, packet.getDimensionId()); + VarInts.writeInt(buffer, packet.getGeneratorId()); + VarInts.writeInt(buffer, packet.getLevelGamemode()); + VarInts.writeInt(buffer, packet.getDifficulty()); + BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); + buffer.writeBoolean(packet.isAchievementsDisabled()); + VarInts.writeInt(buffer, packet.getTime()); + buffer.writeBoolean(packet.getEduEditionOffers() != 0); + buffer.writeBoolean(packet.isEduFeaturesEnabled()); + buffer.writeFloatLE(packet.getRainLevel()); + buffer.writeFloatLE(packet.getLightningLevel()); + buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); + buffer.writeBoolean(packet.isMultiplayerGame()); + buffer.writeBoolean(packet.isBroadcastingToLan()); + VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); + VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); + buffer.writeBoolean(packet.isCommandsEnabled()); + buffer.writeBoolean(packet.isTexturePacksRequired()); + BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); + buffer.writeBoolean(packet.isBonusChestEnabled()); + buffer.writeBoolean(packet.isStartingWithMap()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + buffer.writeIntLE(packet.getServerChunkTickRange()); + buffer.writeBoolean(packet.isBehaviorPackLocked()); + buffer.writeBoolean(packet.isResourcePackLocked()); + buffer.writeBoolean(packet.isFromLockedWorldTemplate()); + buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); + buffer.writeBoolean(packet.isFromWorldTemplate()); + buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); + buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); + + // Level settings end + BedrockUtils.writeString(buffer, packet.getLevelId()); + BedrockUtils.writeString(buffer, packet.getWorldName()); + BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); + buffer.writeBoolean(packet.isTrial()); + buffer.writeLongLE(packet.getCurrentTick()); + VarInts.writeInt(buffer, packet.getEnchantmentSeed()); + + List palette = packet.getBlockPalette().getValue(); + VarInts.writeUnsignedInt(buffer, palette.size()); + for (CompoundTag entry : palette) { + CompoundTag blockTag = entry.getCompound("block"); + BedrockUtils.writeString(buffer, blockTag.getString("name")); + buffer.writeShortLE(entry.getShort("meta")); + buffer.writeShortLE(entry.getShort("id")); + } + + BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { + BedrockUtils.writeString(buf, entry.getIdentifier()); + buf.writeShortLE(entry.getId()); + }); + + BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); + + } + + @Override + public void deserialize(ByteBuf buffer, StartGamePacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setPlayerGamemode(VarInts.readInt(buffer)); + packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readVector2f(buffer)); + // Level settings start + packet.setSeed(VarInts.readInt(buffer)); + packet.setDimensionId(VarInts.readInt(buffer)); + packet.setGeneratorId(VarInts.readInt(buffer)); + packet.setLevelGamemode(VarInts.readInt(buffer)); + packet.setDifficulty(VarInts.readInt(buffer)); + packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); + packet.setAchievementsDisabled(buffer.readBoolean()); + packet.setTime(VarInts.readInt(buffer)); + packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); + packet.setEduFeaturesEnabled(buffer.readBoolean()); + packet.setRainLevel(buffer.readFloatLE()); + packet.setLightningLevel(buffer.readFloatLE()); + packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); + packet.setMultiplayerGame(buffer.readBoolean()); + packet.setBroadcastingToLan(buffer.readBoolean()); + packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); + packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); + packet.setCommandsEnabled(buffer.readBoolean()); + packet.setTexturePacksRequired(buffer.readBoolean()); + BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); + packet.setBonusChestEnabled(buffer.readBoolean()); + packet.setStartingWithMap(buffer.readBoolean()); + packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + packet.setServerChunkTickRange(buffer.readIntLE()); + packet.setBehaviorPackLocked(buffer.readBoolean()); + packet.setResourcePackLocked(buffer.readBoolean()); + packet.setFromLockedWorldTemplate(buffer.readBoolean()); + packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); + packet.setFromWorldTemplate(buffer.readBoolean()); + packet.setWorldTemplateOptionLocked(buffer.readBoolean()); + packet.setOnlySpawningV1Villagers(buffer.readBoolean()); + // Level settings end + packet.setLevelId(BedrockUtils.readString(buffer)); + packet.setWorldName(BedrockUtils.readString(buffer)); + packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); + packet.setTrial(buffer.readBoolean()); + packet.setCurrentTick(buffer.readLongLE()); + packet.setEnchantmentSeed(VarInts.readInt(buffer)); + + int paletteLength = VarInts.readUnsignedInt(buffer); + List palette = new ObjectArrayList<>(paletteLength); + for (int i = 0; i < paletteLength; i++) { + palette.add(CompoundTagBuilder.builder() + .tag(CompoundTagBuilder.builder() + .stringTag("name", BedrockUtils.readString(buffer)) + .build("block")) + .shortTag("meta", buffer.readShortLE()) + .shortTag("id", buffer.readShortLE()) + .buildRootTag()); + } + packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); + + BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> { + String identifier = BedrockUtils.readString(buf); + short id = buf.readShortLE(); + return new StartGamePacket.ItemEntry(identifier, id); + }); + + packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java new file mode 100644 index 000000000..e38727add --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.StopSoundPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StopSoundSerializer_v363 implements PacketSerializer { + public static final StopSoundSerializer_v363 INSTANCE = new StopSoundSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, StopSoundPacket packet) { + BedrockUtils.writeString(buffer, packet.getSoundName()); + buffer.writeBoolean(packet.isStoppingAllSound()); + } + + @Override + public void deserialize(ByteBuf buffer, StopSoundPacket packet) { + packet.setSoundName(BedrockUtils.readString(buffer)); + packet.setStoppingAllSound(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java new file mode 100644 index 000000000..db3e71822 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.StructureBlockUpdatePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StructureBlockUpdateSerializer_v363 implements PacketSerializer { + public static final StructureBlockUpdateSerializer_v363 INSTANCE = new StructureBlockUpdateSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, StructureBlockUpdatePacket packet) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + BedrockUtils.writeStructureEditorData(buffer, packet.getEditorData()); + buffer.writeBoolean(packet.isPowered()); + } + + @Override + public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setEditorData(BedrockUtils.readStructureEditorData(buffer)); + packet.setPowered(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java new file mode 100644 index 000000000..86f54836b --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java @@ -0,0 +1,29 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.StructureTemplateDataExportRequestPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StructureTemplateDataExportRequestSerializer_v363 implements PacketSerializer { + public static final StructureTemplateDataExportRequestSerializer_v363 INSTANCE = new StructureTemplateDataExportRequestSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, StructureTemplateDataExportRequestPacket packet) { + BedrockUtils.writeString(buffer, packet.getName()); + BedrockUtils.writeBlockPosition(buffer, packet.getPosition()); + BedrockUtils.writeStructureSettings(buffer, packet.getSettings()); + buffer.writeByte(packet.getOperation()); + } + + @Override + public void deserialize(ByteBuf buffer, StructureTemplateDataExportRequestPacket packet) { + packet.setName(BedrockUtils.readString(buffer)); + packet.setPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setSettings(BedrockUtils.readStructureSettings(buffer)); + packet.setOperation(buffer.readByte()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java new file mode 100644 index 000000000..75a96a082 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java @@ -0,0 +1,58 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.nbt.tag.Tag; +import com.nukkitx.protocol.bedrock.packet.StructureTemplateDataExportResponsePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StructureTemplateDataExportResponseSerializer_v363 implements PacketSerializer { + public static final StructureTemplateDataExportResponseSerializer_v363 INSTANCE = new StructureTemplateDataExportResponseSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { + BedrockUtils.writeString(buffer, packet.getName()); + boolean save = packet.isSave(); + buffer.writeBoolean(save); + + if (save) { + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { + packet.setName(BedrockUtils.readString(buffer)); + + boolean save = buffer.readBoolean(); + packet.setSave(save); + + if (save) { + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + Tag tag = reader.readTag(); + if (tag instanceof CompoundTag) { + packet.setTag((CompoundTag) tag); + } else { + throw new IllegalArgumentException("Tag received was not a CompoundTag"); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java new file mode 100644 index 000000000..697a08bec --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java @@ -0,0 +1,32 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.SubClientLoginPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.util.AsciiString; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SubClientLoginSerializer_v363 implements PacketSerializer { + public static final SubClientLoginSerializer_v363 INSTANCE = new SubClientLoginSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, SubClientLoginPacket packet) { + AsciiString chainData = packet.getChainData(); + AsciiString skinData = packet.getSkinData(); + VarInts.writeUnsignedInt(buffer, chainData.length() + skinData.length() + 8); + BedrockUtils.writeLEAsciiString(buffer, chainData); + BedrockUtils.writeLEAsciiString(buffer, skinData); + } + + @Override + public void deserialize(ByteBuf buffer, SubClientLoginPacket packet) { + ByteBuf jwt = buffer.readSlice(VarInts.readUnsignedInt(buffer)); + packet.setChainData(BedrockUtils.readLEAsciiString(jwt)); + packet.setSkinData(BedrockUtils.readLEAsciiString(jwt)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java new file mode 100644 index 000000000..890059453 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.TakeItemEntityPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TakeItemEntitySerializer_v363 implements PacketSerializer { + public static final TakeItemEntitySerializer_v363 INSTANCE = new TakeItemEntitySerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, TakeItemEntityPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getItemRuntimeEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + } + + @Override + public void deserialize(ByteBuf buffer, TakeItemEntityPacket packet) { + packet.setItemRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java new file mode 100644 index 000000000..e6f546197 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java @@ -0,0 +1,68 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.TextPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TextSerializer_v363 implements PacketSerializer { + public static final TextSerializer_v363 INSTANCE = new TextSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, TextPacket packet) { + TextPacket.Type type = packet.getType(); + buffer.writeByte(type.ordinal()); + buffer.writeBoolean(packet.isNeedsTranslation()); + + switch (type) { + case CHAT: + case WHISPER: + case ANNOUNCEMENT: + BedrockUtils.writeString(buffer, packet.getSourceName()); + case RAW: + case TIP: + case SYSTEM: + BedrockUtils.writeString(buffer, packet.getMessage()); + break; + case TRANSLATION: + case POPUP: + case JUKEBOX_POPUP: + BedrockUtils.writeString(buffer, packet.getMessage()); + BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString); + break; + } + + BedrockUtils.writeString(buffer, packet.getXuid()); + BedrockUtils.writeString(buffer, packet.getPlatformChatId()); + } + + @Override + public void deserialize(ByteBuf buffer, TextPacket packet) { + TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()]; + packet.setType(type); + packet.setNeedsTranslation(buffer.readBoolean()); + switch (type) { + case CHAT: + case WHISPER: + case ANNOUNCEMENT: + packet.setSourceName(BedrockUtils.readString(buffer)); + case RAW: + case TIP: + case SYSTEM: + packet.setMessage(BedrockUtils.readString(buffer)); + break; + case TRANSLATION: + case POPUP: + case JUKEBOX_POPUP: + packet.setMessage(BedrockUtils.readString(buffer)); + BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString); + break; + } + packet.setXuid(BedrockUtils.readString(buffer)); + packet.setPlatformChatId(BedrockUtils.readString(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java new file mode 100644 index 000000000..39b013c33 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java @@ -0,0 +1,26 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.TransferPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TransferSerializer_v363 implements PacketSerializer { + public static final TransferSerializer_v363 INSTANCE = new TransferSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, TransferPacket packet) { + BedrockUtils.writeString(buffer, packet.getAddress()); + buffer.writeShortLE(packet.getPort()); + } + + @Override + public void deserialize(ByteBuf buffer, TransferPacket packet) { + packet.setAddress(BedrockUtils.readString(buffer)); + packet.setPort(buffer.readUnsignedShortLE()); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java new file mode 100644 index 000000000..6f2ec10ab --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateAttributesSerializer_v363 implements PacketSerializer { + public static final UpdateAttributesSerializer_v363 INSTANCE = new UpdateAttributesSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, UpdateAttributesPacket packet) { + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + BedrockUtils.writeArray(buffer, packet.getAttributes(), BedrockUtils::writePlayerAttribute); + } + + @Override + public void deserialize(ByteBuf buffer, UpdateAttributesPacket packet) { + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + BedrockUtils.readArray(buffer, packet.getAttributes(), BedrockUtils::readPlayerAttribute); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java new file mode 100644 index 000000000..79a65c611 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java @@ -0,0 +1,37 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.protocol.bedrock.packet.UpdateBlockPropertiesPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateBlockPropertiesSerializer_v363 implements PacketSerializer { + public static final UpdateBlockPropertiesSerializer_v363 INSTANCE = new UpdateBlockPropertiesSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, UpdateBlockPropertiesPacket packet) { + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getProperties()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, UpdateBlockPropertiesPacket packet) { + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setProperties(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java new file mode 100644 index 000000000..461981a59 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java @@ -0,0 +1,45 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Set; + +import static com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket.Flag; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateBlockSerializer_v363 implements PacketSerializer { + public static final UpdateBlockSerializer_v363 INSTANCE = new UpdateBlockSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, UpdateBlockPacket packet) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeUnsignedInt(buffer, packet.getRuntimeId()); + int flagValue = 0; + for (Flag flag : packet.getFlags()) { + flagValue |= (1 << flag.ordinal()); + } + VarInts.writeUnsignedInt(buffer, flagValue); + VarInts.writeUnsignedInt(buffer, packet.getDataLayer()); + } + + @Override + public void deserialize(ByteBuf buffer, UpdateBlockPacket packet) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setRuntimeId(VarInts.readUnsignedInt(buffer)); + int flagValue = VarInts.readUnsignedInt(buffer); + Set flags = packet.getFlags(); + for (Flag flag : Flag.values()) { + if ((flagValue & (1 << flag.ordinal())) != 0) { + flags.add(flag); + } + } + packet.setDataLayer(VarInts.readUnsignedInt(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java new file mode 100644 index 000000000..04a78ede2 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java @@ -0,0 +1,49 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.UpdateBlockSyncedPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Set; + +import static com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket.Flag; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateBlockSyncedSerializer_v363 implements PacketSerializer { + public static final UpdateBlockSyncedSerializer_v363 INSTANCE = new UpdateBlockSyncedSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, UpdateBlockSyncedPacket packet) { + BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeUnsignedInt(buffer, packet.getRuntimeId()); + int flagValue = 0; + for (Flag flag : packet.getFlags()) { + flagValue |= (1 << flag.ordinal()); + } + VarInts.writeUnsignedInt(buffer, flagValue); + VarInts.writeUnsignedInt(buffer, packet.getDataLayer()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getUnknownLong1()); + } + + @Override + public void deserialize(ByteBuf buffer, UpdateBlockSyncedPacket packet) { + packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); + packet.setRuntimeId(VarInts.readUnsignedInt(buffer)); + int flagValue = VarInts.readUnsignedInt(buffer); + Set flags = packet.getFlags(); + for (Flag flag : Flag.values()) { + if ((flagValue & (1 << flag.ordinal())) != 0) { + flags.add(flag); + } + } + packet.setDataLayer(VarInts.readUnsignedInt(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + packet.setUnknownLong1(VarInts.readUnsignedLong(buffer)); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java new file mode 100644 index 000000000..15ce50978 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java @@ -0,0 +1,47 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateEquipSerializer_v363 implements PacketSerializer { + public static final UpdateEquipSerializer_v363 INSTANCE = new UpdateEquipSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, UpdateEquipPacket packet) { + buffer.writeByte(packet.getWindowId()); + buffer.writeByte(packet.getWindowType()); + VarInts.writeInt(buffer, packet.getUnknown0()); + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, UpdateEquipPacket packet) { + packet.setWindowId(buffer.readUnsignedByte()); + packet.setWindowType(buffer.readUnsignedByte()); + packet.setUnknown0(VarInts.readInt(buffer)); + packet.setUniqueEntityId(VarInts.readLong(buffer)); + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setTag(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java new file mode 100644 index 000000000..4315b1cf2 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java @@ -0,0 +1,25 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.UpdateSoftEnumPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateSoftEnumSerializer_v363 implements PacketSerializer { + public static final UpdateSoftEnumSerializer_v363 INSTANCE = new UpdateSoftEnumSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, UpdateSoftEnumPacket packet) { + BedrockUtils.writeCommandEnumData(buffer, packet.getSoftEnum()); + buffer.writeByte(packet.getType().ordinal()); + } + + @Override + public void deserialize(ByteBuf buffer, UpdateSoftEnumPacket packet) { + packet.setSoftEnum(BedrockUtils.readCommandEnumData(buffer, true)); + packet.setType(UpdateSoftEnumPacket.Type.values()[buffer.readUnsignedByte()]); + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java new file mode 100644 index 000000000..b6d1a1278 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java @@ -0,0 +1,59 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.packet.UpdateTradePacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateTradeSerializer_v363 implements PacketSerializer { + public static final UpdateTradeSerializer_v363 INSTANCE = new UpdateTradeSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, UpdateTradePacket packet) { + buffer.writeByte(packet.getWindowId()); + buffer.writeByte(packet.getWindowType()); + VarInts.writeInt(buffer, packet.getUnknownInt()); + VarInts.writeInt(buffer, packet.getTradeTier()); + VarInts.writeLong(buffer, packet.getTraderUniqueEntityId()); + VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); + BedrockUtils.writeString(buffer, packet.getDisplayName()); + buffer.writeBoolean(packet.isScreen2()); + buffer.writeBoolean(packet.isWilling()); + try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { + writer.write(packet.getOffers()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(ByteBuf buffer, UpdateTradePacket packet) { + packet.setWindowId(buffer.readUnsignedByte()); + packet.setWindowType(buffer.readUnsignedByte()); + packet.setUnknownInt(VarInts.readInt(buffer)); + packet.setTradeTier(VarInts.readInt(buffer)); + packet.setWilling(buffer.readBoolean()); + packet.setTraderUniqueEntityId(VarInts.readLong(buffer)); + packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); + packet.setDisplayName(BedrockUtils.readString(buffer)); + packet.setScreen2(buffer.readBoolean()); + packet.setWilling(buffer.readBoolean()); + try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { + packet.setOffers(reader.readTag()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java new file mode 100644 index 000000000..b88085e0c --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java @@ -0,0 +1,31 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.protocol.bedrock.packet.VideoStreamConnectPacket; +import com.nukkitx.protocol.bedrock.v363.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class VideoStreamConnectSerializer_v363 implements PacketSerializer { + public static final VideoStreamConnectSerializer_v363 INSTANCE = new VideoStreamConnectSerializer_v363(); + + @Override + public void serialize(ByteBuf buffer, VideoStreamConnectPacket packet) { + BedrockUtils.writeString(buffer, packet.getAddress()); + buffer.writeFloatLE(packet.getScreenshotFrequency()); + buffer.writeByte(packet.getAction().ordinal()); + buffer.writeIntLE(packet.getWidth()); + buffer.writeIntLE(packet.getHeight()); + } + + @Override + public void deserialize(ByteBuf buffer, VideoStreamConnectPacket packet) { + packet.setAddress(BedrockUtils.readString(buffer)); + packet.setScreenshotFrequency(buffer.readFloatLE()); + packet.setAction(VideoStreamConnectPacket.Action.values()[buffer.readUnsignedByte()]); + packet.setWidth(buffer.readIntLE()); + packet.setHeight(buffer.readIntLE()); + } +} diff --git a/bedrock/pom.xml b/bedrock/pom.xml index d62875c73..1d08dda76 100644 --- a/bedrock/pom.xml +++ b/bedrock/pom.xml @@ -20,6 +20,7 @@ bedrock-v340 bedrock-v354 bedrock-v361 + bedrock-v363 bedrock-v388 bedrock-v389 bedrock-v390 From d1b1316fb5ddda2084066a3c5b64216f27bfa5ea Mon Sep 17 00:00:00 2001 From: Brendan Grieve Date: Sat, 9 May 2020 09:26:19 +0800 Subject: [PATCH 02/70] Reference v361 serializers to reduce duplication --- bedrock/bedrock-v363/pom.xml | 6 + .../protocol/bedrock/v363/BedrockUtils.java | 4 +- .../protocol/bedrock/v363/Bedrock_v363.java | 284 ++++++++--------- .../AddBehaviorTreeSerializer_v363.java | 23 -- .../serializer/AddEntitySerializer_v363.java | 40 --- .../AddItemEntitySerializer_v363.java | 36 --- .../AddPaintingSerializer_v363.java | 34 -- .../serializer/AddPlayerSerializer_v363.java | 48 --- .../AdventureSettingsSerializer_v363.java | 96 ------ .../serializer/AnimateSerializer_v363.java | 47 --- .../AnvilDamageSerializer_v363.java | 26 -- ...utomationClientConnectSerializer_v363.java | 24 -- .../AvailableCommandsSerializer_v363.java | 299 ------------------ ...lableEntityIdentifiersSerializer_v363.java | 37 --- .../BiomeDefinitionListSerializer_v363.java | 37 --- .../BlockEntityDataSerializer_v363.java | 40 --- .../serializer/BlockEventSerializer_v363.java | 28 -- .../BlockPickRequestSerializer_v363.java | 27 -- .../serializer/BookEditSerializer_v363.java | 77 ----- .../serializer/BossEventSerializer_v363.java | 77 ----- .../serializer/CameraSerializer_v363.java | 25 -- .../ChangeDimensionSerializer_v363.java | 28 -- .../ChunkRadiusUpdatedSerializer_v363.java | 23 -- .../ClientCacheBlobStatusSerializer_v363.java | 43 --- ...lientCacheMissResponseSerializer_v363.java | 39 --- .../ClientCacheStatusSerializer_v363.java | 22 -- ...lientToServerHandshakeSerializer_v363.java | 22 -- ...ClientboundMapItemDataSerializer_v363.java | 154 --------- .../CommandBlockUpdateSerializer_v363.java | 56 ---- .../CommandOutputSerializer_v363.java | 40 --- .../CommandRequestSerializer_v363.java | 27 -- .../CompletedUsingItemSerializer_v363.java | 28 -- .../ContainerCloseSerializer_v363.java | 22 -- .../ContainerOpenSerializer_v363.java | 31 -- .../ContainerSetDataSerializer_v363.java | 27 -- .../CraftingDataSerializer_v363.java | 137 -------- .../CraftingEventSerializer_v363.java | 37 --- .../serializer/DisconnectSerializer_v363.java | 30 -- .../EducationSettingsSerializer_v363.java | 26 -- .../v363/serializer/EmoteSerializer_v363.java | 29 -- .../EntityEventSerializer_v363.java | 88 ------ .../serializer/EntityFallSerializer_v363.java | 28 -- .../EntityPickRequestSerializer_v363.java | 25 -- .../v363/serializer/EventSerializer_v363.java | 264 ---------------- .../serializer/ExplodeSerializer_v363.java | 31 -- .../GameRulesChangedSerializer_v363.java | 34 -- .../GuiDataPickItemSerializer_v363.java | 28 -- .../serializer/HurtArmorSerializer_v363.java | 24 -- .../serializer/InteractSerializer_v363.java | 36 --- .../InventoryContentSerializer_v363.java | 38 --- .../InventorySlotSerializer_v363.java | 28 -- .../InventoryTransactionSerializer_v363.java | 85 ----- .../ItemFrameDropItemSerializer_v363.java | 24 -- .../serializer/LabTableSerializer_v363.java | 28 -- .../LecternUpdateSerializer_v363.java | 29 -- .../serializer/LevelChunkSerializer_v363.java | 52 --- .../LevelEventGenericSerializer_v363.java | 40 --- .../serializer/LevelEventSerializer_v363.java | 170 ---------- .../LevelSoundEvent1Serializer_v363.java | 292 ----------------- .../LevelSoundEvent2Serializer_v363.java | 36 --- .../LevelSoundEvent3Serializer_v363.java | 37 --- .../v363/serializer/LoginSerializer_v363.java | 38 --- .../MapCreateLockedCopySerializer_v363.java | 25 -- .../MapInfoRequestSerializer_v363.java | 24 -- .../MobArmorEquipmentSerializer_v363.java | 33 -- .../serializer/MobEffectSerializer_v363.java | 34 -- .../MobEquipmentSerializer_v363.java | 32 -- .../ModalFormRequestSerializer_v363.java | 27 -- .../ModalFormResponseSerializer_v363.java | 27 -- .../MoveEntityAbsoluteSerializer_v363.java | 42 --- .../MoveEntityDeltaSerializer_v363.java | 84 ----- .../serializer/MovePlayerSerializer_v363.java | 46 --- .../MultiplayerSettingsSerializer_v363.java | 27 -- ...rkChunkPublisherUpdateSerializer_v363.java | 26 -- .../NetworkSettingsSerializer_v363.java | 23 -- .../NetworkStackLatencySerializer_v363.java | 25 -- .../serializer/NpcRequestSerializer_v363.java | 33 -- ...ScreenTextureAnimationSerializer_v363.java | 22 -- .../PacketHeaderSerializer_v363.java | 31 -- .../PhotoTransferSerializer_v363.java | 33 -- .../serializer/PlaySoundSerializer_v363.java | 30 -- .../serializer/PlayStatusSerializer_v363.java | 25 -- .../PlayerActionSerializer_v363.java | 33 -- .../PlayerAuthInputSerializer_v363.java | 52 --- .../PlayerHotbarSerializer_v363.java | 27 -- .../PlayerInputSerializer_v363.java | 28 -- .../serializer/PlayerListSerializer_v363.java | 70 ---- .../serializer/PlayerSkinSerializer_v363.java | 46 --- .../PurchaseReceiptSerializer_v363.java | 24 -- .../RemoveEntitySerializer_v363.java | 24 -- .../RemoveObjectiveSerializer_v363.java | 24 -- .../RequestChunkRadiusSerializer_v363.java | 24 -- .../ResourcePackChunkDataSerializer_v363.java | 40 --- ...sourcePackChunkRequestSerializer_v363.java | 32 -- ...urcePackClientResponseSerializer_v363.java | 42 --- .../ResourcePackDataInfoSerializer_v363.java | 58 ---- .../ResourcePackStackSerializer_v363.java | 30 -- .../ResourcePacksInfoSerializer_v363.java | 29 -- .../serializer/RespawnSerializer_v363.java | 24 -- .../serializer/RiderJumpSerializer_v363.java | 24 -- .../ScriptCustomEventSerializer_v363.java | 27 -- .../ServerSettingsRequestSerializer_v363.java | 23 -- ...ServerSettingsResponseSerializer_v363.java | 27 -- ...erverToClientHandshakeSerializer_v363.java | 26 -- .../SetCommandsEnabledSerializer_v363.java | 23 -- .../SetDefaultGameTypeSerializer_v363.java | 24 -- .../SetDifficultySerializer_v363.java | 24 -- .../SetDisplayObjectiveSerializer_v363.java | 33 -- .../SetEntityDataSerializer_v363.java | 27 -- .../SetEntityLinkSerializer_v363.java | 24 -- .../SetEntityMotionSerializer_v363.java | 27 -- .../serializer/SetHealthSerializer_v363.java | 24 -- .../SetLastHurtBySerializer_v363.java | 24 -- ...calPlayerAsInitializedSerializer_v363.java | 24 -- .../SetPlayerGameTypeSerializer_v363.java | 24 -- .../serializer/SetScoreSerializer_v363.java | 73 ----- .../SetScoreboardIdentitySerializer_v363.java | 46 --- .../SetSpawnPositionSerializer_v363.java | 29 -- .../serializer/SetTimeSerializer_v363.java | 24 -- .../serializer/SetTitleSerializer_v363.java | 33 -- .../SettingsCommandSerializer_v363.java | 26 -- .../ShowCreditsSerializer_v363.java | 26 -- .../ShowProfileSerializer_v363.java | 24 -- .../ShowStoreOfferSerializer_v363.java | 26 -- .../SimpleEventSerializer_v363.java | 23 -- .../SpawnExperienceOrbSerializer_v363.java | 27 -- .../SpawnParticleEffectSerializer_v363.java | 30 -- .../serializer/StartGameSerializer_v363.java | 159 ---------- .../serializer/StopSoundSerializer_v363.java | 26 -- .../StructureBlockUpdateSerializer_v363.java | 28 -- ...plateDataExportRequestSerializer_v363.java | 29 -- ...lateDataExportResponseSerializer_v363.java | 58 ---- .../SubClientLoginSerializer_v363.java | 32 -- .../TakeItemEntitySerializer_v363.java | 26 -- .../v363/serializer/TextSerializer_v363.java | 68 ---- .../serializer/TransferSerializer_v363.java | 26 -- .../UpdateAttributesSerializer_v363.java | 27 -- .../UpdateBlockPropertiesSerializer_v363.java | 37 --- .../UpdateBlockSerializer_v363.java | 45 --- .../UpdateBlockSyncedSerializer_v363.java | 49 --- .../UpdateEquipSerializer_v363.java | 47 --- .../UpdateSoftEnumSerializer_v363.java | 25 -- .../UpdateTradeSerializer_v363.java | 59 ---- .../VideoStreamConnectSerializer_v363.java | 31 -- 144 files changed, 150 insertions(+), 6261 deletions(-) delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java diff --git a/bedrock/bedrock-v363/pom.xml b/bedrock/bedrock-v363/pom.xml index ec1c5685f..330820393 100644 --- a/bedrock/bedrock-v363/pom.xml +++ b/bedrock/bedrock-v363/pom.xml @@ -18,5 +18,11 @@ ${project.version} compile + + com.nukkitx.protocol + bedrock-v361 + ${project.version} + compile + \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java index d1dca9463..7e65ebd27 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java @@ -14,7 +14,7 @@ import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.packet.ResourcePackStackPacket; import com.nukkitx.protocol.bedrock.packet.ResourcePacksInfoPacket; -import com.nukkitx.protocol.bedrock.v363.serializer.GameRulesChangedSerializer_v363; +import com.nukkitx.protocol.bedrock.v361.serializer.GameRulesChangedSerializer_v361; import com.nukkitx.protocol.util.Int2ObjectBiMap; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; @@ -812,7 +812,7 @@ public static void writeGameRule(ByteBuf buffer, GameRuleData gameRule) { Preconditions.checkNotNull(gameRule, "gameRule"); Object value = gameRule.getValue(); - int type = GameRulesChangedSerializer_v363.RULE_TYPES.get(value.getClass()); + int type = GameRulesChangedSerializer_v361.RULE_TYPES.get(value.getClass()); BedrockUtils.writeString(buffer, gameRule.getName()); VarInts.writeUnsignedInt(buffer, type); diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index cfd99aaf3..482e9fce0 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -2,7 +2,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; -import com.nukkitx.protocol.bedrock.v363.serializer.*; +import com.nukkitx.protocol.bedrock.v361.serializer.*; import lombok.experimental.UtilityClass; @UtilityClass @@ -10,149 +10,149 @@ public class Bedrock_v363 { public static BedrockPacketCodec V363_CODEC = BedrockPacketCodec.builder() .protocolVersion(363) .minecraftVersion("1.12.60") - .headerSerializer(PacketHeaderSerializer_v363.INSTANCE) - .registerPacket(LoginPacket.class, LoginSerializer_v363.INSTANCE, 1) - .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v363.INSTANCE, 2) - .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v363.INSTANCE, 3) - .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v363.INSTANCE, 4) - .registerPacket(DisconnectPacket.class, DisconnectSerializer_v363.INSTANCE, 5) - .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v363.INSTANCE, 6) - .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v363.INSTANCE, 7) - .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v363.INSTANCE, 8) - .registerPacket(TextPacket.class, TextSerializer_v363.INSTANCE, 9) - .registerPacket(SetTimePacket.class, SetTimeSerializer_v363.INSTANCE, 10) - .registerPacket(StartGamePacket.class, StartGameSerializer_v363.INSTANCE, 11) - .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v363.INSTANCE, 12) - .registerPacket(AddEntityPacket.class, AddEntitySerializer_v363.INSTANCE, 13) - .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v363.INSTANCE, 14) - .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v363.INSTANCE, 15) - .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v363.INSTANCE, 17) - .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v363.INSTANCE, 18) - .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v363.INSTANCE, 19) - .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v363.INSTANCE, 20) - .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v363.INSTANCE, 21) - .registerPacket(AddPaintingPacket.class, AddPaintingSerializer_v363.INSTANCE, 22) - .registerPacket(ExplodePacket.class, ExplodeSerializer_v363.INSTANCE, 23) - .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v363.INSTANCE, 24) - .registerPacket(LevelEventPacket.class, LevelEventSerializer_v363.INSTANCE, 25) - .registerPacket(BlockEventPacket.class, BlockEventSerializer_v363.INSTANCE, 26) - .registerPacket(EntityEventPacket.class, EntityEventSerializer_v363.INSTANCE, 27) - .registerPacket(MobEffectPacket.class, MobEffectSerializer_v363.INSTANCE, 28) - .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v363.INSTANCE, 29) - .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v363.INSTANCE, 30) - .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v363.INSTANCE, 31) - .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v363.INSTANCE, 32) - .registerPacket(InteractPacket.class, InteractSerializer_v363.INSTANCE, 33) - .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v363.INSTANCE, 34) - .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v363.INSTANCE, 35) - .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v363.INSTANCE, 36) - .registerPacket(EntityFallPacket.class, EntityFallSerializer_v363.INSTANCE, 37) - .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v363.INSTANCE, 38) - .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v363.INSTANCE, 39) - .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v363.INSTANCE, 40) - .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v363.INSTANCE, 41) - .registerPacket(SetHealthPacket.class, SetHealthSerializer_v363.INSTANCE, 42) - .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v363.INSTANCE, 43) - .registerPacket(AnimatePacket.class, AnimateSerializer_v363.INSTANCE, 44) - .registerPacket(RespawnPacket.class, RespawnSerializer_v363.INSTANCE, 45) - .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v363.INSTANCE, 46) - .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v363.INSTANCE, 47) - .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v363.INSTANCE, 48) - .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v363.INSTANCE, 49) - .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v363.INSTANCE, 50) - .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v363.INSTANCE, 51) - .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v363.INSTANCE, 52) - .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v363.INSTANCE, 53) - .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v363.INSTANCE, 54) - .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v363.INSTANCE, 55) - .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v363.INSTANCE, 56) - .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v363.INSTANCE, 57) - .registerPacket(LevelChunkPacket.class, LevelChunkSerializer_v363.INSTANCE, 58) - .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v363.INSTANCE, 59) - .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v363.INSTANCE, 60) - .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v363.INSTANCE, 61) - .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v363.INSTANCE, 62) - .registerPacket(PlayerListPacket.class, PlayerListSerializer_v363.INSTANCE, 63) - .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v363.INSTANCE, 64) - .registerPacket(EventPacket.class, EventSerializer_v363.INSTANCE, 65) - .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v363.INSTANCE, 66) - .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v363.INSTANCE, 67) - .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v363.INSTANCE, 68) - .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v363.INSTANCE, 69) - .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v363.INSTANCE, 70) - .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v363.INSTANCE, 71) - .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v363.INSTANCE, 72) - .registerPacket(CameraPacket.class, CameraSerializer_v363.INSTANCE, 73) - .registerPacket(BossEventPacket.class, BossEventSerializer_v363.INSTANCE, 74) - .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v363.INSTANCE, 75) - .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v363.INSTANCE, 76) - .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v363.INSTANCE, 77) - .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v363.INSTANCE, 78) - .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v363.INSTANCE, 79) - .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v363.INSTANCE, 80) - .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v363.INSTANCE, 81) - .registerPacket(ResourcePackDataInfoPacket.class, ResourcePackDataInfoSerializer_v363.INSTANCE, 82) - .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v363.INSTANCE, 83) - .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v363.INSTANCE, 84) - .registerPacket(TransferPacket.class, TransferSerializer_v363.INSTANCE, 85) - .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v363.INSTANCE, 86) - .registerPacket(StopSoundPacket.class, StopSoundSerializer_v363.INSTANCE, 87) - .registerPacket(SetTitlePacket.class, SetTitleSerializer_v363.INSTANCE, 88) - .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v363.INSTANCE, 89) - .registerPacket(StructureBlockUpdatePacket.class, StructureBlockUpdateSerializer_v363.INSTANCE, 90) - .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v363.INSTANCE, 91) - .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v363.INSTANCE, 92) - .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v363.INSTANCE, 93) - .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v363.INSTANCE, 94) - .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v363.INSTANCE, 95) - .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v363.INSTANCE, 96) - .registerPacket(BookEditPacket.class, BookEditSerializer_v363.INSTANCE, 97) - .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v363.INSTANCE, 98) - .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v363.INSTANCE, 99) - .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v363.INSTANCE, 100) - .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v363.INSTANCE, 101) - .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v363.INSTANCE, 102) - .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v363.INSTANCE, 103) - .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v363.INSTANCE, 104) - .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v363.INSTANCE, 105) - .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v363.INSTANCE, 106) - .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v363.INSTANCE, 107) - .registerPacket(SetScorePacket.class, SetScoreSerializer_v363.INSTANCE, 108) - .registerPacket(LabTablePacket.class, LabTableSerializer_v363.INSTANCE, 109) - .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v363.INSTANCE, 110) - .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v363.INSTANCE, 111) - .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v363.INSTANCE, 112) - .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v363.INSTANCE, 113) - .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v363.INSTANCE, 114) - .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v363.INSTANCE, 115) - .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v363.INSTANCE, 117) - .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v363.INSTANCE, 118) - .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v363.INSTANCE, 119) - .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v363.INSTANCE, 120) - .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v363.INSTANCE, 121) - .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v363.INSTANCE, 122) - .registerPacket(LevelSoundEventPacket.class, LevelSoundEvent3Serializer_v363.INSTANCE, 123) - .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v363.INSTANCE, 124) - .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v363.INSTANCE, 125) - .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v363.INSTANCE, 126) + .headerSerializer(PacketHeaderSerializer_v361.INSTANCE) + .registerPacket(LoginPacket.class, LoginSerializer_v361.INSTANCE, 1) + .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v361.INSTANCE, 2) + .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v361.INSTANCE, 3) + .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v361.INSTANCE, 4) + .registerPacket(DisconnectPacket.class, DisconnectSerializer_v361.INSTANCE, 5) + .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v361.INSTANCE, 6) + .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v361.INSTANCE, 7) + .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v361.INSTANCE, 8) + .registerPacket(TextPacket.class, TextSerializer_v361.INSTANCE, 9) + .registerPacket(SetTimePacket.class, SetTimeSerializer_v361.INSTANCE, 10) + .registerPacket(StartGamePacket.class, StartGameSerializer_v361.INSTANCE, 11) + .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v361.INSTANCE, 12) + .registerPacket(AddEntityPacket.class, AddEntitySerializer_v361.INSTANCE, 13) + .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v361.INSTANCE, 14) + .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v361.INSTANCE, 15) + .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v361.INSTANCE, 17) + .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v361.INSTANCE, 18) + .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v361.INSTANCE, 19) + .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v361.INSTANCE, 20) + .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v361.INSTANCE, 21) + .registerPacket(AddPaintingPacket.class, AddPaintingSerializer_v361.INSTANCE, 22) + .registerPacket(ExplodePacket.class, ExplodeSerializer_v361.INSTANCE, 23) + .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v361.INSTANCE, 24) + .registerPacket(LevelEventPacket.class, LevelEventSerializer_v361.INSTANCE, 25) + .registerPacket(BlockEventPacket.class, BlockEventSerializer_v361.INSTANCE, 26) + .registerPacket(EntityEventPacket.class, EntityEventSerializer_v361.INSTANCE, 27) + .registerPacket(MobEffectPacket.class, MobEffectSerializer_v361.INSTANCE, 28) + .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v361.INSTANCE, 29) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v361.INSTANCE, 30) + .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v361.INSTANCE, 31) + .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v361.INSTANCE, 32) + .registerPacket(InteractPacket.class, InteractSerializer_v361.INSTANCE, 33) + .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v361.INSTANCE, 34) + .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v361.INSTANCE, 35) + .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v361.INSTANCE, 36) + .registerPacket(EntityFallPacket.class, EntityFallSerializer_v361.INSTANCE, 37) + .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v361.INSTANCE, 38) + .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v361.INSTANCE, 39) + .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v361.INSTANCE, 40) + .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v361.INSTANCE, 41) + .registerPacket(SetHealthPacket.class, SetHealthSerializer_v361.INSTANCE, 42) + .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v361.INSTANCE, 43) + .registerPacket(AnimatePacket.class, AnimateSerializer_v361.INSTANCE, 44) + .registerPacket(RespawnPacket.class, RespawnSerializer_v361.INSTANCE, 45) + .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v361.INSTANCE, 46) + .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v361.INSTANCE, 47) + .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v361.INSTANCE, 48) + .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v361.INSTANCE, 49) + .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v361.INSTANCE, 50) + .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v361.INSTANCE, 51) + .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v361.INSTANCE, 52) + .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v361.INSTANCE, 53) + .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v361.INSTANCE, 54) + .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v361.INSTANCE, 55) + .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v361.INSTANCE, 56) + .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v361.INSTANCE, 57) + .registerPacket(LevelChunkPacket.class, LevelChunkSerializer_v361.INSTANCE, 58) + .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v361.INSTANCE, 59) + .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v361.INSTANCE, 60) + .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v361.INSTANCE, 61) + .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v361.INSTANCE, 62) + .registerPacket(PlayerListPacket.class, PlayerListSerializer_v361.INSTANCE, 63) + .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v361.INSTANCE, 64) + .registerPacket(EventPacket.class, EventSerializer_v361.INSTANCE, 65) + .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v361.INSTANCE, 66) + .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v361.INSTANCE, 67) + .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v361.INSTANCE, 68) + .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v361.INSTANCE, 69) + .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v361.INSTANCE, 70) + .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v361.INSTANCE, 71) + .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v361.INSTANCE, 72) + .registerPacket(CameraPacket.class, CameraSerializer_v361.INSTANCE, 73) + .registerPacket(BossEventPacket.class, BossEventSerializer_v361.INSTANCE, 74) + .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v361.INSTANCE, 75) + .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v361.INSTANCE, 76) + .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v361.INSTANCE, 77) + .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v361.INSTANCE, 78) + .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v361.INSTANCE, 79) + .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v361.INSTANCE, 80) + .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v361.INSTANCE, 81) + .registerPacket(ResourcePackDataInfoPacket.class, ResourcePackDataInfoSerializer_v361.INSTANCE, 82) + .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v361.INSTANCE, 83) + .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v361.INSTANCE, 84) + .registerPacket(TransferPacket.class, TransferSerializer_v361.INSTANCE, 85) + .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v361.INSTANCE, 86) + .registerPacket(StopSoundPacket.class, StopSoundSerializer_v361.INSTANCE, 87) + .registerPacket(SetTitlePacket.class, SetTitleSerializer_v361.INSTANCE, 88) + .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v361.INSTANCE, 89) + .registerPacket(StructureBlockUpdatePacket.class, StructureBlockUpdateSerializer_v361.INSTANCE, 90) + .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v361.INSTANCE, 91) + .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v361.INSTANCE, 92) + .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v361.INSTANCE, 93) + .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v361.INSTANCE, 94) + .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v361.INSTANCE, 95) + .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v361.INSTANCE, 96) + .registerPacket(BookEditPacket.class, BookEditSerializer_v361.INSTANCE, 97) + .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v361.INSTANCE, 98) + .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v361.INSTANCE, 99) + .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v361.INSTANCE, 100) + .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v361.INSTANCE, 101) + .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v361.INSTANCE, 102) + .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v361.INSTANCE, 103) + .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v361.INSTANCE, 104) + .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v361.INSTANCE, 105) + .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v361.INSTANCE, 106) + .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v361.INSTANCE, 107) + .registerPacket(SetScorePacket.class, SetScoreSerializer_v361.INSTANCE, 108) + .registerPacket(LabTablePacket.class, LabTableSerializer_v361.INSTANCE, 109) + .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v361.INSTANCE, 110) + .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v361.INSTANCE, 111) + .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v361.INSTANCE, 112) + .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v361.INSTANCE, 113) + .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v361.INSTANCE, 114) + .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v361.INSTANCE, 115) + .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v361.INSTANCE, 117) + .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v361.INSTANCE, 118) + .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v361.INSTANCE, 119) + .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v361.INSTANCE, 120) + .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v361.INSTANCE, 121) + .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v361.INSTANCE, 122) + .registerPacket(LevelSoundEventPacket.class, LevelSoundEvent3Serializer_v361.INSTANCE, 123) + .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v361.INSTANCE, 124) + .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v361.INSTANCE, 125) + .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v361.INSTANCE, 126) // AddEntityPacket 127 // RemoveEntityPacket 128 - .registerPacket(ClientCacheStatusPacket.class, ClientCacheStatusSerializer_v363.INSTANCE, 129) - .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v363.INSTANCE, 130) - .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v363.INSTANCE, 131) - .registerPacket(StructureTemplateDataExportRequestPacket.class, StructureTemplateDataExportRequestSerializer_v363.INSTANCE, 132) - .registerPacket(StructureTemplateDataExportResponsePacket.class, StructureTemplateDataExportResponseSerializer_v363.INSTANCE, 133) - .registerPacket(UpdateBlockPropertiesPacket.class, UpdateBlockPropertiesSerializer_v363.INSTANCE, 134) - .registerPacket(ClientCacheBlobStatusPacket.class, ClientCacheBlobStatusSerializer_v363.INSTANCE, 135) - .registerPacket(ClientCacheMissResponsePacket.class, ClientCacheMissResponseSerializer_v363.INSTANCE, 136) + .registerPacket(ClientCacheStatusPacket.class, ClientCacheStatusSerializer_v361.INSTANCE, 129) + .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v361.INSTANCE, 130) + .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v361.INSTANCE, 131) + .registerPacket(StructureTemplateDataExportRequestPacket.class, StructureTemplateDataExportRequestSerializer_v361.INSTANCE, 132) + .registerPacket(StructureTemplateDataExportResponsePacket.class, StructureTemplateDataExportResponseSerializer_v361.INSTANCE, 133) + .registerPacket(UpdateBlockPropertiesPacket.class, UpdateBlockPropertiesSerializer_v361.INSTANCE, 134) + .registerPacket(ClientCacheBlobStatusPacket.class, ClientCacheBlobStatusSerializer_v361.INSTANCE, 135) + .registerPacket(ClientCacheMissResponsePacket.class, ClientCacheMissResponseSerializer_v361.INSTANCE, 136) - .registerPacket(EducationSettingsPacket.class, EducationSettingsSerializer_v363.INSTANCE, 137) - .registerPacket(EmotePacket.class, EmoteSerializer_v363.INSTANCE, 138) - .registerPacket(MultiplayerSettingsPacket.class, MultiplayerSettingsSerializer_v363.INSTANCE, 139) - .registerPacket(SettingsCommandPacket.class, SettingsCommandSerializer_v363.INSTANCE, 140) - .registerPacket(AnvilDamagePacket.class, AnvilDamageSerializer_v363.INSTANCE, 141) - .registerPacket(CompletedUsingItemPacket.class, CompletedUsingItemSerializer_v363.INSTANCE, 142) - .registerPacket(NetworkSettingsPacket.class, NetworkSettingsSerializer_v363.INSTANCE, 143) - .registerPacket(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v363.INSTANCE, 144) +// .registerPacket(EducationSettingsPacket.class, EducationSettingsSerializer_v363.INSTANCE, 137) +// .registerPacket(EmotePacket.class, EmoteSerializer_v363.INSTANCE, 138) +// .registerPacket(MultiplayerSettingsPacket.class, MultiplayerSettingsSerializer_v363.INSTANCE, 139) +// .registerPacket(SettingsCommandPacket.class, SettingsCommandSerializer_v363.INSTANCE, 140) +// .registerPacket(AnvilDamagePacket.class, AnvilDamageSerializer_v363.INSTANCE, 141) +// .registerPacket(CompletedUsingItemPacket.class, CompletedUsingItemSerializer_v363.INSTANCE, 142) +// .registerPacket(NetworkSettingsPacket.class, NetworkSettingsSerializer_v363.INSTANCE, 143) +// .registerPacket(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v363.INSTANCE, 144) .build(); } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java deleted file mode 100644 index 5866bc936..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddBehaviorTreeSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.AddBehaviorTreePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddBehaviorTreeSerializer_v363 implements PacketSerializer { - public static final AddBehaviorTreeSerializer_v363 INSTANCE = new AddBehaviorTreeSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AddBehaviorTreePacket packet) { - BedrockUtils.writeString(buffer, packet.getBehaviorTreeJson()); - } - - @Override - public void deserialize(ByteBuf buffer, AddBehaviorTreePacket packet) { - packet.setBehaviorTreeJson(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java deleted file mode 100644 index c9f6d3d2d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddEntitySerializer_v363.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddEntitySerializer_v363 implements PacketSerializer { - public static final AddEntitySerializer_v363 INSTANCE = new AddEntitySerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AddEntityPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeString(buffer, packet.getIdentifier()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeVector3f(buffer, packet.getMotion()); - BedrockUtils.writeVector3f(buffer, packet.getRotation()); - BedrockUtils.writeArray(buffer, packet.getAttributes(), BedrockUtils::writeEntityAttribute); - BedrockUtils.writeEntityData(buffer, packet.getMetadata()); - BedrockUtils.writeArray(buffer, packet.getEntityLinks(), BedrockUtils::writeEntityLink); - } - - @Override - public void deserialize(ByteBuf buffer, AddEntityPacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setIdentifier(BedrockUtils.readString(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setMotion(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readVector3f(buffer)); - BedrockUtils.readArray(buffer, packet.getAttributes(), BedrockUtils::readEntityAttribute); - BedrockUtils.readEntityData(buffer, packet.getMetadata()); - BedrockUtils.readArray(buffer, packet.getEntityLinks(), BedrockUtils::readEntityLink); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java deleted file mode 100644 index a67d8593e..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddItemEntitySerializer_v363.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.AddItemEntityPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddItemEntitySerializer_v363 implements PacketSerializer { - public static final AddItemEntitySerializer_v363 INSTANCE = new AddItemEntitySerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AddItemEntityPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeItemData(buffer, packet.getItemInHand()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeVector3f(buffer, packet.getMotion()); - BedrockUtils.writeEntityData(buffer, packet.getMetadata()); - buffer.writeBoolean(packet.isFromFishing()); - } - - @Override - public void deserialize(ByteBuf buffer, AddItemEntityPacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setItemInHand(BedrockUtils.readItemData(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setMotion(BedrockUtils.readVector3f(buffer)); - BedrockUtils.readEntityData(buffer, packet.getMetadata()); - packet.setFromFishing(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java deleted file mode 100644 index 31a5da475..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPaintingSerializer_v363.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.network.VarInts.readInt; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddPaintingSerializer_v363 implements PacketSerializer { - public static final AddPaintingSerializer_v363 INSTANCE = new AddPaintingSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AddPaintingPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getDirection()); - BedrockUtils.writeString(buffer, packet.getName()); - } - - @Override - public void deserialize(ByteBuf buffer, AddPaintingPacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setDirection(readInt(buffer)); - packet.setName(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java deleted file mode 100644 index 483bf51b0..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AddPlayerSerializer_v363.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddPlayerSerializer_v363 implements PacketSerializer { - public static final AddPlayerSerializer_v363 INSTANCE = new AddPlayerSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AddPlayerPacket packet) { - BedrockUtils.writeUuid(buffer, packet.getUuid()); - BedrockUtils.writeString(buffer, packet.getUsername()); - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeString(buffer, packet.getPlatformChatId()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeVector3f(buffer, packet.getMotion()); - BedrockUtils.writeVector3f(buffer, packet.getRotation()); - BedrockUtils.writeItemData(buffer, packet.getHand()); - BedrockUtils.writeEntityData(buffer, packet.getMetadata()); - AdventureSettingsSerializer_v363.INSTANCE.serialize(buffer, packet.getAdventureSettings()); - BedrockUtils.writeArray(buffer, packet.getEntityLinks(), BedrockUtils::writeEntityLink); - BedrockUtils.writeString(buffer, packet.getDeviceId()); - } - - @Override - public void deserialize(ByteBuf buffer, AddPlayerPacket packet) { - packet.setUuid(BedrockUtils.readUuid(buffer)); - packet.setUsername(BedrockUtils.readString(buffer)); - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setPlatformChatId(BedrockUtils.readString(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setMotion(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readVector3f(buffer)); - packet.setHand(BedrockUtils.readItemData(buffer)); - BedrockUtils.readEntityData(buffer, packet.getMetadata()); - AdventureSettingsSerializer_v363.INSTANCE.deserialize(buffer, packet.getAdventureSettings()); - BedrockUtils.readArray(buffer, packet.getEntityLinks(), BedrockUtils::readEntityLink); - packet.setDeviceId(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java deleted file mode 100644 index 26931445e..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AdventureSettingsSerializer_v363.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.CommandPermission; -import com.nukkitx.protocol.bedrock.data.PlayerPermission; -import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Set; - -import static com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket.Flag.*; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AdventureSettingsSerializer_v363 implements PacketSerializer { - public static final AdventureSettingsSerializer_v363 INSTANCE = new AdventureSettingsSerializer_v363(); - - private static final CommandPermission[] COMMAND_PERMISSIONS = CommandPermission.values(); - private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); - - private static final AdventureSettingsPacket.Flag[] FLAGS_1 = {IMMUTABLE_WORLD, NO_PVP, NO_PVM, null, NO_MVP, AUTO_JUMP, MAY_FLY, NO_CLIP, WORLD_BUILDER, FLYING, MUTE}; - private static final AdventureSettingsPacket.Flag[] FLAGS_2 = {MINE, DOORS_AND_SWITCHES, OPEN_CONTAINERS, ATTACK_PLAYERS, ATTACK_MOBS, OP, null, TELEPORT, BUILD, SET_DEFAULT}; - - private static final Object2IntMap FLAGS_TO_BIT_1 = new Object2IntOpenHashMap<>(); - private static final Object2IntMap FLAGS_TO_BIT_2 = new Object2IntOpenHashMap<>(); - - static { - FLAGS_TO_BIT_1.put(IMMUTABLE_WORLD, 0x1); - FLAGS_TO_BIT_1.put(NO_PVP, 0x2); - FLAGS_TO_BIT_1.put(NO_PVM, 0x4); - FLAGS_TO_BIT_1.put(NO_MVP, 0x10); - FLAGS_TO_BIT_1.put(AUTO_JUMP, 0x20); - FLAGS_TO_BIT_1.put(MAY_FLY, 0x40); - FLAGS_TO_BIT_1.put(NO_CLIP, 0x80); - FLAGS_TO_BIT_1.put(WORLD_BUILDER, 0x100); - FLAGS_TO_BIT_1.put(FLYING, 0x200); - FLAGS_TO_BIT_1.put(MUTE, 0x400); - - FLAGS_TO_BIT_2.put(MINE, 0x1); - FLAGS_TO_BIT_2.put(DOORS_AND_SWITCHES, 0x2); - FLAGS_TO_BIT_2.put(OPEN_CONTAINERS, 0x04); - FLAGS_TO_BIT_2.put(ATTACK_PLAYERS, 0x8); - FLAGS_TO_BIT_2.put(ATTACK_MOBS, 0x10); - FLAGS_TO_BIT_2.put(OP, 0x20); - FLAGS_TO_BIT_2.put(TELEPORT, 0x80); - FLAGS_TO_BIT_2.put(BUILD, 0x100); - FLAGS_TO_BIT_2.put(SET_DEFAULT, 0x200); - } - - - @Override - public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) { - int flags1 = 0; - int flags2 = 0; - for (AdventureSettingsPacket.Flag flag : packet.getFlags()) { - if (FLAGS_TO_BIT_1.containsKey(flag)) { - flags1 |= FLAGS_TO_BIT_1.get(flag); - } else if (FLAGS_TO_BIT_2.containsKey(flag)) { - flags2 |= FLAGS_TO_BIT_2.get(flag); - } - } - VarInts.writeUnsignedInt(buffer, flags1); - VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal()); - VarInts.writeUnsignedInt(buffer, flags2); - VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal()); - VarInts.writeUnsignedInt(buffer, 0); // Useless - buffer.writeLongLE(packet.getUniqueEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) { - int flags1 = VarInts.readUnsignedInt(buffer); - packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]); - int flags2 = VarInts.readUnsignedInt(buffer); - packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]); - VarInts.readUnsignedInt(buffer); // useless - packet.setUniqueEntityId(buffer.readLongLE()); - - Set flags = packet.getFlags(); - for (int i = 0; i < FLAGS_1.length; i++) { - if ((flags1 & (1 << i)) != 0) { - flags.add(FLAGS_1[i]); - } - } - - for (int i = 0; i < FLAGS_2.length; i++) { - if ((flags2 & (1 << i)) != 0) { - flags.add(FLAGS_2[i]); - } - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java deleted file mode 100644 index 8f6200817..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnimateSerializer_v363.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.AnimatePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.AnimatePacket.Action; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AnimateSerializer_v363 implements PacketSerializer { - public static final AnimateSerializer_v363 INSTANCE = new AnimateSerializer_v363(); - private static final Int2ObjectBiMap types = new Int2ObjectBiMap<>(); - - static { - types.put(0, Action.NO_ACTION); - types.put(1, Action.SWING_ARM); - types.put(3, Action.WAKE_UP); - types.put(4, Action.CRITICAL_HIT); - types.put(5, Action.MAGIC_CRITICAL_HIT); - types.put(128, Action.ROW_RIGHT); - types.put(129, Action.ROW_LEFT); - } - - @Override - public void serialize(ByteBuf buffer, AnimatePacket packet) { - Action action = packet.getAction(); - VarInts.writeInt(buffer, types.get(action)); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) { - buffer.writeFloatLE(packet.getRowingTime()); - } - } - - @Override - public void deserialize(ByteBuf buffer, AnimatePacket packet) { - Action action = types.get(VarInts.readInt(buffer)); - packet.setAction(action); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - if (action == AnimatePacket.Action.ROW_LEFT || action == AnimatePacket.Action.ROW_RIGHT) { - packet.setRowingTime(buffer.readFloatLE()); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java deleted file mode 100644 index 411fcb5ba..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AnvilDamageSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.AnvilDamagePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class AnvilDamageSerializer_v363 implements PacketSerializer { - - public static final AnvilDamageSerializer_v363 INSTANCE = new AnvilDamageSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AnvilDamagePacket packet) { - buffer.writeByte(packet.getDamage()); - BedrockUtils.writeBlockPosition(buffer, packet.getPosition()); - } - - @Override - public void deserialize(ByteBuf buffer, AnvilDamagePacket packet) { - packet.setDamage(buffer.readByte()); - packet.setPosition(BedrockUtils.readBlockPosition(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java deleted file mode 100644 index f6ef11349..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AutomationClientConnectSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.AutomationClientConnectPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AutomationClientConnectSerializer_v363 implements PacketSerializer { - public static final AutomationClientConnectSerializer_v363 INSTANCE = new AutomationClientConnectSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, AutomationClientConnectPacket packet) { - BedrockUtils.writeString(buffer, packet.getAddress()); - } - - @Override - public void deserialize(ByteBuf buffer, AutomationClientConnectPacket packet) { - packet.setAddress(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java deleted file mode 100644 index 093e7221f..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java +++ /dev/null @@ -1,299 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.data.CommandData; -import com.nukkitx.protocol.bedrock.data.CommandEnumData; -import com.nukkitx.protocol.bedrock.data.CommandParamData; -import com.nukkitx.protocol.bedrock.data.CommandParamType; -import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.ObjIntConsumer; -import java.util.function.ToIntFunction; - -import static com.nukkitx.protocol.bedrock.data.CommandParamData.Type.*; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AvailableCommandsSerializer_v363 implements PacketSerializer { - private static final InternalLogger log = InternalLoggerFactory.getInstance(AvailableCommandsSerializer_v363.class); - public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); - private static final ObjIntConsumer WRITE_BYTE = ByteBuf::writeByte; - private static final ObjIntConsumer WRITE_SHORT = ByteBuf::writeShortLE; - private static final ObjIntConsumer WRITE_INT = ByteBuf::writeIntLE; - private static final ToIntFunction READ_BYTE = ByteBuf::readUnsignedByte; - private static final ToIntFunction READ_SHORT = ByteBuf::readUnsignedShortLE; - private static final ToIntFunction READ_INT = ByteBuf::readIntLE; - private static final Int2ObjectBiMap PARAM_TYPES = new Int2ObjectBiMap<>(); - - static { - PARAM_TYPES.put(1, INT); - PARAM_TYPES.put(2, FLOAT); - PARAM_TYPES.put(3, VALUE); - PARAM_TYPES.put(4, WILDCARD_INT); - PARAM_TYPES.put(5, OPERATOR); - PARAM_TYPES.put(6, TARGET); - PARAM_TYPES.put(7, WILDCARD_TARGET); - PARAM_TYPES.put(14, FILE_PATH); - PARAM_TYPES.put(18, INT_RANGE); - PARAM_TYPES.put(27, STRING); - PARAM_TYPES.put(29, POSITION); - PARAM_TYPES.put(32, MESSAGE); - PARAM_TYPES.put(34, TEXT); - PARAM_TYPES.put(37, JSON); - PARAM_TYPES.put(44, COMMAND); - } - - @Override - public void serialize(ByteBuf buffer, AvailableCommandsPacket packet) { - Set enumValuesSet = new ObjectOpenHashSet<>(); - Set postfixSet = new ObjectOpenHashSet<>(); - Set enumsSet = new ObjectOpenHashSet<>(); - Set softEnumsSet = new ObjectOpenHashSet<>(); - - // Get all enum values - for (CommandData data : packet.getCommands()) { - if (data.getAliases() != null) { - Collections.addAll(enumValuesSet, data.getAliases().getValues()); - enumsSet.add(data.getAliases()); - } - - for (CommandParamData[] overload : data.getOverloads()) { - for (CommandParamData parameter : overload) { - CommandEnumData commandEnumData = parameter.getEnumData(); - if (commandEnumData != null) { - if (commandEnumData.isSoft()) { - softEnumsSet.add(commandEnumData); - } else { - Collections.addAll(enumValuesSet, commandEnumData.getValues()); - enumsSet.add(commandEnumData); - } - } - - String postfix = parameter.getPostfix(); - if (postfix != null) { - postfixSet.add(postfix); - } - } - } - } - - List enumValues = new ObjectArrayList<>(enumValuesSet); - List postFixes = new ObjectArrayList<>(postfixSet); - List enums = new ObjectArrayList<>(enumsSet); - List softEnums = new ObjectArrayList<>(softEnumsSet); - - // Determine width of enum index - ObjIntConsumer indexWriter; - int valuesSize = enumValues.size(); - if (valuesSize < 0x100) { - indexWriter = WRITE_BYTE; - } else if (valuesSize < 0x10000) { - indexWriter = WRITE_SHORT; - } else { - indexWriter = WRITE_INT; - } - - BedrockUtils.writeArray(buffer, enumValues, BedrockUtils::writeString); - BedrockUtils.writeArray(buffer, postFixes, BedrockUtils::writeString); - - // Write enums - BedrockUtils.writeArray(buffer, enums, (buf, commandEnum) -> { - BedrockUtils.writeString(buf, commandEnum.getName()); - - VarInts.writeUnsignedInt(buffer, commandEnum.getValues().length); - for (String value : commandEnum.getValues()) { - int index = enumValues.indexOf(value); - Preconditions.checkArgument(index > -1, "Invalid enum value detected"); - indexWriter.accept(buf, index); - } - }); - - // Write command data - BedrockUtils.writeArray(buffer, packet.getCommands(), (buf, commandData) -> { - BedrockUtils.writeString(buf, commandData.getName()); - BedrockUtils.writeString(buf, commandData.getDescription()); - byte flags = 0; - if (commandData.getFlags() != null) { - for (CommandData.Flag flag : commandData.getFlags()) { - flags |= 1 << flag.ordinal(); - } - } - buf.writeByte(flags); - buf.writeByte(commandData.getPermission()); - - CommandEnumData aliases = commandData.getAliases(); - buf.writeIntLE(enums.indexOf(aliases)); - - CommandParamData[][] overloads = commandData.getOverloads(); - VarInts.writeUnsignedInt(buf, overloads.length); - for (CommandParamData[] overload : overloads) { - VarInts.writeUnsignedInt(buf, overload.length); - for (CommandParamData param : overload) { - BedrockUtils.writeString(buf, param.getName()); - - int index; - boolean postfix = false; - boolean enumData = false; - boolean softEnum = false; - if (param.getPostfix() != null) { - postfix = true; - index = postFixes.indexOf(param.getPostfix()); - } else if (param.getEnumData() != null) { - if (param.getEnumData().isSoft()) { - softEnum = true; - index = softEnums.indexOf(param.getEnumData()); - } else { - enumData = true; - index = enums.indexOf(param.getEnumData()); - } - } else if (param.getType() != null) { - index = PARAM_TYPES.get(param.getType()); - } else { - throw new IllegalStateException("No param type specified"); - } - - CommandParamType type = new CommandParamType(index, enumData, softEnum, postfix); - - buf.writeIntLE(type.serialize()); - buf.writeBoolean(param.isOptional()); - byte options = 0; - if (param.getOptions() != null) { - for (CommandParamData.Option opt : param.getOptions()) { - options |= 1 << opt.ordinal(); - } - } - buf.writeByte(options); - } - } - }); - - BedrockUtils.writeArray(buffer, softEnums, BedrockUtils::writeCommandEnumData); - } - - @Override - public void deserialize(ByteBuf buffer, AvailableCommandsPacket packet) { - List enumValues = new ObjectArrayList<>(); - List postFixes = new ObjectArrayList<>(); - List enums = new ObjectArrayList<>(); - List commands = new ObjectArrayList<>(); - List softEnums = new ObjectArrayList<>(); - - BedrockUtils.readArray(buffer, enumValues, BedrockUtils::readString); - BedrockUtils.readArray(buffer, postFixes, BedrockUtils::readString); - - // Determine width of enum index - ToIntFunction indexReader; - int valuesSize = enumValues.size(); - if (valuesSize < 0x100) { - indexReader = READ_BYTE; - } else if (valuesSize < 0x10000) { - indexReader = READ_SHORT; - } else { - indexReader = READ_INT; - } - - BedrockUtils.readArray(buffer, enums, buf -> { - String name = BedrockUtils.readString(buf); - - int length = VarInts.readUnsignedInt(buffer); - String[] values = new String[length]; - for (int i = 0; i < length; i++) { - values[i] = enumValues.get(indexReader.applyAsInt(buf)); - } - return new CommandEnumData(name, values, false); - }); - - BedrockUtils.readArray(buffer, commands, buf -> { - String name = BedrockUtils.readString(buf); - String description = BedrockUtils.readString(buf); - byte flags = buf.readByte(); - byte permissions = buf.readByte(); - int aliasesIndex = buf.readIntLE(); - - CommandParamData.Builder[][] overloads = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)][]; - for (int i = 0; i < overloads.length; i++) { - overloads[i] = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)]; - for (int i2 = 0; i2 < overloads[i].length; i2++) { - String parameterName = BedrockUtils.readString(buf); - - CommandParamType type = CommandParamType.deserialize(buf.readIntLE()); - - boolean optional = buf.readBoolean(); - byte unknownByte = buf.readByte(); - - overloads[i][i2] = new CommandParamData.Builder(parameterName, type, optional, unknownByte); - } - } - return new CommandData.Builder(name, description, flags, permissions, aliasesIndex, overloads); - }); - - BedrockUtils.readArray(buffer, softEnums, buf -> BedrockUtils.readCommandEnumData(buffer, true)); - - // Generate command data - - for (CommandData.Builder command : commands) { - byte flagsByte = command.getFlags(); - List flags = new ObjectArrayList<>(); - for (int i = 0; i < 8; i++) { - if (((flagsByte >>> i) & 0xf) != 0) { - flags.add(CommandData.Flag.values()[i]); - } - } - int aliasesIndex = command.getAliases(); - CommandEnumData aliases = aliasesIndex == -1 ? null : enums.get(aliasesIndex); - - CommandParamData.Builder[][] overloadBuilders = command.getOverloads(); - CommandParamData[][] overloads = new CommandParamData[overloadBuilders.length][]; - for (int i = 0; i < overloadBuilders.length; i++) { - overloads[i] = new CommandParamData[overloadBuilders[i].length]; - for (int i2 = 0; i2 < overloadBuilders[i].length; i2++) { - String name = overloadBuilders[i][i2].getName(); - CommandParamType type = overloadBuilders[i][i2].getType(); - boolean optional = overloadBuilders[i][i2].isOptional(); - byte optionsByte = overloadBuilders[i][i2].getOptions(); - List options = new ObjectArrayList<>(); - for (int oi = 0; oi < 8; oi++) { - if (((optionsByte >>> oi) & 0xf) != 0) { - options.add(CommandParamData.Option.values()[oi]); - } - } - - String postfix = null; - CommandEnumData enumData = null; - CommandParamData.Type paramType = null; - if (type.isPostfix()) { - postfix = postFixes.get(type.getValue()); - } else { - if (type.isCommandEnum()) { - enumData = enums.get(type.getValue()); - } else if (type.isSoftEnum()) { - enumData = softEnums.get(type.getValue()); - } else { - paramType = PARAM_TYPES.get(type.getValue()); - if (paramType == null) { - log.debug("Unknown parameter type {} from {} in {}", type.getValue(), name, command.getName()); - } - } - } - overloads[i][i2] = new CommandParamData(name, optional, enumData, paramType, postfix, options); - } - } - - packet.getCommands().add(new CommandData(command.getName(), command.getDescription(), - flags, command.getPermission(), aliases, overloads)); - } - } -} \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java deleted file mode 100644 index 866848067..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableEntityIdentifiersSerializer_v363.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.protocol.bedrock.packet.AvailableEntityIdentifiersPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AvailableEntityIdentifiersSerializer_v363 implements PacketSerializer { - public static final AvailableEntityIdentifiersSerializer_v363 INSTANCE = new AvailableEntityIdentifiersSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) { - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) { - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setTag(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java deleted file mode 100644 index b504324a4..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BiomeDefinitionListSerializer_v363.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BiomeDefinitionListSerializer_v363 implements PacketSerializer { - public static final BiomeDefinitionListSerializer_v363 INSTANCE = new BiomeDefinitionListSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, BiomeDefinitionListPacket packet) { - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) { - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setTag(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java deleted file mode 100644 index 1108b4703..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEntityDataSerializer_v363.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BlockEntityDataSerializer_v363 implements PacketSerializer { - public static final BlockEntityDataSerializer_v363 INSTANCE = new BlockEntityDataSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, BlockEntityDataPacket packet) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getData()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setData(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java deleted file mode 100644 index 6f0ce8554..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockEventSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.BlockEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BlockEventSerializer_v363 implements PacketSerializer { - public static final BlockEventSerializer_v363 INSTANCE = new BlockEventSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, BlockEventPacket packet) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeInt(buffer, packet.getEventType()); - VarInts.writeInt(buffer, packet.getEventData()); - } - - @Override - public void deserialize(ByteBuf buffer, BlockEventPacket packet) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setEventType(VarInts.readInt(buffer)); - packet.setEventData(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java deleted file mode 100644 index 3ce69ef16..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BlockPickRequestSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.BlockPickRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BlockPickRequestSerializer_v363 implements PacketSerializer { - public static final BlockPickRequestSerializer_v363 INSTANCE = new BlockPickRequestSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, BlockPickRequestPacket packet) { - BedrockUtils.writeVector3i(buffer, packet.getBlockPosition()); - buffer.writeBoolean(packet.isAddUserData()); - buffer.writeByte(packet.getHotbarSlot()); - } - - @Override - public void deserialize(ByteBuf buffer, BlockPickRequestPacket packet) { - packet.setBlockPosition(BedrockUtils.readVector3i(buffer)); - packet.setAddUserData(buffer.readBoolean()); - packet.setHotbarSlot(buffer.readUnsignedByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java deleted file mode 100644 index 3a5bce023..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BookEditSerializer_v363.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.BookEditPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.BookEditPacket.Action; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BookEditSerializer_v363 implements PacketSerializer { - public static final BookEditSerializer_v363 INSTANCE = new BookEditSerializer_v363(); - private static final Int2ObjectBiMap types = new Int2ObjectBiMap<>(); - - static { - types.put(0, Action.REPLACE_PAGE); - types.put(1, Action.ADD_PAGE); - types.put(2, Action.DELETE_PAGE); - types.put(3, Action.SWAP_PAGES); - types.put(4, Action.SIGN_BOOK); - } - - @Override - public void serialize(ByteBuf buffer, BookEditPacket packet) { - buffer.writeByte(packet.getAction().ordinal()); - buffer.writeByte(packet.getInventorySlot()); - switch (packet.getAction()) { - case REPLACE_PAGE: - case ADD_PAGE: - buffer.writeByte(packet.getPageNumber()); - BedrockUtils.writeString(buffer, packet.getText()); - BedrockUtils.writeString(buffer, packet.getPhotoName()); - break; - case DELETE_PAGE: - buffer.writeByte(packet.getPageNumber()); - break; - case SWAP_PAGES: - buffer.writeByte(packet.getPageNumber()); - buffer.writeByte(packet.getSecondaryPageNumber()); - break; - case SIGN_BOOK: - BedrockUtils.writeString(buffer, packet.getTitle()); - BedrockUtils.writeString(buffer, packet.getAuthor()); - BedrockUtils.writeString(buffer, packet.getXuid()); - break; - } - } - - @Override - public void deserialize(ByteBuf buffer, BookEditPacket packet) { - packet.setAction(types.get(buffer.readUnsignedByte())); - packet.setInventorySlot(buffer.readUnsignedByte()); - switch (packet.getAction()) { - case REPLACE_PAGE: - case ADD_PAGE: - packet.setPageNumber(buffer.readUnsignedByte()); - packet.setText(BedrockUtils.readString(buffer)); - packet.setPhotoName(BedrockUtils.readString(buffer)); - break; - case DELETE_PAGE: - packet.setPageNumber(buffer.readUnsignedByte()); - break; - case SWAP_PAGES: - packet.setPageNumber(buffer.readUnsignedByte()); - packet.setSecondaryPageNumber(buffer.readUnsignedByte()); - break; - case SIGN_BOOK: - packet.setTitle(BedrockUtils.readString(buffer)); - packet.setAuthor(BedrockUtils.readString(buffer)); - packet.setXuid(BedrockUtils.readString(buffer)); - break; - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java deleted file mode 100644 index 3fe88d22b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/BossEventSerializer_v363.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.BossEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class BossEventSerializer_v363 implements PacketSerializer { - public static final BossEventSerializer_v363 INSTANCE = new BossEventSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, BossEventPacket packet) { - VarInts.writeLong(buffer, packet.getBossUniqueEntityId()); - VarInts.writeUnsignedInt(buffer, packet.getAction().ordinal()); - - switch (packet.getAction()) { - case REGISTER_PLAYER: - case UNREGISTER_PLAYER: - VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); - break; - case SHOW: - BedrockUtils.writeString(buffer, packet.getTitle()); - buffer.writeFloatLE(packet.getHealthPercentage()); - // fall through - case DARKEN_SKY: - buffer.writeShortLE(packet.getDarkenSky()); - // fall through - case OVERLAY: - VarInts.writeUnsignedInt(buffer, packet.getColor()); - VarInts.writeUnsignedInt(buffer, packet.getOverlay()); - break; - case HEALTH_PERCENTAGE: - buffer.writeFloatLE(packet.getHealthPercentage()); - break; - case TITLE: - BedrockUtils.writeString(buffer, packet.getTitle()); - break; - default: - throw new RuntimeException("BossEvent transactionType was unknown!"); - } - } - - @Override - public void deserialize(ByteBuf buffer, BossEventPacket packet) { - packet.setBossUniqueEntityId(VarInts.readInt(buffer)); - BossEventPacket.Action action = BossEventPacket.Action.values()[VarInts.readUnsignedInt(buffer)]; - packet.setAction(action); - - switch (action) { - case REGISTER_PLAYER: - case UNREGISTER_PLAYER: - packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); - break; - case SHOW: - packet.setTitle(BedrockUtils.readString(buffer)); - packet.setHealthPercentage(buffer.readFloatLE()); - // fall through - case DARKEN_SKY: - packet.setDarkenSky(buffer.readUnsignedShortLE()); - // fall through - case OVERLAY: - packet.setColor(VarInts.readUnsignedInt(buffer)); - packet.setOverlay(VarInts.readUnsignedInt(buffer)); - break; - case HEALTH_PERCENTAGE: - packet.setHealthPercentage(buffer.readFloatLE()); - break; - case TITLE: - packet.setTitle(BedrockUtils.readString(buffer)); - break; - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java deleted file mode 100644 index de7ffff14..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CameraSerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.CameraPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CameraSerializer_v363 implements PacketSerializer { - public static final CameraSerializer_v363 INSTANCE = new CameraSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, CameraPacket packet) { - VarInts.writeLong(buffer, packet.getCameraUniqueEntityId()); - VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, CameraPacket packet) { - packet.setCameraUniqueEntityId(VarInts.readLong(buffer)); - packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java deleted file mode 100644 index cacd8dde9..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChangeDimensionSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ChangeDimensionPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ChangeDimensionSerializer_v363 implements PacketSerializer { - public static final ChangeDimensionSerializer_v363 INSTANCE = new ChangeDimensionSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ChangeDimensionPacket packet) { - VarInts.writeInt(buffer, packet.getDimension()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - buffer.writeBoolean(packet.isRespawn()); - } - - @Override - public void deserialize(ByteBuf buffer, ChangeDimensionPacket packet) { - packet.setDimension(VarInts.readInt(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setRespawn(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java deleted file mode 100644 index 66d536caf..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ChunkRadiusUpdatedSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ChunkRadiusUpdatedPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ChunkRadiusUpdatedSerializer_v363 implements PacketSerializer { - public static final ChunkRadiusUpdatedSerializer_v363 INSTANCE = new ChunkRadiusUpdatedSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ChunkRadiusUpdatedPacket packet) { - VarInts.writeInt(buffer, packet.getRadius()); - } - - @Override - public void deserialize(ByteBuf buffer, ChunkRadiusUpdatedPacket packet) { - packet.setRadius(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java deleted file mode 100644 index ef692724e..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheBlobStatusSerializer_v363.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ClientCacheBlobStatusPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.longs.LongList; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.function.LongConsumer; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClientCacheBlobStatusSerializer_v363 implements PacketSerializer { - public static final ClientCacheBlobStatusSerializer_v363 INSTANCE = new ClientCacheBlobStatusSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) { - LongList acks = packet.getAcks(); - LongList nacks = packet.getNaks(); - VarInts.writeUnsignedInt(buffer, acks.size()); - VarInts.writeUnsignedInt(buffer, nacks.size()); - - acks.forEach((LongConsumer) buffer::writeLongLE); - nacks.forEach((LongConsumer) buffer::writeLongLE); - } - - @Override - public void deserialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) { - int acksLength = VarInts.readUnsignedInt(buffer); - int naksLength = VarInts.readUnsignedInt(buffer); - - LongList acks = packet.getAcks(); - for (int i = 0; i < acksLength; i++) { - acks.add(buffer.readLongLE()); - } - - LongList naks = packet.getNaks(); - for (int i = 0; i < naksLength; i++) { - naks.add(buffer.readLongLE()); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java deleted file mode 100644 index af5acdb52..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheMissResponseSerializer_v363.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ClientCacheMissResponsePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClientCacheMissResponseSerializer_v363 implements PacketSerializer { - public static final ClientCacheMissResponseSerializer_v363 INSTANCE = new ClientCacheMissResponseSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { - Long2ObjectMap blobs = packet.getBlobs(); - VarInts.writeUnsignedInt(buffer, blobs.size()); - - blobs.forEach((id, blob) -> { - buffer.writeLongLE(id); - BedrockUtils.writeByteArray(buffer, blob); - }); - } - - @Override - public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { - Long2ObjectMap blobs = packet.getBlobs(); - - int length = VarInts.readUnsignedInt(buffer); - - for (int i = 0; i < length; i++) { - long id = buffer.readLongLE(); - byte[] blob = BedrockUtils.readByteArray(buffer); - blobs.put(id, blob); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java deleted file mode 100644 index 2fb0359c9..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientCacheStatusSerializer_v363.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ClientCacheStatusPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClientCacheStatusSerializer_v363 implements PacketSerializer { - public static final ClientCacheStatusSerializer_v363 INSTANCE = new ClientCacheStatusSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ClientCacheStatusPacket packet) { - buffer.writeBoolean(packet.isSupported()); - } - - @Override - public void deserialize(ByteBuf buffer, ClientCacheStatusPacket packet) { - packet.setSupported(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java deleted file mode 100644 index 9eefe1019..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientToServerHandshakeSerializer_v363.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ClientToServerHandshakePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClientToServerHandshakeSerializer_v363 implements PacketSerializer { - public static final ClientToServerHandshakeSerializer_v363 INSTANCE = new ClientToServerHandshakeSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ClientToServerHandshakePacket packet) { - // No payload - } - - @Override - public void deserialize(ByteBuf buffer, ClientToServerHandshakePacket packet) { - // No payload - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java deleted file mode 100644 index e2d8e1d0f..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ClientboundMapItemDataSerializer_v363.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.MapDecoration; -import com.nukkitx.protocol.bedrock.data.MapTrackedObject; -import com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.longs.LongList; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.List; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ClientboundMapItemDataSerializer_v363 implements PacketSerializer { - public static final ClientboundMapItemDataSerializer_v363 INSTANCE = new ClientboundMapItemDataSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ClientboundMapItemDataPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueMapId()); - - int type = 0; - int[] colors = packet.getColors(); - if (colors != null && colors.length > 0) { - type |= 0x2; - } - List decorations = packet.getDecorations(); - List trackedObjects = packet.getTrackedObjects(); - if (!decorations.isEmpty() && !trackedObjects.isEmpty()) { - type |= 0x4; - } - LongList trackedEntityIds = packet.getTrackedEntityIds(); - if (!trackedEntityIds.isEmpty()) { - type |= 0x8; - } - - VarInts.writeUnsignedInt(buffer, type); - buffer.writeByte(packet.getDimensionId()); - buffer.writeBoolean(packet.isLocked()); - - if ((type & 0x8) != 0) { - VarInts.writeUnsignedInt(buffer, trackedEntityIds.size()); - for (long trackedEntityId : trackedEntityIds) { - VarInts.writeLong(buffer, trackedEntityId); - } - } - - if ((type & 0xe) != 0) { - buffer.writeByte(packet.getScale()); - } - - if ((type & 0x4) != 0) { - VarInts.writeUnsignedInt(buffer, trackedObjects.size()); - for (MapTrackedObject object : trackedObjects) { - switch (object.getType()) { - case BLOCK: - buffer.writeIntLE(object.getType().ordinal()); - BedrockUtils.writeBlockPosition(buffer, object.getPosition()); - break; - case ENTITY: - buffer.writeIntLE(object.getType().ordinal()); - VarInts.writeLong(buffer, object.getEntityId()); - break; - } - } - - VarInts.writeUnsignedInt(buffer, decorations.size()); - for (MapDecoration decoration : decorations) { - buffer.writeByte(decoration.getImage()); - buffer.writeByte(decoration.getRotation()); - buffer.writeByte(decoration.getXOffset()); - buffer.writeByte(decoration.getYOffset()); - BedrockUtils.writeString(buffer, decoration.getLabel()); - VarInts.writeUnsignedInt(buffer, decoration.getColor()); - } - } - - if ((type & 0x2) != 0) { - VarInts.writeInt(buffer, packet.getWidth()); - VarInts.writeInt(buffer, packet.getHeight()); - VarInts.writeInt(buffer, packet.getXOffset()); - VarInts.writeInt(buffer, packet.getYOffset()); - - VarInts.writeUnsignedInt(buffer, colors.length); - for (int color : colors) { - VarInts.writeUnsignedInt(buffer, color); - } - } - } - - @Override - public void deserialize(ByteBuf buffer, ClientboundMapItemDataPacket packet) { - packet.setUniqueMapId(VarInts.readLong(buffer)); - int type = VarInts.readUnsignedInt(buffer); - packet.setDimensionId(buffer.readUnsignedByte()); - packet.setLocked(buffer.readBoolean()); - - if ((type & 0x8) != 0) { - LongList trackedEntityIds = packet.getTrackedEntityIds(); - int length = VarInts.readUnsignedInt(buffer); - for (int i = 0; i < length; i++) { - trackedEntityIds.add(VarInts.readLong(buffer)); - } - } - - if ((type & 0xe) != 0) { - packet.setScale(buffer.readUnsignedByte()); - } - - if ((type & 0x4) != 0) { - List trackedObjects = packet.getTrackedObjects(); - int length = VarInts.readUnsignedInt(buffer); - for (int i = 0; i < length; i++) { - MapTrackedObject.Type objectType = MapTrackedObject.Type.values()[buffer.readIntLE()]; - switch (objectType) { - case BLOCK: - trackedObjects.add(new MapTrackedObject(BedrockUtils.readBlockPosition(buffer))); - break; - case ENTITY: - trackedObjects.add(new MapTrackedObject(VarInts.readLong(buffer))); - break; - } - } - - List decorations = packet.getDecorations(); - length = VarInts.readUnsignedInt(buffer); - for (int i = 0; i < length; i++) { - int image = buffer.readUnsignedByte(); - int rotation = buffer.readUnsignedByte(); - int xOffset = buffer.readUnsignedByte(); - int yOffset = buffer.readUnsignedByte(); - String label = BedrockUtils.readString(buffer); - int color = VarInts.readUnsignedInt(buffer); - decorations.add(new MapDecoration(image, rotation, xOffset, yOffset, label, color)); - } - } - - if ((type & 0x2) != 0) { - packet.setWidth(VarInts.readInt(buffer)); - packet.setHeight(VarInts.readInt(buffer)); - packet.setXOffset(VarInts.readInt(buffer)); - packet.setYOffset(VarInts.readInt(buffer)); - - int length = VarInts.readUnsignedInt(buffer); - int[] colors = new int[length]; - for (int i = 0; i < length; i++) { - colors[i] = VarInts.readUnsignedInt(buffer); - } - packet.setColors(colors); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java deleted file mode 100644 index 3a238866d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandBlockUpdateSerializer_v363.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.CommandBlockUpdatePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CommandBlockUpdateSerializer_v363 implements PacketSerializer { - public static final CommandBlockUpdateSerializer_v363 INSTANCE = new CommandBlockUpdateSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, CommandBlockUpdatePacket packet) { - buffer.writeBoolean(packet.isBlock()); - - if (packet.isBlock()) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeUnsignedInt(buffer, packet.getCommandBlockMode()); - buffer.writeBoolean(packet.isRedstoneMode()); - buffer.writeBoolean(packet.isConditional()); - } else { - VarInts.writeUnsignedLong(buffer, packet.getMinecartRuntimeEntityId()); - } - - BedrockUtils.writeString(buffer, packet.getCommand()); - BedrockUtils.writeString(buffer, packet.getLastOutput()); - BedrockUtils.writeString(buffer, packet.getName()); - buffer.writeBoolean(packet.isOutputTracked()); - buffer.writeIntLE((int) packet.getTickDelay()); - buffer.writeBoolean(packet.isExecutingOnFirstTick()); - } - - @Override - public void deserialize(ByteBuf buffer, CommandBlockUpdatePacket packet) { - packet.setBlock(buffer.readBoolean()); - - if (packet.isBlock()) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setCommandBlockMode(VarInts.readUnsignedInt(buffer)); - packet.setRedstoneMode(buffer.readBoolean()); - packet.setConditional(buffer.readBoolean()); - } else { - packet.setMinecartRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - } - - packet.setCommand(BedrockUtils.readString(buffer)); - packet.setLastOutput(BedrockUtils.readString(buffer)); - packet.setName(BedrockUtils.readString(buffer)); - packet.setOutputTracked(buffer.readBoolean()); - packet.setTickDelay(buffer.readUnsignedIntLE()); - packet.setExecutingOnFirstTick(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java deleted file mode 100644 index 6ab3b9f04..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandOutputSerializer_v363.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.CommandOutputPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CommandOutputSerializer_v363 implements PacketSerializer { - public static final CommandOutputSerializer_v363 INSTANCE = new CommandOutputSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, CommandOutputPacket packet) { - BedrockUtils.writeCommandOriginData(buffer, packet.getCommandOriginData()); - buffer.writeByte(packet.getOutputType()); - VarInts.writeUnsignedInt(buffer, packet.getSuccessCount()); - - BedrockUtils.writeArray(buffer, packet.getMessages(), BedrockUtils::writeCommandOutputMessage); - - if (packet.getOutputType() == 4) { - BedrockUtils.writeString(buffer, packet.getData()); - } - } - - @Override - public void deserialize(ByteBuf buffer, CommandOutputPacket packet) { - packet.setCommandOriginData(BedrockUtils.readCommandOriginData(buffer)); - packet.setOutputType(buffer.readUnsignedByte()); - packet.setSuccessCount(VarInts.readUnsignedInt(buffer)); - - BedrockUtils.readArray(buffer, packet.getMessages(), BedrockUtils::readCommandOutputMessage); - - if (packet.getOutputType() == 4) { - packet.setData(BedrockUtils.readString(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java deleted file mode 100644 index 58cba8c77..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CommandRequestSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CommandRequestSerializer_v363 implements PacketSerializer { - public static final CommandRequestSerializer_v363 INSTANCE = new CommandRequestSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, CommandRequestPacket packet) { - BedrockUtils.writeString(buffer, packet.getCommand()); - BedrockUtils.writeCommandOriginData(buffer, packet.getCommandOriginData()); - buffer.writeBoolean(packet.isInternal()); - } - - @Override - public void deserialize(ByteBuf buffer, CommandRequestPacket packet) { - packet.setCommand(BedrockUtils.readString(buffer)); - packet.setCommandOriginData(BedrockUtils.readCommandOriginData(buffer)); - packet.setInternal(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java deleted file mode 100644 index 4f0019816..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CompletedUsingItemSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.data.ItemAction; -import com.nukkitx.protocol.bedrock.packet.CompletedUsingItemPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class CompletedUsingItemSerializer_v363 implements PacketSerializer { - - public static final CompletedUsingItemSerializer_v363 INSTANCE = new CompletedUsingItemSerializer_v363(); - - private static final ItemAction[] VALUES = ItemAction.values(); - - @Override - public void serialize(ByteBuf buffer, CompletedUsingItemPacket packet) { - buffer.writeShortLE(packet.getItemId()); - buffer.writeIntLE(packet.getAction().ordinal() - 1); // Enum starts at -1 - } - - @Override - public void deserialize(ByteBuf buffer, CompletedUsingItemPacket packet) { - packet.setItemId(buffer.readUnsignedShortLE()); - packet.setAction(VALUES[buffer.readIntLE() + 1]); // Enum starts at -1 - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java deleted file mode 100644 index 9654802de..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerCloseSerializer_v363.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ContainerCloseSerializer_v363 implements PacketSerializer { - public static final ContainerCloseSerializer_v363 INSTANCE = new ContainerCloseSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ContainerClosePacket packet) { - buffer.writeByte(packet.getWindowId()); - } - - @Override - public void deserialize(ByteBuf buffer, ContainerClosePacket packet) { - packet.setWindowId(buffer.readByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java deleted file mode 100644 index 60389e541..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerOpenSerializer_v363.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ContainerOpenSerializer_v363 implements PacketSerializer { - public static final ContainerOpenSerializer_v363 INSTANCE = new ContainerOpenSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ContainerOpenPacket packet) { - buffer.writeByte(packet.getWindowId()); - buffer.writeByte(packet.getType()); - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, ContainerOpenPacket packet) { - packet.setWindowId(buffer.readByte()); - packet.setType(buffer.readByte()); - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setUniqueEntityId(VarInts.readLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java deleted file mode 100644 index 055ac3488..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ContainerSetDataSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ContainerSetDataPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ContainerSetDataSerializer_v363 implements PacketSerializer { - public static final ContainerSetDataSerializer_v363 INSTANCE = new ContainerSetDataSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ContainerSetDataPacket packet) { - buffer.writeByte(packet.getWindowId()); - VarInts.writeInt(buffer, packet.getProperty()); - VarInts.writeInt(buffer, packet.getValue()); - } - - @Override - public void deserialize(ByteBuf buffer, ContainerSetDataPacket packet) { - packet.setWindowId(buffer.readByte()); - packet.setProperty(VarInts.readInt(buffer)); - packet.setValue(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java deleted file mode 100644 index 4a0b3f240..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingDataSerializer_v363.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.CraftingData; -import com.nukkitx.protocol.bedrock.data.CraftingType; -import com.nukkitx.protocol.bedrock.data.ItemData; -import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CraftingDataSerializer_v363 implements PacketSerializer { - public static final CraftingDataSerializer_v363 INSTANCE = new CraftingDataSerializer_v363(); - - private static final InternalLogger log = InternalLoggerFactory.getInstance(CraftingDataSerializer_v363.class); - - @Override - public void serialize(ByteBuf buffer, CraftingDataPacket packet) { - BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { - VarInts.writeInt(buf, craftingData.getType().ordinal()); - switch (craftingData.getType()) { - case SHAPELESS: - case SHAPELESS_CHEMISTRY: - case SHULKER_BOX: - BedrockUtils.writeString(buf, craftingData.getRecipeId()); - BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeRecipeIngredient); - BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); - BedrockUtils.writeUuid(buf, craftingData.getUuid()); - BedrockUtils.writeString(buf, craftingData.getCraftingTag()); - VarInts.writeInt(buf, craftingData.getPriority()); - break; - case SHAPED: - case SHAPED_CHEMISTRY: - BedrockUtils.writeString(buf, craftingData.getRecipeId()); - VarInts.writeInt(buf, craftingData.getWidth()); - VarInts.writeInt(buf, craftingData.getHeight()); - int count = craftingData.getWidth() * craftingData.getHeight(); - ItemData[] inputs = craftingData.getInputs(); - for (int i = 0; i < count; i++) { - BedrockUtils.writeRecipeIngredient(buf, inputs[i]); - } - BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); - BedrockUtils.writeUuid(buf, craftingData.getUuid()); - BedrockUtils.writeString(buf, craftingData.getCraftingTag()); - VarInts.writeInt(buf, craftingData.getPriority()); - break; - case FURNACE: - case FURNACE_DATA: - VarInts.writeInt(buf, craftingData.getInputId()); - if (craftingData.getType() == CraftingType.FURNACE_DATA) { - VarInts.writeInt(buf, craftingData.getInputDamage()); - } - BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); - BedrockUtils.writeString(buf, craftingData.getCraftingTag()); - break; - case MULTI: - BedrockUtils.writeUuid(buf, craftingData.getUuid()); - break; - } - }); - buffer.writeBoolean(packet.isCleanRecipes()); - } - - @Override - public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { - BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { - int typeInt = VarInts.readInt(buf); - CraftingType type = CraftingType.byId(typeInt); - if (type == null) { - throw new IllegalArgumentException("Unknown crafting type: " + typeInt); - } - - switch (type) { - case SHAPELESS: - case SHAPELESS_CHEMISTRY: - case SHULKER_BOX: - String recipeId = BedrockUtils.readString(buf); - int inputCount = VarInts.readUnsignedInt(buf); - ItemData[] inputs = new ItemData[inputCount]; - for (int i = 0; i < inputCount; i++) { - inputs[i] = BedrockUtils.readRecipeIngredient(buf); - } - int outputCount = VarInts.readUnsignedInt(buf); - ItemData[] outputs = new ItemData[outputCount]; - for (int i = 0; i < outputCount; i++) { - outputs[i] = BedrockUtils.readItemData(buf); - } - UUID uuid = BedrockUtils.readUuid(buf); - String craftingTag = BedrockUtils.readString(buf); - int priority = VarInts.readInt(buf); - return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, - outputs, uuid, craftingTag, priority); - case SHAPED: - case SHAPED_CHEMISTRY: - recipeId = BedrockUtils.readString(buf); - int width = VarInts.readInt(buf); - int height = VarInts.readInt(buf); - inputCount = width * height; - inputs = new ItemData[inputCount]; - for (int i = 0; i < inputCount; i++) { - inputs[i] = BedrockUtils.readRecipeIngredient(buf); - } - outputCount = VarInts.readUnsignedInt(buf); - outputs = new ItemData[outputCount]; - for (int i = 0; i < outputCount; i++) { - outputs[i] = BedrockUtils.readItemData(buf); - } - uuid = BedrockUtils.readUuid(buf); - craftingTag = BedrockUtils.readString(buf); - priority = VarInts.readInt(buf); - return new CraftingData(type, recipeId, width, height, -1, -1, inputs, outputs, - uuid, craftingTag, priority); - case FURNACE: - case FURNACE_DATA: - int inputId = VarInts.readInt(buf); - int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; - ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; - craftingTag = BedrockUtils.readString(buf); - return new CraftingData(type, null, -1, -1, inputId, inputDamage, null, - output, null, craftingTag, -1); - case MULTI: - uuid = BedrockUtils.readUuid(buf); - return CraftingData.fromMulti(uuid); - default: - throw new IllegalArgumentException("Unhandled crafting data type: " + type); - } - }); - packet.setCleanRecipes(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java deleted file mode 100644 index 1dc0d5c6f..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/CraftingEventSerializer_v363.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.CraftingEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CraftingEventSerializer_v363 implements PacketSerializer { - public static final CraftingEventSerializer_v363 INSTANCE = new CraftingEventSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, CraftingEventPacket packet) { - buffer.writeByte(packet.getWindowId()); - VarInts.writeInt(buffer, packet.getType()); - BedrockUtils.writeUuid(buffer, packet.getUuid()); - - BedrockUtils.writeArray(buffer, packet.getInputs(), BedrockUtils::writeItemData); - - BedrockUtils.writeArray(buffer, packet.getOutputs(), BedrockUtils::writeItemData); - } - - @Override - public void deserialize(ByteBuf buffer, CraftingEventPacket packet) { - packet.setWindowId(buffer.readByte()); - packet.setType(VarInts.readInt(buffer)); - packet.setUuid(BedrockUtils.readUuid(buffer)); - - BedrockUtils.readArray(buffer, packet.getInputs(), BedrockUtils::readItemData); - - BedrockUtils.readArray(buffer, packet.getOutputs(), BedrockUtils::readItemData); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java deleted file mode 100644 index 365ed9a7c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/DisconnectSerializer_v363.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.DisconnectPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class DisconnectSerializer_v363 implements PacketSerializer { - public static final DisconnectSerializer_v363 INSTANCE = new DisconnectSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, DisconnectPacket packet) { - buffer.writeBoolean(packet.isDisconnectScreenHidden()); - if (!packet.isDisconnectScreenHidden()) { - BedrockUtils.writeString(buffer, packet.getKickMessage()); - } - } - - @Override - public void deserialize(ByteBuf buffer, DisconnectPacket packet) { - packet.setDisconnectScreenHidden(buffer.readBoolean()); - if (!packet.isDisconnectScreenHidden()) { - packet.setKickMessage(BedrockUtils.readString(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java deleted file mode 100644 index 80afb9ba3..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EducationSettingsSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.EducationSettingsPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class EducationSettingsSerializer_v363 implements PacketSerializer { - - public static final EducationSettingsSerializer_v363 INSTANCE = new EducationSettingsSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, EducationSettingsPacket packet) { - BedrockUtils.writeString(buffer, packet.getSettings()); - buffer.writeBoolean(packet.isUnknown0()); - } - - @Override - public void deserialize(ByteBuf buffer, EducationSettingsPacket packet) { - packet.setSettings(BedrockUtils.readString(buffer)); - packet.setUnknown0(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java deleted file mode 100644 index 4acb1a82d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EmoteSerializer_v363.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.EmotePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class EmoteSerializer_v363 implements PacketSerializer { - - public static final EmoteSerializer_v363 INSTANCE = new EmoteSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, EmotePacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeString(buffer, packet.getEmoteId()); - buffer.writeByte(packet.getFlags()); - } - - @Override - public void deserialize(ByteBuf buffer, EmotePacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setEmoteId(BedrockUtils.readString(buffer)); - packet.setFlags(buffer.readByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java deleted file mode 100644 index ba2ccfa7a..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityEventSerializer_v363.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.EntityEventType; -import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.data.EntityEventType.*; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class EntityEventSerializer_v363 implements PacketSerializer { - public static final EntityEventSerializer_v363 INSTANCE = new EntityEventSerializer_v363(); - private static final Int2ObjectBiMap events = new Int2ObjectBiMap<>(); - private static final InternalLogger log = InternalLoggerFactory.getInstance(EntityEventSerializer_v363.class); - - static { - events.put(2, HURT_ANIMATION); - events.put(3, DEATH_ANIMATION); - events.put(4, ARM_SWING); - events.put(6, TAME_FAIL); - events.put(7, TAME_SUCCESS); - events.put(8, SHAKE_WET); - events.put(9, USE_ITEM); - events.put(10, EAT_BLOCK_ANIMATION); - events.put(11, FISH_HOOK_BUBBLE); - events.put(12, FISH_HOOK_POSITION); - events.put(13, FISH_HOOK_HOOK); - events.put(14, FISH_HOOK_LURED); - events.put(15, SQUID_INK_CLOUD); - events.put(16, ZOMBIE_VILLAGER_CURE); - events.put(18, RESPAWN); - events.put(19, IRON_GOLEM_OFFER_FLOWER); - events.put(20, IRON_GOLEM_WITHDRAW_FLOWER); - events.put(21, LOVE_PARTICLES); - events.put(22, VILLAGER_HURT); - events.put(23, VILLAGER_STOP_TRADING); - events.put(24, WITCH_SPELL_PARTICLES); - events.put(25, FIREWORK_PARTICLES); - events.put(27, SILVERFISH_MERGE_WITH_STONE); - events.put(28, GUARDIAN_ATTACK_ANIMATION); - events.put(29, WITCH_DRINK_POTION); - events.put(30, WITCH_THROW_POTION); - events.put(31, MINECART_TNT_PRIME_FUSE); - events.put(34, PLAYER_ADD_XP_LEVELS); - events.put(35, ELDER_GUARDIAN_CURSE); - events.put(36, AGENT_ARM_SWING); - events.put(37, ENDER_DRAGON_DEATH); - events.put(38, DUST_PARTICLES); - events.put(39, ARROW_SHAKE); - events.put(57, EATING_ITEM); - events.put(60, BABY_ANIMAL_FEED); - events.put(61, DEATH_SMOKE_CLOUD); - events.put(62, COMPLETE_TRADE); - events.put(63, REMOVE_LEASH); - events.put(64, CARAVAN); - events.put(65, CONSUME_TOTEM); - events.put(66, CHECK_TREASURE_HUNTER_ACHIEVEMENT); - events.put(67, ENTITY_SPAWN); - events.put(68, DRAGON_FLAMING); - events.put(69, MERGE_ITEMS); - events.put(71, BALLOON_POP); - events.put(72, FIND_TREASURE_BRIBE); - } - - @Override - public void serialize(ByteBuf buffer, EntityEventPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - buffer.writeByte(events.get(packet.getType())); - VarInts.writeInt(buffer, packet.getData()); - } - - @Override - public void deserialize(ByteBuf buffer, EntityEventPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - int event = buffer.readUnsignedByte(); - packet.setType(events.get(event)); - packet.setData(VarInts.readInt(buffer)); - if (packet.getType() == null) { - log.debug("Unknown EntityEvent {} in packet {}", event, packet); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java deleted file mode 100644 index b1e65e754..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityFallSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.EntityFallPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class EntityFallSerializer_v363 implements PacketSerializer { - public static final EntityFallSerializer_v363 INSTANCE = new EntityFallSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, EntityFallPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - buffer.writeFloatLE(packet.getFallDistance()); - buffer.writeBoolean(packet.isInVoid()); - } - - @Override - public void deserialize(ByteBuf buffer, EntityFallPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setFallDistance(buffer.readFloatLE()); - packet.setInVoid(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java deleted file mode 100644 index 21768e929..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EntityPickRequestSerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.EntityPickRequestPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class EntityPickRequestSerializer_v363 implements PacketSerializer { - public static final EntityPickRequestSerializer_v363 INSTANCE = new EntityPickRequestSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, EntityPickRequestPacket packet) { - buffer.writeLongLE(packet.getRuntimeEntityId()); - buffer.writeByte(packet.getHotbarSlot()); - } - - @Override - public void deserialize(ByteBuf buffer, EntityPickRequestPacket packet) { - packet.setRuntimeEntityId(buffer.readLongLE()); - packet.setHotbarSlot(buffer.readUnsignedByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java deleted file mode 100644 index edc891103..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/EventSerializer_v363.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.data.event.*; -import com.nukkitx.protocol.bedrock.packet.EventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Arrays; -import java.util.List; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class EventSerializer_v363 implements PacketSerializer { - public static final EventSerializer_v363 INSTANCE = new EventSerializer_v363(); - - private static final EventDataType[] VALUES = EventDataType.values(); - - @Override - public void serialize(ByteBuf buffer, EventPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - EventData eventData = packet.getEventData(); - VarInts.writeInt(buffer, eventData.getType().ordinal()); - buffer.writeByte(packet.getUnknown0()); - - switch (eventData.getType()) { - case ACHIEVEMENT_AWARDED: - VarInts.writeInt(buffer, ((AchievementAwardedEventData) eventData).getAchievementId()); - break; - case ENTITY_INTERACT: - EntityInteractEventData entityInteractEventData = (EntityInteractEventData) eventData; - VarInts.writeInt(buffer, entityInteractEventData.getInteractionType()); - VarInts.writeInt(buffer, entityInteractEventData.getLegacyEntityTypeId()); - VarInts.writeInt(buffer, entityInteractEventData.getVariant()); - buffer.writeByte(entityInteractEventData.getPaletteColor()); - break; - case PORTAL_BUILT: - VarInts.writeInt(buffer, ((PortalBuiltEventData) eventData).getDimensionId()); - break; - case PORTAL_USED: - PortalUsedEventData portalUsedEventData = (PortalUsedEventData) eventData; - VarInts.writeInt(buffer, portalUsedEventData.getFromDimensionId()); - VarInts.writeInt(buffer, portalUsedEventData.getToDimensionId()); - break; - case MOB_KILLED: - MobKilledEventData mobKilledEventData = (MobKilledEventData) eventData; - VarInts.writeLong(buffer, mobKilledEventData.getKillerUniqueEntityId()); - VarInts.writeLong(buffer, mobKilledEventData.getVictimUniqueEntityId()); - VarInts.writeInt(buffer, mobKilledEventData.getEntityDamageCause()); - VarInts.writeInt(buffer, mobKilledEventData.getVillagerTradeTier()); - BedrockUtils.writeString(buffer, mobKilledEventData.getVillagerDisplayName()); - break; - case CAULDRON_USED: - CauldronUsedEventData cauldronUsedEventData = (CauldronUsedEventData) eventData; - VarInts.writeUnsignedInt(buffer, cauldronUsedEventData.getPotionId()); - VarInts.writeInt(buffer, cauldronUsedEventData.getColor()); - VarInts.writeInt(buffer, cauldronUsedEventData.getFillLevel()); - break; - case PLAYER_DIED: - PlayerDiedEventData playerDiedEventData = (PlayerDiedEventData) eventData; - VarInts.writeInt(buffer, playerDiedEventData.getUnknown0()); - VarInts.writeInt(buffer, playerDiedEventData.getUnknown1()); - VarInts.writeInt(buffer, playerDiedEventData.getEntityDamageCause()); - buffer.writeBoolean(playerDiedEventData.isInRaid()); - break; - case BOSS_KILLED: - BossKilledEventData bossKilledEventData = (BossKilledEventData) eventData; - VarInts.writeLong(buffer, bossKilledEventData.getBossUniqueEntityId()); - VarInts.writeInt(buffer, bossKilledEventData.getPlayerPartySize()); - VarInts.writeInt(buffer, bossKilledEventData.getLegacyEntityTypeId()); - break; - case AGENT_COMMAND: - AgentCommandEventData agentCommandEventData = (AgentCommandEventData) eventData; - VarInts.writeInt(buffer, agentCommandEventData.getAgentResult()); - VarInts.writeInt(buffer, agentCommandEventData.getDataValue()); - BedrockUtils.writeString(buffer, agentCommandEventData.getCommand()); - BedrockUtils.writeString(buffer, agentCommandEventData.getDataKey()); - BedrockUtils.writeString(buffer, agentCommandEventData.getOutput()); - break; - case PATTERN_REMOVED: - PatternRemovedEventData patternRemovedEventData = (PatternRemovedEventData) eventData; - VarInts.writeInt(buffer, patternRemovedEventData.getItemId()); - VarInts.writeInt(buffer, patternRemovedEventData.getAuxValue()); - VarInts.writeInt(buffer, patternRemovedEventData.getPatternsSize()); - VarInts.writeInt(buffer, patternRemovedEventData.getPatternIndex()); - VarInts.writeInt(buffer, patternRemovedEventData.getPatternColor()); - break; - case SLASH_COMMAND_EXECUTED: - SlashCommandExecutedEventData slashCommandExecutedEventData = (SlashCommandExecutedEventData) eventData; - VarInts.writeInt(buffer, slashCommandExecutedEventData.getSuccessCount()); - List outputMessages = slashCommandExecutedEventData.getOutputMessages(); - VarInts.writeInt(buffer, outputMessages.size()); - BedrockUtils.writeString(buffer, slashCommandExecutedEventData.getCommandName()); - BedrockUtils.writeString(buffer, String.join(";", outputMessages)); - break; - case FISH_BUCKETED: - FishBucketedEventData fishBucketedEventData = (FishBucketedEventData) eventData; - VarInts.writeInt(buffer, fishBucketedEventData.getUnknown0()); - VarInts.writeInt(buffer, fishBucketedEventData.getUnknown1()); - VarInts.writeInt(buffer, fishBucketedEventData.getUnknown2()); - buffer.writeBoolean(fishBucketedEventData.isUnknown3()); - break; - case MOB_BORN: - MobBornEventData mobBornEventData = (MobBornEventData) eventData; - VarInts.writeInt(buffer, mobBornEventData.getLegacyEntityTypeId()); - VarInts.writeInt(buffer, mobBornEventData.getVariant()); - buffer.writeByte(mobBornEventData.getColor()); - break; - case PET_DIED: - PetDiedEventData petDiedEventData = (PetDiedEventData) eventData; - buffer.writeBoolean(petDiedEventData.isUnknown0()); - VarInts.writeLong(buffer, petDiedEventData.getKillerUniqueEntityId()); - VarInts.writeLong(buffer, petDiedEventData.getPetUniqueEntityId()); - VarInts.writeInt(buffer, petDiedEventData.getEntityDamageCause()); - VarInts.writeInt(buffer, petDiedEventData.getUnknown1()); - break; - case CAULDRON_BLOCK_USED: - CauldronBlockUsedEventData cauldronBlockUsedEventData = (CauldronBlockUsedEventData) eventData; - VarInts.writeInt(buffer, cauldronBlockUsedEventData.getBlockInteractionType()); - VarInts.writeInt(buffer, cauldronBlockUsedEventData.getUnknown0()); - break; - case COMPOSTER_BLOCK_USED: - ComposterBlockUsedEventData composterBlockUsedEventData = (ComposterBlockUsedEventData) eventData; - VarInts.writeInt(buffer, composterBlockUsedEventData.getBlockInteractionType()); - VarInts.writeInt(buffer, composterBlockUsedEventData.getUnknown0()); - break; - case BELL_BLOCK_USED: - VarInts.writeInt(buffer, ((BellBlockUsedEventData) eventData).getUnknown0()); - break; - case AGENT_CREATED: - // No extra data - break; - } - } - - @Override - public void deserialize(ByteBuf buffer, EventPacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - - int eventId = VarInts.readInt(buffer); - Preconditions.checkElementIndex(eventId, VALUES.length, "EventDataType"); - EventDataType type = VALUES[eventId]; - - packet.setUnknown0(buffer.readByte()); - - EventData data; - - switch (type) { - case ACHIEVEMENT_AWARDED: - data = new AchievementAwardedEventData(VarInts.readInt(buffer)); - break; - case ENTITY_INTERACT: - int interactionType = VarInts.readInt(buffer); - int legacyEntityTypeId = VarInts.readInt(buffer); - int variant = VarInts.readInt(buffer); - int paletteColor = buffer.readUnsignedByte(); - data = new EntityInteractEventData(interactionType, legacyEntityTypeId, variant, paletteColor); - break; - case PORTAL_BUILT: - data = new PortalBuiltEventData(VarInts.readInt(buffer)); - break; - case PORTAL_USED: - int fromDimensionId = VarInts.readInt(buffer); - int toDimensionId = VarInts.readInt(buffer); - data = new PortalUsedEventData(fromDimensionId, toDimensionId); - break; - case MOB_KILLED: - long killerUniqueEntityId = VarInts.readLong(buffer); - long victimUniqueEntityId = VarInts.readLong(buffer); - int entityDamageCause = VarInts.readInt(buffer); - int villagerTradeTier = VarInts.readInt(buffer); - String villagerDisplayName = BedrockUtils.readString(buffer); - data = new MobKilledEventData(killerUniqueEntityId, victimUniqueEntityId, entityDamageCause, - villagerTradeTier, villagerDisplayName); - break; - case CAULDRON_USED: - int potionId = VarInts.readInt(buffer); - int color = VarInts.readInt(buffer); - int fillLevel = VarInts.readInt(buffer); - data = new CauldronUsedEventData(potionId, color, fillLevel); - break; - case PLAYER_DIED: - int unknown0 = VarInts.readInt(buffer); - int unknown1 = VarInts.readInt(buffer); - entityDamageCause = VarInts.readInt(buffer); - boolean inRaid = buffer.readBoolean(); - data = new PlayerDiedEventData(unknown0, unknown1, entityDamageCause, inRaid); - break; - case BOSS_KILLED: - long bossUniqueEntityId = VarInts.readLong(buffer); - int playerPartySize = VarInts.readInt(buffer); - legacyEntityTypeId = VarInts.readInt(buffer); - data = new BossKilledEventData(bossUniqueEntityId, playerPartySize, legacyEntityTypeId); - break; - case AGENT_COMMAND: - int agentResult = VarInts.readInt(buffer); - int dataValue = VarInts.readInt(buffer); - String command = BedrockUtils.readString(buffer); - String dataKey = BedrockUtils.readString(buffer); - String output = BedrockUtils.readString(buffer); - data = new AgentCommandEventData(agentResult, command, dataKey, dataValue, output); - break; - case AGENT_CREATED: - data = AgentCreatedEventData.INSTANCE; - break; - case PATTERN_REMOVED: - int itemId = VarInts.readInt(buffer); - int auxValue = VarInts.readInt(buffer); - int patternsSize = VarInts.readInt(buffer); - int patternIndex = VarInts.readInt(buffer); - int patternColor = VarInts.readInt(buffer); - data = new PatternRemovedEventData(itemId, auxValue, patternsSize, patternIndex, patternColor); - break; - case SLASH_COMMAND_EXECUTED: - int successCount = VarInts.readInt(buffer); - VarInts.readInt(buffer); - String commandName = BedrockUtils.readString(buffer); - List outputMessages = Arrays.asList(BedrockUtils.readString(buffer).split(";")); - data = new SlashCommandExecutedEventData(commandName, successCount, outputMessages); - break; - case FISH_BUCKETED: - unknown0 = VarInts.readInt(buffer); - unknown1 = VarInts.readInt(buffer); - int unknown2 = VarInts.readInt(buffer); - boolean unknown3 = buffer.readBoolean(); - data = new FishBucketedEventData(unknown0, unknown1, unknown2, unknown3); - break; - case MOB_BORN: - legacyEntityTypeId = VarInts.readInt(buffer); - variant = VarInts.readInt(buffer); - color = buffer.readUnsignedByte(); - data = new MobBornEventData(legacyEntityTypeId, variant, color); - break; - case PET_DIED: - boolean unknownBool = buffer.readBoolean(); - killerUniqueEntityId = VarInts.readLong(buffer); - long petUniqueEntityId = VarInts.readLong(buffer); - entityDamageCause = VarInts.readInt(buffer); - unknown1 = VarInts.readInt(buffer); - data = new PetDiedEventData(unknownBool, killerUniqueEntityId, petUniqueEntityId, entityDamageCause, - unknown1); - break; - case CAULDRON_BLOCK_USED: - int blockInterationType = VarInts.readInt(buffer); - unknown0 = VarInts.readInt(buffer); - data = new CauldronBlockUsedEventData(blockInterationType, unknown0); - break; - case COMPOSTER_BLOCK_USED: - blockInterationType = VarInts.readInt(buffer); - unknown0 = VarInts.readInt(buffer); - data = new ComposterBlockUsedEventData(blockInterationType, unknown0); - break; - case BELL_BLOCK_USED: - data = new BellBlockUsedEventData(VarInts.readInt(buffer)); - break; - default: - throw new IllegalArgumentException("Unknown EventDataType"); - } - packet.setEventData(data); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java deleted file mode 100644 index 86e0e1ee5..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ExplodeSerializer_v363.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ExplodePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ExplodeSerializer_v363 implements PacketSerializer { - public static final ExplodeSerializer_v363 INSTANCE = new ExplodeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ExplodePacket packet) { - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, (int) (packet.getRadius() * 32)); - - BedrockUtils.writeArray(buffer, packet.getRecords(), BedrockUtils::writeVector3i); - } - - @Override - public void deserialize(ByteBuf buffer, ExplodePacket packet) { - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setRadius(VarInts.readInt(buffer) / 32f); - - BedrockUtils.readArray(buffer, packet.getRecords(), BedrockUtils::readVector3i); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java deleted file mode 100644 index 7866dc8c0..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GameRulesChangedSerializer_v363.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class GameRulesChangedSerializer_v363 implements PacketSerializer { - public static final GameRulesChangedSerializer_v363 INSTANCE = new GameRulesChangedSerializer_v363(); - - public static final Object2IntMap> RULE_TYPES = new Object2IntOpenHashMap<>(3, 0.5f); - - static { - RULE_TYPES.defaultReturnValue(-1); - RULE_TYPES.put(Boolean.class, 1); - RULE_TYPES.put(Integer.class, 2); - RULE_TYPES.put(Float.class, 3); - } - - @Override - public void serialize(ByteBuf buffer, GameRulesChangedPacket packet) { - BedrockUtils.writeArray(buffer, packet.getGameRules(), BedrockUtils::writeGameRule); - } - - @Override - public void deserialize(ByteBuf buffer, GameRulesChangedPacket packet) { - BedrockUtils.readArray(buffer, packet.getGameRules(), BedrockUtils::readGameRule); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java deleted file mode 100644 index 5be1666e4..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/GuiDataPickItemSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.GuiDataPickItemPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class GuiDataPickItemSerializer_v363 implements PacketSerializer { - public static final GuiDataPickItemSerializer_v363 INSTANCE = new GuiDataPickItemSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, GuiDataPickItemPacket packet) { - BedrockUtils.writeString(buffer, packet.getDescription()); - BedrockUtils.writeString(buffer, packet.getItemEffects()); - buffer.writeIntLE(packet.getHotbarSlot()); - } - - @Override - public void deserialize(ByteBuf buffer, GuiDataPickItemPacket packet) { - packet.setDescription(BedrockUtils.readString(buffer)); - packet.setItemEffects(BedrockUtils.readString(buffer)); - packet.setHotbarSlot(buffer.readIntLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java deleted file mode 100644 index f3cf70f1c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/HurtArmorSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.HurtArmorPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class HurtArmorSerializer_v363 implements PacketSerializer { - public static final HurtArmorSerializer_v363 INSTANCE = new HurtArmorSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, HurtArmorPacket packet) { - VarInts.writeInt(buffer, packet.getHealth()); - } - - @Override - public void deserialize(ByteBuf buffer, HurtArmorPacket packet) { - packet.setHealth(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java deleted file mode 100644 index 15c9de8b7..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InteractSerializer_v363.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.InteractPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class InteractSerializer_v363 implements PacketSerializer { - public static final InteractSerializer_v363 INSTANCE = new InteractSerializer_v363(); - - private static final InteractPacket.Action[] ACTIONS = InteractPacket.Action.values(); - - @Override - public void serialize(ByteBuf buffer, InteractPacket packet) { - buffer.writeByte(packet.getAction().ordinal()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - - if (packet.getAction() == InteractPacket.Action.MOUSEOVER || packet.getAction() == InteractPacket.Action.NPC_OPEN) { - BedrockUtils.writeVector3f(buffer, packet.getMousePosition()); - } - } - - @Override - public void deserialize(ByteBuf buffer, InteractPacket packet) { - packet.setAction(ACTIONS[buffer.readUnsignedByte()]); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - - if (packet.getAction() == InteractPacket.Action.MOUSEOVER || packet.getAction() == InteractPacket.Action.NPC_OPEN) { - packet.setMousePosition(BedrockUtils.readVector3f(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java deleted file mode 100644 index 70b66c2d2..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryContentSerializer_v363.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.ItemData; -import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class InventoryContentSerializer_v363 implements PacketSerializer { - public static final InventoryContentSerializer_v363 INSTANCE = new InventoryContentSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, InventoryContentPacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getContainerId()); - - ItemData[] contents = packet.getContents(); - VarInts.writeUnsignedInt(buffer, contents.length); - for (ItemData content : contents) { - BedrockUtils.writeItemData(buffer, content); - } - } - - @Override - public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { - packet.setContainerId(VarInts.readUnsignedInt(buffer)); - - ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; - for (int i = 0; i < contents.length; i++) { - contents[i] = BedrockUtils.readItemData(buffer); - } - packet.setContents(contents); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java deleted file mode 100644 index 4c8941e3a..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventorySlotSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class InventorySlotSerializer_v363 implements PacketSerializer { - public static final InventorySlotSerializer_v363 INSTANCE = new InventorySlotSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, InventorySlotPacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getContainerId()); - VarInts.writeUnsignedInt(buffer, packet.getSlot()); - BedrockUtils.writeItemData(buffer, packet.getItem()); - } - - @Override - public void deserialize(ByteBuf buffer, InventorySlotPacket packet) { - packet.setContainerId(VarInts.readUnsignedInt(buffer)); - packet.setSlot(VarInts.readUnsignedInt(buffer)); - packet.setItem(BedrockUtils.readItemData(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java deleted file mode 100644 index f34daa7a9..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/InventoryTransactionSerializer_v363.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket.Type; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class InventoryTransactionSerializer_v363 implements PacketSerializer { - public static final InventoryTransactionSerializer_v363 INSTANCE = new InventoryTransactionSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, InventoryTransactionPacket packet) { - Type transactionType = packet.getTransactionType(); - VarInts.writeUnsignedInt(buffer, transactionType.ordinal()); - - BedrockUtils.writeArray(buffer, packet.getActions(), BedrockUtils::writeInventoryAction); - - switch (transactionType) { - case ITEM_USE: - VarInts.writeUnsignedInt(buffer, packet.getActionType()); - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeInt(buffer, packet.getFace()); - VarInts.writeInt(buffer, packet.getHotbarSlot()); - BedrockUtils.writeItemData(buffer, packet.getItemInHand()); - BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); - BedrockUtils.writeVector3f(buffer, packet.getClickPosition()); - VarInts.writeUnsignedInt(buffer, packet.getBlockRuntimeId()); - break; - case ITEM_USE_ON_ENTITY: - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeUnsignedInt(buffer, packet.getActionType()); - VarInts.writeInt(buffer, packet.getHotbarSlot()); - BedrockUtils.writeItemData(buffer, packet.getItemInHand()); - BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); - BedrockUtils.writeVector3f(buffer, packet.getClickPosition()); - break; - case ITEM_RELEASE: - VarInts.writeUnsignedInt(buffer, packet.getActionType()); - VarInts.writeInt(buffer, packet.getHotbarSlot()); - BedrockUtils.writeItemData(buffer, packet.getItemInHand()); - BedrockUtils.writeVector3f(buffer, packet.getHeadPosition()); - } - } - - @Override - public void deserialize(ByteBuf buffer, InventoryTransactionPacket packet) { - Type transactionType = Type.values()[VarInts.readUnsignedInt(buffer)]; - packet.setTransactionType(transactionType); - - BedrockUtils.readArray(buffer, packet.getActions(), BedrockUtils::readInventoryAction); - - switch (transactionType) { - case ITEM_USE: - packet.setActionType(VarInts.readUnsignedInt(buffer)); - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setFace(VarInts.readInt(buffer)); - packet.setHotbarSlot(VarInts.readInt(buffer)); - packet.setItemInHand(BedrockUtils.readItemData(buffer)); - packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); - packet.setClickPosition(BedrockUtils.readVector3f(buffer)); - packet.setBlockRuntimeId(VarInts.readUnsignedInt(buffer)); - break; - case ITEM_USE_ON_ENTITY: - packet.setRuntimeEntityId(VarInts.readUnsignedInt(buffer)); - packet.setActionType(VarInts.readUnsignedInt(buffer)); - packet.setHotbarSlot(VarInts.readInt(buffer)); - packet.setItemInHand(BedrockUtils.readItemData(buffer)); - packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); - packet.setClickPosition(BedrockUtils.readVector3f(buffer)); - break; - case ITEM_RELEASE: - packet.setActionType(VarInts.readUnsignedInt(buffer)); - packet.setHotbarSlot(VarInts.readInt(buffer)); - packet.setItemInHand(BedrockUtils.readItemData(buffer)); - packet.setHeadPosition(BedrockUtils.readVector3f(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java deleted file mode 100644 index f4e889587..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ItemFrameDropItemSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ItemFrameDropItemPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ItemFrameDropItemSerializer_v363 implements PacketSerializer { - public static final ItemFrameDropItemSerializer_v363 INSTANCE = new ItemFrameDropItemSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ItemFrameDropItemPacket packet) { - BedrockUtils.writeVector3i(buffer, packet.getBlockPosition()); - } - - @Override - public void deserialize(ByteBuf buffer, ItemFrameDropItemPacket packet) { - packet.setBlockPosition(BedrockUtils.readVector3i(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java deleted file mode 100644 index d2dabaf90..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LabTableSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.LabTablePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LabTableSerializer_v363 implements PacketSerializer { - public static final LabTableSerializer_v363 INSTANCE = new LabTableSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, LabTablePacket packet) { - buffer.writeByte(packet.getUnknownByte0()); - BedrockUtils.writeVector3i(buffer, packet.getBlockEntityPosition()); - buffer.writeByte(packet.getReactionType()); - } - - @Override - public void deserialize(ByteBuf buffer, LabTablePacket packet) { - packet.setUnknownByte0(buffer.readByte()); - packet.setBlockEntityPosition(BedrockUtils.readVector3i(buffer)); - packet.setReactionType(buffer.readByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java deleted file mode 100644 index 754a36bf1..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LecternUpdateSerializer_v363.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.LecternUpdatePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LecternUpdateSerializer_v363 implements PacketSerializer { - public static final LecternUpdateSerializer_v363 INSTANCE = new LecternUpdateSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, LecternUpdatePacket packet) { - buffer.writeByte(packet.getPage()); - buffer.writeByte(packet.getTotalPages()); - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - buffer.writeBoolean(packet.isDroppingBook()); - } - - @Override - public void deserialize(ByteBuf buffer, LecternUpdatePacket packet) { - packet.setPage(buffer.readUnsignedByte()); - packet.setTotalPages(buffer.readUnsignedByte()); - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setDroppingBook(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java deleted file mode 100644 index 6d3a305c6..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelChunkSerializer_v363.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.longs.LongList; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelChunkSerializer_v363 implements PacketSerializer { - public static final LevelChunkSerializer_v363 INSTANCE = new LevelChunkSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, LevelChunkPacket packet) { - VarInts.writeInt(buffer, packet.getChunkX()); - VarInts.writeInt(buffer, packet.getChunkZ()); - VarInts.writeUnsignedInt(buffer, packet.getSubChunksLength()); - buffer.writeBoolean(packet.isCachingEnabled()); - if (packet.isCachingEnabled()) { - LongList blobIds = packet.getBlobIds(); - VarInts.writeUnsignedInt(buffer, blobIds.size()); - - for (long blobId : blobIds) { - buffer.writeLongLE(blobId); - } - } - - BedrockUtils.writeByteArray(buffer, packet.getData()); - } - - @Override - public void deserialize(ByteBuf buffer, LevelChunkPacket packet) { - packet.setChunkX(VarInts.readInt(buffer)); - packet.setChunkZ(VarInts.readInt(buffer)); - packet.setSubChunksLength(VarInts.readUnsignedInt(buffer)); - packet.setCachingEnabled(buffer.readBoolean()); - - if (packet.isCachingEnabled()) { - LongList blobIds = packet.getBlobIds(); - int length = VarInts.readUnsignedInt(buffer); - - for (int i = 0; i < length; i++) { - blobIds.add(buffer.readLongLE()); - } - } - packet.setData(BedrockUtils.readByteArray(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java deleted file mode 100644 index 1f4a64ff7..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventGenericSerializer_v363.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.LevelEventGenericPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelEventGenericSerializer_v363 implements PacketSerializer { - public static final LevelEventGenericSerializer_v363 INSTANCE = new LevelEventGenericSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, LevelEventGenericPacket packet) { - VarInts.writeInt(buffer, packet.getEventId()); - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, LevelEventGenericPacket packet) { - packet.setEventId(VarInts.readInt(buffer)); - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setTag(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java deleted file mode 100644 index 481a02c19..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelEventSerializer_v363.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.LevelEventType; -import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.data.LevelEventType.*; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelEventSerializer_v363 implements PacketSerializer { - public static final LevelEventSerializer_v363 INSTANCE = new LevelEventSerializer_v363(); - - private static final InternalLogger log = InternalLoggerFactory.getInstance(LevelEventSerializer_v363.class); - private static final Int2ObjectBiMap events = new Int2ObjectBiMap<>(); - - static { - events.put(1000, SOUND_CLICK); - events.put(1001, SOUND_CLICK_FAIL); - events.put(1002, SOUND_SHOOT); - events.put(1003, SOUND_DOOR); - events.put(1004, SOUND_FIZZ); - events.put(1005, SOUND_IGNITE); - events.put(1007, SOUND_GHAST); - events.put(1008, SOUND_GHAST_SHOOT); - events.put(1009, SOUND_BLAZE_SHOOT); - events.put(1010, SOUND_DOOR_BUMP); - events.put(1012, SOUND_DOOR_CRASH); - events.put(1018, SOUND_ENDERMAN_TELEPORT); - events.put(1020, SOUND_ANVIL_BREAK); - events.put(1021, SOUND_ANVIL_USE); - events.put(1022, SOUND_ANVIL_FALL); - events.put(1030, SOUND_POP); - events.put(1032, SOUND_PORTAL); - events.put(1040, SOUND_ITEMFRAME_ADD_ITEM); - events.put(1041, SOUND_ITEMFRAME_REMOVE); - events.put(1042, SOUND_ITEMFRAME_PLACE); - events.put(1043, SOUND_ITEMFRAME_REMOVE_ITEM); - events.put(1044, SOUND_ITEMFRAME_ROTATE_ITEM); - events.put(1050, SOUND_CAMERA); - events.put(1051, SOUND_ORB); - events.put(1052, SOUND_TOTEM); - events.put(1060, SOUND_ARMOR_STAND_BREAK); - events.put(1061, SOUND_ARMOR_STAND_HIT); - events.put(1062, SOUND_ARMOR_STAND_FALL); - events.put(1063, SOUND_ARMOR_STAND_PLACE); - events.put(2000, SHOOT); - events.put(2001, DESTROY); - events.put(2002, SPLASH); - events.put(2003, EYE_DESPAWN); - events.put(2004, ENTITY_SPAWN); - events.put(2005, BONEMEAL); - events.put(2006, GUARDIAN_CURSE); - events.put(2008, BLOCK_FORCE_FIELD); - events.put(2009, PROJECTILE_HIT); - events.put(2010, DRAGON_EGG_TELEPORT); - events.put(2013, ENDERMAN_TELEPORT); - events.put(2014, PUNCH_BLOCK); - events.put(2015, WATER_SPLASH); - events.put(3001, START_RAIN); - events.put(3002, START_THUNDER); - events.put(3003, STOP_RAIN); - events.put(3004, STOP_THUNDER); - events.put(3005, PAUSE_GAME); - events.put(3500, REDSTONE_TRIGGER); - events.put(3501, CAULDRON_EXPLODE); - events.put(3502, CAULDRON_DYE_ARMOR); - events.put(3503, CAULDRON_CLEAN_ARMOR); - events.put(3504, CAULDRON_FILL_POTION); - events.put(3505, CAULDRON_TAKE_POTION); - events.put(3506, CAULDRON_FILL_WATER); - events.put(3507, CAULDRON_TAKE_WATER); - events.put(3508, CAULDRON_ADD_DYE); - events.put(3509, CAULDRON_CLEAN_BANNER); - events.put(3600, BLOCK_START_BREAK); - events.put(3601, BLOCK_STOP_BREAK); - events.put(3602, BLOCK_CONTINUE_BREAK); - events.put(4000, SET_DATA); - events.put(9800, PLAYERS_SLEEPING); - - // Particles - events.put((1 | 0x4000), PARTICLE_BUBBLE); - // 2 same as 1 - events.put((3 | 0x4000), PARTICLE_CRITICAL); - events.put((4 | 0x4000), PARTICLE_BLOCK_FORCE_FIELD); - events.put((5 | 0x4000), PARTICLE_SMOKE); - events.put((6 | 0x4000), PARTICLE_EXPLODE); - events.put((7 | 0x4000), PARTICLE_EVAPORATION); - events.put((8 | 0x4000), PARTICLE_FLAME); - events.put((9 | 0x4000), PARTICLE_LAVA); - events.put((10 | 0x4000), PARTICLE_LARGE_SMOKE); - events.put((11 | 0x4000), PARTICLE_REDSTONE); - events.put((12 | 0x4000), PARTICLE_RISING_RED_DUST); - // 62 same as 12 - events.put((13 | 0x4000), PARTICLE_ITEM_BREAK); - events.put((14 | 0x4000), PARTICLE_SNOWBALL_POOF); - events.put((15 | 0x4000), PARTICLE_HUGE_EXPLODE); - // 60 same as 15 - events.put((16 | 0x4000), PARTICLE_HUGE_EXPLODE_SEED); - events.put((17 | 0x4000), PARTICLE_MOB_FLAME); - events.put((18 | 0x4000), PARTICLE_HEART); - events.put((19 | 0x4000), PARTICLE_TERRAIN); - events.put((20 | 0x4000), PARTICLE_TOWN_AURA); - // 61 same as 20 - events.put((21 | 0x4000), PARTICLE_PORTAL); - // 22 same as 21 - events.put((23 | 0x4000), PARTICLE_SPLASH); - // 24 same as 23 - events.put((25 | 0x4000), PARTICLE_WATER_WAKE); - events.put((26 | 0x4000), PARTICLE_DRIP_WATER); - events.put((27 | 0x4000), PARTICLE_DRIP_LAVA); - events.put((28 | 0x4000), PARTICLE_FALLING_DUST); - events.put((29 | 0x4000), PARTICLE_MOB_SPELL); - events.put((30 | 0x4000), PARTICLE_MOB_SPELL_AMBIENT); - events.put((31 | 0x4000), PARTICLE_MOB_SPELL_INSTANTANEOUS); - events.put((32 | 0x4000), PARTICLE_INK); - events.put((33 | 0x4000), PARTICLE_SLIME); - events.put((34 | 0x4000), PARTICLE_RAIN_SPLASH); - events.put((35 | 0x4000), PARTICLE_VILLAGER_ANGRY); - // 59 same as 35 - events.put((36 | 0x4000), PARTICLE_VILLAGER_HAPPY); - events.put((37 | 0x4000), PARTICLE_ENCHANTMENT_TABLE); - events.put((38 | 0x4000), PARTICLE_TRACKING_EMITTER); - events.put((39 | 0x4000), PARTICLE_NOTE); - events.put((40 | 0x4000), PARTICLE_WITCH_SPELL); - events.put((41 | 0x4000), PARTICLE_CARROT); - // 42 unknown - events.put((43 | 0x4000), PARTICLE_END_ROD); - // 58 same as 43 - events.put((44 | 0x4000), PARTICLE_DRAGONS_BREATH); - events.put((45 | 0x4000), PARTICLE_SPIT); - events.put((46 | 0x4000), PARTICLE_TOTEM); - events.put((47 | 0x4000), PARTICLE_FOOD); - events.put((48 | 0x4000), PARTICLE_FIREWORKS_STARTER); - events.put((49 | 0x4000), PARTICLE_FIREWORKS_SPARK); - events.put((50 | 0x4000), PARTICLE_FIREWORKS_OVERLAY); - events.put((51 | 0x4000), PARTICLE_BALLOON_GAS); - events.put((52 | 0x4000), PARTICLE_COLORED_FLAME); - events.put((53 | 0x4000), PARTICLE_SPARKLER); - events.put((54 | 0x4000), PARTICLE_CONDUIT); - events.put((55 | 0x4000), PARTICLE_BUBBLE_COLUMN_UP); - events.put((56 | 0x4000), PARTICLE_BUBBLE_COLUMN_DOWN); - events.put((57 | 0x4000), PARTICLE_SNEEZE); - } - - @Override - public void serialize(ByteBuf buffer, LevelEventPacket packet) { - VarInts.writeInt(buffer, events.get(packet.getType())); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getData()); - } - - @Override - public void deserialize(ByteBuf buffer, LevelEventPacket packet) { - int eventId = VarInts.readInt(buffer); - packet.setType(events.get(eventId)); - if (packet.getType() == null) { - log.debug("Unknown Level Event {} received", eventId); - } - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setData(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java deleted file mode 100644 index d611a90bf..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent1Serializer_v363.java +++ /dev/null @@ -1,292 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.SoundEvent; -import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent1Packet; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.data.SoundEvent.*; - - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelSoundEvent1Serializer_v363 implements PacketSerializer { - public static final LevelSoundEvent1Serializer_v363 INSTANCE = new LevelSoundEvent1Serializer_v363(); - - static final Int2ObjectBiMap SOUNDS = new Int2ObjectBiMap<>(2, 0.5F, 255, UNDEFINED); - - static { - SOUNDS.put(0, ITEM_USE_ON); - SOUNDS.put(1, HIT); - SOUNDS.put(2, STEP); - SOUNDS.put(3, FLY); - SOUNDS.put(4, JUMP); - SOUNDS.put(5, BREAK); - SOUNDS.put(6, PLACE); - SOUNDS.put(7, HEAVY_STEP); - SOUNDS.put(8, GALLOP); - SOUNDS.put(9, FALL); - SOUNDS.put(10, AMBIENT); - SOUNDS.put(11, AMBIENT_BABY); - SOUNDS.put(12, AMBIENT_IN_WATER); - SOUNDS.put(13, BREATHE); - SOUNDS.put(14, DEATH); - SOUNDS.put(15, DEATH_IN_WATER); - SOUNDS.put(16, DEATH_TO_ZOMBIE); - SOUNDS.put(17, HURT); - SOUNDS.put(18, HURT_IN_WATER); - SOUNDS.put(19, MAD); - SOUNDS.put(20, BOOST); - SOUNDS.put(21, BOW); - SOUNDS.put(22, SQUISH_BIG); - SOUNDS.put(23, SQUISH_SMALL); - SOUNDS.put(24, FALL_BIG); - SOUNDS.put(25, FALL_SMALL); - SOUNDS.put(26, SPLASH); - SOUNDS.put(27, FIZZ); - SOUNDS.put(28, FLAP); - SOUNDS.put(29, SWIM); - SOUNDS.put(30, DRINK); - SOUNDS.put(31, EAT); - SOUNDS.put(32, TAKEOFF); - SOUNDS.put(33, SHAKE); - SOUNDS.put(34, PLOP); - SOUNDS.put(35, LAND); - SOUNDS.put(36, SADDLE); - SOUNDS.put(37, ARMOR); - SOUNDS.put(38, MOB_ARMOR_STAND_PLACE); - SOUNDS.put(39, ADD_CHEST); - SOUNDS.put(40, THROW); - SOUNDS.put(41, ATTACK); - SOUNDS.put(42, ATTACK_NODAMAGE); - SOUNDS.put(43, ATTACK_STRONG); - SOUNDS.put(44, WARN); - SOUNDS.put(45, SHEAR); - SOUNDS.put(46, MILK); - SOUNDS.put(47, THUNDER); - SOUNDS.put(48, EXPLODE); - SOUNDS.put(49, FIRE); - SOUNDS.put(50, IGNITE); - SOUNDS.put(51, FUSE); - SOUNDS.put(52, STARE); - SOUNDS.put(53, SPAWN); - SOUNDS.put(54, SHOOT); - SOUNDS.put(55, BREAK_BLOCK); - SOUNDS.put(56, LAUNCH); - SOUNDS.put(57, BLAST); - SOUNDS.put(58, LARGE_BLAST); - SOUNDS.put(59, TWINKLE); - SOUNDS.put(60, REMEDY); - SOUNDS.put(61, UNFECT); - SOUNDS.put(62, LEVELUP); - SOUNDS.put(63, BOW_HIT); - SOUNDS.put(64, BULLET_HIT); - SOUNDS.put(65, EXTINGUISH_FIRE); - SOUNDS.put(66, ITEM_FIZZ); - SOUNDS.put(67, CHEST_OPEN); - SOUNDS.put(68, CHEST_CLOSED); - SOUNDS.put(69, SHULKERBOX_OPEN); - SOUNDS.put(70, SHULKERBOX_CLOSED); - SOUNDS.put(71, ENDERCHEST_OPEN); - SOUNDS.put(72, ENDERCHEST_CLOSED); - SOUNDS.put(73, POWER_ON); - SOUNDS.put(74, POWER_OFF); - SOUNDS.put(75, ATTACH); - SOUNDS.put(76, DETACH); - SOUNDS.put(77, DENY); - SOUNDS.put(78, TRIPOD); - SOUNDS.put(79, POP); - SOUNDS.put(80, DROP_SLOT); - SOUNDS.put(81, NOTE); - SOUNDS.put(82, THORNS); - SOUNDS.put(83, PISTON_IN); - SOUNDS.put(84, PISTON_OUT); - SOUNDS.put(85, PORTAL); - SOUNDS.put(86, WATER); - SOUNDS.put(87, LAVA_POP); - SOUNDS.put(88, LAVA); - SOUNDS.put(89, BURP); - SOUNDS.put(90, BUCKET_FILL_WATER); - SOUNDS.put(91, BUCKET_FILL_LAVA); - SOUNDS.put(92, BUCKET_EMPTY_WATER); - SOUNDS.put(93, BUCKET_EMPTY_LAVA); - SOUNDS.put(94, ARMOR_EQUIP_CHAIN); - SOUNDS.put(95, ARMOR_EQUIP_DIAMOND); - SOUNDS.put(96, ARMOR_EQUIP_GENERIC); - SOUNDS.put(97, ARMOR_EQUIP_GOLD); - SOUNDS.put(98, ARMOR_EQUIP_IRON); - SOUNDS.put(99, ARMOR_EQUIP_LEATHER); - SOUNDS.put(100, ARMOR_EQUIP_ELYTRA); - SOUNDS.put(101, RECORD_13); - SOUNDS.put(102, RECORD_CAT); - SOUNDS.put(103, RECORD_BLOCKS); - SOUNDS.put(104, RECORD_CHIRP); - SOUNDS.put(105, RECORD_FAR); - SOUNDS.put(106, RECORD_MALL); - SOUNDS.put(107, RECORD_MELLOHI); - SOUNDS.put(108, RECORD_STAL); - SOUNDS.put(109, RECORD_STRAD); - SOUNDS.put(110, RECORD_WARD); - SOUNDS.put(111, RECORD_11); - SOUNDS.put(112, RECORD_WAIT); - SOUNDS.put(113, STOP_RECORD); //Not really a sound - SOUNDS.put(114, FLOP); - SOUNDS.put(115, ELDERGUARDIAN_CURSE); - SOUNDS.put(116, MOB_WARNING); - SOUNDS.put(117, MOB_WARNING_BABY); - SOUNDS.put(118, TELEPORT); - SOUNDS.put(119, SHULKER_OPEN); - SOUNDS.put(120, SHULKER_CLOSE); - SOUNDS.put(121, HAGGLE); - SOUNDS.put(122, HAGGLE_YES); - SOUNDS.put(123, HAGGLE_NO); - SOUNDS.put(124, HAGGLE_IDLE); - SOUNDS.put(125, CHORUSGROW); - SOUNDS.put(126, CHORUSDEATH); - SOUNDS.put(127, GLASS); - SOUNDS.put(128, POTION_BREWED); - SOUNDS.put(129, CAST_SPELL); - SOUNDS.put(130, PREPARE_ATTACK); - SOUNDS.put(131, PREPARE_SUMMON); - SOUNDS.put(132, PREPARE_WOLOLO); - SOUNDS.put(133, FANG); - SOUNDS.put(134, CHARGE); - SOUNDS.put(135, CAMERA_TAKE_PICTURE); - SOUNDS.put(136, LEASHKNOT_PLACE); - SOUNDS.put(137, LEASHKNOT_BREAK); - SOUNDS.put(138, GROWL); - SOUNDS.put(139, WHINE); - SOUNDS.put(140, PANT); - SOUNDS.put(141, PURR); - SOUNDS.put(142, PURREOW); - SOUNDS.put(143, DEATH_MIN_VOLUME); - SOUNDS.put(144, DEATH_MID_VOLUME); - SOUNDS.put(145, IMITATE_BLAZE); - SOUNDS.put(146, IMITATE_CAVE_SPIDER); - SOUNDS.put(147, IMITATE_CREEPER); - SOUNDS.put(148, IMITATE_ELDER_GUARDIAN); - SOUNDS.put(149, IMITATE_ENDER_DRAGON); - SOUNDS.put(150, IMITATE_ENDERMAN); - SOUNDS.put(152, IMITATE_EVOCATION_ILLAGER); - SOUNDS.put(153, IMITATE_GHAST); - SOUNDS.put(154, IMITATE_HUSK); - SOUNDS.put(155, IMITATE_ILLUSION_ILLAGER); - SOUNDS.put(156, IMITATE_MAGMA_CUBE); - SOUNDS.put(157, IMITATE_POLAR_BEAR); - SOUNDS.put(158, IMITATE_SHULKER); - SOUNDS.put(159, IMITATE_SILVERFISH); - SOUNDS.put(160, IMITATE_SKELETON); - SOUNDS.put(161, IMITATE_SLIME); - SOUNDS.put(162, IMITATE_SPIDER); - SOUNDS.put(163, IMITATE_STRAY); - SOUNDS.put(164, IMITATE_VEX); - SOUNDS.put(165, IMITATE_VINDICATION_ILLAGER); - SOUNDS.put(166, IMITATE_WITCH); - SOUNDS.put(167, IMITATE_WITHER); - SOUNDS.put(168, IMITATE_WITHER_SKELETON); - SOUNDS.put(169, IMITATE_WOLF); - SOUNDS.put(170, IMITATE_ZOMBIE); - SOUNDS.put(171, IMITATE_ZOMBIE_PIGMAN); - SOUNDS.put(172, IMITATE_ZOMBIE_VILLAGER); - SOUNDS.put(173, BLOCK_END_PORTAL_FRAME_FILL); - SOUNDS.put(174, BLOCK_END_PORTAL_SPAWN); - SOUNDS.put(175, RANDOM_ANVIL_USE); - SOUNDS.put(176, BOTTLE_DRAGONBREATH); - SOUNDS.put(177, PORTAL_TRAVEL); - SOUNDS.put(178, ITEM_TRIDENT_HIT); - SOUNDS.put(179, ITEM_TRIDENT_RETURN); - SOUNDS.put(180, ITEM_TRIDENT_RIPTIDE_1); - SOUNDS.put(181, ITEM_TRIDENT_RIPTIDE_2); - SOUNDS.put(182, ITEM_TRIDENT_RIPTIDE_3); - SOUNDS.put(183, ITEM_TRIDENT_THROW); - SOUNDS.put(184, ITEM_TRIDENT_THUNDER); - SOUNDS.put(185, ITEM_TRIDENT_HIT_GROUND); - SOUNDS.put(186, DEFAULT); - SOUNDS.put(188, ELEMENT_CONSTRUCTOR_OPEN); - SOUNDS.put(189, ICE_BOMB_HIT); - SOUNDS.put(190, BALLOON_POP); - SOUNDS.put(191, LT_REACTION_ICE_BOMB); - SOUNDS.put(192, LT_REACTION_BLEACH); - SOUNDS.put(193, LT_REACTION_E_PASTE); - SOUNDS.put(194, LT_REACTION_E_PASTE2); - SOUNDS.put(199, LT_REACTION_FERTILIZER); - SOUNDS.put(200, LT_REACTION_FIREBALL); - SOUNDS.put(201, LT_REACTION_MG_SALT); - SOUNDS.put(202, LT_REACTION_MISC_FIRE); - SOUNDS.put(203, LT_REACTION_FIRE); - SOUNDS.put(204, LT_REACTION_MISC_EXPLOSION); - SOUNDS.put(205, LT_REACTION_MISC_MYSTICAL); - SOUNDS.put(206, LT_REACTION_MISC_MYSTICAL2); - SOUNDS.put(207, LT_REACTION_PRODUCT); - SOUNDS.put(208, SPARKLER_USE); - SOUNDS.put(209, GLOWSTICK_USE); - SOUNDS.put(210, SPARKLER_ACTIVE); - SOUNDS.put(211, CONVERT_TO_DROWNED); - SOUNDS.put(212, BUCKET_FILL_FISH); - SOUNDS.put(213, BUCKET_EMPTY_FISH); - SOUNDS.put(214, BUBBLE_UP); - SOUNDS.put(215, BUBBLE_DOWN); - SOUNDS.put(216, BUBBLE_POP); - SOUNDS.put(217, BUBBLE_UP_INSIDE); - SOUNDS.put(218, BUBBLE_DOWN_INSIDE); - SOUNDS.put(219, HURT_BABY); - SOUNDS.put(220, DEATH_BABY); - SOUNDS.put(221, STEP_BABY); - SOUNDS.put(223, BORN); - SOUNDS.put(224, BLOCK_TURTLE_EGG_BREAK); - SOUNDS.put(225, BLOCK_TURTLE_EGG_CRACK); - SOUNDS.put(226, BLOCK_TURTLE_EGG_HATCH); - SOUNDS.put(228, BLOCK_TURTLE_EGG_ATTACK); - SOUNDS.put(229, BEACON_ACTIVATE); - SOUNDS.put(230, BEACON_AMBIENT); - SOUNDS.put(231, BEACON_DEACTIVATE); - SOUNDS.put(232, BEACON_POWER); - SOUNDS.put(233, CONDUIT_ACTIVATE); - SOUNDS.put(234, CONDUIT_AMBIENT); - SOUNDS.put(235, CONDUIT_ATTACK); - SOUNDS.put(236, CONDUIT_DEACTIVATE); - SOUNDS.put(237, CONDUIT_SHORT); - SOUNDS.put(238, SWOOP); - SOUNDS.put(239, BLOCK_BAMBOO_SAPLING_PLACE); - SOUNDS.put(240, PRE_SNEEZE); - SOUNDS.put(241, SNEEZE); - SOUNDS.put(242, AMBIENT_TAME); - SOUNDS.put(243, SCARED); - SOUNDS.put(244, BLOCK_SCAFFOLDING_CLIMB); - SOUNDS.put(245, CROSSBOW_LOADING_START); - SOUNDS.put(246, CROSSBOW_LOADING_MIDDLE); - SOUNDS.put(247, CROSSBOW_LOADING_END); - SOUNDS.put(248, CROSSBOW_SHOOT); - SOUNDS.put(249, CROSSBOW_QUICK_CHARGE_START); - SOUNDS.put(250, CROSSBOW_QUICK_CHARGE_MIDDLE); - SOUNDS.put(251, CROSSBOW_QUICK_CHARGE_END); - SOUNDS.put(252, AMBIENT_AGGRESSIVE); - SOUNDS.put(253, AMBIENT_WORRIED); - SOUNDS.put(254, CANT_BREED); - SOUNDS.put(255, UNDEFINED); - } - - @Override - public void serialize(ByteBuf buffer, LevelSoundEvent1Packet packet) { - VarInts.writeInt(buffer, SOUNDS.get(packet.getSound())); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getExtraData()); - VarInts.writeInt(buffer, packet.getPitch()); - buffer.writeBoolean(packet.isBabySound()); - buffer.writeBoolean(packet.isRelativeVolumeDisabled()); - } - - @Override - public void deserialize(ByteBuf buffer, LevelSoundEvent1Packet packet) { - packet.setSound(SOUNDS.get(VarInts.readInt(buffer))); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setExtraData(VarInts.readInt(buffer)); - packet.setPitch(VarInts.readInt(buffer)); - packet.setBabySound(buffer.readBoolean()); - packet.setRelativeVolumeDisabled(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java deleted file mode 100644 index 0e044866b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent2Serializer_v363.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.v363.serializer.LevelSoundEvent1Serializer_v363.SOUNDS; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelSoundEvent2Serializer_v363 implements PacketSerializer { - public static final LevelSoundEvent2Serializer_v363 INSTANCE = new LevelSoundEvent2Serializer_v363(); - - @Override - public void serialize(ByteBuf buffer, LevelSoundEvent2Packet packet) { - buffer.writeByte(SOUNDS.get(packet.getSound())); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getExtraData()); - BedrockUtils.writeString(buffer, packet.getIdentifier()); - buffer.writeBoolean(packet.isBabySound()); - buffer.writeBoolean(packet.isRelativeVolumeDisabled()); - } - - @Override - public void deserialize(ByteBuf buffer, LevelSoundEvent2Packet packet) { - packet.setSound(SOUNDS.get(buffer.readUnsignedByte())); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setExtraData(VarInts.readInt(buffer)); - packet.setIdentifier(BedrockUtils.readString(buffer)); - packet.setBabySound(buffer.readBoolean()); - packet.setRelativeVolumeDisabled(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java deleted file mode 100644 index 6f76a1b4d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LevelSoundEvent3Serializer_v363.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.v363.serializer.LevelSoundEvent1Serializer_v363.SOUNDS; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LevelSoundEvent3Serializer_v363 implements PacketSerializer { - public static final LevelSoundEvent3Serializer_v363 INSTANCE = new LevelSoundEvent3Serializer_v363(); - - @Override - public void serialize(ByteBuf buffer, LevelSoundEventPacket packet) { - VarInts.writeUnsignedInt(buffer, SOUNDS.get(packet.getSound())); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getExtraData()); - BedrockUtils.writeString(buffer, packet.getIdentifier()); - buffer.writeBoolean(packet.isBabySound()); - buffer.writeBoolean(packet.isRelativeVolumeDisabled()); - } - - @Override - public void deserialize(ByteBuf buffer, LevelSoundEventPacket packet) { - packet.setSound(SOUNDS.get(VarInts.readUnsignedInt(buffer))); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setExtraData(VarInts.readInt(buffer)); - packet.setIdentifier(BedrockUtils.readString(buffer)); - packet.setBabySound(buffer.readBoolean()); - packet.setRelativeVolumeDisabled(buffer.readBoolean()); - } -} - diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java deleted file mode 100644 index d76beaf4d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/LoginSerializer_v363.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.LoginPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.util.AsciiString; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LoginSerializer_v363 implements PacketSerializer { - public static final LoginSerializer_v363 INSTANCE = new LoginSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, LoginPacket packet) { - buffer.writeInt(packet.getProtocolVersion()); - - AsciiString chainData = packet.getChainData(); - AsciiString skinData = packet.getSkinData(); - - VarInts.writeUnsignedInt(buffer, chainData.length() + skinData.length() + 8); - - BedrockUtils.writeLEAsciiString(buffer, chainData); - BedrockUtils.writeLEAsciiString(buffer, skinData); - } - - @Override - public void deserialize(ByteBuf buffer, LoginPacket packet) { - packet.setProtocolVersion(buffer.readInt()); - - ByteBuf jwt = buffer.readSlice(VarInts.readUnsignedInt(buffer)); // Get the JWT. - packet.setChainData(BedrockUtils.readLEAsciiString(jwt)); - packet.setSkinData(BedrockUtils.readLEAsciiString(jwt)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java deleted file mode 100644 index 244c7a4ab..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapCreateLockedCopySerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MapCreateLockedCopyPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MapCreateLockedCopySerializer_v363 implements PacketSerializer { - public static final MapCreateLockedCopySerializer_v363 INSTANCE = new MapCreateLockedCopySerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, MapCreateLockedCopyPacket packet) { - VarInts.writeLong(buffer, packet.getOriginalMapId()); - VarInts.writeLong(buffer, packet.getNewMapId()); - } - - @Override - public void deserialize(ByteBuf buffer, MapCreateLockedCopyPacket packet) { - packet.setOriginalMapId(VarInts.readLong(buffer)); - packet.setNewMapId(VarInts.readLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java deleted file mode 100644 index d293dd5c4..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MapInfoRequestSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MapInfoRequestSerializer_v363 implements PacketSerializer { - public static final MapInfoRequestSerializer_v363 INSTANCE = new MapInfoRequestSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, MapInfoRequestPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueMapId()); - } - - @Override - public void deserialize(ByteBuf buffer, MapInfoRequestPacket packet) { - packet.setUniqueMapId(VarInts.readLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java deleted file mode 100644 index 463e5fa10..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobArmorEquipmentSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MobArmorEquipmentSerializer_v363 implements PacketSerializer { - public static final MobArmorEquipmentSerializer_v363 INSTANCE = new MobArmorEquipmentSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, MobArmorEquipmentPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeItemData(buffer, packet.getHelmet()); - BedrockUtils.writeItemData(buffer, packet.getChestplate()); - BedrockUtils.writeItemData(buffer, packet.getLeggings()); - BedrockUtils.writeItemData(buffer, packet.getBoots()); - } - - @Override - public void deserialize(ByteBuf buffer, MobArmorEquipmentPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setHelmet(BedrockUtils.readItemData(buffer)); - packet.setChestplate(BedrockUtils.readItemData(buffer)); - packet.setLeggings(BedrockUtils.readItemData(buffer)); - packet.setBoots(BedrockUtils.readItemData(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java deleted file mode 100644 index 481ae22de..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEffectSerializer_v363.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MobEffectPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MobEffectSerializer_v363 implements PacketSerializer { - public static final MobEffectSerializer_v363 INSTANCE = new MobEffectSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, MobEffectPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - buffer.writeByte(packet.getEvent().ordinal()); - VarInts.writeInt(buffer, packet.getEffectId()); - VarInts.writeInt(buffer, packet.getAmplifier()); - buffer.writeBoolean(packet.isParticles()); - VarInts.writeInt(buffer, packet.getDuration()); - } - - @Override - public void deserialize(ByteBuf buffer, MobEffectPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setEvent(MobEffectPacket.Event.values()[buffer.readUnsignedByte()]); - packet.setEffectId(VarInts.readInt(buffer)); - packet.setAmplifier(VarInts.readInt(buffer)); - packet.setParticles(buffer.readBoolean()); - packet.setDuration(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java deleted file mode 100644 index 5ff83ce6b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MobEquipmentSerializer_v363.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MobEquipmentSerializer_v363 implements PacketSerializer { - public static final MobEquipmentSerializer_v363 INSTANCE = new MobEquipmentSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, MobEquipmentPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeItemData(buffer, packet.getItem()); - buffer.writeByte(packet.getInventorySlot()); - buffer.writeByte(packet.getHotbarSlot()); - buffer.writeByte(packet.getContainerId()); - } - - @Override - public void deserialize(ByteBuf buffer, MobEquipmentPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setItem(BedrockUtils.readItemData(buffer)); - packet.setInventorySlot(buffer.readUnsignedByte()); - packet.setHotbarSlot(buffer.readUnsignedByte()); - packet.setContainerId(buffer.readByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java deleted file mode 100644 index 72a19b485..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormRequestSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ModalFormRequestSerializer_v363 implements PacketSerializer { - public static final ModalFormRequestSerializer_v363 INSTANCE = new ModalFormRequestSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ModalFormRequestPacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getFormId()); - BedrockUtils.writeString(buffer, packet.getFormData()); - } - - @Override - public void deserialize(ByteBuf buffer, ModalFormRequestPacket packet) { - packet.setFormId(VarInts.readUnsignedInt(buffer)); - packet.setFormData(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java deleted file mode 100644 index 81607d764..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ModalFormResponseSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ModalFormResponsePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ModalFormResponseSerializer_v363 implements PacketSerializer { - public static final ModalFormResponseSerializer_v363 INSTANCE = new ModalFormResponseSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ModalFormResponsePacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getFormId()); - BedrockUtils.writeString(buffer, packet.getFormData()); - } - - @Override - public void deserialize(ByteBuf buffer, ModalFormResponsePacket packet) { - packet.setFormId(VarInts.readUnsignedInt(buffer)); - packet.setFormData(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java deleted file mode 100644 index 1af179e15..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityAbsoluteSerializer_v363.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MoveEntityAbsoluteSerializer_v363 implements PacketSerializer { - public static final MoveEntityAbsoluteSerializer_v363 INSTANCE = new MoveEntityAbsoluteSerializer_v363(); - - private static final int FLAG_ON_GROUND = 0x1; - private static final int FLAG_TELEPORTED = 0x2; - - @Override - public void serialize(ByteBuf buffer, MoveEntityAbsolutePacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - int flags = 0; - if (packet.isOnGround()) { - flags |= FLAG_ON_GROUND; - } - if (packet.isTeleported()) { - flags |= FLAG_TELEPORTED; - } - buffer.writeByte(flags); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeByteRotation(buffer, packet.getRotation()); - } - - @Override - public void deserialize(ByteBuf buffer, MoveEntityAbsolutePacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - int flags = buffer.readUnsignedByte(); - packet.setOnGround((flags & FLAG_ON_GROUND) != 0); - packet.setTeleported((flags & FLAG_TELEPORTED) != 0); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readByteRotation(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java deleted file mode 100644 index b879b81ac..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MoveEntityDeltaSerializer_v363.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MoveEntityDeltaPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MoveEntityDeltaSerializer_v363 implements PacketSerializer { - public static final MoveEntityDeltaSerializer_v363 INSTANCE = new MoveEntityDeltaSerializer_v363(); - - private static final int HAS_X = 0x01; - private static final int HAS_Y = 0x02; - private static final int HAS_Z = 0x4; - private static final int HAS_PITCH = 0x8; - private static final int HAS_YAW = 0x10; - private static final int HAS_ROLL = 0x20; - - @Override - public void serialize(ByteBuf buffer, MoveEntityDeltaPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - byte flags = 0; - Vector3i movementDelta = packet.getMovementDelta(); - Vector3f rotationDelta = packet.getRotationDelta(); - flags |= movementDelta.getX() != 0 ? HAS_X : 0; - flags |= movementDelta.getY() != 0 ? HAS_Y : 0; - flags |= movementDelta.getZ() != 0 ? HAS_Z : 0; - flags |= rotationDelta.getX() != 0 ? HAS_PITCH : 0; - flags |= rotationDelta.getY() != 0 ? HAS_YAW : 0; - flags |= rotationDelta.getZ() != 0 ? HAS_ROLL : 0; - buffer.writeByte(flags); - if ((flags & HAS_X) != 0) { - VarInts.writeInt(buffer, movementDelta.getX()); - } - if ((flags & HAS_Y) != 0) { - VarInts.writeInt(buffer, movementDelta.getY()); - } - if ((flags & HAS_Z) != 0) { - VarInts.writeInt(buffer, movementDelta.getZ()); - } - if ((flags & HAS_PITCH) != 0) { - BedrockUtils.writeByteAngle(buffer, rotationDelta.getX()); - } - if ((flags & HAS_YAW) != 0) { - BedrockUtils.writeByteAngle(buffer, rotationDelta.getY()); - } - if ((flags & HAS_ROLL) != 0) { - BedrockUtils.writeByteAngle(buffer, rotationDelta.getZ()); - } - } - - @Override - public void deserialize(ByteBuf buffer, MoveEntityDeltaPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - byte flags = buffer.readByte(); - int x = 0, y = 0, z = 0; - float pitch = 0, yaw = 0, roll = 0; - if ((flags & HAS_X) != 0) { - x = VarInts.readInt(buffer); - } - if ((flags & HAS_Y) != 0) { - y = VarInts.readInt(buffer); - } - if ((flags & HAS_Z) != 0) { - z = VarInts.readInt(buffer); - } - if ((flags & HAS_PITCH) != 0) { - pitch = BedrockUtils.readByteAngle(buffer); - } - if ((flags & HAS_YAW) != 0) { - yaw = BedrockUtils.readByteAngle(buffer); - } - if ((flags & HAS_ROLL) != 0) { - roll = BedrockUtils.readByteAngle(buffer); - } - packet.setMovementDelta(Vector3i.from(x, y, z)); - packet.setRotationDelta(Vector3f.from(pitch, yaw, roll)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java deleted file mode 100644 index d89be426c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MovePlayerSerializer_v363.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.MovePlayerPacket.Mode; -import static com.nukkitx.protocol.bedrock.packet.MovePlayerPacket.TeleportationCause; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MovePlayerSerializer_v363 implements PacketSerializer { - public static final MovePlayerSerializer_v363 INSTANCE = new MovePlayerSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, MovePlayerPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeVector3f(buffer, packet.getRotation()); - buffer.writeByte(packet.getMode().ordinal()); - buffer.writeBoolean(packet.isOnGround()); - VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); - if (packet.getMode() == Mode.TELEPORT) { - buffer.writeIntLE(packet.getTeleportationCause().ordinal()); - buffer.writeIntLE(packet.getEntityType()); - } - } - - @Override - public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readVector3f(buffer)); - packet.setMode(Mode.values()[buffer.readByte()]); - packet.setOnGround(buffer.readBoolean()); - packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - if (packet.getMode() == Mode.TELEPORT) { - packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); - packet.setEntityType(buffer.readIntLE()); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java deleted file mode 100644 index 05434b5f9..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/MultiplayerSettingsSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.MultiplayerMode; -import com.nukkitx.protocol.bedrock.packet.MultiplayerSettingsPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class MultiplayerSettingsSerializer_v363 implements PacketSerializer { - - public static final MultiplayerSettingsSerializer_v363 INSTANCE = new MultiplayerSettingsSerializer_v363(); - - private static final MultiplayerMode[] VALUES = MultiplayerMode.values(); - - @Override - public void serialize(ByteBuf buffer, MultiplayerSettingsPacket packet) { - VarInts.writeInt(buffer, packet.getMode().ordinal()); - } - - @Override - public void deserialize(ByteBuf buffer, MultiplayerSettingsPacket packet) { - packet.setMode(VALUES[VarInts.readInt(buffer)]); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java deleted file mode 100644 index 286c9ae07..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkChunkPublisherUpdateSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NetworkChunkPublisherUpdateSerializer_v363 implements PacketSerializer { - public static final NetworkChunkPublisherUpdateSerializer_v363 INSTANCE = new NetworkChunkPublisherUpdateSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, NetworkChunkPublisherUpdatePacket packet) { - BedrockUtils.writeVector3i(buffer, packet.getPosition()); - VarInts.writeUnsignedInt(buffer, packet.getRadius()); - } - - @Override - public void deserialize(ByteBuf buffer, NetworkChunkPublisherUpdatePacket packet) { - packet.setPosition(BedrockUtils.readVector3i(buffer)); - packet.setRadius(VarInts.readUnsignedInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java deleted file mode 100644 index 87e946296..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkSettingsSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.NetworkSettingsPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class NetworkSettingsSerializer_v363 implements PacketSerializer { - - public static final NetworkSettingsSerializer_v363 INSTANCE = new NetworkSettingsSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, NetworkSettingsPacket packet) { - buffer.writeShortLE(packet.getCompressionThresholdByteSize()); - } - - @Override - public void deserialize(ByteBuf buffer, NetworkSettingsPacket packet) { - packet.setCompressionThresholdByteSize(buffer.readUnsignedShortLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java deleted file mode 100644 index 496a1ff0e..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NetworkStackLatencySerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NetworkStackLatencySerializer_v363 implements PacketSerializer { - public static final NetworkStackLatencySerializer_v363 INSTANCE = new NetworkStackLatencySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, NetworkStackLatencyPacket packet) { - buffer.writeLongLE(packet.getTimestamp()); - buffer.writeBoolean(packet.isSendBack()); - } - - @Override - public void deserialize(ByteBuf buffer, NetworkStackLatencyPacket packet) { - packet.setTimestamp(buffer.readLongLE()); - packet.setSendBack(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java deleted file mode 100644 index f31a0017b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/NpcRequestSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.NpcRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.NpcRequestPacket.Type; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NpcRequestSerializer_v363 implements PacketSerializer { - public static final NpcRequestSerializer_v363 INSTANCE = new NpcRequestSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, NpcRequestPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - buffer.writeByte(packet.getRequestType().ordinal()); - BedrockUtils.writeString(buffer, packet.getCommand()); - buffer.writeByte(packet.getActionType()); - } - - @Override - public void deserialize(ByteBuf buffer, NpcRequestPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setRequestType(Type.values()[buffer.readUnsignedByte()]); - packet.setCommand(BedrockUtils.readString(buffer)); - packet.setActionType(buffer.readUnsignedByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java deleted file mode 100644 index 98a6a037a..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/OnScreenTextureAnimationSerializer_v363.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.OnScreenTextureAnimationPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class OnScreenTextureAnimationSerializer_v363 implements PacketSerializer { - public static final OnScreenTextureAnimationSerializer_v363 INSTANCE = new OnScreenTextureAnimationSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, OnScreenTextureAnimationPacket packet) { - buffer.writeIntLE((int) packet.getEffectId()); - } - - @Override - public void deserialize(ByteBuf buffer, OnScreenTextureAnimationPacket packet) { - packet.setEffectId(buffer.readUnsignedIntLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java deleted file mode 100644 index 8374ca447..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PacketHeaderSerializer_v363.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.PacketHeader; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PacketHeaderSerializer_v363 implements PacketSerializer { - public static final PacketHeaderSerializer_v363 INSTANCE = new PacketHeaderSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PacketHeader packet) { - int header = 0; - header |= (packet.getPacketId() & 0x3ff); - header |= (packet.getSenderId() & 3) << 10; - header |= (packet.getClientId() & 3) << 12; - VarInts.writeUnsignedInt(buffer, header); - } - - @Override - public void deserialize(ByteBuf buffer, PacketHeader packet) { - int header = VarInts.readUnsignedInt(buffer); - packet.setPacketId(header & 0x3ff); - packet.setSenderId((header >>> 10) & 3); - packet.setClientId((header >>> 12) & 3); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java deleted file mode 100644 index 61892a14b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PhotoTransferSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.PhotoTransferPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PhotoTransferSerializer_v363 implements PacketSerializer { - public static final PhotoTransferSerializer_v363 INSTANCE = new PhotoTransferSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PhotoTransferPacket packet) { - BedrockUtils.writeString(buffer, packet.getName()); - byte[] data = packet.getData(); - VarInts.writeUnsignedInt(buffer, data.length); - buffer.writeBytes(data); - BedrockUtils.writeString(buffer, packet.getBookId()); - } - - @Override - public void deserialize(ByteBuf buffer, PhotoTransferPacket packet) { - packet.setName(BedrockUtils.readString(buffer)); - byte[] data = new byte[VarInts.readUnsignedInt(buffer)]; - buffer.readBytes(data); - packet.setData(data); - packet.setBookId(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java deleted file mode 100644 index 5565ea2d0..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlaySoundSerializer_v363.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.PlaySoundPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlaySoundSerializer_v363 implements PacketSerializer { - public static final PlaySoundSerializer_v363 INSTANCE = new PlaySoundSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlaySoundPacket packet) { - BedrockUtils.writeString(buffer, packet.getSound()); - BedrockUtils.writeBlockPosition(buffer, packet.getPosition().mul(8).toInt()); - buffer.writeFloatLE(packet.getVolume()); - buffer.writeFloatLE(packet.getPitch()); - } - - @Override - public void deserialize(ByteBuf buffer, PlaySoundPacket packet) { - packet.setSound(BedrockUtils.readString(buffer)); - packet.setPosition(BedrockUtils.readBlockPosition(buffer).toFloat().div(8)); - packet.setVolume(buffer.readFloatLE()); - packet.setPitch(buffer.readFloatLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java deleted file mode 100644 index d59177226..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayStatusSerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.PlayStatusPacket.Status; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayStatusSerializer_v363 implements PacketSerializer { - public static final PlayStatusSerializer_v363 INSTANCE = new PlayStatusSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlayStatusPacket packet) { - buffer.writeInt(packet.getStatus().ordinal()); - } - - @Override - public void deserialize(ByteBuf buffer, PlayStatusPacket packet) { - packet.setStatus(Status.values()[buffer.readInt()]); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java deleted file mode 100644 index fe0f1fca5..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerActionSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.PlayerActionPacket.Action; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerActionSerializer_v363 implements PacketSerializer { - public static final PlayerActionSerializer_v363 INSTANCE = new PlayerActionSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlayerActionPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeInt(buffer, packet.getAction().ordinal()); - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeInt(buffer, packet.getFace()); - } - - @Override - public void deserialize(ByteBuf buffer, PlayerActionPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setAction(Action.values()[VarInts.readInt(buffer)]); - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setFace(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java deleted file mode 100644 index 44d083154..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerAuthInputSerializer_v363.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.math.vector.Vector2f; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.PlayerAuthInputPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerAuthInputSerializer_v363 implements PacketSerializer { - - public static final PlayerAuthInputSerializer_v363 INSTANCE = new PlayerAuthInputSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, PlayerAuthInputPacket packet) { - Vector3f rotation = packet.getRotation(); - buffer.writeFloatLE(rotation.getX()); - buffer.writeFloatLE(rotation.getY()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - buffer.writeFloatLE(packet.getMotion().getX()); - buffer.writeFloatLE(packet.getMotion().getY()); - buffer.writeFloatLE(rotation.getZ()); - VarInts.writeUnsignedLong(buffer, packet.getInputData()); - VarInts.writeUnsignedInt(buffer, packet.getInputMode()); - VarInts.writeUnsignedInt(buffer, packet.getPlayMode()); - - if (packet.getPlayMode() == 4) { // VR MODE - BedrockUtils.writeVector3f(buffer, packet.getVrGazeDirection()); - } - } - - @Override - public void deserialize(ByteBuf buffer, PlayerAuthInputPacket packet) { - float x = buffer.readFloatLE(); - float y = buffer.readFloatLE(); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setMotion(Vector2f.from(buffer.readFloatLE(), buffer.readFloatLE())); - float z = buffer.readFloatLE(); - packet.setRotation(Vector3f.from(x, y, z)); - packet.setInputData(VarInts.readUnsignedLong(buffer)); - packet.setInputMode(VarInts.readUnsignedInt(buffer)); - packet.setPlayMode(VarInts.readUnsignedInt(buffer)); - - if (packet.getPlayMode() == 4) { - packet.setVrGazeDirection(BedrockUtils.readVector3f(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java deleted file mode 100644 index 2e0e0c148..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerHotbarSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerHotbarSerializer_v363 implements PacketSerializer { - public static final PlayerHotbarSerializer_v363 INSTANCE = new PlayerHotbarSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, PlayerHotbarPacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getSelectedHotbarSlot()); - buffer.writeByte(packet.getContainerId()); - buffer.writeBoolean(packet.isSelectHotbarSlot()); - } - - @Override - public void deserialize(ByteBuf buffer, PlayerHotbarPacket packet) { - packet.setSelectedHotbarSlot(VarInts.readUnsignedInt(buffer)); - packet.setContainerId(buffer.readUnsignedByte()); - packet.setSelectHotbarSlot(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java deleted file mode 100644 index 717a3f996..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerInputSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.PlayerInputPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerInputSerializer_v363 implements PacketSerializer { - public static final PlayerInputSerializer_v363 INSTANCE = new PlayerInputSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlayerInputPacket packet) { - BedrockUtils.writeVector2f(buffer, packet.getInputMotion()); - buffer.writeBoolean(packet.isJumping()); - buffer.writeBoolean(packet.isSneaking()); - } - - @Override - public void deserialize(ByteBuf buffer, PlayerInputPacket packet) { - packet.setInputMotion(BedrockUtils.readVector2f(buffer)); - packet.setJumping(buffer.readBoolean()); - packet.setSneaking(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java deleted file mode 100644 index 78258a2fc..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.ImageData; -import com.nukkitx.protocol.bedrock.data.SerializedSkin; -import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Action; -import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Entry; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerListSerializer_v363 implements PacketSerializer { - public static final PlayerListSerializer_v363 INSTANCE = new PlayerListSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlayerListPacket packet) { - buffer.writeByte(packet.getAction().ordinal()); - VarInts.writeUnsignedInt(buffer, packet.getEntries().size()); - - for (Entry entry : packet.getEntries()) { - BedrockUtils.writeUuid(buffer, entry.getUuid()); - - if (packet.getAction() == Action.ADD) { - VarInts.writeLong(buffer, entry.getEntityId()); - BedrockUtils.writeString(buffer, entry.getName()); - SerializedSkin skin = entry.getSkin(); - BedrockUtils.writeString(buffer, skin.getSkinId()); - skin.getSkinData().checkLegacySkinSize(); - BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); - skin.getCapeData().checkLegacyCapeSize(); - BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); - BedrockUtils.writeString(buffer, skin.getGeometryName()); - BedrockUtils.writeString(buffer, skin.getGeometryData()); - BedrockUtils.writeString(buffer, entry.getXuid()); - BedrockUtils.writeString(buffer, entry.getPlatformChatId()); - } - } - } - - @Override - public void deserialize(ByteBuf buffer, PlayerListPacket packet) { - Action action = Action.values()[buffer.readUnsignedByte()]; - packet.setAction(action); - int length = VarInts.readUnsignedInt(buffer); - - for (int i = 0; i < length; i++) { - Entry entry = new Entry(BedrockUtils.readUuid(buffer)); - - if (action == Action.ADD) { - entry.setEntityId(VarInts.readLong(buffer)); - entry.setName(BedrockUtils.readString(buffer)); - String skinId = BedrockUtils.readString(buffer); - ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); - ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); - String geometryName = BedrockUtils.readString(buffer); - String geometryData = BedrockUtils.readString(buffer); - entry.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, false)); - entry.setXuid(BedrockUtils.readString(buffer)); - entry.setPlatformChatId(BedrockUtils.readString(buffer)); - } - packet.getEntries().add(entry); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java deleted file mode 100644 index a5f07467c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerSkinSerializer_v363.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.data.ImageData; -import com.nukkitx.protocol.bedrock.data.SerializedSkin; -import com.nukkitx.protocol.bedrock.packet.PlayerSkinPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerSkinSerializer_v363 implements PacketSerializer { - public static final PlayerSkinSerializer_v363 INSTANCE = new PlayerSkinSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PlayerSkinPacket packet) { - BedrockUtils.writeUuid(buffer, packet.getUuid()); - SerializedSkin skin = packet.getSkin(); - BedrockUtils.writeString(buffer, skin.getSkinId()); - BedrockUtils.writeString(buffer, packet.getNewSkinName()); - BedrockUtils.writeString(buffer, packet.getOldSkinName()); - skin.getSkinData().checkLegacySkinSize(); - BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); - skin.getCapeData().checkLegacyCapeSize(); - BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); - BedrockUtils.writeString(buffer, skin.getGeometryName()); - BedrockUtils.writeString(buffer, skin.getGeometryData()); - buffer.writeBoolean(skin.isPremium()); - } - - @Override - public void deserialize(ByteBuf buffer, PlayerSkinPacket packet) { - packet.setUuid(BedrockUtils.readUuid(buffer)); - String skinId = BedrockUtils.readString(buffer); - packet.setNewSkinName(BedrockUtils.readString(buffer)); - packet.setOldSkinName(BedrockUtils.readString(buffer)); - ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); - ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); - String geometryName = BedrockUtils.readString(buffer); - String geometryData = BedrockUtils.readString(buffer); - boolean premium = buffer.readBoolean(); - packet.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, premium)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java deleted file mode 100644 index eca51b511..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PurchaseReceiptSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.PurchaseReceiptPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PurchaseReceiptSerializer_v363 implements PacketSerializer { - public static final PurchaseReceiptSerializer_v363 INSTANCE = new PurchaseReceiptSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, PurchaseReceiptPacket packet) { - BedrockUtils.writeArray(buffer, packet.getReceipts(), BedrockUtils::writeString); - } - - @Override - public void deserialize(ByteBuf buffer, PurchaseReceiptPacket packet) { - BedrockUtils.readArray(buffer, packet.getReceipts(), BedrockUtils::readString); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java deleted file mode 100644 index d85606aa1..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveEntitySerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class RemoveEntitySerializer_v363 implements PacketSerializer { - public static final RemoveEntitySerializer_v363 INSTANCE = new RemoveEntitySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, RemoveEntityPacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, RemoveEntityPacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java deleted file mode 100644 index 34c1e4c29..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RemoveObjectiveSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class RemoveObjectiveSerializer_v363 implements PacketSerializer { - public static final RemoveObjectiveSerializer_v363 INSTANCE = new RemoveObjectiveSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, RemoveObjectivePacket packet) { - BedrockUtils.writeString(buffer, packet.getObjectiveId()); - } - - @Override - public void deserialize(ByteBuf buffer, RemoveObjectivePacket packet) { - packet.setObjectiveId(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java deleted file mode 100644 index a2d0f0309..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RequestChunkRadiusSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.RequestChunkRadiusPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class RequestChunkRadiusSerializer_v363 implements PacketSerializer { - public static final RequestChunkRadiusSerializer_v363 INSTANCE = new RequestChunkRadiusSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, RequestChunkRadiusPacket packet) { - VarInts.writeInt(buffer, packet.getRadius()); - } - - @Override - public void deserialize(ByteBuf buffer, RequestChunkRadiusPacket packet) { - packet.setRadius(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java deleted file mode 100644 index 6d87dca98..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkDataSerializer_v363.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePackChunkDataPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePackChunkDataSerializer_v363 implements PacketSerializer { - public static final ResourcePackChunkDataSerializer_v363 INSTANCE = new ResourcePackChunkDataSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ResourcePackChunkDataPacket packet) { - String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); - BedrockUtils.writeString(buffer, packInfo); - buffer.writeIntLE(packet.getChunkIndex()); - buffer.writeLongLE(packet.getProgress()); - byte[] data = packet.getData(); - buffer.writeIntLE(data.length); - buffer.writeBytes(data); - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePackChunkDataPacket packet) { - String[] packInfo = BedrockUtils.readString(buffer).split("_"); - packet.setPackId(UUID.fromString(packInfo[0])); - if (packInfo.length > 1) { - packet.setPackVersion(packInfo[1]); - } - packet.setChunkIndex(buffer.readIntLE()); - packet.setProgress(buffer.readLongLE()); - byte[] data = new byte[buffer.readIntLE()]; - buffer.readBytes(data); - packet.setData(data); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java deleted file mode 100644 index ec6926ffd..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackChunkRequestSerializer_v363.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePackChunkRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePackChunkRequestSerializer_v363 implements PacketSerializer { - public static final ResourcePackChunkRequestSerializer_v363 INSTANCE = new ResourcePackChunkRequestSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ResourcePackChunkRequestPacket packet) { - String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); - BedrockUtils.writeString(buffer, packInfo); - buffer.writeIntLE(packet.getChunkIndex()); - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePackChunkRequestPacket packet) { - String[] packInfo = BedrockUtils.readString(buffer).split("_"); - packet.setPackId(UUID.fromString(packInfo[0])); - if (packInfo.length > 1) { - packet.setPackVersion(packInfo[1]); - } - packet.setChunkIndex(buffer.readIntLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java deleted file mode 100644 index 565068159..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackClientResponseSerializer_v363.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePackClientResponsePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.List; - -import static com.nukkitx.protocol.bedrock.packet.ResourcePackClientResponsePacket.Status; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePackClientResponseSerializer_v363 implements PacketSerializer { - public static final ResourcePackClientResponseSerializer_v363 INSTANCE = new ResourcePackClientResponseSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ResourcePackClientResponsePacket packet) { - buffer.writeByte(packet.getStatus().ordinal()); - - List packIds = packet.getPackIds(); - buffer.writeShortLE(packIds.size()); - - for (String packId : packIds) { - BedrockUtils.writeString(buffer, packId); - } - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePackClientResponsePacket packet) { - Status status = Status.values()[buffer.readByte()]; - packet.setStatus(status); - - List packIds = packet.getPackIds(); - int packIdsCount = buffer.readShortLE(); - for (int i = 0; i < packIdsCount; i++) { - packIds.add(BedrockUtils.readString(buffer)); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java deleted file mode 100644 index 2d9d71a74..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackDataInfoSerializer_v363.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePackDataInfoPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -import static com.nukkitx.protocol.bedrock.packet.ResourcePackDataInfoPacket.Type.*; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePackDataInfoSerializer_v363 implements PacketSerializer { - public static final ResourcePackDataInfoSerializer_v363 INSTANCE = new ResourcePackDataInfoSerializer_v363(); - - public static final Int2ObjectBiMap TYPES = new Int2ObjectBiMap<>(INVALID); - - static { - TYPES.put(0, INVALID); - TYPES.put(1, RESOURCE); - TYPES.put(2, BEHAVIOR); - TYPES.put(3, WORLD_TEMPLATE); - TYPES.put(4, ADDON); - TYPES.put(5, SKINS); - TYPES.put(6, CACHED); - TYPES.put(7, COPY_PROTECTED); - } - - @Override - public void serialize(ByteBuf buffer, ResourcePackDataInfoPacket packet) { - String packInfo = packet.getPackId().toString() + (packet.getPackVersion() == null ? "" : '_' + packet.getPackVersion()); - BedrockUtils.writeString(buffer, packInfo); - buffer.writeIntLE((int) packet.getMaxChunkSize()); - buffer.writeIntLE((int) packet.getChunkCount()); - buffer.writeLongLE(packet.getCompressedPackSize()); - BedrockUtils.writeByteArray(buffer, packet.getHash()); - buffer.writeBoolean(packet.isPremium()); - buffer.writeByte(TYPES.get(packet.getType())); - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePackDataInfoPacket packet) { - String[] packInfo = BedrockUtils.readString(buffer).split("_"); - packet.setPackId(UUID.fromString(packInfo[0])); - if (packInfo.length > 1) { - packet.setPackVersion(packInfo[1]); - } - packet.setMaxChunkSize(buffer.readUnsignedIntLE()); - packet.setChunkCount(buffer.readUnsignedIntLE()); - packet.setCompressedPackSize(buffer.readLongLE()); - packet.setHash(BedrockUtils.readByteArray(buffer)); - packet.setPremium(buffer.readBoolean()); - packet.setType(TYPES.get(buffer.readUnsignedByte())); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java deleted file mode 100644 index f05fbb649..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePackStackSerializer_v363.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePackStackPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePackStackSerializer_v363 implements PacketSerializer { - public static final ResourcePackStackSerializer_v363 INSTANCE = new ResourcePackStackSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ResourcePackStackPacket packet) { - buffer.writeBoolean(packet.isForcedToAccept()); - BedrockUtils.writeArray(buffer, packet.getBehaviorPacks(), BedrockUtils::writePackInstanceEntry); - BedrockUtils.writeArray(buffer, packet.getResourcePacks(), BedrockUtils::writePackInstanceEntry); - buffer.writeBoolean(packet.isExperimental()); - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePackStackPacket packet) { - packet.setForcedToAccept(buffer.readBoolean()); - BedrockUtils.readArray(buffer, packet.getBehaviorPacks(), BedrockUtils::readPackInstanceEntry); - BedrockUtils.readArray(buffer, packet.getResourcePacks(), BedrockUtils::readPackInstanceEntry); - packet.setExperimental(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java deleted file mode 100644 index 0dfa02b14..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ResourcePacksInfoSerializer_v363.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ResourcePacksInfoPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ResourcePacksInfoSerializer_v363 implements PacketSerializer { - public static final ResourcePacksInfoSerializer_v363 INSTANCE = new ResourcePacksInfoSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, ResourcePacksInfoPacket packet) { - buffer.writeBoolean(packet.isForcedToAccept()); - buffer.writeBoolean(packet.isScriptingEnabled()); - BedrockUtils.writePacksInfoEntries(buffer, packet.getBehaviorPackInfos()); - BedrockUtils.writePacksInfoEntries(buffer, packet.getResourcePackInfos()); - } - - @Override - public void deserialize(ByteBuf buffer, ResourcePacksInfoPacket packet) { - packet.setForcedToAccept(buffer.readBoolean()); - packet.setScriptingEnabled(buffer.readBoolean()); - packet.getBehaviorPackInfos().addAll(BedrockUtils.readPacksInfoEntries(buffer)); - packet.getResourcePackInfos().addAll(BedrockUtils.readPacksInfoEntries(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java deleted file mode 100644 index 20f1f1017..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RespawnSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.RespawnPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class RespawnSerializer_v363 implements PacketSerializer { - public static final RespawnSerializer_v363 INSTANCE = new RespawnSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, RespawnPacket packet) { - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - } - - @Override - public void deserialize(ByteBuf buffer, RespawnPacket packet) { - packet.setPosition(BedrockUtils.readVector3f(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java deleted file mode 100644 index 784dae19a..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/RiderJumpSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.RiderJumpPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class RiderJumpSerializer_v363 implements PacketSerializer { - public static final RiderJumpSerializer_v363 INSTANCE = new RiderJumpSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, RiderJumpPacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getJumpStrength()); - } - - @Override - public void deserialize(ByteBuf buffer, RiderJumpPacket packet) { - packet.setJumpStrength(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java deleted file mode 100644 index b0a754afe..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ScriptCustomEventSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ScriptCustomEventPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ScriptCustomEventSerializer_v363 implements PacketSerializer { - public static final ScriptCustomEventSerializer_v363 INSTANCE = new ScriptCustomEventSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ScriptCustomEventPacket packet) { - BedrockUtils.writeString(buffer, packet.getEventName()); - BedrockUtils.writeString(buffer, packet.getData()); - } - - @Override - public void deserialize(ByteBuf buffer, ScriptCustomEventPacket packet) { - packet.setEventName(BedrockUtils.readString(buffer)); - packet.setData(BedrockUtils.readString(buffer)); - } -} - diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java deleted file mode 100644 index 0acfb0894..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsRequestSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ServerSettingsRequestSerializer_v363 implements PacketSerializer { - public static final ServerSettingsRequestSerializer_v363 INSTANCE = new ServerSettingsRequestSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ServerSettingsRequestPacket packet) { - // No payload - } - - @Override - public void deserialize(ByteBuf buffer, ServerSettingsRequestPacket packet) { - // No payload - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java deleted file mode 100644 index 73f60105d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerSettingsResponseSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ServerSettingsResponseSerializer_v363 implements PacketSerializer { - public static final ServerSettingsResponseSerializer_v363 INSTANCE = new ServerSettingsResponseSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ServerSettingsResponsePacket packet) { - VarInts.writeUnsignedInt(buffer, packet.getFormId()); - BedrockUtils.writeString(buffer, packet.getFormData()); - } - - @Override - public void deserialize(ByteBuf buffer, ServerSettingsResponsePacket packet) { - packet.setFormId(VarInts.readUnsignedInt(buffer)); - packet.setFormData(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java deleted file mode 100644 index d9ff66501..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ServerToClientHandshakeSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.annotation.NoEncryption; -import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoEncryption // This is sent in plain text to complete the Diffie Hellman key exchange. -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ServerToClientHandshakeSerializer_v363 implements PacketSerializer { - public static final ServerToClientHandshakeSerializer_v363 INSTANCE = new ServerToClientHandshakeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ServerToClientHandshakePacket packet) { - BedrockUtils.writeString(buffer, packet.getJwt()); - } - - @Override - public void deserialize(ByteBuf buffer, ServerToClientHandshakePacket packet) { - packet.setJwt(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java deleted file mode 100644 index b06cf1121..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetCommandsEnabledSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.SetCommandsEnabledPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetCommandsEnabledSerializer_v363 implements PacketSerializer { - public static final SetCommandsEnabledSerializer_v363 INSTANCE = new SetCommandsEnabledSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetCommandsEnabledPacket packet) { - buffer.writeBoolean(packet.isCommandsEnabled()); - } - - @Override - public void deserialize(ByteBuf buffer, SetCommandsEnabledPacket packet) { - packet.setCommandsEnabled(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java deleted file mode 100644 index 86404cf1c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDefaultGameTypeSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetDefaultGameTypePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetDefaultGameTypeSerializer_v363 implements PacketSerializer { - public static final SetDefaultGameTypeSerializer_v363 INSTANCE = new SetDefaultGameTypeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetDefaultGameTypePacket packet) { - VarInts.writeInt(buffer, packet.getGamemode()); - } - - @Override - public void deserialize(ByteBuf buffer, SetDefaultGameTypePacket packet) { - packet.setGamemode(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java deleted file mode 100644 index d7dc3c25d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDifficultySerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetDifficultySerializer_v363 implements PacketSerializer { - public static final SetDifficultySerializer_v363 INSTANCE = new SetDifficultySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetDifficultyPacket packet) { - VarInts.writeInt(buffer, packet.getDifficulty()); - } - - @Override - public void deserialize(ByteBuf buffer, SetDifficultyPacket packet) { - packet.setDifficulty(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java deleted file mode 100644 index c9fd21040..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetDisplayObjectiveSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetDisplayObjectiveSerializer_v363 implements PacketSerializer { - public static final SetDisplayObjectiveSerializer_v363 INSTANCE = new SetDisplayObjectiveSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetDisplayObjectivePacket packet) { - BedrockUtils.writeString(buffer, packet.getDisplaySlot()); - BedrockUtils.writeString(buffer, packet.getObjectiveId()); - BedrockUtils.writeString(buffer, packet.getDisplayName()); - BedrockUtils.writeString(buffer, packet.getCriteria()); - VarInts.writeInt(buffer, packet.getSortOrder()); - } - - @Override - public void deserialize(ByteBuf buffer, SetDisplayObjectivePacket packet) { - packet.setDisplaySlot(BedrockUtils.readString(buffer)); - packet.setObjectiveId(BedrockUtils.readString(buffer)); - packet.setDisplayName(BedrockUtils.readString(buffer)); - packet.setCriteria(BedrockUtils.readString(buffer)); - packet.setSortOrder(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java deleted file mode 100644 index 24792b970..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityDataSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetEntityDataSerializer_v363 implements PacketSerializer { - public static final SetEntityDataSerializer_v363 INSTANCE = new SetEntityDataSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetEntityDataPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeEntityData(buffer, packet.getMetadata()); - } - - @Override - public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - BedrockUtils.readEntityData(buffer, packet.getMetadata()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java deleted file mode 100644 index 19671c51d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityLinkSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetEntityLinkSerializer_v363 implements PacketSerializer { - public static final SetEntityLinkSerializer_v363 INSTANCE = new SetEntityLinkSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetEntityLinkPacket packet) { - BedrockUtils.writeEntityLink(buffer, packet.getEntityLink()); - } - - @Override - public void deserialize(ByteBuf buffer, SetEntityLinkPacket packet) { - packet.setEntityLink(BedrockUtils.readEntityLink(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java deleted file mode 100644 index 988a704d6..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetEntityMotionSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetEntityMotionSerializer_v363 implements PacketSerializer { - public static final SetEntityMotionSerializer_v363 INSTANCE = new SetEntityMotionSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetEntityMotionPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeVector3f(buffer, packet.getMotion()); - } - - @Override - public void deserialize(ByteBuf buffer, SetEntityMotionPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setMotion(BedrockUtils.readVector3f(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java deleted file mode 100644 index 6d9c69d28..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetHealthSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetHealthPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetHealthSerializer_v363 implements PacketSerializer { - public static final SetHealthSerializer_v363 INSTANCE = new SetHealthSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetHealthPacket packet) { - VarInts.writeInt(buffer, packet.getHealth()); - } - - @Override - public void deserialize(ByteBuf buffer, SetHealthPacket packet) { - packet.setHealth(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java deleted file mode 100644 index ced4e4b7a..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLastHurtBySerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetLastHurtByPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetLastHurtBySerializer_v363 implements PacketSerializer { - public static final SetLastHurtBySerializer_v363 INSTANCE = new SetLastHurtBySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetLastHurtByPacket packet) { - VarInts.writeInt(buffer, packet.getEntityTypeId()); - } - - @Override - public void deserialize(ByteBuf buffer, SetLastHurtByPacket packet) { - packet.setEntityTypeId(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java deleted file mode 100644 index dcf9654f5..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetLocalPlayerAsInitializedSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetLocalPlayerAsInitializedSerializer_v363 implements PacketSerializer { - public static final SetLocalPlayerAsInitializedSerializer_v363 INSTANCE = new SetLocalPlayerAsInitializedSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetLocalPlayerAsInitializedPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, SetLocalPlayerAsInitializedPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java deleted file mode 100644 index a7f2b00b1..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetPlayerGameTypeSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetPlayerGameTypeSerializer_v363 implements PacketSerializer { - public static final SetPlayerGameTypeSerializer_v363 INSTANCE = new SetPlayerGameTypeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) { - VarInts.writeInt(buffer, packet.getGamemode()); - } - - @Override - public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) { - packet.setGamemode(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java deleted file mode 100644 index b9bccafee..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreSerializer_v363.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.ScoreInfo; -import com.nukkitx.protocol.bedrock.packet.SetScorePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import static com.nukkitx.protocol.bedrock.packet.SetScorePacket.Action; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetScoreSerializer_v363 implements PacketSerializer { - public static final SetScoreSerializer_v363 INSTANCE = new SetScoreSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetScorePacket packet) { - Action action = packet.getAction(); - buffer.writeByte(action.ordinal()); - - BedrockUtils.writeArray(buffer, packet.getInfos(), (buf, scoreInfo) -> { - VarInts.writeLong(buf, scoreInfo.getScoreboardId()); - BedrockUtils.writeString(buf, scoreInfo.getObjectiveId()); - buf.writeIntLE(scoreInfo.getScore()); - if (action == Action.SET) { - buf.writeByte(scoreInfo.getType().ordinal()); - switch (scoreInfo.getType()) { - case ENTITY: - case PLAYER: - VarInts.writeLong(buf, scoreInfo.getEntityId()); - break; - case FAKE: - BedrockUtils.writeString(buf, scoreInfo.getName()); - break; - default: - throw new IllegalArgumentException("Invalid score info received"); - } - } - }); - } - - @Override - public void deserialize(ByteBuf buffer, SetScorePacket packet) { - Action action = Action.values()[buffer.readUnsignedByte()]; - packet.setAction(action); - - BedrockUtils.readArray(buffer, packet.getInfos(), buf -> { - long scoreboardId = VarInts.readLong(buf); - String objectiveId = BedrockUtils.readString(buf); - int score = buf.readIntLE(); - if (action == Action.SET) { - ScoreInfo.ScorerType type = ScoreInfo.ScorerType.values()[buf.readUnsignedByte()]; - switch (type) { - case ENTITY: - case PLAYER: - long entityId = VarInts.readLong(buf); - return new ScoreInfo(scoreboardId, objectiveId, score, type, entityId); - case FAKE: - String name = BedrockUtils.readString(buf); - return new ScoreInfo(scoreboardId, objectiveId, score, name); - default: - throw new IllegalArgumentException("Invalid score info received"); - } - } else { - return new ScoreInfo(scoreboardId, objectiveId, score); - } - }); - } - -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java deleted file mode 100644 index e8fbbadc3..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetScoreboardIdentitySerializer_v363.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -import static com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket.Action; -import static com.nukkitx.protocol.bedrock.packet.SetScoreboardIdentityPacket.Entry; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetScoreboardIdentitySerializer_v363 implements PacketSerializer { - public static final SetScoreboardIdentitySerializer_v363 INSTANCE = new SetScoreboardIdentitySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetScoreboardIdentityPacket packet) { - SetScoreboardIdentityPacket.Action action = packet.getAction(); - buffer.writeByte(action.ordinal()); - BedrockUtils.writeArray(buffer, packet.getEntries(), (buf, entry) -> { - VarInts.writeLong(buffer, entry.getScoreboardId()); - if (action == SetScoreboardIdentityPacket.Action.ADD) { - BedrockUtils.writeUuid(buffer, entry.getUuid()); - } - }); - } - - @Override - public void deserialize(ByteBuf buffer, SetScoreboardIdentityPacket packet) { - Action action = Action.values()[buffer.readUnsignedByte()]; - packet.setAction(action); - BedrockUtils.readArray(buffer, packet.getEntries(), buf -> { - long scoreboardId = VarInts.readLong(buffer); - UUID uuid = null; - if (action == Action.ADD) { - uuid = BedrockUtils.readUuid(buffer); - } - return new Entry(scoreboardId, uuid); - }); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java deleted file mode 100644 index c5ba67d25..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetSpawnPositionSerializer_v363.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetSpawnPositionPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetSpawnPositionSerializer_v363 implements PacketSerializer { - public static final SetSpawnPositionSerializer_v363 INSTANCE = new SetSpawnPositionSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetSpawnPositionPacket packet) { - VarInts.writeInt(buffer, packet.getSpawnType().ordinal()); - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - buffer.writeBoolean(packet.isSpawnForced()); - } - - @Override - public void deserialize(ByteBuf buffer, SetSpawnPositionPacket packet) { - packet.setSpawnType(SetSpawnPositionPacket.Type.values()[VarInts.readInt(buffer)]); - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setSpawnForced(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java deleted file mode 100644 index 30df04e1c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTimeSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetTimePacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetTimeSerializer_v363 implements PacketSerializer { - public static final SetTimeSerializer_v363 INSTANCE = new SetTimeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetTimePacket packet) { - VarInts.writeInt(buffer, packet.getTime()); - } - - @Override - public void deserialize(ByteBuf buffer, SetTimePacket packet) { - packet.setTime(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java deleted file mode 100644 index e071ace7c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SetTitleSerializer_v363.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SetTitlePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SetTitleSerializer_v363 implements PacketSerializer { - public static final SetTitleSerializer_v363 INSTANCE = new SetTitleSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SetTitlePacket packet) { - VarInts.writeInt(buffer, packet.getType().ordinal()); - BedrockUtils.writeString(buffer, packet.getText()); - VarInts.writeInt(buffer, packet.getFadeInTime()); - VarInts.writeInt(buffer, packet.getStayTime()); - VarInts.writeInt(buffer, packet.getFadeOutTime()); - } - - @Override - public void deserialize(ByteBuf buffer, SetTitlePacket packet) { - packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]); - packet.setText(BedrockUtils.readString(buffer)); - packet.setFadeInTime(VarInts.readInt(buffer)); - packet.setStayTime(VarInts.readInt(buffer)); - packet.setFadeOutTime(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java deleted file mode 100644 index 263222270..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SettingsCommandSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.SettingsCommandPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class SettingsCommandSerializer_v363 implements PacketSerializer { - - public static final SettingsCommandSerializer_v363 INSTANCE = new SettingsCommandSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, SettingsCommandPacket packet) { - BedrockUtils.writeString(buffer, packet.getCommand()); - buffer.writeBoolean(packet.isSuppressingOutput()); - } - - @Override - public void deserialize(ByteBuf buffer, SettingsCommandPacket packet) { - packet.setCommand(BedrockUtils.readString(buffer)); - packet.setSuppressingOutput(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java deleted file mode 100644 index 34ea8e21d..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowCreditsSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShowCreditsSerializer_v363 implements PacketSerializer { - public static final ShowCreditsSerializer_v363 INSTANCE = new ShowCreditsSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ShowCreditsPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeInt(buffer, packet.getStatus().ordinal()); - } - - @Override - public void deserialize(ByteBuf buffer, ShowCreditsPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setStatus(ShowCreditsPacket.Status.values()[VarInts.readInt(buffer)]); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java deleted file mode 100644 index 1842a4f01..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowProfileSerializer_v363.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ShowProfilePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShowProfileSerializer_v363 implements PacketSerializer { - public static final ShowProfileSerializer_v363 INSTANCE = new ShowProfileSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ShowProfilePacket packet) { - BedrockUtils.writeString(buffer, packet.getXuid()); - } - - @Override - public void deserialize(ByteBuf buffer, ShowProfilePacket packet) { - packet.setXuid(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java deleted file mode 100644 index 3ad433a2c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/ShowStoreOfferSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.ShowStoreOfferPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShowStoreOfferSerializer_v363 implements PacketSerializer { - public static final ShowStoreOfferSerializer_v363 INSTANCE = new ShowStoreOfferSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, ShowStoreOfferPacket packet) { - BedrockUtils.writeString(buffer, packet.getOfferId()); - buffer.writeBoolean(packet.isShownToAll()); - } - - @Override - public void deserialize(ByteBuf buffer, ShowStoreOfferPacket packet) { - packet.setOfferId(BedrockUtils.readString(buffer)); - packet.setShownToAll(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java deleted file mode 100644 index e1b9d1278..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SimpleEventSerializer_v363.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.SimpleEventPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SimpleEventSerializer_v363 implements PacketSerializer { - public static final SimpleEventSerializer_v363 INSTANCE = new SimpleEventSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SimpleEventPacket packet) { - buffer.writeShortLE(packet.getEvent()); - } - - @Override - public void deserialize(ByteBuf buffer, SimpleEventPacket packet) { - packet.setEvent(buffer.readShortLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java deleted file mode 100644 index 65e7c26d3..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnExperienceOrbSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SpawnExperienceOrbSerializer_v363 implements PacketSerializer { - public static final SpawnExperienceOrbSerializer_v363 INSTANCE = new SpawnExperienceOrbSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SpawnExperienceOrbPacket packet) { - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - VarInts.writeInt(buffer, packet.getAmount()); - } - - @Override - public void deserialize(ByteBuf buffer, SpawnExperienceOrbPacket packet) { - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setAmount(VarInts.readInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java deleted file mode 100644 index b570c0d62..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SpawnParticleEffectSerializer_v363.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SpawnParticleEffectPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SpawnParticleEffectSerializer_v363 implements PacketSerializer { - public static final SpawnParticleEffectSerializer_v363 INSTANCE = new SpawnParticleEffectSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, SpawnParticleEffectPacket packet) { - buffer.writeByte(packet.getDimensionId()); - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - BedrockUtils.writeVector3f(buffer, packet.getPosition()); - BedrockUtils.writeString(buffer, packet.getIdentifier()); - } - - @Override - public void deserialize(ByteBuf buffer, SpawnParticleEffectPacket packet) { - packet.setDimensionId(buffer.readUnsignedByte()); - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setPosition(BedrockUtils.readVector3f(buffer)); - packet.setIdentifier(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java deleted file mode 100644 index 6224aacf9..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.CompoundTagBuilder; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.nbt.tag.ListTag; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.GamePublishSetting; -import com.nukkitx.protocol.bedrock.data.PlayerPermission; -import com.nukkitx.protocol.bedrock.packet.StartGamePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.List; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StartGameSerializer_v363 implements PacketSerializer { - public static final StartGameSerializer_v363 INSTANCE = new StartGameSerializer_v363(); - - private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); - - @Override - public void serialize(ByteBuf buffer, StartGamePacket packet) { - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeInt(buffer, packet.getPlayerGamemode()); - BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); - BedrockUtils.writeVector2f(buffer, packet.getRotation()); - // Level settings start - VarInts.writeInt(buffer, packet.getSeed()); - VarInts.writeInt(buffer, packet.getDimensionId()); - VarInts.writeInt(buffer, packet.getGeneratorId()); - VarInts.writeInt(buffer, packet.getLevelGamemode()); - VarInts.writeInt(buffer, packet.getDifficulty()); - BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); - buffer.writeBoolean(packet.isAchievementsDisabled()); - VarInts.writeInt(buffer, packet.getTime()); - buffer.writeBoolean(packet.getEduEditionOffers() != 0); - buffer.writeBoolean(packet.isEduFeaturesEnabled()); - buffer.writeFloatLE(packet.getRainLevel()); - buffer.writeFloatLE(packet.getLightningLevel()); - buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); - buffer.writeBoolean(packet.isMultiplayerGame()); - buffer.writeBoolean(packet.isBroadcastingToLan()); - VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); - VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); - buffer.writeBoolean(packet.isCommandsEnabled()); - buffer.writeBoolean(packet.isTexturePacksRequired()); - BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); - buffer.writeBoolean(packet.isBonusChestEnabled()); - buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); - buffer.writeIntLE(packet.getServerChunkTickRange()); - buffer.writeBoolean(packet.isBehaviorPackLocked()); - buffer.writeBoolean(packet.isResourcePackLocked()); - buffer.writeBoolean(packet.isFromLockedWorldTemplate()); - buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); - buffer.writeBoolean(packet.isFromWorldTemplate()); - buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); - buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); - - // Level settings end - BedrockUtils.writeString(buffer, packet.getLevelId()); - BedrockUtils.writeString(buffer, packet.getWorldName()); - BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); - buffer.writeBoolean(packet.isTrial()); - buffer.writeLongLE(packet.getCurrentTick()); - VarInts.writeInt(buffer, packet.getEnchantmentSeed()); - - List palette = packet.getBlockPalette().getValue(); - VarInts.writeUnsignedInt(buffer, palette.size()); - for (CompoundTag entry : palette) { - CompoundTag blockTag = entry.getCompound("block"); - BedrockUtils.writeString(buffer, blockTag.getString("name")); - buffer.writeShortLE(entry.getShort("meta")); - buffer.writeShortLE(entry.getShort("id")); - } - - BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { - BedrockUtils.writeString(buf, entry.getIdentifier()); - buf.writeShortLE(entry.getId()); - }); - - BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); - - } - - @Override - public void deserialize(ByteBuf buffer, StartGamePacket packet) { - packet.setUniqueEntityId(VarInts.readLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setPlayerGamemode(VarInts.readInt(buffer)); - packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readVector2f(buffer)); - // Level settings start - packet.setSeed(VarInts.readInt(buffer)); - packet.setDimensionId(VarInts.readInt(buffer)); - packet.setGeneratorId(VarInts.readInt(buffer)); - packet.setLevelGamemode(VarInts.readInt(buffer)); - packet.setDifficulty(VarInts.readInt(buffer)); - packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); - packet.setAchievementsDisabled(buffer.readBoolean()); - packet.setTime(VarInts.readInt(buffer)); - packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); - packet.setEduFeaturesEnabled(buffer.readBoolean()); - packet.setRainLevel(buffer.readFloatLE()); - packet.setLightningLevel(buffer.readFloatLE()); - packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); - packet.setMultiplayerGame(buffer.readBoolean()); - packet.setBroadcastingToLan(buffer.readBoolean()); - packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); - packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); - packet.setCommandsEnabled(buffer.readBoolean()); - packet.setTexturePacksRequired(buffer.readBoolean()); - BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); - packet.setBonusChestEnabled(buffer.readBoolean()); - packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); - packet.setServerChunkTickRange(buffer.readIntLE()); - packet.setBehaviorPackLocked(buffer.readBoolean()); - packet.setResourcePackLocked(buffer.readBoolean()); - packet.setFromLockedWorldTemplate(buffer.readBoolean()); - packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); - packet.setFromWorldTemplate(buffer.readBoolean()); - packet.setWorldTemplateOptionLocked(buffer.readBoolean()); - packet.setOnlySpawningV1Villagers(buffer.readBoolean()); - // Level settings end - packet.setLevelId(BedrockUtils.readString(buffer)); - packet.setWorldName(BedrockUtils.readString(buffer)); - packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); - packet.setTrial(buffer.readBoolean()); - packet.setCurrentTick(buffer.readLongLE()); - packet.setEnchantmentSeed(VarInts.readInt(buffer)); - - int paletteLength = VarInts.readUnsignedInt(buffer); - List palette = new ObjectArrayList<>(paletteLength); - for (int i = 0; i < paletteLength; i++) { - palette.add(CompoundTagBuilder.builder() - .tag(CompoundTagBuilder.builder() - .stringTag("name", BedrockUtils.readString(buffer)) - .build("block")) - .shortTag("meta", buffer.readShortLE()) - .shortTag("id", buffer.readShortLE()) - .buildRootTag()); - } - packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); - - BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> { - String identifier = BedrockUtils.readString(buf); - short id = buf.readShortLE(); - return new StartGamePacket.ItemEntry(identifier, id); - }); - - packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java deleted file mode 100644 index e38727add..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StopSoundSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.StopSoundPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StopSoundSerializer_v363 implements PacketSerializer { - public static final StopSoundSerializer_v363 INSTANCE = new StopSoundSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, StopSoundPacket packet) { - BedrockUtils.writeString(buffer, packet.getSoundName()); - buffer.writeBoolean(packet.isStoppingAllSound()); - } - - @Override - public void deserialize(ByteBuf buffer, StopSoundPacket packet) { - packet.setSoundName(BedrockUtils.readString(buffer)); - packet.setStoppingAllSound(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java deleted file mode 100644 index db3e71822..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureBlockUpdateSerializer_v363.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.StructureBlockUpdatePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StructureBlockUpdateSerializer_v363 implements PacketSerializer { - public static final StructureBlockUpdateSerializer_v363 INSTANCE = new StructureBlockUpdateSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, StructureBlockUpdatePacket packet) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - BedrockUtils.writeStructureEditorData(buffer, packet.getEditorData()); - buffer.writeBoolean(packet.isPowered()); - } - - @Override - public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setEditorData(BedrockUtils.readStructureEditorData(buffer)); - packet.setPowered(buffer.readBoolean()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java deleted file mode 100644 index 86f54836b..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportRequestSerializer_v363.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.StructureTemplateDataExportRequestPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StructureTemplateDataExportRequestSerializer_v363 implements PacketSerializer { - public static final StructureTemplateDataExportRequestSerializer_v363 INSTANCE = new StructureTemplateDataExportRequestSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, StructureTemplateDataExportRequestPacket packet) { - BedrockUtils.writeString(buffer, packet.getName()); - BedrockUtils.writeBlockPosition(buffer, packet.getPosition()); - BedrockUtils.writeStructureSettings(buffer, packet.getSettings()); - buffer.writeByte(packet.getOperation()); - } - - @Override - public void deserialize(ByteBuf buffer, StructureTemplateDataExportRequestPacket packet) { - packet.setName(BedrockUtils.readString(buffer)); - packet.setPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setSettings(BedrockUtils.readStructureSettings(buffer)); - packet.setOperation(buffer.readByte()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java deleted file mode 100644 index 75a96a082..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StructureTemplateDataExportResponseSerializer_v363.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.nbt.tag.Tag; -import com.nukkitx.protocol.bedrock.packet.StructureTemplateDataExportResponsePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StructureTemplateDataExportResponseSerializer_v363 implements PacketSerializer { - public static final StructureTemplateDataExportResponseSerializer_v363 INSTANCE = new StructureTemplateDataExportResponseSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { - BedrockUtils.writeString(buffer, packet.getName()); - boolean save = packet.isSave(); - buffer.writeBoolean(save); - - if (save) { - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - @Override - public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { - packet.setName(BedrockUtils.readString(buffer)); - - boolean save = buffer.readBoolean(); - packet.setSave(save); - - if (save) { - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - Tag tag = reader.readTag(); - if (tag instanceof CompoundTag) { - packet.setTag((CompoundTag) tag); - } else { - throw new IllegalArgumentException("Tag received was not a CompoundTag"); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java deleted file mode 100644 index 697a08bec..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/SubClientLoginSerializer_v363.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.SubClientLoginPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.util.AsciiString; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class SubClientLoginSerializer_v363 implements PacketSerializer { - public static final SubClientLoginSerializer_v363 INSTANCE = new SubClientLoginSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, SubClientLoginPacket packet) { - AsciiString chainData = packet.getChainData(); - AsciiString skinData = packet.getSkinData(); - VarInts.writeUnsignedInt(buffer, chainData.length() + skinData.length() + 8); - BedrockUtils.writeLEAsciiString(buffer, chainData); - BedrockUtils.writeLEAsciiString(buffer, skinData); - } - - @Override - public void deserialize(ByteBuf buffer, SubClientLoginPacket packet) { - ByteBuf jwt = buffer.readSlice(VarInts.readUnsignedInt(buffer)); - packet.setChainData(BedrockUtils.readLEAsciiString(jwt)); - packet.setSkinData(BedrockUtils.readLEAsciiString(jwt)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java deleted file mode 100644 index 890059453..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TakeItemEntitySerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.TakeItemEntityPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TakeItemEntitySerializer_v363 implements PacketSerializer { - public static final TakeItemEntitySerializer_v363 INSTANCE = new TakeItemEntitySerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, TakeItemEntityPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getItemRuntimeEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - } - - @Override - public void deserialize(ByteBuf buffer, TakeItemEntityPacket packet) { - packet.setItemRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java deleted file mode 100644 index e6f546197..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TextSerializer_v363.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.TextPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TextSerializer_v363 implements PacketSerializer { - public static final TextSerializer_v363 INSTANCE = new TextSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, TextPacket packet) { - TextPacket.Type type = packet.getType(); - buffer.writeByte(type.ordinal()); - buffer.writeBoolean(packet.isNeedsTranslation()); - - switch (type) { - case CHAT: - case WHISPER: - case ANNOUNCEMENT: - BedrockUtils.writeString(buffer, packet.getSourceName()); - case RAW: - case TIP: - case SYSTEM: - BedrockUtils.writeString(buffer, packet.getMessage()); - break; - case TRANSLATION: - case POPUP: - case JUKEBOX_POPUP: - BedrockUtils.writeString(buffer, packet.getMessage()); - BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString); - break; - } - - BedrockUtils.writeString(buffer, packet.getXuid()); - BedrockUtils.writeString(buffer, packet.getPlatformChatId()); - } - - @Override - public void deserialize(ByteBuf buffer, TextPacket packet) { - TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()]; - packet.setType(type); - packet.setNeedsTranslation(buffer.readBoolean()); - switch (type) { - case CHAT: - case WHISPER: - case ANNOUNCEMENT: - packet.setSourceName(BedrockUtils.readString(buffer)); - case RAW: - case TIP: - case SYSTEM: - packet.setMessage(BedrockUtils.readString(buffer)); - break; - case TRANSLATION: - case POPUP: - case JUKEBOX_POPUP: - packet.setMessage(BedrockUtils.readString(buffer)); - BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString); - break; - } - packet.setXuid(BedrockUtils.readString(buffer)); - packet.setPlatformChatId(BedrockUtils.readString(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java deleted file mode 100644 index 39b013c33..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/TransferSerializer_v363.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.TransferPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TransferSerializer_v363 implements PacketSerializer { - public static final TransferSerializer_v363 INSTANCE = new TransferSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, TransferPacket packet) { - BedrockUtils.writeString(buffer, packet.getAddress()); - buffer.writeShortLE(packet.getPort()); - } - - @Override - public void deserialize(ByteBuf buffer, TransferPacket packet) { - packet.setAddress(BedrockUtils.readString(buffer)); - packet.setPort(buffer.readUnsignedShortLE()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java deleted file mode 100644 index 6f2ec10ab..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateAttributesSerializer_v363.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateAttributesSerializer_v363 implements PacketSerializer { - public static final UpdateAttributesSerializer_v363 INSTANCE = new UpdateAttributesSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, UpdateAttributesPacket packet) { - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - BedrockUtils.writeArray(buffer, packet.getAttributes(), BedrockUtils::writePlayerAttribute); - } - - @Override - public void deserialize(ByteBuf buffer, UpdateAttributesPacket packet) { - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - BedrockUtils.readArray(buffer, packet.getAttributes(), BedrockUtils::readPlayerAttribute); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java deleted file mode 100644 index 79a65c611..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockPropertiesSerializer_v363.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.protocol.bedrock.packet.UpdateBlockPropertiesPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateBlockPropertiesSerializer_v363 implements PacketSerializer { - public static final UpdateBlockPropertiesSerializer_v363 INSTANCE = new UpdateBlockPropertiesSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, UpdateBlockPropertiesPacket packet) { - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getProperties()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, UpdateBlockPropertiesPacket packet) { - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setProperties(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java deleted file mode 100644 index 461981a59..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSerializer_v363.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Set; - -import static com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket.Flag; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateBlockSerializer_v363 implements PacketSerializer { - public static final UpdateBlockSerializer_v363 INSTANCE = new UpdateBlockSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, UpdateBlockPacket packet) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeUnsignedInt(buffer, packet.getRuntimeId()); - int flagValue = 0; - for (Flag flag : packet.getFlags()) { - flagValue |= (1 << flag.ordinal()); - } - VarInts.writeUnsignedInt(buffer, flagValue); - VarInts.writeUnsignedInt(buffer, packet.getDataLayer()); - } - - @Override - public void deserialize(ByteBuf buffer, UpdateBlockPacket packet) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setRuntimeId(VarInts.readUnsignedInt(buffer)); - int flagValue = VarInts.readUnsignedInt(buffer); - Set flags = packet.getFlags(); - for (Flag flag : Flag.values()) { - if ((flagValue & (1 << flag.ordinal())) != 0) { - flags.add(flag); - } - } - packet.setDataLayer(VarInts.readUnsignedInt(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java deleted file mode 100644 index 04a78ede2..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateBlockSyncedSerializer_v363.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.UpdateBlockSyncedPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Set; - -import static com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket.Flag; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateBlockSyncedSerializer_v363 implements PacketSerializer { - public static final UpdateBlockSyncedSerializer_v363 INSTANCE = new UpdateBlockSyncedSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, UpdateBlockSyncedPacket packet) { - BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition()); - VarInts.writeUnsignedInt(buffer, packet.getRuntimeId()); - int flagValue = 0; - for (Flag flag : packet.getFlags()) { - flagValue |= (1 << flag.ordinal()); - } - VarInts.writeUnsignedInt(buffer, flagValue); - VarInts.writeUnsignedInt(buffer, packet.getDataLayer()); - VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeUnsignedLong(buffer, packet.getUnknownLong1()); - } - - @Override - public void deserialize(ByteBuf buffer, UpdateBlockSyncedPacket packet) { - packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer)); - packet.setRuntimeId(VarInts.readUnsignedInt(buffer)); - int flagValue = VarInts.readUnsignedInt(buffer); - Set flags = packet.getFlags(); - for (Flag flag : Flag.values()) { - if ((flagValue & (1 << flag.ordinal())) != 0) { - flags.add(flag); - } - } - packet.setDataLayer(VarInts.readUnsignedInt(buffer)); - packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setUnknownLong1(VarInts.readUnsignedLong(buffer)); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java deleted file mode 100644 index 15ce50978..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateEquipSerializer_v363.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateEquipSerializer_v363 implements PacketSerializer { - public static final UpdateEquipSerializer_v363 INSTANCE = new UpdateEquipSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, UpdateEquipPacket packet) { - buffer.writeByte(packet.getWindowId()); - buffer.writeByte(packet.getWindowType()); - VarInts.writeInt(buffer, packet.getUnknown0()); - VarInts.writeLong(buffer, packet.getUniqueEntityId()); - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, UpdateEquipPacket packet) { - packet.setWindowId(buffer.readUnsignedByte()); - packet.setWindowType(buffer.readUnsignedByte()); - packet.setUnknown0(VarInts.readInt(buffer)); - packet.setUniqueEntityId(VarInts.readLong(buffer)); - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setTag(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java deleted file mode 100644 index 4315b1cf2..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateSoftEnumSerializer_v363.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.UpdateSoftEnumPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateSoftEnumSerializer_v363 implements PacketSerializer { - public static final UpdateSoftEnumSerializer_v363 INSTANCE = new UpdateSoftEnumSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, UpdateSoftEnumPacket packet) { - BedrockUtils.writeCommandEnumData(buffer, packet.getSoftEnum()); - buffer.writeByte(packet.getType().ordinal()); - } - - @Override - public void deserialize(ByteBuf buffer, UpdateSoftEnumPacket packet) { - packet.setSoftEnum(BedrockUtils.readCommandEnumData(buffer, true)); - packet.setType(UpdateSoftEnumPacket.Type.values()[buffer.readUnsignedByte()]); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java deleted file mode 100644 index b6d1a1278..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/UpdateTradeSerializer_v363.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.packet.UpdateTradePacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class UpdateTradeSerializer_v363 implements PacketSerializer { - public static final UpdateTradeSerializer_v363 INSTANCE = new UpdateTradeSerializer_v363(); - - - @Override - public void serialize(ByteBuf buffer, UpdateTradePacket packet) { - buffer.writeByte(packet.getWindowId()); - buffer.writeByte(packet.getWindowType()); - VarInts.writeInt(buffer, packet.getUnknownInt()); - VarInts.writeInt(buffer, packet.getTradeTier()); - VarInts.writeLong(buffer, packet.getTraderUniqueEntityId()); - VarInts.writeLong(buffer, packet.getPlayerUniqueEntityId()); - BedrockUtils.writeString(buffer, packet.getDisplayName()); - buffer.writeBoolean(packet.isScreen2()); - buffer.writeBoolean(packet.isWilling()); - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(packet.getOffers()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void deserialize(ByteBuf buffer, UpdateTradePacket packet) { - packet.setWindowId(buffer.readUnsignedByte()); - packet.setWindowType(buffer.readUnsignedByte()); - packet.setUnknownInt(VarInts.readInt(buffer)); - packet.setTradeTier(VarInts.readInt(buffer)); - packet.setWilling(buffer.readBoolean()); - packet.setTraderUniqueEntityId(VarInts.readLong(buffer)); - packet.setPlayerUniqueEntityId(VarInts.readLong(buffer)); - packet.setDisplayName(BedrockUtils.readString(buffer)); - packet.setScreen2(buffer.readBoolean()); - packet.setWilling(buffer.readBoolean()); - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - packet.setOffers(reader.readTag()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java deleted file mode 100644 index b88085e0c..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/VideoStreamConnectSerializer_v363.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.packet.VideoStreamConnectPacket; -import com.nukkitx.protocol.bedrock.v363.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import io.netty.buffer.ByteBuf; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class VideoStreamConnectSerializer_v363 implements PacketSerializer { - public static final VideoStreamConnectSerializer_v363 INSTANCE = new VideoStreamConnectSerializer_v363(); - - @Override - public void serialize(ByteBuf buffer, VideoStreamConnectPacket packet) { - BedrockUtils.writeString(buffer, packet.getAddress()); - buffer.writeFloatLE(packet.getScreenshotFrequency()); - buffer.writeByte(packet.getAction().ordinal()); - buffer.writeIntLE(packet.getWidth()); - buffer.writeIntLE(packet.getHeight()); - } - - @Override - public void deserialize(ByteBuf buffer, VideoStreamConnectPacket packet) { - packet.setAddress(BedrockUtils.readString(buffer)); - packet.setScreenshotFrequency(buffer.readFloatLE()); - packet.setAction(VideoStreamConnectPacket.Action.values()[buffer.readUnsignedByte()]); - packet.setWidth(buffer.readIntLE()); - packet.setHeight(buffer.readIntLE()); - } -} From 3d77ab7cfd43811e90200b4dfd55cb81d89545e0 Mon Sep 17 00:00:00 2001 From: Brendan Grieve Date: Mon, 11 May 2020 15:22:13 +0800 Subject: [PATCH 03/70] Implement bedrock-v363 StartGamePacket --- .../protocol/bedrock/v363/Bedrock_v363.java | 3 +- .../serializer/StartGameSerializer_v363.java | 178 ++++++++++++++++++ 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index 482e9fce0..abb65a02b 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; +import com.nukkitx.protocol.bedrock.v363.serializer.StartGameSerializer_v363; import lombok.experimental.UtilityClass; @UtilityClass @@ -21,7 +22,7 @@ public class Bedrock_v363 { .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v361.INSTANCE, 8) .registerPacket(TextPacket.class, TextSerializer_v361.INSTANCE, 9) .registerPacket(SetTimePacket.class, SetTimeSerializer_v361.INSTANCE, 10) - .registerPacket(StartGamePacket.class, StartGameSerializer_v361.INSTANCE, 11) + .registerPacket(StartGamePacket.class, StartGameSerializer_v363.INSTANCE, 11) .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v361.INSTANCE, 12) .registerPacket(AddEntityPacket.class, AddEntitySerializer_v361.INSTANCE, 13) .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v361.INSTANCE, 14) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java new file mode 100644 index 000000000..f6374dd63 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -0,0 +1,178 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.nbt.CompoundTagBuilder; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.nbt.tag.ListTag; +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.GamePublishSetting; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.packet.StartGamePacket; +import com.nukkitx.protocol.bedrock.v361.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class StartGameSerializer_v363 implements PacketSerializer { + public static final StartGameSerializer_v363 INSTANCE = new StartGameSerializer_v363(); + + private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); + + @Override + public void serialize(ByteBuf buffer, StartGamePacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); + VarInts.writeInt(buffer, packet.getPlayerGamemode()); + BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); + BedrockUtils.writeVector2f(buffer, packet.getRotation()); + // Level settings start + VarInts.writeInt(buffer, packet.getSeed()); + VarInts.writeInt(buffer, packet.getDimensionId()); + VarInts.writeInt(buffer, packet.getGeneratorId()); + VarInts.writeInt(buffer, packet.getLevelGamemode()); + VarInts.writeInt(buffer, packet.getDifficulty()); + BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); + buffer.writeBoolean(packet.isAchievementsDisabled()); + VarInts.writeInt(buffer, packet.getTime()); + buffer.writeBoolean(packet.getEduEditionOffers() != 0); + buffer.writeBoolean(packet.isEduFeaturesEnabled()); + buffer.writeFloatLE(packet.getRainLevel()); + buffer.writeFloatLE(packet.getLightningLevel()); + + // Unknown + buffer.writeByte(0); + + buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); + buffer.writeBoolean(packet.isMultiplayerGame()); + buffer.writeBoolean(packet.isBroadcastingToLan()); + VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); + VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); + buffer.writeBoolean(packet.isCommandsEnabled()); + buffer.writeBoolean(packet.isTexturePacksRequired()); + BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); + buffer.writeBoolean(packet.isBonusChestEnabled()); + buffer.writeBoolean(packet.isStartingWithMap()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + buffer.writeIntLE(packet.getServerChunkTickRange()); + buffer.writeBoolean(packet.isBehaviorPackLocked()); + buffer.writeBoolean(packet.isResourcePackLocked()); + buffer.writeBoolean(packet.isFromLockedWorldTemplate()); + buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); + buffer.writeBoolean(packet.isFromWorldTemplate()); + buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); + buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); + + // Unknown + buffer.writeBytes(new byte[] {0x10, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0}); + + // Level settings end + BedrockUtils.writeString(buffer, packet.getLevelId()); + BedrockUtils.writeString(buffer, packet.getWorldName()); + BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); + buffer.writeBoolean(packet.isTrial()); + buffer.writeLongLE(packet.getCurrentTick()); + VarInts.writeInt(buffer, packet.getEnchantmentSeed()); + + List palette = packet.getBlockPalette().getValue(); + VarInts.writeUnsignedInt(buffer, palette.size()); + for (CompoundTag entry : palette) { + CompoundTag blockTag = entry.getCompound("block"); + BedrockUtils.writeString(buffer, blockTag.getString("name")); + buffer.writeShortLE(entry.getShort("meta")); + buffer.writeShortLE(entry.getShort("id")); + } + + BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { + BedrockUtils.writeString(buf, entry.getIdentifier()); + buf.writeShortLE(entry.getId()); + }); + + BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); + + } + + @Override + public void deserialize(ByteBuf buffer, StartGamePacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); + + packet.setPlayerGamemode(VarInts.readInt(buffer)); + packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); + packet.setRotation(BedrockUtils.readVector2f(buffer)); + + // Level settings start + packet.setSeed(VarInts.readInt(buffer)); + packet.setDimensionId(VarInts.readInt(buffer)); + packet.setGeneratorId(VarInts.readInt(buffer)); + packet.setLevelGamemode(VarInts.readInt(buffer)); + packet.setDifficulty(VarInts.readInt(buffer)); + packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); + packet.setAchievementsDisabled(buffer.readBoolean()); + packet.setTime(VarInts.readInt(buffer)); + packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); + packet.setEduFeaturesEnabled(buffer.readBoolean()); + packet.setRainLevel(buffer.readFloatLE()); + packet.setLightningLevel(buffer.readFloatLE()); + + // unknown: Mine: 0x0 + buffer.readBoolean(); + + packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); + packet.setMultiplayerGame(buffer.readBoolean()); + packet.setBroadcastingToLan(buffer.readBoolean()); + packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); + packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); + packet.setCommandsEnabled(buffer.readBoolean()); + packet.setTexturePacksRequired(buffer.readBoolean()); + + BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); + packet.setBonusChestEnabled(buffer.readBoolean()); + packet.setStartingWithMap(buffer.readBoolean()); + packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + packet.setServerChunkTickRange(buffer.readIntLE()); + + packet.setBehaviorPackLocked(buffer.readBoolean()); + packet.setResourcePackLocked(buffer.readBoolean()); + packet.setFromLockedWorldTemplate(buffer.readBoolean()); + packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); + packet.setFromWorldTemplate(buffer.readBoolean()); + packet.setWorldTemplateOptionLocked(buffer.readBoolean()); + packet.setOnlySpawningV1Villagers(buffer.readBoolean()); + + // Unknown: Mine: 0x10 0x0 0x0 0x0 0x10 0x0 0x0 0x0 + buffer.readLong(); + + // Level settings end + packet.setLevelId(BedrockUtils.readString(buffer)); + packet.setWorldName(BedrockUtils.readString(buffer)); + packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); + packet.setTrial(buffer.readBoolean()); + packet.setCurrentTick(buffer.readLongLE()); + packet.setEnchantmentSeed(VarInts.readInt(buffer)); + + int paletteLength = VarInts.readUnsignedInt(buffer); + List palette = new ObjectArrayList<>(paletteLength); + for (int i = 0; i < paletteLength; i++) { + palette.add(CompoundTagBuilder.builder() + .tag(CompoundTagBuilder.builder() + .stringTag("name", BedrockUtils.readString(buffer)) + .build("block")) + .shortTag("meta", buffer.readShortLE()) + .shortTag("id", buffer.readShortLE()) + .buildRootTag()); + } + packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); + + BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> { + String identifier = BedrockUtils.readString(buf); + short id = buf.readShortLE(); + return new StartGamePacket.ItemEntry(identifier, id); + }); + + packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); + } +} From 154aae1e0be9d21cce98558a0323bdd96a977ede Mon Sep 17 00:00:00 2001 From: Brendan Grieve Date: Mon, 11 May 2020 17:55:57 +0800 Subject: [PATCH 04/70] Implement bedrock-v363 PlayerListSerializer Mostly similar to v361 except it has 2 booleans per entry which corresponds to teacher/host flags. --- .../protocol/bedrock/v363/Bedrock_v363.java | 3 +- .../serializer/PlayerListSerializer_v363.java | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index abb65a02b..5a832994c 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; +import com.nukkitx.protocol.bedrock.v363.serializer.PlayerListSerializer_v363; import com.nukkitx.protocol.bedrock.v363.serializer.StartGameSerializer_v363; import lombok.experimental.UtilityClass; @@ -73,7 +74,7 @@ public class Bedrock_v363 { .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v361.INSTANCE, 60) .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v361.INSTANCE, 61) .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v361.INSTANCE, 62) - .registerPacket(PlayerListPacket.class, PlayerListSerializer_v361.INSTANCE, 63) + .registerPacket(PlayerListPacket.class, PlayerListSerializer_v363.INSTANCE, 63) .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v361.INSTANCE, 64) .registerPacket(EventPacket.class, EventSerializer_v361.INSTANCE, 65) .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v361.INSTANCE, 66) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java new file mode 100644 index 000000000..8064e1860 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java @@ -0,0 +1,75 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.ImageData; +import com.nukkitx.protocol.bedrock.data.SerializedSkin; +import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; +import com.nukkitx.protocol.bedrock.v361.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Action; +import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Entry; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlayerListSerializer_v363 implements PacketSerializer { + public static final PlayerListSerializer_v363 INSTANCE = new PlayerListSerializer_v363(); + + + @Override + public void serialize(ByteBuf buffer, PlayerListPacket packet) { + buffer.writeByte(packet.getAction().ordinal()); + VarInts.writeUnsignedInt(buffer, packet.getEntries().size()); + + for (Entry entry : packet.getEntries()) { + BedrockUtils.writeUuid(buffer, entry.getUuid()); + + if (packet.getAction() == Action.ADD) { + VarInts.writeLong(buffer, entry.getEntityId()); + BedrockUtils.writeString(buffer, entry.getName()); + SerializedSkin skin = entry.getSkin(); + BedrockUtils.writeString(buffer, skin.getSkinId()); + skin.getSkinData().checkLegacySkinSize(); + BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); + skin.getCapeData().checkLegacyCapeSize(); + BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); + BedrockUtils.writeString(buffer, skin.getGeometryName()); + BedrockUtils.writeString(buffer, skin.getGeometryData()); + BedrockUtils.writeString(buffer, entry.getXuid()); + BedrockUtils.writeString(buffer, entry.getPlatformChatId()); + buffer.writeBoolean(entry.isTeacher()); + buffer.writeBoolean(entry.isHost()); + } + } + } + + @Override + public void deserialize(ByteBuf buffer, PlayerListPacket packet) { + Action action = Action.values()[buffer.readUnsignedByte()]; + packet.setAction(action); + int length = VarInts.readUnsignedInt(buffer); + + for (int i = 0; i < length; i++) { + Entry entry = new Entry(BedrockUtils.readUuid(buffer)); + + if (action == Action.ADD) { + entry.setEntityId(VarInts.readLong(buffer)); + entry.setName(BedrockUtils.readString(buffer)); + String skinId = BedrockUtils.readString(buffer); + ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); + ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); + String geometryName = BedrockUtils.readString(buffer); + String geometryData = BedrockUtils.readString(buffer); + entry.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, false)); + entry.setXuid(BedrockUtils.readString(buffer)); + entry.setPlatformChatId(BedrockUtils.readString(buffer)); + + entry.setTeacher(buffer.readBoolean()); + entry.setHost(buffer.readBoolean()); + } + packet.getEntries().add(entry); + } + } +} From 574e924dd81968b9df38bfd6e48249659c1d71d6 Mon Sep 17 00:00:00 2001 From: Brendan Grieve Date: Mon, 11 May 2020 19:09:57 +0800 Subject: [PATCH 05/70] Add Additional Command flag (UNKNOWN_7) --- .../java/com/nukkitx/protocol/bedrock/data/CommandData.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/CommandData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/CommandData.java index 97597787c..f1e603d65 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/CommandData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/CommandData.java @@ -56,6 +56,7 @@ public enum Flag { EXECUTE, TYPE, CHEAT, - UNKNOWN_6 + UNKNOWN_6, + UNKNOWN_7 } } From 581113d62ff9d24a927270fbb960eadd973ed1f7 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Tue, 12 May 2020 16:53:25 +0800 Subject: [PATCH 06/70] Update Version to 2.5.7-SNAPSHOT --- bedrock/bedrock-common/pom.xml | 2 +- bedrock/bedrock-v291/pom.xml | 2 +- bedrock/bedrock-v313/pom.xml | 2 +- bedrock/bedrock-v332/pom.xml | 2 +- bedrock/bedrock-v340/pom.xml | 2 +- bedrock/bedrock-v354/pom.xml | 2 +- bedrock/bedrock-v361/pom.xml | 2 +- bedrock/bedrock-v363/pom.xml | 2 +- bedrock/bedrock-v388/pom.xml | 2 +- bedrock/bedrock-v389/pom.xml | 2 +- bedrock/bedrock-v390/pom.xml | 2 +- bedrock/pom.xml | 2 +- common/pom.xml | 2 +- pom.xml | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bedrock/bedrock-common/pom.xml b/bedrock/bedrock-common/pom.xml index 78d295f60..4234fb3e4 100644 --- a/bedrock/bedrock-common/pom.xml +++ b/bedrock/bedrock-common/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v291/pom.xml b/bedrock/bedrock-v291/pom.xml index d6553469f..7a8de902e 100644 --- a/bedrock/bedrock-v291/pom.xml +++ b/bedrock/bedrock-v291/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v313/pom.xml b/bedrock/bedrock-v313/pom.xml index 7d3c6dc76..fe80d4cf0 100644 --- a/bedrock/bedrock-v313/pom.xml +++ b/bedrock/bedrock-v313/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v332/pom.xml b/bedrock/bedrock-v332/pom.xml index cba917249..7a08e2c86 100644 --- a/bedrock/bedrock-v332/pom.xml +++ b/bedrock/bedrock-v332/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v340/pom.xml b/bedrock/bedrock-v340/pom.xml index f58946c46..f7c9cd079 100644 --- a/bedrock/bedrock-v340/pom.xml +++ b/bedrock/bedrock-v340/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v354/pom.xml b/bedrock/bedrock-v354/pom.xml index 9def57094..b6be3950e 100644 --- a/bedrock/bedrock-v354/pom.xml +++ b/bedrock/bedrock-v354/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v361/pom.xml b/bedrock/bedrock-v361/pom.xml index 64bbf90b5..54327a49e 100644 --- a/bedrock/bedrock-v361/pom.xml +++ b/bedrock/bedrock-v361/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v363/pom.xml b/bedrock/bedrock-v363/pom.xml index 330820393..9881a1dde 100644 --- a/bedrock/bedrock-v363/pom.xml +++ b/bedrock/bedrock-v363/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6 + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v388/pom.xml b/bedrock/bedrock-v388/pom.xml index 487c71298..3bdc3f8ce 100644 --- a/bedrock/bedrock-v388/pom.xml +++ b/bedrock/bedrock-v388/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v389/pom.xml b/bedrock/bedrock-v389/pom.xml index 18c9476f8..5c9627958 100644 --- a/bedrock/bedrock-v389/pom.xml +++ b/bedrock/bedrock-v389/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/bedrock-v390/pom.xml b/bedrock/bedrock-v390/pom.xml index 5acded096..94d60969a 100644 --- a/bedrock/bedrock-v390/pom.xml +++ b/bedrock/bedrock-v390/pom.xml @@ -5,7 +5,7 @@ bedrock-parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/bedrock/pom.xml b/bedrock/pom.xml index 1d08dda76..8259bea75 100644 --- a/bedrock/pom.xml +++ b/bedrock/pom.xml @@ -9,7 +9,7 @@ parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT diff --git a/common/pom.xml b/common/pom.xml index 39e59a824..cd38b78bf 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ parent com.nukkitx.protocol - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index fcad8edd5..6dfc8b515 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.nukkitx.protocol parent pom - 2.5.6-SNAPSHOT + 2.5.7-SNAPSHOT Protocol Parent A protocol library for Minecraft https://github.com/NukkitX/Protocol From 1135b9c441f3ffb20e99ba821f1145d127a86521 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 18 Jun 2020 07:28:06 +0800 Subject: [PATCH 07/70] Misc Fixes Changes: * Fix a bug in AvailableCommandsSerializer which uses incorret bitwise operations * Added Metadata recorded * Update StartGamePacket EduOffers to not lose data --- .../protocol/bedrock/data/EntityData.java | 10 +- .../protocol/bedrock/data/EntityFlag.java | 5 +- .../protocol/bedrock/v363/BedrockUtils.java | 8 + .../protocol/bedrock/v363/Bedrock_v363.java | 3 +- .../AvailableCommandsSerializer_v363.java | 300 ++++++++++++++++++ .../serializer/StartGameSerializer_v363.java | 4 +- 6 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityData.java index d917ea553..b414d98ec 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityData.java @@ -104,7 +104,15 @@ public enum EntityData { INTERACTIVE_TAG(Type.STRING), TRADE_TIER(Type.INT), MAX_TRADE_TIER(Type.INT), - TRADE_XP(Type.INT); + TRADE_XP(Type.INT), + + // Unknown but seen + UNKNOWN_105(Type.INT), + UNKNOWN_106(Type.BYTE), + UNKNOWN_107(Type.FLOAT), + UNKNOWN_108(Type.FLOAT), + UNKNOWN_109(Type.STRING); + private final Type type; private final boolean flags; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityFlag.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityFlag.java index 65ff2d87a..deadc2903 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityFlag.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/EntityFlag.java @@ -85,5 +85,8 @@ public enum EntityFlag { STUNNED, ROARING, DELAYED_ATTACKING, - AVOIDING_MOBS + AVOIDING_MOBS, + + // Unknowns but seen + UNKNOWN_87 } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java index 7e65ebd27..cca12a095 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java @@ -90,6 +90,7 @@ public final class BedrockUtils { METADATAS.put(49, WITHER_TARGET_1); METADATAS.put(50, WITHER_TARGET_2); METADATAS.put(51, WITHER_TARGET_3); + METADATAS.put(52, WITHER_AERIAL_ATTACK); METADATAS.put(53, BOUNDING_BOX_WIDTH); METADATAS.put(54, BOUNDING_BOX_HEIGHT); @@ -142,6 +143,12 @@ public final class BedrockUtils { METADATAS.put(102, TRADE_XP); METADATAS.put(103, SKIN_ID); + METADATAS.put(105, UNKNOWN_105); + METADATAS.put(106, UNKNOWN_106); + METADATAS.put(107, UNKNOWN_107); + METADATAS.put(108, UNKNOWN_108); + METADATAS.put(109, UNKNOWN_109); + METADATA_FLAGS.put(0, EntityFlag.ON_FIRE); METADATA_FLAGS.put(1, EntityFlag.SNEAKING); @@ -215,6 +222,7 @@ public final class BedrockUtils { METADATA_FLAGS.put(70, EntityFlag.FALL_THROUGH_SCAFFOLDING); METADATA_FLAGS.put(71, EntityFlag.BLOCKING); METADATA_FLAGS.put(72, EntityFlag.DISABLE_BLOCKING); + METADATA_FLAGS.put(87, EntityFlag.UNKNOWN_87); METADATA_FLAGS.put(75, EntityFlag.SLEEPING); diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index 5a832994c..8e4c8810d 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; +import com.nukkitx.protocol.bedrock.v363.serializer.AvailableCommandsSerializer_v363; import com.nukkitx.protocol.bedrock.v363.serializer.PlayerListSerializer_v363; import com.nukkitx.protocol.bedrock.v363.serializer.StartGameSerializer_v363; import lombok.experimental.UtilityClass; @@ -87,7 +88,7 @@ public class Bedrock_v363 { .registerPacket(CameraPacket.class, CameraSerializer_v361.INSTANCE, 73) .registerPacket(BossEventPacket.class, BossEventSerializer_v361.INSTANCE, 74) .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v361.INSTANCE, 75) - .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v361.INSTANCE, 76) + .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v363.INSTANCE, 76) .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v361.INSTANCE, 77) .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v361.INSTANCE, 78) .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v361.INSTANCE, 79) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java new file mode 100644 index 000000000..9edf8a2e1 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java @@ -0,0 +1,300 @@ +package com.nukkitx.protocol.bedrock.v363.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.CommandData; +import com.nukkitx.protocol.bedrock.data.CommandEnumData; +import com.nukkitx.protocol.bedrock.data.CommandParamData; +import com.nukkitx.protocol.bedrock.data.CommandParamType; +import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; +import com.nukkitx.protocol.bedrock.v361.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.util.Int2ObjectBiMap; +import io.netty.buffer.ByteBuf; +import io.netty.util.internal.logging.InternalLogger; +import io.netty.util.internal.logging.InternalLoggerFactory; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.ObjIntConsumer; +import java.util.function.ToIntFunction; + +import static com.nukkitx.protocol.bedrock.data.CommandParamData.Type.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AvailableCommandsSerializer_v363 implements PacketSerializer { + private static final InternalLogger log = InternalLoggerFactory.getInstance(AvailableCommandsSerializer_v363.class); + public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); + private static final ObjIntConsumer WRITE_BYTE = ByteBuf::writeByte; + private static final ObjIntConsumer WRITE_SHORT = ByteBuf::writeShortLE; + private static final ObjIntConsumer WRITE_INT = ByteBuf::writeIntLE; + private static final ToIntFunction READ_BYTE = ByteBuf::readUnsignedByte; + private static final ToIntFunction READ_SHORT = ByteBuf::readUnsignedShortLE; + private static final ToIntFunction READ_INT = ByteBuf::readIntLE; + private static final Int2ObjectBiMap PARAM_TYPES = new Int2ObjectBiMap<>(); + + static { + PARAM_TYPES.put(1, INT); + PARAM_TYPES.put(2, FLOAT); + PARAM_TYPES.put(3, VALUE); + PARAM_TYPES.put(4, WILDCARD_INT); + PARAM_TYPES.put(5, OPERATOR); + PARAM_TYPES.put(6, TARGET); + PARAM_TYPES.put(7, WILDCARD_TARGET); + PARAM_TYPES.put(14, FILE_PATH); + PARAM_TYPES.put(18, INT_RANGE); + PARAM_TYPES.put(27, STRING); + PARAM_TYPES.put(29, POSITION); + PARAM_TYPES.put(32, MESSAGE); + PARAM_TYPES.put(34, TEXT); + PARAM_TYPES.put(37, JSON); + PARAM_TYPES.put(44, COMMAND); + } + + @Override + public void serialize(ByteBuf buffer, AvailableCommandsPacket packet) { + Set enumValuesSet = new ObjectOpenHashSet<>(); + Set postfixSet = new ObjectOpenHashSet<>(); + Set enumsSet = new ObjectOpenHashSet<>(); + Set softEnumsSet = new ObjectOpenHashSet<>(); + + // Get all enum values + for (CommandData data : packet.getCommands()) { + if (data.getAliases() != null) { + Collections.addAll(enumValuesSet, data.getAliases().getValues()); + enumsSet.add(data.getAliases()); + } + + for (CommandParamData[] overload : data.getOverloads()) { + for (CommandParamData parameter : overload) { + CommandEnumData commandEnumData = parameter.getEnumData(); + if (commandEnumData != null) { + if (commandEnumData.isSoft()) { + softEnumsSet.add(commandEnumData); + } else { + Collections.addAll(enumValuesSet, commandEnumData.getValues()); + enumsSet.add(commandEnumData); + } + } + + String postfix = parameter.getPostfix(); + if (postfix != null) { + postfixSet.add(postfix); + } + } + } + } + + List enumValues = new ObjectArrayList<>(enumValuesSet); + List postFixes = new ObjectArrayList<>(postfixSet); + List enums = new ObjectArrayList<>(enumsSet); + List softEnums = new ObjectArrayList<>(softEnumsSet); + + // Determine width of enum index + ObjIntConsumer indexWriter; + int valuesSize = enumValues.size(); + if (valuesSize < 0x100) { + indexWriter = WRITE_BYTE; + } else if (valuesSize < 0x10000) { + indexWriter = WRITE_SHORT; + } else { + indexWriter = WRITE_INT; + } + + BedrockUtils.writeArray(buffer, enumValues, BedrockUtils::writeString); + BedrockUtils.writeArray(buffer, postFixes, BedrockUtils::writeString); + + // Write enums + BedrockUtils.writeArray(buffer, enums, (buf, commandEnum) -> { + BedrockUtils.writeString(buf, commandEnum.getName()); + + VarInts.writeUnsignedInt(buffer, commandEnum.getValues().length); + for (String value : commandEnum.getValues()) { + int index = enumValues.indexOf(value); + Preconditions.checkArgument(index > -1, "Invalid enum value detected"); + indexWriter.accept(buf, index); + } + }); + + // Write command data + BedrockUtils.writeArray(buffer, packet.getCommands(), (buf, commandData) -> { + BedrockUtils.writeString(buf, commandData.getName()); + BedrockUtils.writeString(buf, commandData.getDescription()); + byte flags = 0; + if (commandData.getFlags() != null) { + for (CommandData.Flag flag : commandData.getFlags()) { + flags |= 1 << flag.ordinal(); + } + } + buf.writeByte(flags); + buf.writeByte(commandData.getPermission()); + + CommandEnumData aliases = commandData.getAliases(); + buf.writeIntLE(enums.indexOf(aliases)); + + CommandParamData[][] overloads = commandData.getOverloads(); + VarInts.writeUnsignedInt(buf, overloads.length); + for (CommandParamData[] overload : overloads) { + VarInts.writeUnsignedInt(buf, overload.length); + for (CommandParamData param : overload) { + BedrockUtils.writeString(buf, param.getName()); + + int index; + boolean postfix = false; + boolean enumData = false; + boolean softEnum = false; + if (param.getPostfix() != null) { + postfix = true; + index = postFixes.indexOf(param.getPostfix()); + } else if (param.getEnumData() != null) { + if (param.getEnumData().isSoft()) { + softEnum = true; + index = softEnums.indexOf(param.getEnumData()); + } else { + enumData = true; + index = enums.indexOf(param.getEnumData()); + } + } else if (param.getType() != null) { + index = PARAM_TYPES.get(param.getType()); + } else { + throw new IllegalStateException("No param type specified"); + } + + CommandParamType type = new CommandParamType(index, enumData, softEnum, postfix); + + buf.writeIntLE(type.serialize()); + buf.writeBoolean(param.isOptional()); + byte options = 0; + if (param.getOptions() != null) { + for (CommandParamData.Option opt : param.getOptions()) { + options |= 1 << opt.ordinal(); + } + } + buf.writeByte(options); + } + } + }); + + BedrockUtils.writeArray(buffer, softEnums, BedrockUtils::writeCommandEnumData); + } + + @Override + public void deserialize(ByteBuf buffer, AvailableCommandsPacket packet) { + List enumValues = new ObjectArrayList<>(); + List postFixes = new ObjectArrayList<>(); + List enums = new ObjectArrayList<>(); + List commands = new ObjectArrayList<>(); + List softEnums = new ObjectArrayList<>(); + + BedrockUtils.readArray(buffer, enumValues, BedrockUtils::readString); + BedrockUtils.readArray(buffer, postFixes, BedrockUtils::readString); + + // Determine width of enum index + ToIntFunction indexReader; + int valuesSize = enumValues.size(); + if (valuesSize < 0x100) { + indexReader = READ_BYTE; + } else if (valuesSize < 0x10000) { + indexReader = READ_SHORT; + } else { + indexReader = READ_INT; + } + + BedrockUtils.readArray(buffer, enums, buf -> { + String name = BedrockUtils.readString(buf); + + int length = VarInts.readUnsignedInt(buffer); + String[] values = new String[length]; + for (int i = 0; i < length; i++) { + values[i] = enumValues.get(indexReader.applyAsInt(buf)); + } + return new CommandEnumData(name, values, false); + }); + + BedrockUtils.readArray(buffer, commands, buf -> { + String name = BedrockUtils.readString(buf); + String description = BedrockUtils.readString(buf); + byte flags = buf.readByte(); + byte permissions = buf.readByte(); + int aliasesIndex = buf.readIntLE(); + + CommandParamData.Builder[][] overloads = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)][]; + for (int i = 0; i < overloads.length; i++) { + overloads[i] = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)]; + for (int i2 = 0; i2 < overloads[i].length; i2++) { + String parameterName = BedrockUtils.readString(buf); + + CommandParamType type = CommandParamType.deserialize(buf.readIntLE()); + + boolean optional = buf.readBoolean(); + byte unknownByte = buf.readByte(); + + overloads[i][i2] = new CommandParamData.Builder(parameterName, type, optional, unknownByte); + } + } + return new CommandData.Builder(name, description, flags, permissions, aliasesIndex, overloads); + }); + + BedrockUtils.readArray(buffer, softEnums, buf -> BedrockUtils.readCommandEnumData(buffer, true)); + + // Generate command data + + for (CommandData.Builder command : commands) { + byte flagsByte = command.getFlags(); + List flags = new ObjectArrayList<>(); + + for (int i = 0; i < 8; i++) { + if (((flagsByte >>> i) & 0x1) != 0) { + flags.add(CommandData.Flag.values()[i]); + } + } + int aliasesIndex = command.getAliases(); + CommandEnumData aliases = aliasesIndex == -1 ? null : enums.get(aliasesIndex); + + CommandParamData.Builder[][] overloadBuilders = command.getOverloads(); + CommandParamData[][] overloads = new CommandParamData[overloadBuilders.length][]; + for (int i = 0; i < overloadBuilders.length; i++) { + overloads[i] = new CommandParamData[overloadBuilders[i].length]; + for (int i2 = 0; i2 < overloadBuilders[i].length; i2++) { + String name = overloadBuilders[i][i2].getName(); + CommandParamType type = overloadBuilders[i][i2].getType(); + boolean optional = overloadBuilders[i][i2].isOptional(); + byte optionsByte = overloadBuilders[i][i2].getOptions(); + List options = new ObjectArrayList<>(); + for (int oi = 0; oi < 8; oi++) { + if (((optionsByte >>> oi) & 0xf) != 0) { + options.add(CommandParamData.Option.values()[oi]); + } + } + + String postfix = null; + CommandEnumData enumData = null; + CommandParamData.Type paramType = null; + if (type.isPostfix()) { + postfix = postFixes.get(type.getValue()); + } else { + if (type.isCommandEnum()) { + enumData = enums.get(type.getValue()); + } else if (type.isSoftEnum()) { + enumData = softEnums.get(type.getValue()); + } else { + paramType = PARAM_TYPES.get(type.getValue()); + if (paramType == null) { + log.debug("Unknown parameter type {} from {} in {}", type.getValue(), name, command.getName()); + } + } + } + overloads[i][i2] = new CommandParamData(name, optional, enumData, paramType, postfix, options); + } + } + + packet.getCommands().add(new CommandData(command.getName(), command.getDescription(), + flags, command.getPermission(), aliases, overloads)); + } + } +} \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index f6374dd63..612de807a 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -38,7 +38,7 @@ public void serialize(ByteBuf buffer, StartGamePacket packet) { BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); VarInts.writeInt(buffer, packet.getTime()); - buffer.writeBoolean(packet.getEduEditionOffers() != 0); + buffer.writeByte(packet.getEduEditionOffers()); buffer.writeBoolean(packet.isEduFeaturesEnabled()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); @@ -113,7 +113,7 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); - packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); + packet.setEduEditionOffers(buffer.readByte()); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); From 9d1c4313475a7200f85afb21d86e3a762a4c8847 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Wed, 24 Jun 2020 22:13:16 +0800 Subject: [PATCH 08/70] Implement 1.16 fixes to allow a working ProxyPass --- .../protocol/bedrock/BedrockSession.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java index f2b25961e..38deddc9e 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java @@ -17,6 +17,7 @@ import com.nukkitx.protocol.bedrock.wrapper.BedrockWrapperSerializer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.PooledByteBufAllocator; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -131,8 +132,8 @@ public synchronized void sendWrapped(ByteBuf compressed, boolean encrypt) { withTrailer.writeBytes(compressed); withTrailer.writeBytes(trailer); - this.encryptionCipher.cipher(withTrailer.internalNioBuffer(0, withTrailer.writerIndex()), - finalPayload.internalNioBuffer(1, withTrailer.writerIndex())); + this.encryptionCipher.cipher(withTrailer.nioBuffer(), finalPayload.internalNioBuffer(1, withTrailer.readableBytes())); + finalPayload.writerIndex(finalPayload.readerIndex()+withTrailer.readableBytes()+1); } else { finalPayload.writeBytes(compressed); } @@ -205,8 +206,8 @@ private byte[] generateTrailer(ByteBuf buf) { keyBuf.writeBytes(this.agreedKey.getEncoded()); hash.update(counterBuf.internalNioBuffer(0, 8)); - hash.update(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes())); - hash.update(keyBuf.internalNioBuffer(0, keyBuf.readableBytes())); + hash.update(buf.nioBuffer()); + hash.update(keyBuf.nioBuffer()); byte[] digested = hash.digest(); return Arrays.copyOf(digested, 8); } finally { @@ -254,11 +255,11 @@ public void onWrappedPacket(final ByteBuf wrappedData) { try { if (this.isEncrypted()) { // Decryption - batched = ByteBufAllocator.DEFAULT.directBuffer(wrappedData.readableBytes()); - this.decryptionCipher.cipher(wrappedData.internalNioBuffer(wrappedData.readerIndex(), wrappedData.readableBytes()), - batched.internalNioBuffer(0, wrappedData.readableBytes())); + batched = PooledByteBufAllocator.DEFAULT.directBuffer(wrappedData.readableBytes()); + this.decryptionCipher.cipher(wrappedData.nioBuffer(), batched.internalNioBuffer(0, wrappedData.readableBytes())); + // TODO: Maybe verify the checksum? - batched = batched.slice(0, batched.readableBytes() - 8); + batched.writerIndex(wrappedData.readableBytes()+1-8); } else { // Encryption not enabled so it should be readable. batched = wrappedData; From 5364b7c65b4ab08991e087a1cb015fb0c7968319 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Wed, 24 Jun 2020 22:16:59 +0800 Subject: [PATCH 09/70] Change to ByteBufAllocator --- .../main/java/com/nukkitx/protocol/bedrock/BedrockSession.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java index 38deddc9e..e03083f97 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockSession.java @@ -17,7 +17,6 @@ import com.nukkitx.protocol.bedrock.wrapper.BedrockWrapperSerializer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.PooledByteBufAllocator; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -255,7 +254,7 @@ public void onWrappedPacket(final ByteBuf wrappedData) { try { if (this.isEncrypted()) { // Decryption - batched = PooledByteBufAllocator.DEFAULT.directBuffer(wrappedData.readableBytes()); + batched = ByteBufAllocator.DEFAULT.directBuffer(wrappedData.readableBytes()); this.decryptionCipher.cipher(wrappedData.nioBuffer(), batched.internalNioBuffer(0, wrappedData.readableBytes())); // TODO: Maybe verify the checksum? From e14af7b49295a711cfd82b99215dfbcfc9446ec9 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 00:31:28 +0800 Subject: [PATCH 10/70] WIP on startgamepacket --- .../protocol/bedrock/BedrockPacketCodec.java | 43 +++++++++++++++++++ .../protocol/bedrock/v407/Bedrock_v407.java | 2 +- .../serializer/StartGameSerializer_v407.java | 17 +++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index 39fe8f400..cba598320 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -5,6 +5,7 @@ import com.nukkitx.protocol.bedrock.packet.UnknownPacket; import com.nukkitx.protocol.util.Int2ObjectBiMap; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -18,6 +19,10 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; @Immutable @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -51,9 +56,47 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept throw new PacketSerializeException("Packet ID " + id + " does not exist", e); } + ByteBuf dupe = buf.duplicate(); try { + serializer.deserialize(buf, this.helper, packet); } catch (Exception e) { + byte[] dupeBytes = new byte[dupe.readableBytes()]; + dupe.readBytes(dupeBytes); + + System.err.println(packet); + StringBuilder b = new StringBuilder(); + for(int i=0;i= 'a' && c <= 'z') + || (c >= 'A' && c<= 'Z') + || (c >= '0' && c<= '9')) { + b.append((char)dupeBytes[i]); + } else { + b.append("."); + } + b.append(" "); + } + + File debugFile = new File(packet.getClass().getSimpleName() + ".txt"); + try (PrintStream out = new PrintStream(new FileOutputStream(debugFile))) { + out.println(b.toString()); + } catch (FileNotFoundException fileNotFoundException) { + fileNotFoundException.printStackTrace(); + } + + throw new PacketSerializeException("Error whilst deserializing " + packet, e); } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index e0667af4a..dba48d36c 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -30,7 +30,7 @@ public class Bedrock_v407 { .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v291.INSTANCE, 8) .registerPacket(TextPacket.class, TextSerializer_v332.INSTANCE, 9) .registerPacket(SetTimePacket.class, SetTimeSerializer_v291.INSTANCE, 10) - .registerPacket(StartGamePacket.class, StartGameSerializer_v388.INSTANCE, 11) + .registerPacket(StartGamePacket.class, StartGameSerializer_v407.INSTANCE, 11) .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v388.INSTANCE, 12) .registerPacket(AddEntityPacket.class, AddEntitySerializer_v313.INSTANCE, 13) .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v291.INSTANCE, 14) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java index 4effc105c..be56b06bd 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java @@ -106,6 +106,12 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setRotation(helper.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); + + //@Todo + buffer.readByte(); // 0 + buffer.readByte(); // 0 + helper.readString(buffer); // plains + packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGameType(GameType.from(VarInts.readInt(buffer))); @@ -115,9 +121,12 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setDayCycleStopTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(VarInts.readInt(buffer)); packet.setEduFeaturesEnabled(buffer.readBoolean()); - packet.setUnknownString0(helper.readString(buffer)); +// packet.setUnknownString0(helper.readString(buffer)); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); + + buffer.readByte(); // 0 + packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); @@ -140,6 +149,12 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setVanillaVersion(helper.readString(buffer)); packet.setUnknownInt0(buffer.readIntLE()); packet.setUnknownInt1(buffer.readIntLE()); + + // @Todo + buffer.readByte(); // 0 + buffer.readByte(); // 0 + + // Level settings end packet.setLevelId(helper.readString(buffer)); packet.setLevelName(helper.readString(buffer)); From f73481dbc79f0534b678690e2c52d496d75d072b Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 07:42:58 +0800 Subject: [PATCH 11/70] Implement StartGamePacket serializing --- .../serializer/StartGameSerializer_v407.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java index be56b06bd..15acfe5c4 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java @@ -36,6 +36,12 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke helper.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); + + //@Todo + buffer.writeByte(0); + buffer.writeByte(0); + helper.writeString(buffer, "plains"); + VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGameType().ordinal()); @@ -45,9 +51,13 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke VarInts.writeInt(buffer, packet.getDayCycleStopTime()); VarInts.writeInt(buffer, packet.getEduEditionOffers()); buffer.writeBoolean(packet.isEduFeaturesEnabled()); - helper.writeString(buffer, packet.getUnknownString0()); +// helper.writeString(buffer, packet.getUnknownString0()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); + + //@Todo + buffer.writeByte(0); + buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); buffer.writeBoolean(packet.isMultiplayerGame()); buffer.writeBoolean(packet.isBroadcastingToLan()); @@ -71,6 +81,10 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke buffer.writeIntLE(packet.getUnknownInt0()); buffer.writeIntLE(packet.getUnknownInt1()); + // @Todo + buffer.writeByte(0); + buffer.writeByte(0); + // Level settings end helper.writeString(buffer, packet.getLevelId()); helper.writeString(buffer, packet.getLevelName()); @@ -125,6 +139,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); + //@Todo buffer.readByte(); // 0 packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); @@ -154,7 +169,6 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac buffer.readByte(); // 0 buffer.readByte(); // 0 - // Level settings end packet.setLevelId(helper.readString(buffer)); packet.setLevelName(helper.readString(buffer)); From 75042cd9834243430145cd3ca5bbc451e66f94fd Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 09:35:27 +0800 Subject: [PATCH 12/70] Implement readImage,writeImage which solves PlayerListPacket exceptions --- .../v388/BedrockPacketHelper_v388.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java index 7fa463692..27e2fc59c 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java @@ -133,4 +133,23 @@ public void writeSkin(ByteBuf buffer, SerializedSkin skin) { this.writeString(buffer, skin.getCapeId()); this.writeString(buffer, skin.getFullSkinId()); } + + @Override + public ImageData readImage(ByteBuf buffer) { + requireNonNull(buffer, "buffer is null"); + int width = buffer.readIntLE(); + int height = buffer.readIntLE(); + byte[] image = readByteArray(buffer); + return ImageData.of(width, height, image); + } + + @Override + public void writeImage(ByteBuf buffer, ImageData image) { + requireNonNull(buffer, "buffer is null"); + requireNonNull(image, "image is null"); + + buffer.writeIntLE(image.getWidth()); + buffer.writeIntLE(image.getHeight()); + writeByteArray(buffer, image.getImage()); + } } From ec374cdb54b86732305df23dc4e47c9648d8ad4f Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 13:38:05 +0800 Subject: [PATCH 13/70] Implement CraftingDataPacket and all its associated helpers --- .../protocol/bedrock/BedrockPacketCodec.java | 75 +++---- .../protocol/bedrock/BedrockPacketHelper.java | 78 ++++++++ .../data/inventory/ContainerMixData.java | 6 +- .../bedrock/data/inventory/CraftingData.java | 129 +++++++++--- .../bedrock/data/inventory/PotionMixData.java | 17 +- .../bedrock/packet/CraftingDataPacket.java | 2 +- .../CraftingDataSerializer_v388.java | 14 +- .../v407/BedrockPacketHelper_v407.java | 2 + .../protocol/bedrock/v407/Bedrock_v407.java | 2 +- .../CraftingDataSerializer_v407.java | 187 ++++++++++++++++++ 10 files changed, 437 insertions(+), 75 deletions(-) create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CraftingDataSerializer_v407.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index cba598320..e4717da71 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -41,6 +41,43 @@ public static Builder builder() { return new Builder(); } + private void dumpPacket(ByteBuf buf, BedrockPacket packet) { + byte[] dupeBytes = new byte[buf.readableBytes()]; + buf.readBytes(dupeBytes); + + System.err.println(packet); + StringBuilder b = new StringBuilder(); + for(int i=0;i= 'a' && c <= 'z') + || (c >= 'A' && c<= 'Z') + || (c >= '0' && c<= '9')) { + b.append((char)dupeBytes[i]); + } else { + b.append("."); + } + b.append(" "); + } + + File debugFile = new File(packet.getClass().getSimpleName() + ".txt"); + try (PrintStream out = new PrintStream(new FileOutputStream(debugFile))) { + out.println(b.toString()); + } catch (FileNotFoundException fileNotFoundException) { + fileNotFoundException.printStackTrace(); + } + } + public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeException { BedrockPacket packet; BedrockPacketSerializer serializer; @@ -61,46 +98,12 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept serializer.deserialize(buf, this.helper, packet); } catch (Exception e) { - byte[] dupeBytes = new byte[dupe.readableBytes()]; - dupe.readBytes(dupeBytes); - - System.err.println(packet); - StringBuilder b = new StringBuilder(); - for(int i=0;i= 'a' && c <= 'z') - || (c >= 'A' && c<= 'Z') - || (c >= '0' && c<= '9')) { - b.append((char)dupeBytes[i]); - } else { - b.append("."); - } - b.append(" "); - } - - File debugFile = new File(packet.getClass().getSimpleName() + ".txt"); - try (PrintStream out = new PrintStream(new FileOutputStream(debugFile))) { - out.println(b.toString()); - } catch (FileNotFoundException fileNotFoundException) { - fileNotFoundException.printStackTrace(); - } - - + dumpPacket(dupe, packet); throw new PacketSerializeException("Error whilst deserializing " + packet, e); } if (log.isDebugEnabled() && buf.isReadable()) { + dumpPacket(dupe, packet); log.debug(packet.getClass().getSimpleName() + " still has " + buf.readableBytes() + " bytes to read!"); } return packet; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index a1d32fc4c..ac6905e62 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -16,7 +16,9 @@ import com.nukkitx.protocol.bedrock.data.command.CommandOriginData; import com.nukkitx.protocol.bedrock.data.command.CommandParamType; import com.nukkitx.protocol.bedrock.data.entity.*; +import com.nukkitx.protocol.bedrock.data.inventory.ContainerMixData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; import com.nukkitx.protocol.bedrock.data.skin.ImageData; import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin; import com.nukkitx.protocol.bedrock.data.structure.StructureSettings; @@ -40,6 +42,8 @@ import java.util.function.BiFunction; import java.util.function.Function; +import static java.util.Objects.requireNonNull; + public abstract class BedrockPacketHelper { protected static final InternalLogger log = InternalLoggerFactory.getInstance(BedrockPacketHelper.class); @@ -468,4 +472,78 @@ public void writeTag(ByteBuf buffer, Tag tag) { throw new RuntimeException(e); } } + + public ItemData readRecipeIngredient(ByteBuf buffer) { + requireNonNull(buffer, "buffer is null"); + + int id = VarInts.readInt(buffer); + + if (id == 0) { + // We don't need to read anything extra. + return ItemData.AIR; + } + + int meta = VarInts.readInt(buffer); + int count = VarInts.readInt(buffer); + + return ItemData.of(id, (short) meta, count); + } + + public void writeRecipeIngredient(ByteBuf buffer, ItemData item) { + requireNonNull(buffer, "buffer is null"); + requireNonNull(item, "item is null"); + + VarInts.writeInt(buffer, item.getId()); + + if (item.getId() == 0) { + return; + } + + VarInts.writeInt(buffer, item.getDamage()); + VarInts.writeInt(buffer, item.getCount()); + } + + public PotionMixData readPotionRecipe(ByteBuf buffer) { + requireNonNull(buffer, "buffer is null"); + + return new PotionMixData( + VarInts.readInt(buffer), + VarInts.readInt(buffer), + VarInts.readInt(buffer), + VarInts.readInt(buffer), + VarInts.readInt(buffer), + VarInts.readInt(buffer) + ); + } + + public void writePotionRecipe(ByteBuf buffer, PotionMixData data) { + requireNonNull(buffer, "buffer is null"); + requireNonNull(data, "data is null"); + + VarInts.writeInt(buffer, data.getInputId()); + VarInts.writeInt(buffer, data.getInputMeta()); + VarInts.writeInt(buffer, data.getReagentId()); + VarInts.writeInt(buffer, data.getReagentMeta()); + VarInts.writeInt(buffer, data.getOutputId()); + VarInts.writeInt(buffer, data.getOutputMeta()); + } + + public ContainerMixData readContainerChangeRecipe(ByteBuf buffer) { + requireNonNull(buffer, "buffer is null"); + + return new ContainerMixData( + VarInts.readInt(buffer), + VarInts.readInt(buffer), + VarInts.readInt(buffer) + ); + } + + public void writeContainerChangeRecipe(ByteBuf buffer, ContainerMixData data) { + requireNonNull(buffer, "buffer is null"); + requireNonNull(data, "data is null"); + + VarInts.writeInt(buffer, data.getInputId()); + VarInts.writeInt(buffer, data.getReagentId()); + VarInts.writeInt(buffer, data.getOutputId()); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerMixData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerMixData.java index 8061c41af..520b16e48 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerMixData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerMixData.java @@ -4,7 +4,7 @@ @Value public class ContainerMixData { - private final int fromItemId; - private final int ingredient; - private final int toItemId; + private final int inputId; + private final int reagentId; + private final int outputId; } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/CraftingData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/CraftingData.java index 8caafb290..289773f4b 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/CraftingData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/CraftingData.java @@ -19,92 +19,173 @@ public class CraftingData { private final UUID uuid; private final String craftingTag; private final int priority; + private final int networkId; + + // @Todo changed networkId to id to match rest of code + + public CraftingData(CraftingDataType type, String recipeId, int width, int height, int inputId, int inputDamage, ItemData[] inputs, + ItemData[] outputs, UUID uuid, String craftingTag, int priority) { + this(type, recipeId, width, height, inputId, inputDamage, inputs, outputs, uuid, craftingTag, priority, -1); + } + + public CraftingData(CraftingDataType type, int width, int height, int inputId, int inputDamage, ItemData[] inputs, + ItemData[] outputs, UUID uuid, String craftingTag, int networkId) { + this(type, null, width, height, inputId, inputDamage, inputs, outputs, uuid, craftingTag, 0, networkId); + } public CraftingData(CraftingDataType type, int width, int height, int inputId, int inputDamage, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { - this.type = type; - this.recipeId = null; - this.width = width; - this.height = height; - this.inputId = inputId; - this.inputDamage = inputDamage; - this.inputs = inputs; - this.outputs = outputs; - this.uuid = uuid; - this.craftingTag = craftingTag; - this.priority = 0; + this(type, null, width, height, inputId, inputDamage, inputs, outputs, uuid, craftingTag, 0, -1); + } + + public static CraftingData fromFurnaceData(int inputId, int inputDamage, ItemData output, String craftingTag, + int networkId) { + return new CraftingData(CraftingDataType.FURNACE_DATA, null, -1, -1, inputId, inputDamage, + null, new ItemData[]{output}, null, craftingTag, -1, networkId); } public static CraftingData fromFurnaceData(int inputId, int inputDamage, ItemData output, String craftingTag) { return new CraftingData(CraftingDataType.FURNACE_DATA, null, -1, -1, inputId, inputDamage, - null, new ItemData[]{output}, null, craftingTag, -1); + null, new ItemData[]{output}, null, craftingTag, -1, -1); + } + + public static CraftingData fromFurnace(int inputId, ItemData input, String craftingTag, int networkId) { + return new CraftingData(CraftingDataType.FURNACE, null, -1, -1, inputId, -1, + null, new ItemData[]{input}, null, craftingTag, -1, networkId); } public static CraftingData fromFurnace(int inputId, ItemData input, String craftingTag) { return new CraftingData(CraftingDataType.FURNACE, null, -1, -1, inputId, -1, - null, new ItemData[]{input}, null, craftingTag, -1); + null, new ItemData[]{input}, null, craftingTag, -1, -1); + } + + public static CraftingData fromShapeless(String recipeId, ItemData[] inputs, ItemData[] outputs, UUID uuid, + String craftingTag, int priority, int networkId) { + return new CraftingData(CraftingDataType.SHAPELESS, recipeId, -1, -1, -1, -1, + inputs, outputs, uuid, craftingTag, priority, networkId); } public static CraftingData fromShapeless(String recipeId, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, int priority) { return new CraftingData(CraftingDataType.SHAPELESS, recipeId, -1, -1, -1, -1, - inputs, outputs, uuid, craftingTag, priority); + inputs, outputs, uuid, craftingTag, priority, -1); + } + + public static CraftingData fromShaped(String recipeId, int width, int height, ItemData[] inputs, + ItemData[] outputs, UUID uuid, String craftingTag, int priority, + int networkId) { + return new CraftingData(CraftingDataType.SHAPED, recipeId, width, height, -1, -1, inputs, + outputs, uuid, craftingTag, priority, networkId); } public static CraftingData fromShaped(String recipeId, int width, int height, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, int priority) { return new CraftingData(CraftingDataType.SHAPED, recipeId, width, height, -1, -1, inputs, - outputs, uuid, craftingTag, priority); + outputs, uuid, craftingTag, priority, -1); + } + + public static CraftingData fromShapelessChemistry(String recipeId, ItemData[] inputs, ItemData[] outputs, + UUID uuid, String craftingTag, int priority, int networkId) { + return new CraftingData(CraftingDataType.SHAPELESS_CHEMISTRY, recipeId, -1, -1, -1, + -1, inputs, outputs, uuid, craftingTag, priority, networkId); } public static CraftingData fromShapelessChemistry(String recipeId, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, int priority) { return new CraftingData(CraftingDataType.SHAPELESS_CHEMISTRY, recipeId, -1, -1, -1, - -1, inputs, outputs, uuid, craftingTag, priority); + -1, inputs, outputs, uuid, craftingTag, priority, -1); + } + + public static CraftingData fromShapedChemistry(String recipeId, int width, int height, ItemData[] inputs, + ItemData[] outputs, UUID uuid, String craftingTag, int priority, + int networkId) { + return new CraftingData(CraftingDataType.SHAPED_CHEMISTRY, recipeId, width, height, -1, -1, + inputs, outputs, uuid, craftingTag, priority, networkId); } public static CraftingData fromShapedChemistry(String recipeId, int width, int height, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, int priority) { return new CraftingData(CraftingDataType.SHAPED_CHEMISTRY, recipeId, width, height, -1, -1, - inputs, outputs, uuid, craftingTag, priority); + inputs, outputs, uuid, craftingTag, priority, -1); + } + + public static CraftingData fromShulkerBox(String recipeId, ItemData[] inputs, ItemData[] outputs, UUID uuid, + String craftingTag, int priority, int networkId) { + return new CraftingData(CraftingDataType.SHULKER_BOX, recipeId, -1, -1, -1, -1, + inputs, outputs, uuid, craftingTag, priority, networkId); } public static CraftingData fromShulkerBox(String recipeId, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, int priority) { return new CraftingData(CraftingDataType.SHULKER_BOX, recipeId, -1, -1, -1, -1, - inputs, outputs, uuid, craftingTag, priority); + inputs, outputs, uuid, craftingTag, priority, -1); + } + + public static CraftingData fromMulti(UUID uuid, int networkId) { + return new CraftingData(CraftingDataType.MULTI, null, -1, -1, -1, -1, + null, null, uuid, null, -1, networkId); } public static CraftingData fromMulti(UUID uuid) { return new CraftingData(CraftingDataType.MULTI, null, -1, -1, -1, -1, - null, null, uuid, null, -1); + null, null, uuid, null, -1, -1); + } + + public static CraftingData fromShapeless(ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, + int networkId) { + return new CraftingData(CraftingDataType.SHAPELESS, "", -1, -1, -1, -1, inputs, outputs, + uuid, craftingTag, 0, networkId); } public static CraftingData fromShapeless(ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { return new CraftingData(CraftingDataType.SHAPELESS, "", -1, -1, -1, -1, inputs, outputs, - uuid, craftingTag, 0); + uuid, craftingTag, 0, -1); + } + + public static CraftingData fromShaped(int width, int height, ItemData[] inputs, ItemData[] outputs, UUID uuid, + String craftingTag, int networkId) { + return new CraftingData(CraftingDataType.SHAPED, "", width, height, -1, -1, inputs, outputs, uuid, + craftingTag, 0, networkId); } public static CraftingData fromShaped(int width, int height, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { return new CraftingData(CraftingDataType.SHAPED, "", width, height, -1, -1, inputs, outputs, uuid, - craftingTag, 0); + craftingTag, 0, -1); + } + + public static CraftingData fromShapelessChemistry(ItemData[] inputs, ItemData[] outputs, UUID uuid, + String craftingTag, int networkId) { + return new CraftingData(CraftingDataType.SHAPELESS_CHEMISTRY, "", -1, -1, -1, -1, + inputs, outputs, uuid, craftingTag, 0, networkId); } public static CraftingData fromShapelessChemistry(ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { return new CraftingData(CraftingDataType.SHAPELESS_CHEMISTRY, "", -1, -1, -1, -1, - inputs, outputs, uuid, craftingTag, 0); + inputs, outputs, uuid, craftingTag, 0, -1); + } + + public static CraftingData fromShapedChemistry(int width, int height, ItemData[] inputs, ItemData[] outputs, + UUID uuid, String craftingTag, int networkId) { + return new CraftingData(CraftingDataType.SHAPED_CHEMISTRY, "", width, height, -1, -1, inputs, + outputs, uuid, craftingTag, 0, networkId); } public static CraftingData fromShapedChemistry(int width, int height, ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { return new CraftingData(CraftingDataType.SHAPED_CHEMISTRY, "", width, height, -1, -1, inputs, - outputs, uuid, craftingTag, 0); + outputs, uuid, craftingTag, 0, -1); + } + + public static CraftingData fromShulkerBox(ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag, + int networkId) { + return new CraftingData(CraftingDataType.SHULKER_BOX, "", -1, -1, -1, -1, inputs, outputs, + uuid, craftingTag, 0, networkId); } public static CraftingData fromShulkerBox(ItemData[] inputs, ItemData[] outputs, UUID uuid, String craftingTag) { return new CraftingData(CraftingDataType.SHULKER_BOX, "", -1, -1, -1, -1, inputs, outputs, - uuid, craftingTag, 0); + uuid, craftingTag, 0, -1); } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/PotionMixData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/PotionMixData.java index 32a220a41..f939aef9c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/PotionMixData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/PotionMixData.java @@ -2,9 +2,20 @@ import lombok.Value; +/** + * Represents a potion mixing recipe which may be used in a brewing stand. + */ @Value public class PotionMixData { - private final int fromPotionId; - private final int ingredient; - private final int toPotionId; + // Potion to be put in + private final int inputId; + private final int inputMeta; + + // Item to be added to the brewing stand to brew the output potion + private final int reagentId; + private final int reagentMeta; + + // Output Potion + private final int outputId; + private final int outputMeta; } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CraftingDataPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CraftingDataPacket.java index 90504b61e..8eaca21e9 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CraftingDataPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CraftingDataPacket.java @@ -14,7 +14,7 @@ import java.util.List; @Data -@ToString(exclude = {"craftingData"}) +@ToString @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class CraftingDataPacket extends BedrockPacket { private final List craftingData = new ObjectArrayList<>(); diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/CraftingDataSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/CraftingDataSerializer_v388.java index c6aeff2e9..9bbfec9fc 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/CraftingDataSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/CraftingDataSerializer_v388.java @@ -40,14 +40,14 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataPa }); helper.writeArray(buffer, packet.getPotionMixData(), (buf, potionMixData) -> { - VarInts.writeInt(buf, potionMixData.getFromPotionId()); - VarInts.writeInt(buf, potionMixData.getIngredient()); - VarInts.writeInt(buf, potionMixData.getToPotionId()); + VarInts.writeInt(buf, potionMixData.getInputId()); + VarInts.writeInt(buf, potionMixData.getReagentId()); + VarInts.writeInt(buf, potionMixData.getOutputId()); }); helper.writeArray(buffer, packet.getContainerMixData(), (buf, containerMixData) -> { - VarInts.writeInt(buf, containerMixData.getFromItemId()); - VarInts.writeInt(buf, containerMixData.getIngredient()); - VarInts.writeInt(buf, containerMixData.getToItemId()); + VarInts.writeInt(buf, containerMixData.getInputId()); + VarInts.writeInt(buf, containerMixData.getReagentId()); + VarInts.writeInt(buf, containerMixData.getOutputId()); }); buffer.writeBoolean(packet.isCleanRecipes()); @@ -80,7 +80,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingData int fromPotionId = VarInts.readInt(buf); int ingredient = VarInts.readInt(buf); int toPotionId = VarInts.readInt(buf); - return new PotionMixData(fromPotionId, ingredient, toPotionId); + return new PotionMixData(fromPotionId, 0, ingredient, 0, toPotionId, 0); }); helper.readArray(buffer, packet.getContainerMixData(), buf -> { int fromItemId = VarInts.readInt(buf); diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java index 472f272b4..e84780d9f 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java @@ -6,6 +6,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; + @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v407 extends BedrockPacketHelper_v390 { public static final BedrockPacketHelper_v407 INSTANCE = new BedrockPacketHelper_v407(); @@ -37,4 +38,5 @@ protected void registerEntityFlags() { this.addEntityFlag(93, EntityFlag.ADMIRING); this.addEntityFlag(94, EntityFlag.CELEBRATING_SPECIAL); } + } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index dba48d36c..b03905b57 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -70,7 +70,7 @@ public class Bedrock_v407 { .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v291.INSTANCE, 49) .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v291.INSTANCE, 50) .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v291.INSTANCE, 51) - .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v388.INSTANCE, 52) + .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v407.INSTANCE, 52) .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v291.INSTANCE, 53) .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v291.INSTANCE, 54) .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v291.INSTANCE, 55) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CraftingDataSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CraftingDataSerializer_v407.java new file mode 100644 index 000000000..b98133158 --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CraftingDataSerializer_v407.java @@ -0,0 +1,187 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.data.inventory.CraftingData; +import com.nukkitx.protocol.bedrock.data.inventory.CraftingDataType; +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CraftingDataSerializer_v407 implements BedrockPacketSerializer { + public static final CraftingDataSerializer_v407 INSTANCE = new CraftingDataSerializer_v407(); + + protected static final ItemData[] EMPTY_ARRAY = {}; + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataPacket packet) { + helper.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { + VarInts.writeInt(buf, craftingData.getType().ordinal()); + switch (craftingData.getType()) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + this.writeShapelessRecipe(buf, helper, craftingData); + break; + case SHAPED: + case SHAPED_CHEMISTRY: + this.writeShapedRecipe(buf, helper, craftingData); + break; + case FURNACE: + this.writeFurnaceRecipe(buf, helper, craftingData); + break; + case FURNACE_DATA: + this.writeFurnaceDataRecipe(buf, helper, craftingData); + break; + case MULTI: + this.writeMultiRecipe(buf, helper, craftingData); + break; + } + }); + + // Potions + helper.writeArray(buffer, packet.getPotionMixData(), (buf, data) -> helper.writePotionRecipe(buf, data)); + + // Potion Container Change + helper.writeArray(buffer, packet.getContainerMixData(), (buf, data) -> helper.writeContainerChangeRecipe(buf, data)); + + buffer.writeBoolean(packet.isCleanRecipes()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataPacket packet) { + helper.readArray(buffer, packet.getCraftingData(), buf -> { + int typeInt = VarInts.readInt(buf); + CraftingDataType type = CraftingDataType.byId(typeInt); + + switch (type) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + return this.readShapelessRecipe(buf, helper, type); + case SHAPED: + case SHAPED_CHEMISTRY: + return this.readShapedRecipe(buf, helper, type); + case FURNACE: + return this.readFurnaceRecipe(buf, helper, type); + case FURNACE_DATA: + return this.readFurnaceDataRecipe(buf, helper, type); + case MULTI: + return this.readMultiRecipe(buf, helper, type); + default: + throw new IllegalArgumentException("Unhandled crafting data type: " + type); + } + }); + + // Potions + helper.readArray(buffer, packet.getPotionMixData(), helper::readPotionRecipe); + + // Potion Container Change + helper.readArray(buffer, packet.getContainerMixData(), helper::readContainerChangeRecipe); + + packet.setCleanRecipes(buffer.readBoolean()); + } + + protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type) { + String recipeId = helper.readString(buffer); + ItemData[] inputs = helper.readArray(buffer, EMPTY_ARRAY, helper::readRecipeIngredient); + ItemData[] outputs = helper.readArray(buffer, EMPTY_ARRAY, helper::readItem); + + UUID uuid = helper.readUuid(buffer); + String craftingTag = helper.readString(buffer); + int priority = VarInts.readInt(buffer); + int networkId = VarInts.readUnsignedInt(buffer); + return new CraftingData(type, recipeId,-1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority, networkId); + } + + protected void writeShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingData data) { + helper.writeString(buffer, data.getRecipeId()); + helper.writeArray(buffer, data.getInputs(), helper::writeRecipeIngredient); + helper.writeArray(buffer, data.getOutputs(), helper::writeItem); + + helper.writeUuid(buffer, data.getUuid()); + helper.writeString(buffer, data.getCraftingTag()); + VarInts.writeInt(buffer, data.getPriority()); + VarInts.writeUnsignedInt(buffer, data.getNetworkId()); + } + + protected CraftingData readShapedRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type) { + String recipeId = helper.readString(buffer); + int width = VarInts.readInt(buffer); + int height = VarInts.readInt(buffer); + int inputCount = width * height; + ItemData[] inputs = new ItemData[inputCount]; + for (int i = 0; i < inputCount; i++) { + inputs[i] = helper.readRecipeIngredient(buffer); + } + ItemData[] outputs = helper.readArray(buffer, EMPTY_ARRAY, helper::readItem); + UUID uuid = helper.readUuid(buffer); + String craftingTag = helper.readString(buffer); + int priority = VarInts.readInt(buffer); + int networkId = VarInts.readUnsignedInt(buffer); + return new CraftingData(type, recipeId, width, height, -1, -1, inputs, outputs, uuid, craftingTag, priority, networkId); + } + + protected void writeShapedRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingData data) { + helper.writeString(buffer, data.getRecipeId()); + VarInts.writeInt(buffer, data.getWidth()); + VarInts.writeInt(buffer, data.getHeight()); + int count = data.getWidth() * data.getHeight(); + ItemData[] inputs = data.getInputs(); + for (int i = 0; i < count; i++) { + helper.writeRecipeIngredient(buffer, inputs[i]); + } + helper.writeArray(buffer, data.getOutputs(), helper::writeItem); + helper.writeUuid(buffer, data.getUuid()); + helper.writeString(buffer, data.getCraftingTag()); + VarInts.writeInt(buffer, data.getPriority()); + VarInts.writeUnsignedInt(buffer, data.getNetworkId()); + } + + protected CraftingData readFurnaceRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type) { + int inputId = VarInts.readInt(buffer); + ItemData[] output = new ItemData[]{helper.readItem(buffer)}; + String craftingTag = helper.readString(buffer); + return new CraftingData(type, -1, -1, inputId, -1, null, output, + null, craftingTag); + } + + protected void writeFurnaceRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingData data) { + VarInts.writeInt(buffer, data.getInputId()); + helper.writeItem(buffer, data.getOutputs()[0]); + helper.writeString(buffer, data.getCraftingTag()); + } + + protected CraftingData readFurnaceDataRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type) { + int inputId = VarInts.readInt(buffer); + int inputDamage = VarInts.readInt(buffer); + ItemData[] output = new ItemData[]{helper.readItem(buffer)}; + String craftingTag = helper.readString(buffer); + return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, + null, craftingTag); + } + + protected void writeFurnaceDataRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingData data) { + VarInts.writeInt(buffer, data.getInputId()); + VarInts.writeInt(buffer, data.getInputDamage()); + helper.writeItem(buffer, data.getOutputs()[0]); + helper.writeString(buffer, data.getCraftingTag()); + } + + protected CraftingData readMultiRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type) { + UUID uuid = helper.readUuid(buffer); + int networkId = VarInts.readUnsignedInt(buffer); + return CraftingData.fromMulti(uuid, networkId); + } + + protected void writeMultiRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingData data) { + helper.writeUuid(buffer, data.getUuid()); + VarInts.writeUnsignedInt(buffer, data.getNetworkId()); + } +} From c78547a023b7028f7ef119b541d36891edf24560 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 13:51:48 +0800 Subject: [PATCH 14/70] Implement ItemSlotPacket Add the item networkId --- .../bedrock/packet/InventorySlotPacket.java | 1 + .../protocol/bedrock/v407/Bedrock_v407.java | 2 +- .../InventorySlotSerializer_v407.java | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java index bdc251aef..414929cfc 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java @@ -13,6 +13,7 @@ public class InventorySlotPacket extends BedrockPacket { private int containerId; private int slot; private ItemData item; + private int itemNetworkId; @Override public final boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index b03905b57..706d942b7 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -68,7 +68,7 @@ public class Bedrock_v407 { .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v291.INSTANCE, 47) .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v291.INSTANCE, 48) .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v291.INSTANCE, 49) - .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v291.INSTANCE, 50) + .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v407.INSTANCE, 50) .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v291.INSTANCE, 51) .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v407.INSTANCE, 52) .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v291.INSTANCE, 53) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java new file mode 100644 index 000000000..031a4960c --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java @@ -0,0 +1,30 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class InventorySlotSerializer_v407 implements BedrockPacketSerializer { + public static final InventorySlotSerializer_v407 INSTANCE = new InventorySlotSerializer_v407(); + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventorySlotPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getItemNetworkId()); + VarInts.writeUnsignedInt(buffer, packet.getContainerId()); + VarInts.writeUnsignedInt(buffer, packet.getSlot()); + helper.writeItem(buffer, packet.getItem()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, InventorySlotPacket packet) { + packet.setItemNetworkId(VarInts.readInt(buffer)); + packet.setContainerId(VarInts.readUnsignedInt(buffer)); + packet.setSlot(VarInts.readUnsignedInt(buffer)); + packet.setItem(helper.readItem(buffer)); + } +} From d0e53b2aa88ac829ec7df714fb3cca4526da2baa Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 14:04:38 +0800 Subject: [PATCH 15/70] Implement SetSpawnPositionPacket Adds the playerPosition --- .../packet/SetSpawnPositionPacket.java | 17 ++++++++++ .../protocol/bedrock/v407/Bedrock_v407.java | 2 +- .../SetSpawnPositionSerializer_v407.java | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/SetSpawnPositionSerializer_v407.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java index a018c84b1..b887f27f5 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java @@ -10,8 +10,25 @@ @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class SetSpawnPositionPacket extends BedrockPacket { + // spawnType is the type of spawn to set. It is either PLAYER_SPAWN or WORLD_SPAWN, and specifies + // the behaviour of the spawn set. If WORLD_SPAWN is set, the position to which compasses will point is + // also changed. private Type spawnType; + + // blockPosition is the new position of the spawn that was set. If spawnType is WORLD_SPAWN, compasses will + // point to this position. As of 1.16, blockPosition is always the position of the player. private Vector3i blockPosition; + + // dimensionId is the ID of the dimension that had its spawn updated. This is specifically relevant for + // behaviour added in 1.16 such as the respawn anchor, which allows setting the spawn in a specific + // dimension. + private int dimensionId; + + // SpawnPosition is a new field added in 1.16. It holds the spawn position of the world. This spawn + // position is {-2147483648, -2147483648, -2147483648} for a default spawn position. + private Vector3i spawnPosition; + + @Deprecated private boolean spawnForced; @Override diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index 706d942b7..3140947d6 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -61,7 +61,7 @@ public class Bedrock_v407 { .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v291.INSTANCE, 40) .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v291.INSTANCE, 41) .registerPacket(SetHealthPacket.class, SetHealthSerializer_v291.INSTANCE, 42) - .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v291.INSTANCE, 43) + .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v407.INSTANCE, 43) .registerPacket(AnimatePacket.class, AnimateSerializer_v291.INSTANCE, 44) .registerPacket(RespawnPacket.class, RespawnSerializer_v388.INSTANCE, 45) .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v291.INSTANCE, 46) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/SetSpawnPositionSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/SetSpawnPositionSerializer_v407.java new file mode 100644 index 000000000..c83f62086 --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/SetSpawnPositionSerializer_v407.java @@ -0,0 +1,31 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.packet.SetSpawnPositionPacket; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class SetSpawnPositionSerializer_v407 implements BedrockPacketSerializer { + public static final SetSpawnPositionSerializer_v407 INSTANCE = new SetSpawnPositionSerializer_v407(); + + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, SetSpawnPositionPacket packet) { + VarInts.writeInt(buffer, packet.getSpawnType().ordinal()); + helper.writeBlockPosition(buffer, packet.getBlockPosition()); + VarInts.writeInt(buffer, packet.getDimensionId()); + helper.writeBlockPosition(buffer, packet.getSpawnPosition()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, SetSpawnPositionPacket packet) { + packet.setSpawnType(SetSpawnPositionPacket.Type.values()[VarInts.readInt(buffer)]); + packet.setBlockPosition(helper.readBlockPosition(buffer)); + packet.setDimensionId(VarInts.readInt(buffer)); + packet.setSpawnPosition(helper.readBlockPosition(buffer)); + } +} From 65298c69028db1f416ccaae6cf840ac47d324b70 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 14:19:15 +0800 Subject: [PATCH 16/70] Add ItemDataInstance that contains a reference to an ItemData and the server network ID. Also updated InventorySetSlotPacket to deprecated the direct access and provide the instance access instead. --- .../data/inventory/ItemDataInstance.java | 28 +++++++++++++++++++ .../bedrock/packet/InventorySlotPacket.java | 7 ++++- .../InventorySlotSerializer_v407.java | 10 ++++--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java new file mode 100644 index 000000000..df55e6500 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java @@ -0,0 +1,28 @@ +package com.nukkitx.protocol.bedrock.data.inventory; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import lombok.Value; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents a unique instance of an item stack. These instances carry a specific network ID that is persistent for the stack. + */ + +@Value +@Immutable +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class ItemDataInstance { + // networkId is the network ID of the item stack. If the stack is empty, 0 is always written for this + // field. If not, the field should be set to 1 if the server authoritative inventories are disabled in the + // StartGame packet, or to a unique stack ID if it is enabled. + private final int networkId; + + // item is the actual itemStack + private final ItemData item; + + public static ItemDataInstance of(int networkId, ItemData itemData) { + return new ItemDataInstance(networkId, itemData); + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java index 414929cfc..3899f65de 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; import lombok.EqualsAndHashCode; @@ -12,8 +13,12 @@ public class InventorySlotPacket extends BedrockPacket { private int containerId; private int slot; + + // instance is an instance of an ItemStack. As of 1.16 ItemStacks have an networkId. + private ItemDataInstance instance; + + @Deprecated private ItemData item; - private int itemNetworkId; @Override public final boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java index 031a4960c..2a00aab55 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java @@ -3,6 +3,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import io.netty.buffer.ByteBuf; import lombok.AccessLevel; @@ -14,17 +15,18 @@ public class InventorySlotSerializer_v407 implements BedrockPacketSerializer Date: Thu, 25 Jun 2020 14:28:17 +0800 Subject: [PATCH 17/70] Implement InventoryContentPacket and associated helpers --- .../protocol/bedrock/BedrockPacketHelper.java | 13 +++++++ .../packet/InventoryContentPacket.java | 4 ++ .../protocol/bedrock/v407/Bedrock_v407.java | 2 +- .../InventoryContentSerializer_v407.java | 38 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index ac6905e62..daee97fc1 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -18,6 +18,7 @@ import com.nukkitx.protocol.bedrock.data.entity.*; import com.nukkitx.protocol.bedrock.data.inventory.ContainerMixData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; import com.nukkitx.protocol.bedrock.data.skin.ImageData; import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin; @@ -546,4 +547,16 @@ public void writeContainerChangeRecipe(ByteBuf buffer, ContainerMixData data) { VarInts.writeInt(buffer, data.getReagentId()); VarInts.writeInt(buffer, data.getOutputId()); } + + public ItemDataInstance readItemInstance(ByteBuf buffer) { + return ItemDataInstance.of( + VarInts.readInt(buffer), + readItem(buffer) + ); + } + + public void writeItemInstance(ByteBuf buffer, ItemDataInstance data) { + VarInts.writeInt(buffer, data.getNetworkId()); + writeItem(buffer, data.getItem()); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java index aa46f9b71..2c3ee70fd 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; import lombok.EqualsAndHashCode; @@ -10,7 +11,10 @@ @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class InventoryContentPacket extends BedrockPacket { + @Deprecated private ItemData[] contents; + + private ItemDataInstance[] instances; private int containerId; @Override diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index 3140947d6..483ad9410 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -67,7 +67,7 @@ public class Bedrock_v407 { .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v291.INSTANCE, 46) .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v291.INSTANCE, 47) .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v291.INSTANCE, 48) - .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v291.INSTANCE, 49) + .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v407.INSTANCE, 49) .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v407.INSTANCE, 50) .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v291.INSTANCE, 51) .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v407.INSTANCE, 52) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java new file mode 100644 index 000000000..795a50821 --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java @@ -0,0 +1,38 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; +import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class InventoryContentSerializer_v407 implements BedrockPacketSerializer { + public static final InventoryContentSerializer_v407 INSTANCE = new InventoryContentSerializer_v407(); + + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryContentPacket packet) { + VarInts.writeUnsignedInt(buffer, packet.getContainerId()); + + ItemDataInstance[] instances = packet.getInstances(); + VarInts.writeUnsignedInt(buffer, instances.length); + for (ItemDataInstance content : instances) { + helper.writeItemInstance(buffer, content); + } + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryContentPacket packet) { + packet.setContainerId(VarInts.readUnsignedInt(buffer)); + + ItemDataInstance[] instances = new ItemDataInstance[VarInts.readUnsignedInt(buffer)]; + for (int i = 0; i < instances.length; i++) { + instances[i] = helper.readItemInstance(buffer); + } + packet.setInstances(instances); + } +} From c267e40a56c9ee34676aa5f94ffcce85b2b60f16 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 14:47:03 +0800 Subject: [PATCH 18/70] Implement CreativeContentPacket --- .../bedrock/packet/CreativeContentPacket.java | 10 ++++++++-- .../CreativeContentSerializer_v407.java | 16 +++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java index fc383f043..73ccf40c7 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java @@ -2,20 +2,26 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; -import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Data; import lombok.EqualsAndHashCode; + +/** + * CreativeContent is a packet sent by the server to set the creative inventory's content for a player. + * Introduced in 1.16, this packet replaces the previous method - sending an InventoryContent packet with + * creative inventory window ID. + */ @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class CreativeContentPacket extends BedrockPacket { /** * Item entries for the creative menu. Each item must have a unique ID for the net ID manager */ - private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); + private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); @Override public boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java index bbfe2a20a..9f51f96a2 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java @@ -3,7 +3,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; -import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.packet.CreativeContentPacket; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -18,21 +18,19 @@ public class CreativeContentSerializer_v407 implements BedrockPacketSerializer entry : packet.getEntries().int2ObjectEntrySet()) { - VarInts.writeUnsignedInt(buffer, entry.getIntKey()); - helper.writeItem(buffer, entry.getValue()); + for (ItemDataInstance instance : packet.getEntries().values()) { + helper.writeItemInstance(buffer, instance); } } @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CreativeContentPacket packet) { - Int2ObjectMap entries = packet.getEntries(); + Int2ObjectMap entries = packet.getEntries(); - int count = VarInts.readInt(buffer); + int count = VarInts.readUnsignedInt(buffer); for (int i = 0; i < count; i++) { - int creativeNetId = VarInts.readUnsignedInt(buffer); - ItemData item = helper.readItem(buffer); - if (entries.putIfAbsent(creativeNetId, item) != null) { + ItemDataInstance instance = helper.readItemInstance(buffer); + if (entries.putIfAbsent(instance.getNetworkId(), instance) != null) { throw new IllegalStateException("Creative content net ID collision!"); } } From b6edff821f9c276aa163b1a34b66c2b71eca4a84 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 16:54:57 +0800 Subject: [PATCH 19/70] Fix missing AvailbleCommandsSerializer static instance variable --- .../v388/serializer/AvailableCommandsSerializer_v388.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java index f8ee22efc..cd51159c4 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java @@ -13,6 +13,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class AvailableCommandsSerializer_v388 extends AvailableCommandsSerializer_v340 { + public static final AvailableCommandsSerializer_v388 INSTANCE = new AvailableCommandsSerializer_v388(); @Override From 4966ec34449bf6067fbc1a6969e44d261c65d433 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 20:26:46 +0800 Subject: [PATCH 20/70] Flatten ItemData networkID --- .../protocol/bedrock/BedrockPacketHelper.java | 13 --------- .../data/inventory/ItemDataInstance.java | 28 ------------------- .../bedrock/packet/CreativeContentPacket.java | 4 +-- .../packet/InventoryContentPacket.java | 22 +++++++++++---- .../bedrock/packet/InventorySlotPacket.java | 7 +---- .../CreativeContentSerializer_v407.java | 14 ++++++---- .../InventoryContentSerializer_v407.java | 19 +++++++------ .../InventorySlotSerializer_v407.java | 10 +++---- 8 files changed, 42 insertions(+), 75 deletions(-) delete mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index daee97fc1..ac6905e62 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -18,7 +18,6 @@ import com.nukkitx.protocol.bedrock.data.entity.*; import com.nukkitx.protocol.bedrock.data.inventory.ContainerMixData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; import com.nukkitx.protocol.bedrock.data.skin.ImageData; import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin; @@ -547,16 +546,4 @@ public void writeContainerChangeRecipe(ByteBuf buffer, ContainerMixData data) { VarInts.writeInt(buffer, data.getReagentId()); VarInts.writeInt(buffer, data.getOutputId()); } - - public ItemDataInstance readItemInstance(ByteBuf buffer) { - return ItemDataInstance.of( - VarInts.readInt(buffer), - readItem(buffer) - ); - } - - public void writeItemInstance(ByteBuf buffer, ItemDataInstance data) { - VarInts.writeInt(buffer, data.getNetworkId()); - writeItem(buffer, data.getItem()); - } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java deleted file mode 100644 index df55e6500..000000000 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemDataInstance.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nukkitx.protocol.bedrock.data.inventory; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import lombok.Value; - -import javax.annotation.concurrent.Immutable; - -/** - * Represents a unique instance of an item stack. These instances carry a specific network ID that is persistent for the stack. - */ - -@Value -@Immutable -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class ItemDataInstance { - // networkId is the network ID of the item stack. If the stack is empty, 0 is always written for this - // field. If not, the field should be set to 1 if the server authoritative inventories are disabled in the - // StartGame packet, or to a unique stack ID if it is enabled. - private final int networkId; - - // item is the actual itemStack - private final ItemData item; - - public static ItemDataInstance of(int networkId, ItemData itemData) { - return new ItemDataInstance(networkId, itemData); - } -} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java index 73ccf40c7..59607116e 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java @@ -2,7 +2,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -21,7 +21,7 @@ public class CreativeContentPacket extends BedrockPacket { /** * Item entries for the creative menu. Each item must have a unique ID for the net ID manager */ - private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); + private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); @Override public boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java index 2c3ee70fd..172f3206c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java @@ -3,18 +3,16 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class InventoryContentPacket extends BedrockPacket { - @Deprecated - private ItemData[] contents; - - private ItemDataInstance[] instances; + private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); private int containerId; @Override @@ -25,4 +23,18 @@ public final boolean handle(BedrockPacketHandler handler) { public BedrockPacketType getPacketType() { return BedrockPacketType.INVENTORY_CONTENT; } + + @Deprecated + public final ItemData[] getContents() { + return entries.values().toArray(new ItemData[0]); + } + + @Deprecated + public void setContents(ItemData[] data) { + entries.clear(); + for(int i = 0;i < data.length; i++) { + entries.put(i, data[i]); + } + } + } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java index 3899f65de..ef050cb0b 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventorySlotPacket.java @@ -3,7 +3,6 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,11 +12,7 @@ public class InventorySlotPacket extends BedrockPacket { private int containerId; private int slot; - - // instance is an instance of an ItemStack. As of 1.16 ItemStacks have an networkId. - private ItemDataInstance instance; - - @Deprecated + private int networkId; private ItemData item; @Override diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java index 9f51f96a2..e83e6c03c 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java @@ -3,7 +3,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.packet.CreativeContentPacket; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -18,19 +18,21 @@ public class CreativeContentSerializer_v407 implements BedrockPacketSerializer entry : packet.getEntries().int2ObjectEntrySet()) { + VarInts.writeInt(buffer, entry.getIntKey()); + helper.writeItem(buffer, entry.getValue()); } } @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CreativeContentPacket packet) { - Int2ObjectMap entries = packet.getEntries(); + Int2ObjectMap entries = packet.getEntries(); int count = VarInts.readUnsignedInt(buffer); for (int i = 0; i < count; i++) { - ItemDataInstance instance = helper.readItemInstance(buffer); - if (entries.putIfAbsent(instance.getNetworkId(), instance) != null) { + int creativeNetId = VarInts.readInt(buffer); + ItemData item = helper.readItem(buffer); + if (entries.putIfAbsent(creativeNetId, item) != null) { throw new IllegalStateException("Creative content net ID collision!"); } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java index 795a50821..a2f8c0a68 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryContentSerializer_v407.java @@ -3,9 +3,10 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -18,10 +19,10 @@ public class InventoryContentSerializer_v407 implements BedrockPacketSerializer< public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryContentPacket packet) { VarInts.writeUnsignedInt(buffer, packet.getContainerId()); - ItemDataInstance[] instances = packet.getInstances(); - VarInts.writeUnsignedInt(buffer, instances.length); - for (ItemDataInstance content : instances) { - helper.writeItemInstance(buffer, content); + VarInts.writeUnsignedInt(buffer, packet.getEntries().size()); + for (Int2ObjectMap.Entry entry : packet.getEntries().int2ObjectEntrySet()) { + VarInts.writeInt(buffer, entry.getIntKey()); + helper.writeItem(buffer, entry.getValue()); } } @@ -29,10 +30,10 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryConte public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); - ItemDataInstance[] instances = new ItemDataInstance[VarInts.readUnsignedInt(buffer)]; - for (int i = 0; i < instances.length; i++) { - instances[i] = helper.readItemInstance(buffer); + int count = VarInts.readUnsignedInt(buffer); + for (int i = 0; i < count; i++) { + int networkId = VarInts.readInt(buffer); + packet.getEntries().put(networkId, helper.readItem(buffer)); } - packet.setInstances(instances); } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java index 2a00aab55..ee9103f7d 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java @@ -3,7 +3,6 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; -import com.nukkitx.protocol.bedrock.data.inventory.ItemDataInstance; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import io.netty.buffer.ByteBuf; import lombok.AccessLevel; @@ -15,18 +14,17 @@ public class InventorySlotSerializer_v407 implements BedrockPacketSerializer Date: Thu, 25 Jun 2020 22:55:37 +0800 Subject: [PATCH 21/70] Implement AvailableCommandsPacket + Contraints --- .../protocol/bedrock/BedrockPacketHelper.java | 16 ++++++++++++++++ .../command/CommandEnumConstraintData.java | 19 +++++++++++++++++++ .../command/CommandEnumConstraintType.java | 16 ++++++++++++++++ .../data/command/CommandParamData.java | 6 ++---- .../packet/AvailableCommandsPacket.java | 2 ++ .../AvailableCommandsSerializer_v291.java | 13 ++++++------- .../AvailableCommandsSerializer_v388.java | 5 ++++- 7 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintType.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index ac6905e62..33e601bb0 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -12,6 +12,8 @@ import com.nukkitx.protocol.bedrock.data.GameRuleData; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.SoundEvent; +import com.nukkitx.protocol.bedrock.data.command.CommandEnumConstraintData; +import com.nukkitx.protocol.bedrock.data.command.CommandEnumConstraintType; import com.nukkitx.protocol.bedrock.data.command.CommandEnumData; import com.nukkitx.protocol.bedrock.data.command.CommandOriginData; import com.nukkitx.protocol.bedrock.data.command.CommandParamType; @@ -37,6 +39,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.List; import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.BiFunction; @@ -546,4 +549,17 @@ public void writeContainerChangeRecipe(ByteBuf buffer, ContainerMixData data) { VarInts.writeInt(buffer, data.getReagentId()); VarInts.writeInt(buffer, data.getOutputId()); } + + public CommandEnumConstraintData readCommandEnumConstraints(ByteBuf buffer, List enums, List enumValues) { + int valueIndex = buffer.readIntLE(); + int enumIndex = buffer.readIntLE(); + CommandEnumConstraintType[] constraints = readArray(buffer, new CommandEnumConstraintType[0], + buf -> CommandEnumConstraintType.byId(buffer.readByte())); + + return new CommandEnumConstraintData( + enumValues.get(valueIndex), + enums.get(enumIndex).getName(), + constraints + ); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java new file mode 100644 index 000000000..66cad8dc1 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java @@ -0,0 +1,19 @@ +package com.nukkitx.protocol.bedrock.data.command; + +import lombok.Value; + +/** + * CommandEnumConstraintData is sent in the AvailableCommandsPacket to limit what values of an enum may be used + * taking in account things such as whether cheats are enabled. + */ +@Value +public class CommandEnumConstraintData { + // The option in an enum that the constraints should be applied to. + String option; + + // The name of the enum of which the option above should be constrained. + String name; + + // List of constraints that should be applied to the enum option. + CommandEnumConstraintType[] constraints; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintType.java new file mode 100644 index 000000000..7edb15e45 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintType.java @@ -0,0 +1,16 @@ +package com.nukkitx.protocol.bedrock.data.command; + +public enum CommandEnumConstraintType { + CHEATS_ENABLED, + UNKNOWN_1, + UNKNOWN_2; + + private static final CommandEnumConstraintType[] VALUES = values(); + + public static CommandEnumConstraintType byId(int id) { + if (id >= 0 && id < VALUES.length) { + return VALUES[id]; + } + throw new UnsupportedOperationException("Unknown CommandEnumConstraintType ID: " + id); + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandParamData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandParamData.java index f190ba3fc..2865474a1 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandParamData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandParamData.java @@ -24,11 +24,9 @@ public static class Builder { private final boolean optional; private final byte options; + @Deprecated public Builder(String name, CommandSymbolData type, boolean optional) { - this.name = name; - this.type = type; - this.optional = optional; - this.options = 0; + this(name, type, optional, (byte) 0); } } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AvailableCommandsPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AvailableCommandsPacket.java index f8bfe72f4..044213576 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AvailableCommandsPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AvailableCommandsPacket.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.command.CommandData; +import com.nukkitx.protocol.bedrock.data.command.CommandEnumConstraintData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.Data; @@ -14,6 +15,7 @@ @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class AvailableCommandsPacket extends BedrockPacket { private final List commands = new ObjectArrayList<>(); + private final List constraints = new ObjectArrayList<>(); @Override public final boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java index 495ea3c5e..f921d4565 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java @@ -278,12 +278,11 @@ protected void writeParameter(ByteBuf buffer, BedrockPacketHelper helper, Comman } protected CommandParamData.Builder readParameter(ByteBuf buffer, BedrockPacketHelper helper) { - String parameterName = helper.readString(buffer); - - CommandSymbolData type = CommandSymbolData.deserialize(buffer.readIntLE()); - - boolean optional = buffer.readBoolean(); - - return new CommandParamData.Builder(parameterName, type, optional); + return new CommandParamData.Builder( + helper.readString(buffer), + CommandSymbolData.deserialize(buffer.readIntLE()), + buffer.readBoolean(), + buffer.readByte() + ); } } \ No newline at end of file diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java index cd51159c4..89216363d 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java @@ -80,7 +80,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom List options = new ObjectArrayList<>(); for (int idx = 0; idx < 8; idx++) { if ((optionsByte & (1 << idx)) != 0) { - options.add(OPTIONS[i]); + options.add(OPTIONS[idx]); } } @@ -91,5 +91,8 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom packet.getCommands().add(new CommandData(command.getName(), command.getDescription(), flagList, command.getPermission(), aliases, overloads)); } + + // Constraints + helper.readArray(buffer, packet.getConstraints(), buf -> helper.readCommandEnumConstraints(buf, enums, enumValues)); } } \ No newline at end of file From d9d855a18c4af866a3b924a11f8364f084455394 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 22:59:18 +0800 Subject: [PATCH 22/70] Fix InventorySlotSerializer serializing --- .../bedrock/v407/serializer/InventorySlotSerializer_v407.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java index ee9103f7d..c201a8870 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java @@ -14,7 +14,7 @@ public class InventorySlotSerializer_v407 implements BedrockPacketSerializer Date: Thu, 25 Jun 2020 23:37:42 +0800 Subject: [PATCH 23/70] Fix LevelSoundEvent and LevelSoundEvent2 (untested) --- .../protocol/bedrock/v407/Bedrock_v407.java | 4 +-- .../LevelSoundEvent2Serializer_v407.java | 34 ++++++++++++++++++ .../LevelSoundEventSerializer_v407.java | 35 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEvent2Serializer_v407.java create mode 100644 bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEventSerializer_v407.java diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index 483ad9410..f57f34e04 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -137,10 +137,10 @@ public class Bedrock_v407 { .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v291.INSTANCE, 117) .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v332.INSTANCE, 118) .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v313.INSTANCE, 119) - .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v313.INSTANCE, 120) + .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v407.INSTANCE, 120) .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v313.INSTANCE, 121) .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v313.INSTANCE, 122) - .registerPacket(LevelSoundEventPacket.class, LevelSoundEventSerializer_v332.INSTANCE, 123) + .registerPacket(LevelSoundEventPacket.class, LevelSoundEventSerializer_v407.INSTANCE, 123) .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v361.INSTANCE, 124) .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v354.INSTANCE, 125) .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v361.INSTANCE, 126) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEvent2Serializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEvent2Serializer_v407.java new file mode 100644 index 000000000..6d8db56a6 --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEvent2Serializer_v407.java @@ -0,0 +1,34 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class LevelSoundEvent2Serializer_v407 implements BedrockPacketSerializer { + public static final LevelSoundEvent2Serializer_v407 INSTANCE = new LevelSoundEvent2Serializer_v407(); + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, LevelSoundEvent2Packet packet) { + VarInts.writeUnsignedInt(buffer, helper.getSoundEventId(packet.getSound())); + helper.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getExtraData()); + helper.writeString(buffer, packet.getIdentifier()); + buffer.writeBoolean(packet.isBabySound()); + buffer.writeBoolean(packet.isRelativeVolumeDisabled()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, LevelSoundEvent2Packet packet) { + packet.setSound(helper.getSoundEvent(VarInts.readUnsignedInt(buffer))); + packet.setPosition(helper.readVector3f(buffer)); + packet.setExtraData(VarInts.readInt(buffer)); + packet.setIdentifier(helper.readString(buffer)); + packet.setBabySound(buffer.readBoolean()); + packet.setRelativeVolumeDisabled(buffer.readBoolean()); + } +} diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEventSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEventSerializer_v407.java new file mode 100644 index 000000000..5c0c8c1fc --- /dev/null +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/LevelSoundEventSerializer_v407.java @@ -0,0 +1,35 @@ +package com.nukkitx.protocol.bedrock.v407.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; +import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class LevelSoundEventSerializer_v407 implements BedrockPacketSerializer { + public static final LevelSoundEventSerializer_v407 INSTANCE = new LevelSoundEventSerializer_v407(); + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, LevelSoundEventPacket packet) { + VarInts.writeUnsignedInt(buffer, helper.getSoundEventId(packet.getSound())); + helper.writeVector3f(buffer, packet.getPosition()); + VarInts.writeInt(buffer, packet.getExtraData()); + helper.writeString(buffer, packet.getIdentifier()); + buffer.writeBoolean(packet.isBabySound()); + buffer.writeBoolean(packet.isRelativeVolumeDisabled()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, LevelSoundEventPacket packet) { + packet.setSound(helper.getSoundEvent(VarInts.readUnsignedInt(buffer))); + packet.setPosition(helper.readVector3f(buffer)); + packet.setExtraData(VarInts.readInt(buffer)); + packet.setIdentifier(helper.readString(buffer)); + packet.setBabySound(buffer.readBoolean()); + packet.setRelativeVolumeDisabled(buffer.readBoolean()); + } +} + From 7eb30b514988424f27b8e575d587707269f979c0 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 25 Jun 2020 23:59:30 +0800 Subject: [PATCH 24/70] Temporarily disable contraints (again) to allow working with Geyser for now. --- .../v388/serializer/AvailableCommandsSerializer_v388.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java index 89216363d..6aaf2662a 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java @@ -1,5 +1,6 @@ package com.nukkitx.protocol.bedrock.v388.serializer; +import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.command.*; import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; @@ -19,6 +20,9 @@ public class AvailableCommandsSerializer_v388 extends AvailableCommandsSerialize @Override public void serialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCommandsPacket packet) { super.serialize(buffer, helper, packet); + + // Constraints - @TODO + //helper.writeArray(buffer, packet.getConstraints(), (buf, data) -> helper.writeCommandEnumConstraints(buf, enums, enumValues)); } @Override @@ -92,7 +96,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom flagList, command.getPermission(), aliases, overloads)); } - // Constraints - helper.readArray(buffer, packet.getConstraints(), buf -> helper.readCommandEnumConstraints(buf, enums, enumValues)); + // Constraints - @TODO + //helper.readArray(buffer, packet.getConstraints(), buf -> helper.readCommandEnumConstraints(buf, enums, enumValues)); } } \ No newline at end of file From 7e09d51c0325774855dd7a93e78c882502b768c4 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 13:17:08 +0800 Subject: [PATCH 25/70] Implement Fully Working AvailableCommandsPacket serializer with contraints --- .../protocol/bedrock/BedrockPacketHelper.java | 14 +++- .../command/CommandEnumConstraintData.java | 2 +- .../data/command/CommandSymbolData.java | 2 +- .../AvailableCommandsSerializer_v291.java | 6 +- .../AvailableCommandsSerializer_v388.java | 74 +++++++++++++++++-- .../v407/BedrockPacketHelper_v407.java | 22 ++++++ 6 files changed, 108 insertions(+), 12 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index 33e601bb0..ced36df7f 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -39,11 +39,15 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.OptionalInt; +import java.util.Set; import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; +import java.util.stream.IntStream; import static java.util.Objects.requireNonNull; @@ -558,8 +562,16 @@ public CommandEnumConstraintData readCommandEnumConstraints(ByteBuf buffer, List return new CommandEnumConstraintData( enumValues.get(valueIndex), - enums.get(enumIndex).getName(), + enums.get(enumIndex), constraints ); } + + public void writeCommandEnumConstraints(ByteBuf buffer, CommandEnumConstraintData data, List enums, List enumValues) { + buffer.writeIntLE(enumValues.indexOf(data.getOption())); + buffer.writeIntLE(enums.indexOf(data.getEnumData())); + writeArray(buffer, data.getConstraints(), (buf, constraint) -> { + buf.writeByte(constraint.ordinal()); + }); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java index 66cad8dc1..49a6d01d0 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandEnumConstraintData.java @@ -12,7 +12,7 @@ public class CommandEnumConstraintData { String option; // The name of the enum of which the option above should be constrained. - String name; + CommandEnumData enumData; // List of constraints that should be applied to the enum option. CommandEnumConstraintType[] constraints; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandSymbolData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandSymbolData.java index ee50b8a4a..8cfe53541 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandSymbolData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/command/CommandSymbolData.java @@ -20,7 +20,7 @@ public static CommandSymbolData deserialize(int type) { boolean commandEnum = (type & ARG_FLAG_ENUM) != 0; boolean softEnum = (type & ARG_FLAG_SOFT_ENUM) != 0; boolean postfix = (type & ARG_FLAG_POSTFIX) != 0; - Preconditions.checkState(postfix || (type & ARG_FLAG_VALID) != 0, "Invalid command param type"); + Preconditions.checkState(postfix || (type & ARG_FLAG_VALID) != 0, "Invalid command param type: " + type); return new CommandSymbolData(value, commandEnum, softEnum, postfix); } diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java index f921d4565..ffd305fea 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java @@ -174,7 +174,7 @@ protected void writeEnums(ByteBuf buffer, BedrockPacketHelper helper, List -1, "Invalid enum value detected"); + Preconditions.checkArgument(index > -1, "Invalid enum value detected: " + value); indexWriter.accept(buf, index); } }); @@ -268,7 +268,7 @@ protected void writeParameter(ByteBuf buffer, BedrockPacketHelper helper, Comman } else if (param.getType() != null) { index = helper.getCommandParamId(param.getType()); } else { - throw new IllegalStateException("No param type specified"); + throw new IllegalStateException("No param type specified: " + param); } CommandSymbolData type = new CommandSymbolData(index, enumData, softEnum, postfix); @@ -282,7 +282,7 @@ protected CommandParamData.Builder readParameter(ByteBuf buffer, BedrockPacketHe helper.readString(buffer), CommandSymbolData.deserialize(buffer.readIntLE()), buffer.readBoolean(), - buffer.readByte() + (byte) 0 ); } } \ No newline at end of file diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java index 6aaf2662a..90adb8730 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/AvailableCommandsSerializer_v388.java @@ -1,16 +1,20 @@ package com.nukkitx.protocol.bedrock.v388.serializer; -import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.command.*; import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; import com.nukkitx.protocol.bedrock.v340.serializer.AvailableCommandsSerializer_v340; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class AvailableCommandsSerializer_v388 extends AvailableCommandsSerializer_v340 { @@ -19,10 +23,68 @@ public class AvailableCommandsSerializer_v388 extends AvailableCommandsSerialize @Override public void serialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCommandsPacket packet) { - super.serialize(buffer, helper, packet); + Set enumValuesSet = new ObjectOpenHashSet<>(); + Set postfixSet = new ObjectOpenHashSet<>(); + Set enumsSet = new ObjectOpenHashSet<>(); + Set softEnumsSet = new ObjectOpenHashSet<>(); + + // Get all enum values + for (CommandData data : packet.getCommands()) { + if (data.getAliases() != null) { + Collections.addAll(enumValuesSet, data.getAliases().getValues()); + enumsSet.add(data.getAliases()); + } + + for (CommandParamData[] overload : data.getOverloads()) { + for (CommandParamData parameter : overload) { + CommandEnumData commandEnumData = parameter.getEnumData(); + if (commandEnumData != null) { + if (commandEnumData.isSoft()) { + softEnumsSet.add(commandEnumData); + } else { + Collections.addAll(enumValuesSet, commandEnumData.getValues()); + enumsSet.add(commandEnumData); + } + } + + String postfix = parameter.getPostfix(); + if (postfix != null) { + postfixSet.add(postfix); + } + } + } + } + + // Add Constraint Enums + for(CommandEnumData enumData : packet.getConstraints().stream().map(CommandEnumConstraintData::getEnumData).collect(Collectors.toList())) { + if (enumData.isSoft()) { + softEnumsSet.add(enumData); + } else { + enumsSet.add(enumData); + } + enumValuesSet.addAll(Arrays.asList(enumData.getValues())); + } + + List enumValues = new ObjectArrayList<>(enumValuesSet); + List postFixes = new ObjectArrayList<>(postfixSet); + List enums = new ObjectArrayList<>(enumsSet); + List softEnums = new ObjectArrayList<>(softEnumsSet); + + helper.writeArray(buffer, enumValues, helper::writeString); + helper.writeArray(buffer, postFixes, helper::writeString); + + this.writeEnums(buffer, helper, enumValues, enums); + + helper.writeArray(buffer, packet.getCommands(), (buf, command) -> { + this.writeCommand(buffer, helper, command, enums, softEnums, postFixes); + }); + + helper.writeArray(buffer, softEnums, helper::writeCommandEnum); - // Constraints - @TODO - //helper.writeArray(buffer, packet.getConstraints(), (buf, data) -> helper.writeCommandEnumConstraints(buf, enums, enumValues)); + // Constraints + helper.writeArray(buffer, packet.getConstraints(), (buf, constraint) -> { + helper.writeCommandEnumConstraints(buf, constraint, enums, enumValues); + }); } @Override @@ -96,7 +158,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom flagList, command.getPermission(), aliases, overloads)); } - // Constraints - @TODO - //helper.readArray(buffer, packet.getConstraints(), buf -> helper.readCommandEnumConstraints(buf, enums, enumValues)); + // Constraints + helper.readArray(buffer, packet.getConstraints(), buf -> helper.readCommandEnumConstraints(buf, enums, enumValues)); } } \ No newline at end of file diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java index e84780d9f..09fc0fc15 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java @@ -1,11 +1,15 @@ package com.nukkitx.protocol.bedrock.v407; +import com.nukkitx.protocol.bedrock.data.command.CommandParamType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.v390.BedrockPacketHelper_v390; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import static com.nukkitx.protocol.bedrock.data.command.CommandParamType.*; +import static com.nukkitx.protocol.bedrock.data.command.CommandParamType.TARGET; + @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v407 extends BedrockPacketHelper_v390 { @@ -39,4 +43,22 @@ protected void registerEntityFlags() { this.addEntityFlag(94, EntityFlag.CELEBRATING_SPECIAL); } + @Override + protected void registerCommandParams() { + super.registerCommandParams(); + this.addCommandParam(1, INT); + this.addCommandParam(2, FLOAT); + this.addCommandParam(3, VALUE); + this.addCommandParam(4, WILDCARD_INT); + this.addCommandParam(5, OPERATOR); + this.addCommandParam(6, TARGET); + this.addCommandParam(14, FILE_PATH); + this.addCommandParam(29, STRING); + this.addCommandParam(38, CommandParamType.POSITION); + this.addCommandParam(41, MESSAGE); + this.addCommandParam(43, CommandParamType.TEXT); + this.addCommandParam(47, CommandParamType.JSON); + this.addCommandParam(54, CommandParamType.COMMAND); + } + } From 45a2146cf969b96fc764df109b5a85ca6b29d955 Mon Sep 17 00:00:00 2001 From: Sleepybear Date: Thu, 25 Jun 2020 09:49:55 -0700 Subject: [PATCH 26/70] fix InventoryTransaction --- .../data/inventory/InventoryActionData.java | 9 ++- .../packet/InventoryTransactionPacket.java | 1 + .../InventoryTransactionSerializer_v340.java | 4 +- .../protocol/bedrock/v407/Bedrock_v407.java | 13 ++-- .../InventoryTransactionSerializer_v407.java | 60 ++++++++++++++++++- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/InventoryActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/InventoryActionData.java index 3962ec958..81d12f758 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/InventoryActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/InventoryActionData.java @@ -1,15 +1,22 @@ package com.nukkitx.protocol.bedrock.data.inventory; +import lombok.AllArgsConstructor; import lombok.Value; @Value +@AllArgsConstructor public class InventoryActionData { private final InventorySource source; private final int slot; private final ItemData fromItem; private final ItemData toItem; + private final int stackNetworkId; + + public InventoryActionData(InventorySource source, int slot, ItemData fromItem, ItemData toItem) { + this(source, slot, fromItem, toItem, 0); + } public InventoryActionData reverse() { - return new InventoryActionData(source, slot, toItem, fromItem); + return new InventoryActionData(source, slot, toItem, fromItem, stackNetworkId); } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryTransactionPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryTransactionPacket.java index 9f75d3dee..e60611d45 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryTransactionPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryTransactionPacket.java @@ -31,6 +31,7 @@ public class InventoryTransactionPacket extends BedrockPacket { private Vector3f playerPosition; private Vector3f clickPosition; private Vector3f headPosition; + private boolean hasNetworkIds; /** * Runtime ID of block being picked. * ItemUseInventoryTransaction only diff --git a/bedrock/bedrock-v340/src/main/java/com/nukkitx/protocol/bedrock/v340/serializer/InventoryTransactionSerializer_v340.java b/bedrock/bedrock-v340/src/main/java/com/nukkitx/protocol/bedrock/v340/serializer/InventoryTransactionSerializer_v340.java index eacf3abbb..1d0ffd9e3 100644 --- a/bedrock/bedrock-v340/src/main/java/com/nukkitx/protocol/bedrock/v340/serializer/InventoryTransactionSerializer_v340.java +++ b/bedrock/bedrock-v340/src/main/java/com/nukkitx/protocol/bedrock/v340/serializer/InventoryTransactionSerializer_v340.java @@ -16,13 +16,13 @@ public class InventoryTransactionSerializer_v340 extends InventoryTransactionSer public void readItemUse(ByteBuf buffer, BedrockPacketHelper helper, InventoryTransactionPacket packet) { super.readItemUse(buffer, helper, packet); - VarInts.writeUnsignedInt(buffer, packet.getBlockRuntimeId()); + packet.setBlockRuntimeId(VarInts.readUnsignedInt(buffer)); } @Override public void writeItemUse(ByteBuf buffer, BedrockPacketHelper helper, InventoryTransactionPacket packet) { super.writeItemUse(buffer, helper, packet); - packet.setBlockRuntimeId(VarInts.readUnsignedInt(buffer)); + VarInts.writeUnsignedInt(buffer, packet.getBlockRuntimeId()); } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java index f57f34e04..e499bf945 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/Bedrock_v407.java @@ -3,9 +3,14 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v291.serializer.*; -import com.nukkitx.protocol.bedrock.v313.serializer.*; -import com.nukkitx.protocol.bedrock.v332.serializer.*; -import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; +import com.nukkitx.protocol.bedrock.v313.serializer.AddEntitySerializer_v313; +import com.nukkitx.protocol.bedrock.v313.serializer.AvailableEntityIdentifiersSerializer_v313; +import com.nukkitx.protocol.bedrock.v313.serializer.BiomeDefinitionListSerializer_v313; +import com.nukkitx.protocol.bedrock.v313.serializer.NetworkChunkPublisherUpdateSerializer_v313; +import com.nukkitx.protocol.bedrock.v332.serializer.NetworkStackLatencySerializer_v332; +import com.nukkitx.protocol.bedrock.v332.serializer.ResourcePacksInfoSerializer_v332; +import com.nukkitx.protocol.bedrock.v332.serializer.SpawnParticleEffectSerializer_v332; +import com.nukkitx.protocol.bedrock.v332.serializer.TextSerializer_v332; import com.nukkitx.protocol.bedrock.v354.serializer.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; import com.nukkitx.protocol.bedrock.v388.serializer.*; @@ -48,7 +53,7 @@ public class Bedrock_v407 { .registerPacket(EntityEventPacket.class, EntityEventSerializer_v291.INSTANCE, 27) .registerPacket(MobEffectPacket.class, MobEffectSerializer_v291.INSTANCE, 28) .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v291.INSTANCE, 29) - .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v340.INSTANCE, 30) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v407.INSTANCE, 30) .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v291.INSTANCE, 31) .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v291.INSTANCE, 32) .registerPacket(InteractPacket.class, InteractSerializer_v388.INSTANCE, 33) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java index c8cffffb5..c5d45669b 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java @@ -2,7 +2,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; -import com.nukkitx.protocol.bedrock.data.inventory.LegacySetItemSlotData; +import com.nukkitx.protocol.bedrock.data.inventory.*; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; import io.netty.buffer.ByteBuf; @@ -13,6 +13,7 @@ public class InventoryTransactionSerializer_v407 extends InventoryTransactionSerializer_v340 { public static final InventoryTransactionSerializer_v407 INSTANCE = new InventoryTransactionSerializer_v407(); + private boolean hasNetworkIds; @Override public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryTransactionPacket packet) { int legacyRequestId = packet.getLegacyRequestId(); @@ -25,7 +26,23 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryTrans }); } - super.serialize(buffer, helper, packet); + TransactionType transactionType = packet.getTransactionType(); + VarInts.writeUnsignedInt(buffer, transactionType.ordinal()); + + //buffer.writeBoolean(packet.isHasNetworkIds()); + helper.writeArray(buffer, packet.getActions(), this::writeAction); + + switch (transactionType) { + case ITEM_USE: + this.writeItemUse(buffer, helper, packet); + break; + case ITEM_USE_ON_ENTITY: + this.writeItemUseOnEntity(buffer, helper, packet); + break; + case ITEM_RELEASE: + this.writeItemRelease(buffer, helper, packet); + break; + } } @Override @@ -41,6 +58,43 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryTra }); } - super.deserialize(buffer, helper, packet); + TransactionType transactionType = TransactionType.values()[VarInts.readUnsignedInt(buffer)]; + packet.setTransactionType(transactionType); + hasNetworkIds = buffer.readBoolean(); + packet.setHasNetworkIds(hasNetworkIds); + helper.readArray(buffer, packet.getActions(), this::readAction); + + switch (transactionType) { + case ITEM_USE: + this.readItemUse(buffer, helper, packet); + break; + case ITEM_USE_ON_ENTITY: + this.readItemUseOnEntity(buffer, helper, packet); + break; + case ITEM_RELEASE: + this.readItemRelease(buffer, helper, packet); + break; + } + } + + @Override + public InventoryActionData readAction(ByteBuf buffer, BedrockPacketHelper helper) { + InventorySource source = this.readSource(buffer); + int slot = VarInts.readUnsignedInt(buffer); + ItemData fromItem = helper.readItem(buffer); + ItemData toItem = helper.readItem(buffer); + int networkStackId = 0; + if (hasNetworkIds) { + networkStackId = VarInts.readInt(buffer); + } + return new InventoryActionData(source, slot, fromItem, toItem, networkStackId); + } + + @Override + public void writeAction(ByteBuf buffer, BedrockPacketHelper helper, InventoryActionData action) { + super.writeAction(buffer, helper, action); + if (hasNetworkIds) { + VarInts.writeInt(buffer, action.getStackNetworkId()); + } } } From bb03608cc3bdb72283a6a0bd51550d3c4b8db0a8 Mon Sep 17 00:00:00 2001 From: Sleepybear Date: Thu, 25 Jun 2020 10:23:45 -0700 Subject: [PATCH 27/70] fix ContainerType enum --- .../nukkitx/protocol/bedrock/data/inventory/ContainerType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerType.java index f827649ed..14dacadb8 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerType.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ContainerType.java @@ -47,7 +47,7 @@ public enum ContainerType { static { ContainerType[] types = values(); - int arrayLength = types[types.length - 1].id + 9; + int arrayLength = types[types.length - 1].id + 9 + 1; VALUES = new ContainerType[arrayLength]; for (ContainerType type : types) { From a5605681de472e958d84072c4a49f25b9ea15c45 Mon Sep 17 00:00:00 2001 From: Sleepybear Date: Thu, 25 Jun 2020 18:37:45 -0700 Subject: [PATCH 28/70] Update TextPacket info --- .../com/nukkitx/protocol/bedrock/packet/TextPacket.java | 3 ++- .../bedrock/v332/serializer/TextSerializer_v332.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/TextPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/TextPacket.java index ec9b416e1..75958239d 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/TextPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/TextPacket.java @@ -39,6 +39,7 @@ public enum Type { SYSTEM, WHISPER, ANNOUNCEMENT, - JSON + OBJECT, + OBJECT_WHISPER } } diff --git a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/TextSerializer_v332.java b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/TextSerializer_v332.java index 6f7fa9bc1..a1a6d19fd 100644 --- a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/TextSerializer_v332.java +++ b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/TextSerializer_v332.java @@ -25,7 +25,8 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, TextPacket pac case RAW: case TIP: case SYSTEM: - case JSON: + case OBJECT: + case OBJECT_WHISPER: helper.writeString(buffer, packet.getMessage()); break; case TRANSLATION: @@ -56,7 +57,8 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, TextPacket p case RAW: case TIP: case SYSTEM: - case JSON: + case OBJECT: + case OBJECT_WHISPER: packet.setMessage(helper.readString(buffer)); break; case TRANSLATION: From 42176a40fad07e4ffa1a968130c5c0d64788d485 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 13:45:42 +0800 Subject: [PATCH 29/70] Write hasNetworkIds to InventoryTransaction --- .../v407/serializer/InventoryTransactionSerializer_v407.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java index c5d45669b..144cbb4e6 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventoryTransactionSerializer_v407.java @@ -29,7 +29,7 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, InventoryTrans TransactionType transactionType = packet.getTransactionType(); VarInts.writeUnsignedInt(buffer, transactionType.ordinal()); - //buffer.writeBoolean(packet.isHasNetworkIds()); + buffer.writeBoolean(packet.isHasNetworkIds()); helper.writeArray(buffer, packet.getActions(), this::writeAction); switch (transactionType) { From 3a7fa5f065c00810f0b93304e95aa78f7938538b Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 13:46:42 +0800 Subject: [PATCH 30/70] Fix PlayerSkinSerializer_v390 --- .../bedrock/v390/serializer/PlayerSkinSerializer_v390.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bedrock/bedrock-v390/src/main/java/com/nukkitx/protocol/bedrock/v390/serializer/PlayerSkinSerializer_v390.java b/bedrock/bedrock-v390/src/main/java/com/nukkitx/protocol/bedrock/v390/serializer/PlayerSkinSerializer_v390.java index f3e8b74e1..2fdf78f85 100644 --- a/bedrock/bedrock-v390/src/main/java/com/nukkitx/protocol/bedrock/v390/serializer/PlayerSkinSerializer_v390.java +++ b/bedrock/bedrock-v390/src/main/java/com/nukkitx/protocol/bedrock/v390/serializer/PlayerSkinSerializer_v390.java @@ -20,7 +20,7 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, PlayerSkinPack @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, PlayerSkinPacket packet) { - super.serialize(buffer, helper, packet); + super.deserialize(buffer, helper, packet); if (buffer.isReadable()) packet.setTrustedSkin(buffer.readBoolean()); } From 503f3fb93a5e8063636d45b41a5521d6c7e88b5e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Fri, 26 Jun 2020 01:51:56 -0400 Subject: [PATCH 31/70] Entity metadata fixes (#2) - Reintroduce @ToString on Entity Flags - Add a super method where needed --- .../com/nukkitx/protocol/bedrock/data/entity/EntityFlags.java | 2 ++ .../nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityFlags.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityFlags.java index 0e7759168..4e8fa902c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityFlags.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityFlags.java @@ -6,9 +6,11 @@ import io.netty.util.internal.logging.InternalLoggerFactory; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; +import lombok.ToString; import javax.annotation.Nonnull; +@ToString public class EntityFlags { private static final InternalLogger log = InternalLoggerFactory.getInstance(EntityFlags.class); diff --git a/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java b/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java index ab78b5a74..93cc96aca 100644 --- a/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java +++ b/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java @@ -17,6 +17,8 @@ public class BedrockPacketHelper_v354 extends BedrockPacketHelper_v340 { @Override protected void registerEntityData() { + super.registerEntityData(); + this.addEntityData(102, TRADE_XP); } From da89a63a86c63fbbf500b204c6ca0fd2f50e5c32 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 14:46:10 +0800 Subject: [PATCH 32/70] Clean up StartGamePacket with new variable names --- .../protocol/bedrock/data/SpawnBiomeType.java | 15 ++++++ .../bedrock/packet/StartGamePacket.java | 11 +++-- .../serializer/StartGameSerializer_v407.java | 47 ++++++------------- 3 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/SpawnBiomeType.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/SpawnBiomeType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/SpawnBiomeType.java new file mode 100644 index 000000000..2b1991cf8 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/SpawnBiomeType.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data; + +public enum SpawnBiomeType { + DEFAULT, + USER_DEFINED; + + private static final SpawnBiomeType[] VALUES = values(); + + public static SpawnBiomeType byId(int id) { + if (id >= 0 && id < VALUES.length) { + return VALUES[id]; + } + throw new UnsupportedOperationException("Unknown SpawnBiomeType ID: " + id); + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/StartGamePacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/StartGamePacket.java index 984927ddc..b5fcd9d2c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/StartGamePacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/StartGamePacket.java @@ -11,6 +11,7 @@ import com.nukkitx.protocol.bedrock.data.GameRuleData; import com.nukkitx.protocol.bedrock.data.GameType; import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.data.SpawnBiomeType; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -36,6 +37,8 @@ public class StartGamePacket extends BedrockPacket { private Vector2f rotation; // Level settings start private int seed; + private SpawnBiomeType spawnBiomeType = SpawnBiomeType.DEFAULT; + private String customBiomeName = ""; private int dimensionId; private int generatorId; private GameType levelGameType; @@ -45,7 +48,7 @@ public class StartGamePacket extends BedrockPacket { private int dayCycleStopTime; private int eduEditionOffers; private boolean eduFeaturesEnabled; - private String unknownString0; + private String educationProductionId = ""; private float rainLevel; private float lightningLevel; private boolean platformLockedContentConfirmed; @@ -68,8 +71,10 @@ public class StartGamePacket extends BedrockPacket { private boolean worldTemplateOptionLocked; private boolean onlySpawningV1Villagers; private String vanillaVersion; - private int unknownInt0; - private int unknownInt1; + private int limitedWorldWidth; + private int limitedWorldHeight; + private boolean netherType; + private boolean forceExperimentalGameplay; // Level settings end private String levelId; private String levelName; diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java index 15acfe5c4..2f3df8f0a 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/StartGameSerializer_v407.java @@ -11,6 +11,7 @@ import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameType; import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.data.SpawnBiomeType; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; @@ -36,12 +37,8 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke helper.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); - - //@Todo - buffer.writeByte(0); - buffer.writeByte(0); - helper.writeString(buffer, "plains"); - + buffer.writeShortLE(packet.getSpawnBiomeType().ordinal()); + helper.writeString(buffer, packet.getCustomBiomeName()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGameType().ordinal()); @@ -51,13 +48,10 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke VarInts.writeInt(buffer, packet.getDayCycleStopTime()); VarInts.writeInt(buffer, packet.getEduEditionOffers()); buffer.writeBoolean(packet.isEduFeaturesEnabled()); -// helper.writeString(buffer, packet.getUnknownString0()); + helper.writeString(buffer, packet.getEducationProductionId()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); - //@Todo - buffer.writeByte(0); - buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); buffer.writeBoolean(packet.isMultiplayerGame()); buffer.writeBoolean(packet.isBroadcastingToLan()); @@ -78,12 +72,10 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); helper.writeString(buffer, packet.getVanillaVersion()); - buffer.writeIntLE(packet.getUnknownInt0()); - buffer.writeIntLE(packet.getUnknownInt1()); - - // @Todo - buffer.writeByte(0); - buffer.writeByte(0); + buffer.writeIntLE(packet.getLimitedWorldWidth()); + buffer.writeIntLE(packet.getLimitedWorldHeight()); + buffer.writeBoolean(packet.isNetherType()); + buffer.writeBoolean(packet.isForceExperimentalGameplay()); // Level settings end helper.writeString(buffer, packet.getLevelId()); @@ -120,12 +112,8 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setRotation(helper.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); - - //@Todo - buffer.readByte(); // 0 - buffer.readByte(); // 0 - helper.readString(buffer); // plains - + packet.setSpawnBiomeType(SpawnBiomeType.byId(buffer.readShortLE())); + packet.setCustomBiomeName(helper.readString(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGameType(GameType.from(VarInts.readInt(buffer))); @@ -135,13 +123,10 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setDayCycleStopTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(VarInts.readInt(buffer)); packet.setEduFeaturesEnabled(buffer.readBoolean()); -// packet.setUnknownString0(helper.readString(buffer)); + packet.setEducationProductionId(helper.readString(buffer)); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); - //@Todo - buffer.readByte(); // 0 - packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); @@ -162,12 +147,10 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setWorldTemplateOptionLocked(buffer.readBoolean()); packet.setOnlySpawningV1Villagers(buffer.readBoolean()); packet.setVanillaVersion(helper.readString(buffer)); - packet.setUnknownInt0(buffer.readIntLE()); - packet.setUnknownInt1(buffer.readIntLE()); - - // @Todo - buffer.readByte(); // 0 - buffer.readByte(); // 0 + packet.setLimitedWorldWidth(buffer.readIntLE()); + packet.setLimitedWorldHeight(buffer.readIntLE()); + packet.setNetherType(buffer.readBoolean()); + packet.setForceExperimentalGameplay(buffer.readBoolean()); // Level settings end packet.setLevelId(helper.readString(buffer)); From b0a53ba8ee54f9ff6fb748c665fb596b72a6f889 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 14:46:49 +0800 Subject: [PATCH 33/70] More debugging. This will catch exceptions that geyser seems to suppress for serializing packets. --- .../com/nukkitx/protocol/bedrock/BedrockPacketCodec.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index e4717da71..e6486d85e 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -41,6 +41,7 @@ public static Builder builder() { return new Builder(); } + //@TODO Remove Debugging private void dumpPacket(ByteBuf buf, BedrockPacket packet) { byte[] dupeBytes = new byte[buf.readableBytes()]; buf.readBytes(dupeBytes); @@ -98,11 +99,13 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept serializer.deserialize(buf, this.helper, packet); } catch (Exception e) { + //@TODO Remove Debugging dumpPacket(dupe, packet); throw new PacketSerializeException("Error whilst deserializing " + packet, e); } if (log.isDebugEnabled() && buf.isReadable()) { + //@TODO Remove Debugging dumpPacket(dupe, packet); log.debug(packet.getClass().getSimpleName() + " still has " + buf.readableBytes() + " bytes to read!"); } @@ -121,6 +124,8 @@ public void tryEncode(ByteBuf buf, BedrockPacket packet) throws PacketSerializeE } serializer.serialize(buf, this.helper, packet); } catch (Exception e) { + //@TODO Remove Debugging + e.printStackTrace(); throw new PacketSerializeException("Error whilst serializing " + packet, e); } finally { ReferenceCountUtil.release(packet); From 78b1928760fe7b8d2b735010056696a795ae72e8 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 14:52:08 +0800 Subject: [PATCH 34/70] Fix suppresed NPE with AdventureSettingsPacket --- .../protocol/bedrock/packet/AdventureSettingsPacket.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java index 592c62374..ea406a679 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java @@ -16,8 +16,8 @@ @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class AdventureSettingsPacket extends BedrockPacket { private final Set settings = new ObjectOpenHashSet<>(); - private CommandPermission commandPermission; - private PlayerPermission playerPermission; + private CommandPermission commandPermission = CommandPermission.NORMAL; + private PlayerPermission playerPermission = PlayerPermission.VISITOR; private long uniqueEntityId; @Override From 49d11ff52bd53c066ba6445c696b906d98398084 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 15:03:06 +0800 Subject: [PATCH 35/70] Fix NPE for missing entityEvent --- .../com/nukkitx/protocol/bedrock/BedrockPacketHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index ced36df7f..a1b2ca045 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -105,6 +105,11 @@ protected final void addLevelEvent(int index, LevelEventType levelEventType) { } public final int getEntityEventId(EntityEventType type) { + // @TODO For speed we may want a flag that disables this check for production use + if (!this.entityEvents.containsValue(type)) { + log.debug("Unknown EntityEventType: ", type); + return this.entityEvents.get(EntityEventType.NONE); + } return this.entityEvents.get(type); } From 0e54d6078e65953311b4d643077a38bee74b9bbf Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 15:14:06 +0800 Subject: [PATCH 36/70] Provide default spawnPosition --- .../java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java | 1 + .../nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index e6486d85e..e8afb1956 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -125,6 +125,7 @@ public void tryEncode(ByteBuf buf, BedrockPacket packet) throws PacketSerializeE serializer.serialize(buf, this.helper, packet); } catch (Exception e) { //@TODO Remove Debugging + System.err.println("Error whilst serializing " + packet); e.printStackTrace(); throw new PacketSerializeException("Error whilst serializing " + packet, e); } finally { diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java index b887f27f5..ee7575d39 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/SetSpawnPositionPacket.java @@ -26,7 +26,7 @@ public class SetSpawnPositionPacket extends BedrockPacket { // SpawnPosition is a new field added in 1.16. It holds the spawn position of the world. This spawn // position is {-2147483648, -2147483648, -2147483648} for a default spawn position. - private Vector3i spawnPosition; + private Vector3i spawnPosition = Vector3i.from(-2147483648, -2147483648, -2147483648); @Deprecated private boolean spawnForced; From aa103bd57e8a9aa81c0157a4e1b5bc3fb092792b Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 15:32:31 +0800 Subject: [PATCH 37/70] Log missing EntityEvent, LevelEvent and SoundEvents --- .../protocol/bedrock/BedrockPacketHelper.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index a1b2ca045..c492ce3ba 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -107,17 +107,26 @@ protected final void addLevelEvent(int index, LevelEventType levelEventType) { public final int getEntityEventId(EntityEventType type) { // @TODO For speed we may want a flag that disables this check for production use if (!this.entityEvents.containsValue(type)) { - log.debug("Unknown EntityEventType: ", type); + log.debug("Unknown EntityEventType: {}", type); return this.entityEvents.get(EntityEventType.NONE); } return this.entityEvents.get(type); } public final EntityEventType getEntityEvent(int id) { + // @TODO For speed we may want a flag that disables this check for production use + if (!entityEvents.containsKey(id)) { + log.debug("Unknown EntityEvent: {}", id); + return EntityEventType.NONE; + } return this.entityEvents.get(id); } public final int getSoundEventId(SoundEvent event) { + if (!soundEvents.containsValue(event)) { + log.debug("Unknown SoundEvent {} received", event); + return soundEvents.get(SoundEvent.UNDEFINED); + } return this.soundEvents.get(event); } @@ -131,6 +140,11 @@ public final SoundEvent getSoundEvent(int id) { } public final int getLevelEventId(LevelEventType event) { + // @TODO For speed we may want a flag that disables this check for production use + if (!this.levelEvents.containsValue(event)) { + log.debug("Unknown LevelEventType: {}", event); + return this.levelEvents.get(LevelEventType.UNDEFINED); + } return this.levelEvents.get(event); } From 4c7bd5a9ad0d65c72f4b88273b58365080b8c9d6 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Fri, 26 Jun 2020 19:36:08 +0800 Subject: [PATCH 38/70] Fix SetEntityLinkPacket --- .../bedrock/data/entity/EntityLinkData.java | 19 +++++++++++- .../v407/BedrockPacketHelper_v407.java | 29 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityLinkData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityLinkData.java index 28d55bdd0..9e026f645 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityLinkData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/entity/EntityLinkData.java @@ -1,17 +1,34 @@ package com.nukkitx.protocol.bedrock.data.entity; +import lombok.AllArgsConstructor; import lombok.Value; @Value +@AllArgsConstructor public class EntityLinkData { private final long from; private final long to; private final Type type; private final boolean immediate; + private final boolean riderInitiated; + + @Deprecated + public EntityLinkData(long from, long to, Type type, boolean immediate) { + this(from, to, type, immediate, false); + } public enum Type { REMOVE, RIDER, - PASSENGER + PASSENGER; + + private static final Type[] VALUES = values(); + + public static Type byId(int id) { + if (id >= 0 && id < VALUES.length) { + return VALUES[id]; + } + throw new UnsupportedOperationException("Unknown EntityLinkData.Type ID: " + id); + } } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java index 09fc0fc15..50787e864 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java @@ -1,9 +1,13 @@ package com.nukkitx.protocol.bedrock.v407; +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; import com.nukkitx.protocol.bedrock.data.command.CommandParamType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; +import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData; import com.nukkitx.protocol.bedrock.v390.BedrockPacketHelper_v390; +import io.netty.buffer.ByteBuf; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -61,4 +65,29 @@ protected void registerCommandParams() { this.addCommandParam(54, CommandParamType.COMMAND); } + @Override + public EntityLinkData readEntityLink(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "buffer"); + + return new EntityLinkData( + VarInts.readLong(buffer), + VarInts.readLong(buffer), + EntityLinkData.Type.byId(buffer.readUnsignedByte()), + buffer.readBoolean(), + buffer.readBoolean() + ); + } + + @Override + public void writeEntityLink(ByteBuf buffer, EntityLinkData entityLink) { + Preconditions.checkNotNull(buffer, "buffer"); + Preconditions.checkNotNull(entityLink, "entityLink"); + + VarInts.writeLong(buffer, entityLink.getFrom()); + VarInts.writeLong(buffer, entityLink.getTo()); + buffer.writeByte(entityLink.getType().ordinal()); + buffer.writeBoolean(entityLink.isImmediate()); + buffer.writeBoolean(entityLink.isRiderInitiated()); + } + } From 8946ef7279b89d09a2eb363f3c3959ec80d5af80 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Fri, 26 Jun 2020 17:07:16 -0800 Subject: [PATCH 39/70] Sort InventoryContentPacket entry map --- .../protocol/bedrock/packet/InventoryContentPacket.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java index 172f3206c..7a0ee0134 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/InventoryContentPacket.java @@ -4,15 +4,15 @@ import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class InventoryContentPacket extends BedrockPacket { - private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); + private final Int2ObjectSortedMap entries = new Int2ObjectRBTreeMap<>(); private int containerId; @Override From eacc81a40d63ba78136e7d419efcc665aae1d61b Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Fri, 26 Jun 2020 17:21:51 -0800 Subject: [PATCH 40/70] Fix v407 InventorySlotSerializer --- .../bedrock/v407/serializer/InventorySlotSerializer_v407.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java index c201a8870..6bc09af57 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/InventorySlotSerializer_v407.java @@ -14,17 +14,17 @@ public class InventorySlotSerializer_v407 implements BedrockPacketSerializer Date: Sat, 27 Jun 2020 11:32:06 +0800 Subject: [PATCH 41/70] Add missing CommandParamTypes - WILDCARD_TARGET, BLOCK_POSITION --- .../bedrock/v407/BedrockPacketHelper_v407.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java index 50787e864..9dfe08487 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java @@ -49,20 +49,21 @@ protected void registerEntityFlags() { @Override protected void registerCommandParams() { - super.registerCommandParams(); this.addCommandParam(1, INT); this.addCommandParam(2, FLOAT); this.addCommandParam(3, VALUE); this.addCommandParam(4, WILDCARD_INT); this.addCommandParam(5, OPERATOR); this.addCommandParam(6, TARGET); + this.addCommandParam(7, WILDCARD_TARGET); this.addCommandParam(14, FILE_PATH); this.addCommandParam(29, STRING); - this.addCommandParam(38, CommandParamType.POSITION); + this.addCommandParam(37, BLOCK_POSITION); + this.addCommandParam(38, POSITION); this.addCommandParam(41, MESSAGE); - this.addCommandParam(43, CommandParamType.TEXT); - this.addCommandParam(47, CommandParamType.JSON); - this.addCommandParam(54, CommandParamType.COMMAND); + this.addCommandParam(43, TEXT); + this.addCommandParam(47, JSON); + this.addCommandParam(54, COMMAND); } @Override From f0f2ea08521d5ab1c9b64c473338c36cb38753c3 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 27 Jun 2020 13:34:06 +0800 Subject: [PATCH 42/70] Temporarily store a packets bytes to a raw field to aid in debugging binary compatiblity A modified proxypass will grab this and compare against a re-encoded packet. --- .../protocol/bedrock/BedrockPacket.java | 5 +++ .../protocol/bedrock/BedrockPacketCodec.java | 43 ++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java index 404b0f672..384bbb1cb 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.MinecraftPacket; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; +import lombok.ToString; @Data public abstract class BedrockPacket implements MinecraftPacket { @@ -10,6 +11,10 @@ public abstract class BedrockPacket implements MinecraftPacket { private int senderId; private int clientId; + // @TODO Remove Debugging + @ToString.Exclude + private byte[] raw; + public abstract boolean handle(BedrockPacketHandler handler); public abstract BedrockPacketType getPacketType(); diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index e8afb1956..ba7cd7650 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -41,44 +41,45 @@ public static Builder builder() { return new Builder(); } - //@TODO Remove Debugging - private void dumpPacket(ByteBuf buf, BedrockPacket packet) { - byte[] dupeBytes = new byte[buf.readableBytes()]; - buf.readBytes(dupeBytes); - - System.err.println(packet); + // @TODO Remove Debugging + public void dumpBytes(File file, byte[] bytes) { StringBuilder b = new StringBuilder(); - for(int i=0;i= 'a' && c <= 'z') || (c >= 'A' && c<= 'Z') || (c >= '0' && c<= '9')) { - b.append((char)dupeBytes[i]); + b.append((char)bytes[i]); } else { b.append("."); } b.append(" "); } - File debugFile = new File(packet.getClass().getSimpleName() + ".txt"); - try (PrintStream out = new PrintStream(new FileOutputStream(debugFile))) { + try (PrintStream out = new PrintStream(new FileOutputStream(file))) { out.println(b.toString()); } catch (FileNotFoundException fileNotFoundException) { fileNotFoundException.printStackTrace(); } } + private byte[] byteBufToByteArray(ByteBuf buf) { + byte[] bytes = new byte[buf.readableBytes()]; + buf.duplicate().readBytes(bytes); + return bytes; + } + public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeException { BedrockPacket packet; BedrockPacketSerializer serializer; @@ -94,19 +95,21 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept throw new PacketSerializeException("Packet ID " + id + " does not exist", e); } - ByteBuf dupe = buf.duplicate(); + // @TODO Remove Debugging + packet.setRaw(byteBufToByteArray(buf)); // For those watching, this is used in ProxyPass to compare in and out bytes try { - serializer.deserialize(buf, this.helper, packet); } catch (Exception e) { - //@TODO Remove Debugging - dumpPacket(dupe, packet); + // @TODO Remove Debugging + System.err.println("tryDecode(): Unable to serialize " + packet); + e.printStackTrace(); + dumpBytes(new File(packet.getClass().getSimpleName() + ".txt"), packet.getRaw()); throw new PacketSerializeException("Error whilst deserializing " + packet, e); } if (log.isDebugEnabled() && buf.isReadable()) { - //@TODO Remove Debugging - dumpPacket(dupe, packet); + // @TODO Remove Debugging + dumpBytes(new File(packet.getClass().getSimpleName() + ".txt"), packet.getRaw()); log.debug(packet.getClass().getSimpleName() + " still has " + buf.readableBytes() + " bytes to read!"); } return packet; @@ -124,7 +127,7 @@ public void tryEncode(ByteBuf buf, BedrockPacket packet) throws PacketSerializeE } serializer.serialize(buf, this.helper, packet); } catch (Exception e) { - //@TODO Remove Debugging + // @TODO Remove Debugging - Needed because Geyser suppresses this exception System.err.println("Error whilst serializing " + packet); e.printStackTrace(); throw new PacketSerializeException("Error whilst serializing " + packet, e); From 036a8c8e6e826829cd88d1c37f8a0268bbbc03f0 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 27 Jun 2020 15:28:31 +0800 Subject: [PATCH 43/70] Provide Binary Compatibility for AdventureSettingsPacket, AddPlayerPacket --- .../protocol/bedrock/packet/AdventureSettingsPacket.java | 4 ++-- .../protocol/bedrock/v361/BedrockPacketHelper_v361.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java index ea406a679..e6aacd68c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/AdventureSettingsPacket.java @@ -6,7 +6,7 @@ import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.data.command.CommandPermission; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import lombok.Data; import lombok.EqualsAndHashCode; @@ -15,7 +15,7 @@ @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class AdventureSettingsPacket extends BedrockPacket { - private final Set settings = new ObjectOpenHashSet<>(); + private final Set settings = new ObjectLinkedOpenHashSet<>(); private CommandPermission commandPermission = CommandPermission.NORMAL; private PlayerPermission playerPermission = PlayerPermission.VISITOR; private long uniqueEntityId; diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index a26358eaa..6969edbde 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -25,7 +25,9 @@ import lombok.NoArgsConstructor; import java.io.IOException; +import java.util.Comparator; import java.util.Map; +import java.util.stream.Collectors; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v361 extends BedrockPacketHelper_v354 { @@ -131,7 +133,9 @@ public void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) { VarInts.writeUnsignedInt(buffer, entityDataMap.size()); - for (Map.Entry entry : entityDataMap.entrySet()) { + for (Map.Entry entry : entityDataMap.entrySet().stream() + .sorted(Comparator.comparingInt(o -> entityData.get(o.getKey()))) + .collect(Collectors.toList())) { int index = buffer.writerIndex(); VarInts.writeUnsignedInt(buffer, this.entityData.get(entry.getKey())); Object object = entry.getValue(); From c3211fce656a044cce48ce5d9fa48b30068acb02 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 27 Jun 2020 17:25:22 +0800 Subject: [PATCH 44/70] Retain Sorting for CreativeContentPacket --- .../protocol/bedrock/packet/CreativeContentPacket.java | 7 ++++--- .../v407/serializer/CreativeContentSerializer_v407.java | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java index 59607116e..fe2de7fb8 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/CreativeContentPacket.java @@ -4,11 +4,12 @@ import com.nukkitx.protocol.bedrock.BedrockPacketType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.Map; + /** * CreativeContent is a packet sent by the server to set the creative inventory's content for a player. @@ -21,7 +22,7 @@ public class CreativeContentPacket extends BedrockPacket { /** * Item entries for the creative menu. Each item must have a unique ID for the net ID manager */ - private final Int2ObjectMap entries = new Int2ObjectOpenHashMap<>(); + private final Map entries = new Int2ObjectLinkedOpenHashMap<>(); @Override public boolean handle(BedrockPacketHandler handler) { diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java index e83e6c03c..d57ce8a64 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/CreativeContentSerializer_v407.java @@ -6,10 +6,11 @@ import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.packet.CreativeContentPacket; import io.netty.buffer.ByteBuf; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Map; + @NoArgsConstructor(access = AccessLevel.PROTECTED) public class CreativeContentSerializer_v407 implements BedrockPacketSerializer { @@ -18,15 +19,15 @@ public class CreativeContentSerializer_v407 implements BedrockPacketSerializer entry : packet.getEntries().int2ObjectEntrySet()) { - VarInts.writeInt(buffer, entry.getIntKey()); + for (Map.Entry entry : packet.getEntries().entrySet()) { + VarInts.writeInt(buffer, entry.getKey()); helper.writeItem(buffer, entry.getValue()); } } @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CreativeContentPacket packet) { - Int2ObjectMap entries = packet.getEntries(); + Map entries = packet.getEntries(); int count = VarInts.readUnsignedInt(buffer); for (int i = 0; i < count; i++) { From 61c0a1554244148e09ae64c9c6f1a70a3cf4a67e Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 27 Jun 2020 19:44:16 +0800 Subject: [PATCH 45/70] Fix EventSerializer_v291 to properly serialize --- .../bedrock/v291/serializer/EventSerializer_v291.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java index cc2265fbf..b0f0aabdc 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java @@ -62,11 +62,13 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, EventPacket pa VarInts.writeInt(buffer, eventData.getType().ordinal()); buffer.writeByte(packet.getUsePlayerId()); - BiFunction function = this.readers.get(eventData.getType()); + TriConsumer function = this.writers.get(eventData.getType()); if (function == null) { throw new UnsupportedOperationException("Unknown event type " + eventData.getType()); } + + function.accept(buffer, helper, eventData); } @Override From d765fdaf9842976fcafe1164c4f245ef1602148c Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 27 Jun 2020 19:57:53 +0800 Subject: [PATCH 46/70] Remove Debugging --- .../protocol/bedrock/BedrockPacket.java | 5 -- .../protocol/bedrock/BedrockPacketCodec.java | 55 ------------------- .../protocol/bedrock/BedrockPacketHelper.java | 4 -- 3 files changed, 64 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java index 384bbb1cb..404b0f672 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacket.java @@ -3,7 +3,6 @@ import com.nukkitx.protocol.MinecraftPacket; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; -import lombok.ToString; @Data public abstract class BedrockPacket implements MinecraftPacket { @@ -11,10 +10,6 @@ public abstract class BedrockPacket implements MinecraftPacket { private int senderId; private int clientId; - // @TODO Remove Debugging - @ToString.Exclude - private byte[] raw; - public abstract boolean handle(BedrockPacketHandler handler); public abstract BedrockPacketType getPacketType(); diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index ba7cd7650..39fe8f400 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -5,7 +5,6 @@ import com.nukkitx.protocol.bedrock.packet.UnknownPacket; import com.nukkitx.protocol.util.Int2ObjectBiMap; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -19,10 +18,6 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.PrintStream; @Immutable @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -41,45 +36,6 @@ public static Builder builder() { return new Builder(); } - // @TODO Remove Debugging - public void dumpBytes(File file, byte[] bytes) { - StringBuilder b = new StringBuilder(); - for(int i=0;i= 'a' && c <= 'z') - || (c >= 'A' && c<= 'Z') - || (c >= '0' && c<= '9')) { - b.append((char)bytes[i]); - } else { - b.append("."); - } - b.append(" "); - } - - try (PrintStream out = new PrintStream(new FileOutputStream(file))) { - out.println(b.toString()); - } catch (FileNotFoundException fileNotFoundException) { - fileNotFoundException.printStackTrace(); - } - } - - private byte[] byteBufToByteArray(ByteBuf buf) { - byte[] bytes = new byte[buf.readableBytes()]; - buf.duplicate().readBytes(bytes); - return bytes; - } - public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeException { BedrockPacket packet; BedrockPacketSerializer serializer; @@ -95,21 +51,13 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept throw new PacketSerializeException("Packet ID " + id + " does not exist", e); } - // @TODO Remove Debugging - packet.setRaw(byteBufToByteArray(buf)); // For those watching, this is used in ProxyPass to compare in and out bytes try { serializer.deserialize(buf, this.helper, packet); } catch (Exception e) { - // @TODO Remove Debugging - System.err.println("tryDecode(): Unable to serialize " + packet); - e.printStackTrace(); - dumpBytes(new File(packet.getClass().getSimpleName() + ".txt"), packet.getRaw()); throw new PacketSerializeException("Error whilst deserializing " + packet, e); } if (log.isDebugEnabled() && buf.isReadable()) { - // @TODO Remove Debugging - dumpBytes(new File(packet.getClass().getSimpleName() + ".txt"), packet.getRaw()); log.debug(packet.getClass().getSimpleName() + " still has " + buf.readableBytes() + " bytes to read!"); } return packet; @@ -127,9 +75,6 @@ public void tryEncode(ByteBuf buf, BedrockPacket packet) throws PacketSerializeE } serializer.serialize(buf, this.helper, packet); } catch (Exception e) { - // @TODO Remove Debugging - Needed because Geyser suppresses this exception - System.err.println("Error whilst serializing " + packet); - e.printStackTrace(); throw new PacketSerializeException("Error whilst serializing " + packet, e); } finally { ReferenceCountUtil.release(packet); diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index c492ce3ba..2b657f99c 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -39,15 +39,11 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.OptionalInt; -import java.util.Set; import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; -import java.util.stream.IntStream; import static java.util.Objects.requireNonNull; From ad6fd219b2fe63f91aa9e2b2104fc19aa667956f Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 10:24:41 +0800 Subject: [PATCH 47/70] Start work on ItemStackRequest Data --- .../inventory/StackRequestActionType.java | 27 +++++++++++++++++++ .../inventory/StackRequestSlotInfoData.java | 17 ++++++++++++ ...AutoCraftRecipeStackRequestActionData.java | 9 +++++++ .../BeaconPaymentStackRequestActionData.java | 13 +++++++++ .../ConsumeStackRequestActionData.java | 8 ++++++ .../CraftCreativeStackRequestActionData.java | 11 ++++++++ ...tNonImplementedStackRequestActionData.java | 9 +++++++ .../CraftRecipeStackRequestActionData.java | 14 ++++++++++ ...sultsDeprecatedStackRequestActionData.java | 15 +++++++++++ .../CreateStackRequestActionData.java | 15 +++++++++++ .../DestroyStackRequestActionData.java | 15 +++++++++++ .../DropStackRequestActionData.java | 20 ++++++++++++++ .../LabTableCombineRequestActionData.java | 7 +++++ .../StackRequestActionData.java | 5 ++++ .../SwapStackRequestActionData.java | 8 ++++++ .../TakeStackRequestActionData.java | 8 ++++++ .../TransferStackRequestActionData.java | 18 +++++++++++++ .../ItemStackRequestSerializer_v407.java | 4 +-- 18 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftNonImplementedStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/LabTableCombineRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/StackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java new file mode 100644 index 000000000..0f070287d --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java @@ -0,0 +1,27 @@ +package com.nukkitx.protocol.bedrock.data.inventory; + +public enum StackRequestActionType { + TAKE, + PLACE, + SWAP, + DROP, + DESTROY, + CONSUME, + CREATE, + LAB_TABLE_COMBINE, + BEACON_PAYMENT, + CRAFT_RECIPE, + CRAFT_RECIPE_AUTO, + CRAFT_CREATIVE, + CRAFT_NON_IMPLEMENTED_DEPRECATED, + CRAFT_RESULTS_DEPRECATED; + + private static final StackRequestActionType[] VALUES = values(); + + public static StackRequestActionType byId(int id) { + if (id >= 0 && id < VALUES.length) { + return VALUES[id]; + } + throw new UnsupportedOperationException("Unknown StackRequestActionType ID: " + id); + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java new file mode 100644 index 000000000..1fa54a428 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java @@ -0,0 +1,17 @@ +package com.nukkitx.protocol.bedrock.data.inventory; + +/** + * Holds information on a specific slot client-side. + */ +public class StackRequestSlotInfoData { + // ContainerId is the ID of the container the slot was in + byte ContainerId; + + // slot is the index of the slot within the container + byte slot; + + // stackNetworkId is the unique stack ID that the client assumes to be present in this slot. The server + // must check if these IDs match. If they do not match, servers should reject the stack request that the + // action holding this info was in. + int stackNetworkId; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java new file mode 100644 index 000000000..10ef0af3f --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java @@ -0,0 +1,9 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * AutoCraftRecipeStackRequestActionData is sent by the client similarly to the CraftRecipeStackRequestActionData. The + * only difference is that the recipe is automatically created and crafted by shift clicking the recipe book. + */ +public class AutoCraftRecipeStackRequestActionData extends CraftRecipeStackRequestActionData { + +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java new file mode 100644 index 000000000..6b6589505 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java @@ -0,0 +1,13 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * BeaconPaymentStackRequestActionData is sent by the client when it submits an item to enable effects from a + * beacon. These items will have been moved into the beacon item slot in advance. + */ +public class BeaconPaymentStackRequestActionData extends StackRequestActionData { + // The primary effect selected in the beacon + int primaryEffect; + + // The secondary effect selected in the beacon + int secondaryEffect; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java new file mode 100644 index 000000000..f1a750fe1 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java @@ -0,0 +1,8 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * ConsumeStackRequestAction is sent by the client when it uses an item to craft another item. The original + * item is 'consumed'. + */ +public class ConsumeStackRequestActionData extends DestroyStackRequestActionData { +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java new file mode 100644 index 000000000..7b83ade2a --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java @@ -0,0 +1,11 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * CraftCreativeStackRequestActionData is sent by the client when it takes an item out of the creative inventory. + * The item is thus not really crafted, but instantly created. + */ +public class CraftCreativeStackRequestActionData extends StackRequestActionData { + // creativeItemNetworkId is the network ID of the creative item that is being created. This is one of the + // creative item network IDs sent in the CreativeContent packet. + int creativeItemNetworkId; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftNonImplementedStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftNonImplementedStackRequestActionData.java new file mode 100644 index 000000000..7383d0272 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftNonImplementedStackRequestActionData.java @@ -0,0 +1,9 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * CraftNonImplementedStackRequestActionData is an action sent for inventory actions that aren't yet implemented + * in the new system. These include, for example, anvils + */ +public class CraftNonImplementedStackRequestActionData extends StackRequestActionData { + +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java new file mode 100644 index 000000000..68662f0aa --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java @@ -0,0 +1,14 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * CraftRecipeStackRequestActionData is sent by the client the moment it begins crafting an item. This is the + * first action sent, before the Consume and Create item stack request actions. + * This action is also sent when an item is enchanted. Enchanting should be treated mostly the same way as + * crafting, where the old item is consumed. + */ +public class CraftRecipeStackRequestActionData extends StackRequestActionData { + // recipeNetworkId is the network ID of the recipe that is about to be crafted. This network ID matches + // one of the recipes sent in the CraftingData packet, where each of the recipes have a RecipeNetworkID as + // of 1.16. + int recipeNetworkId; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java new file mode 100644 index 000000000..9616f7cf0 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; + +/** + * CraftResultsDeprecatedStackRequestAction is an additional, deprecated packet sent by the client after + * crafting. It holds the final results and the amount of times the recipe was crafted. It shouldn't be used. + * This action is also sent when an item is enchanted. Enchanting should be treated mostly the same way as + * crafting, where the old item is consumed. + */ +public class CraftResultsDeprecatedStackRequestActionData extends StackRequestActionData { + ItemData[] resultItems; + + byte timesCrafted; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java new file mode 100644 index 000000000..55d8b4cdf --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * CreateStackRequestActionData is sent by the client when an item is created through being used as part of a + * recipe. For example, when milk is used to craft a cake, the buckets are leftover. The buckets are moved to + * the slot sent by the client here. + * Note that before this is sent, an action for consuming all items in the crafting table/grid is sent. Items + * that are not fully consumed when used for a recipe should not be destroyed there, but instead, should be + * turned into their respective resulting items. + */ +public class CreateStackRequestActionData extends StackRequestActionData { + // The slot to which the results of the crafting ingredients are to be placed + byte slot; + +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java new file mode 100644 index 000000000..c7a969b1d --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + +/** + * DestroyStackRequestActionData is sent by the client when it destroys an item in creative mode by moving it + * back into the creative inventory. + */ +public class DestroyStackRequestActionData extends StackRequestActionData { + // count is the count of items removed from the source slot + byte count; + + // source is the source slot from which items are destroyed + StackRequestSlotInfoData source; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java new file mode 100644 index 000000000..053327d88 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java @@ -0,0 +1,20 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + +/** + * DropStackRequestActionData is sent by the client when it drops an item out of the inventory when it has its + * inventory opened. This action is not sent when a player drops an item out of the hotbar using the Q button + * (or the equivalent on mobile). The InventoryTransaction packet is still used for that action, regardless of + * whether the item stack network IDs are used or not. + */ +public class DropStackRequestActionData extends StackRequestActionData { + // count is the count of items removed from the source slot + byte count; + + // source is the source slot from which items are dropped to the ground + StackRequestSlotInfoData source; + + // ?? Perhaps deals with order of items being dropped? Normally false. + boolean randomly; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/LabTableCombineRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/LabTableCombineRequestActionData.java new file mode 100644 index 000000000..18adf43fd --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/LabTableCombineRequestActionData.java @@ -0,0 +1,7 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * LabTableCombineStackRequestActionData is sent by the client when it uses a lab table to combine item stacks. + */ +public class LabTableCombineRequestActionData extends StackRequestActionData { +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/StackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/StackRequestActionData.java new file mode 100644 index 000000000..6e4ab569f --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/StackRequestActionData.java @@ -0,0 +1,5 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +public class StackRequestActionData { + +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java new file mode 100644 index 000000000..875ec4345 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java @@ -0,0 +1,8 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * SwapStackRequestActionData is sent by the client to swap the item in its cursor with an item present in another + * container. The two item stacks swap places. + */ +public class SwapStackRequestActionData extends TransferStackRequestActionData { +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java new file mode 100644 index 000000000..2f8bb803c --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java @@ -0,0 +1,8 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +/** + * TakeStackRequestActionData is sent by the client to the server to take x amount of items from one slot in a + * container to the cursor. + */ +public class TakeStackRequestActionData extends TransferStackRequestActionData { +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java new file mode 100644 index 000000000..706dc72da --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java @@ -0,0 +1,18 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + +/** + * TransferStackRequestActionData is the structure shared by StackRequestActions that transfer items from one + * slot into another + */ +public class TransferStackRequestActionData extends StackRequestActionData { + // Count of the item in the source slot that was taken towards the destination slot. + byte count; + + // Source from which count of the itemstack is taken + StackRequestSlotInfoData source; + + // Destination to which count of the itemstack is put + StackRequestSlotInfoData destination; +} diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java index 6402574fa..e6756a3f0 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java @@ -77,7 +77,7 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReque @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackRequestPacket packet) { helper.readArray(buffer, packet.getRequests(), buf -> { - int unknownVarInt0 = VarInts.readInt(buf); + int requestId = VarInts.readInt(buf); List actions = new ArrayList<>(); helper.readArray(buf, actions, byteBuf -> { @@ -146,7 +146,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReq return new ItemStackAction(type, bool0, byte0, varInt0, varInt1, baseByte0, baseByte1, baseByte2, baseVarInt0, flagsByte0, flagsByte1, flagsVarInt0, items); }); - return new ItemStackRequestPacket.Request(unknownVarInt0, actions); + return new ItemStackRequestPacket.Request(requestId, actions); }); } } From 05a5c41fb36277cf1718d0b133b59ea6cdcdff62 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 13:05:15 +0800 Subject: [PATCH 48/70] Start work on Deserializing --- ...on.java => ItemStackActionDeprecated.java} | 3 +- .../data/inventory/ItemStackRequestData.java | 18 ++ .../inventory/StackRequestSlotInfoData.java | 3 + ...AutoCraftRecipeStackRequestActionData.java | 3 + .../BeaconPaymentStackRequestActionData.java | 5 + .../ConsumeStackRequestActionData.java | 5 + .../CraftCreativeStackRequestActionData.java | 5 + .../CraftRecipeStackRequestActionData.java | 5 + ...sultsDeprecatedStackRequestActionData.java | 4 + .../CreateStackRequestActionData.java | 5 + .../DestroyStackRequestActionData.java | 4 + .../DropStackRequestActionData.java | 4 + .../PlaceStackRequestActionData.java | 15 ++ .../SwapStackRequestActionData.java | 5 + .../TakeStackRequestActionData.java | 7 + .../TransferStackRequestActionData.java | 6 + .../packet/ItemStackRequestPacket.java | 11 +- .../ItemStackRequestSerializer_v407.java | 220 +++++++++++++----- 18 files changed, 256 insertions(+), 72 deletions(-) rename bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/{ItemStackAction.java => ItemStackActionDeprecated.java} (97%) create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java create mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/PlaceStackRequestActionData.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackAction.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackActionDeprecated.java similarity index 97% rename from bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackAction.java rename to bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackActionDeprecated.java index ca0eff2ea..808b41ba7 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackAction.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackActionDeprecated.java @@ -6,7 +6,8 @@ import java.util.StringJoiner; @Value -public class ItemStackAction { +@Deprecated +public class ItemStackActionDeprecated { private final byte type; private final boolean bool0; private final byte byte0; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java new file mode 100644 index 000000000..1d6dae91e --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java @@ -0,0 +1,18 @@ +package com.nukkitx.protocol.bedrock.data.inventory; + +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; + +/** + * ItemStackRequestData represents a single request present in an ItemStackRequest packet sent by the client to + * change an item in an inventory. + * Item stack requests are either approved or rejected by the server using the ItemStackResponse packet. + */ +public class ItemStackRequestData { + // requestId is a unique ID for the request. This ID is used by the server to send a response for this + // specific request in the ItemStackResponse packet. + int requestId; + + // actions is a list of actions performed by the client. The actual type of the actions depends on which + // ID was present + StackRequestActionData[] actions; +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java index 1fa54a428..7fac686da 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestSlotInfoData.java @@ -1,8 +1,11 @@ package com.nukkitx.protocol.bedrock.data.inventory; +import lombok.Value; + /** * Holds information on a specific slot client-side. */ +@Value public class StackRequestSlotInfoData { // ContainerId is the ID of the container the slot was in byte ContainerId; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java index 10ef0af3f..4dc3f588f 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/AutoCraftRecipeStackRequestActionData.java @@ -6,4 +6,7 @@ */ public class AutoCraftRecipeStackRequestActionData extends CraftRecipeStackRequestActionData { + public AutoCraftRecipeStackRequestActionData(int recipeNetworkId) { + super(recipeNetworkId); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java index 6b6589505..e9aa4e572 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/BeaconPaymentStackRequestActionData.java @@ -1,9 +1,14 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * BeaconPaymentStackRequestActionData is sent by the client when it submits an item to enable effects from a * beacon. These items will have been moved into the beacon item slot in advance. */ +@Getter +@AllArgsConstructor public class BeaconPaymentStackRequestActionData extends StackRequestActionData { // The primary effect selected in the beacon int primaryEffect; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java index f1a750fe1..5df5b9f5e 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/ConsumeStackRequestActionData.java @@ -1,8 +1,13 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + /** * ConsumeStackRequestAction is sent by the client when it uses an item to craft another item. The original * item is 'consumed'. */ public class ConsumeStackRequestActionData extends DestroyStackRequestActionData { + public ConsumeStackRequestActionData(byte count, StackRequestSlotInfoData source) { + super(count, source); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java index 7b83ade2a..9a20a04d2 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftCreativeStackRequestActionData.java @@ -1,9 +1,14 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * CraftCreativeStackRequestActionData is sent by the client when it takes an item out of the creative inventory. * The item is thus not really crafted, but instantly created. */ +@Getter +@AllArgsConstructor public class CraftCreativeStackRequestActionData extends StackRequestActionData { // creativeItemNetworkId is the network ID of the creative item that is being created. This is one of the // creative item network IDs sent in the CreativeContent packet. diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java index 68662f0aa..17cd62c36 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftRecipeStackRequestActionData.java @@ -1,11 +1,16 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * CraftRecipeStackRequestActionData is sent by the client the moment it begins crafting an item. This is the * first action sent, before the Consume and Create item stack request actions. * This action is also sent when an item is enchanted. Enchanting should be treated mostly the same way as * crafting, where the old item is consumed. */ +@Getter +@AllArgsConstructor public class CraftRecipeStackRequestActionData extends StackRequestActionData { // recipeNetworkId is the network ID of the recipe that is about to be crafted. This network ID matches // one of the recipes sent in the CraftingData packet, where each of the recipes have a RecipeNetworkID as diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java index 9616f7cf0..87a4af1e1 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CraftResultsDeprecatedStackRequestActionData.java @@ -1,6 +1,8 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * CraftResultsDeprecatedStackRequestAction is an additional, deprecated packet sent by the client after @@ -8,6 +10,8 @@ * This action is also sent when an item is enchanted. Enchanting should be treated mostly the same way as * crafting, where the old item is consumed. */ +@Getter +@AllArgsConstructor public class CraftResultsDeprecatedStackRequestActionData extends StackRequestActionData { ItemData[] resultItems; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java index 55d8b4cdf..d5ae6867a 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/CreateStackRequestActionData.java @@ -1,5 +1,8 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * CreateStackRequestActionData is sent by the client when an item is created through being used as part of a * recipe. For example, when milk is used to craft a cake, the buckets are leftover. The buckets are moved to @@ -8,6 +11,8 @@ * that are not fully consumed when used for a recipe should not be destroyed there, but instead, should be * turned into their respective resulting items. */ +@Getter +@AllArgsConstructor public class CreateStackRequestActionData extends StackRequestActionData { // The slot to which the results of the crafting ingredients are to be placed byte slot; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java index c7a969b1d..d6af228fc 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DestroyStackRequestActionData.java @@ -1,11 +1,15 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * DestroyStackRequestActionData is sent by the client when it destroys an item in creative mode by moving it * back into the creative inventory. */ +@Getter +@AllArgsConstructor public class DestroyStackRequestActionData extends StackRequestActionData { // count is the count of items removed from the source slot byte count; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java index 053327d88..d5b917d21 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/DropStackRequestActionData.java @@ -1,6 +1,8 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * DropStackRequestActionData is sent by the client when it drops an item out of the inventory when it has its @@ -8,6 +10,8 @@ * (or the equivalent on mobile). The InventoryTransaction packet is still used for that action, regardless of * whether the item stack network IDs are used or not. */ +@AllArgsConstructor +@Getter public class DropStackRequestActionData extends StackRequestActionData { // count is the count of items removed from the source slot byte count; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/PlaceStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/PlaceStackRequestActionData.java new file mode 100644 index 000000000..9e7dba089 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/PlaceStackRequestActionData.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + + +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + +/** + * TakeStackRequestActionData is sent by the client to the server to take x amount of items from one slot in a + * container to the cursor. + */ + +public class PlaceStackRequestActionData extends TransferStackRequestActionData { + public PlaceStackRequestActionData(byte count, StackRequestSlotInfoData source, StackRequestSlotInfoData destination) { + super(count, source, destination); + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java index 875ec4345..c415fd5ee 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/SwapStackRequestActionData.java @@ -1,8 +1,13 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + /** * SwapStackRequestActionData is sent by the client to swap the item in its cursor with an item present in another * container. The two item stacks swap places. */ public class SwapStackRequestActionData extends TransferStackRequestActionData { + public SwapStackRequestActionData(byte count, StackRequestSlotInfoData source, StackRequestSlotInfoData destination) { + super(count, source, destination); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java index 2f8bb803c..074b4f646 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TakeStackRequestActionData.java @@ -1,8 +1,15 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; + +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; + /** * TakeStackRequestActionData is sent by the client to the server to take x amount of items from one slot in a * container to the cursor. */ + public class TakeStackRequestActionData extends TransferStackRequestActionData { + public TakeStackRequestActionData(byte count, StackRequestSlotInfoData source, StackRequestSlotInfoData destination) { + super(count, source, destination); + } } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java index 706dc72da..0596afabf 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/stackrequestactions/TransferStackRequestActionData.java @@ -1,11 +1,17 @@ package com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Value; /** * TransferStackRequestActionData is the structure shared by StackRequestActions that transfer items from one * slot into another */ +@Getter +@AllArgsConstructor public class TransferStackRequestActionData extends StackRequestActionData { // Count of the item in the source slot that was taken towards the destination slot. byte count; diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java index 04269fa68..6d1e5afbb 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java @@ -2,7 +2,8 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackAction; +import com.nukkitx.protocol.bedrock.data.inventory.ItemStackActionDeprecated; +import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequestData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; import lombok.Data; import lombok.EqualsAndHashCode; @@ -14,7 +15,7 @@ @Data @EqualsAndHashCode(callSuper = false) public class ItemStackRequestPacket extends BedrockPacket { - private final List requests = new ArrayList<>(); + private final List requests = new ArrayList<>(); @Override public boolean handle(BedrockPacketHandler handler) { @@ -25,10 +26,4 @@ public boolean handle(BedrockPacketHandler handler) { public BedrockPacketType getPacketType() { return BedrockPacketType.ITEM_STACK_REQUEST; } - - @Value - public static class Request { - private final int requestId; - private final List actions; - } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java index e6756a3f0..f3a5b7002 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java @@ -4,7 +4,24 @@ import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackAction; +import com.nukkitx.protocol.bedrock.data.inventory.ItemStackActionDeprecated; +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestActionType; +import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.AutoCraftRecipeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.BeaconPaymentStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.ConsumeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftCreativeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftNonImplementedStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftRecipeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftResultsDeprecatedStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CreateStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.DestroyStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.DropStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.LabTableCombineRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.PlaceStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.SwapStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.TakeStackRequestActionData; import com.nukkitx.protocol.bedrock.packet.ItemStackRequestPacket; import io.netty.buffer.ByteBuf; import lombok.AccessLevel; @@ -74,77 +91,154 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReque }); } + public StackRequestSlotInfoData readStackRequestSlotInfo(ByteBuf buffer, BedrockPacketHelper helper) { + return new StackRequestSlotInfoData( + buffer.readByte(), + buffer.readByte(), + VarInts.readInt(buffer) + ); + } + @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackRequestPacket packet) { helper.readArray(buffer, packet.getRequests(), buf -> { int requestId = VarInts.readInt(buf); - List actions = new ArrayList<>(); + List actions = new ArrayList<>(); helper.readArray(buf, actions, byteBuf -> { - byte type = byteBuf.readByte(); - - boolean bool0 = false; - byte byte0 = 0; - int varInt0 = 0; - int varInt1 = 0; - byte baseByte0 = 0; - byte baseByte1 = 0; - byte baseByte2 = 0; - int baseVarInt0 = 0; - byte flagsByte0 = 0; - byte flagsByte1 = 0; - int flagsVarInt0 = 0; - List items = null; + StackRequestActionType type = StackRequestActionType.byId(byteBuf.readByte()); switch (type) { - case 0: - case 1: - case 2: - baseByte0 = byteBuf.readByte(); - baseByte1 = byteBuf.readByte(); - baseByte2 = byteBuf.readByte(); - baseVarInt0 = VarInts.readInt(byteBuf); - flagsByte0 = byteBuf.readByte(); - flagsByte1 = byteBuf.readByte(); - flagsVarInt0 = VarInts.readInt(byteBuf); - break; - case 3: - baseByte0 = byteBuf.readByte(); - baseByte1 = byteBuf.readByte(); - baseByte2 = byteBuf.readByte(); - baseVarInt0 = VarInts.readInt(byteBuf); - bool0 = byteBuf.readBoolean(); - break; - case 4: - case 5: - baseByte0 = byteBuf.readByte(); - baseByte1 = byteBuf.readByte(); - baseByte2 = byteBuf.readByte(); - baseVarInt0 = VarInts.readInt(byteBuf); - break; - case 6: - byte0 = byteBuf.readByte(); - break; - case 8: - varInt0 = VarInts.readInt(byteBuf); - varInt1 = VarInts.readInt(byteBuf); - break; - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - varInt0 = VarInts.readUnsignedInt(byteBuf); - break; - case 17: - items = new ArrayList<>(); - helper.readArray(byteBuf, items, helper::readItem); - break; + case TAKE: + return new TakeStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper), + readStackRequestSlotInfo(byteBuf, helper) + ); + case PLACE: + return new PlaceStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper), + readStackRequestSlotInfo(byteBuf, helper) + ); + case SWAP: + return new SwapStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper), + readStackRequestSlotInfo(byteBuf, helper) + ); + case DROP: + return new DropStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper), + byteBuf.readBoolean() + ); + case DESTROY: + return new DestroyStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper) + ); + case CONSUME: + return new ConsumeStackRequestActionData( + byteBuf.readByte(), + readStackRequestSlotInfo(byteBuf, helper) + ); + case CREATE: + return new CreateStackRequestActionData( + byteBuf.readByte() + ); + case LAB_TABLE_COMBINE: + return new LabTableCombineRequestActionData(); + case BEACON_PAYMENT: + return new BeaconPaymentStackRequestActionData( + VarInts.readInt(byteBuf), + VarInts.readInt(byteBuf) + ); + case CRAFT_RECIPE: + return new CraftRecipeStackRequestActionData( + VarInts.readInt(byteBuf) + ); + case CRAFT_RECIPE_AUTO: + return new AutoCraftRecipeStackRequestActionData( + VarInts.readInt(byteBuf) + ); + case CRAFT_CREATIVE: + return new CraftCreativeStackRequestActionData( + VarInts.readInt(byteBuf) + ); + case CRAFT_RESULTS_DEPRECATED: + return new CraftResultsDeprecatedStackRequestActionData( + helper.readArray(byteBuf, new ItemData[0], helper::readItem), + byteBuf.readByte() + ); } - return new ItemStackAction(type, bool0, byte0, varInt0, varInt1, baseByte0, baseByte1, baseByte2, - baseVarInt0, flagsByte0, flagsByte1, flagsVarInt0, items); + + // Fallback + return new CraftNonImplementedStackRequestActionData(); + + +// boolean bool0 = false; +// byte byte0 = 0; +// int varInt0 = 0; +// int varInt1 = 0; +// byte baseByte0 = 0; +// byte baseByte1 = 0; +// byte baseByte2 = 0; +// int baseVarInt0 = 0; +// byte flagsByte0 = 0; +// byte flagsByte1 = 0; +// int flagsVarInt0 = 0; +// List items = null; +// +// switch (type) { +// case 0: +// case 1: +// case 2: +// baseByte0 = byteBuf.readByte(); +// baseByte1 = byteBuf.readByte(); +// baseByte2 = byteBuf.readByte(); +// baseVarInt0 = VarInts.readInt(byteBuf); +// flagsByte0 = byteBuf.readByte(); +// flagsByte1 = byteBuf.readByte(); +// flagsVarInt0 = VarInts.readInt(byteBuf); +// break; +// case 3: +// baseByte0 = byteBuf.readByte(); +// baseByte1 = byteBuf.readByte(); +// baseByte2 = byteBuf.readByte(); +// baseVarInt0 = VarInts.readInt(byteBuf); +// bool0 = byteBuf.readBoolean(); +// break; +// case 4: +// case 5: +// baseByte0 = byteBuf.readByte(); +// baseByte1 = byteBuf.readByte(); +// baseByte2 = byteBuf.readByte(); +// baseVarInt0 = VarInts.readInt(byteBuf); +// break; +// case 6: +// byte0 = byteBuf.readByte(); +// break; +// case 8: +// varInt0 = VarInts.readInt(byteBuf); +// varInt1 = VarInts.readInt(byteBuf); +// break; +// case 9: +// case 10: +// case 11: +// case 12: +// case 13: +// case 14: +// case 15: +// varInt0 = VarInts.readUnsignedInt(byteBuf); +// break; +// case 17: +// items = new ArrayList<>(); +// helper.readArray(byteBuf, items, helper::readItem); +// break; +// } +// return new ItemStackActionDeprecated(type, bool0, byte0, varInt0, varInt1, baseByte0, baseByte1, baseByte2, +// baseVarInt0, flagsByte0, flagsByte1, flagsVarInt0, items); }); return new ItemStackRequestPacket.Request(requestId, actions); }); From d95704b01e438132229a5ccdac8e6e8dcf68b57c Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 17:16:59 +0800 Subject: [PATCH 49/70] Implement ItemStackRequest Serializer, Packet and Data --- .../data/inventory/ItemStackRequestData.java | 4 + .../inventory/StackRequestActionType.java | 64 +++++-- .../ItemStackRequestSerializer_v407.java | 161 ++++++------------ 3 files changed, 103 insertions(+), 126 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java index 1d6dae91e..84e993fde 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java @@ -1,12 +1,16 @@ package com.nukkitx.protocol.bedrock.data.inventory; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; +import lombok.AllArgsConstructor; +import lombok.Getter; /** * ItemStackRequestData represents a single request present in an ItemStackRequest packet sent by the client to * change an item in an inventory. * Item stack requests are either approved or rejected by the server using the ItemStackResponse packet. */ +@Getter +@AllArgsConstructor public class ItemStackRequestData { // requestId is a unique ID for the request. This ID is used by the server to send a response for this // specific request in the ItemStackResponse packet. diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java index 0f070287d..c9e77d9d6 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/StackRequestActionType.java @@ -1,22 +1,51 @@ package com.nukkitx.protocol.bedrock.data.inventory; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.AutoCraftRecipeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.BeaconPaymentStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.ConsumeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftCreativeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftNonImplementedStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftRecipeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CraftResultsDeprecatedStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.CreateStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.DestroyStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.DropStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.LabTableCombineRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.PlaceStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.SwapStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.TakeStackRequestActionData; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; +import java.util.EnumMap; +import java.util.Map; +import java.util.stream.Collectors; + +@Getter +@AllArgsConstructor public enum StackRequestActionType { - TAKE, - PLACE, - SWAP, - DROP, - DESTROY, - CONSUME, - CREATE, - LAB_TABLE_COMBINE, - BEACON_PAYMENT, - CRAFT_RECIPE, - CRAFT_RECIPE_AUTO, - CRAFT_CREATIVE, - CRAFT_NON_IMPLEMENTED_DEPRECATED, - CRAFT_RESULTS_DEPRECATED; + TAKE(TakeStackRequestActionData.class), + PLACE(PlaceStackRequestActionData.class), + SWAP(SwapStackRequestActionData.class), + DROP(DropStackRequestActionData.class), + DESTROY(DestroyStackRequestActionData.class), + CONSUME(ConsumeStackRequestActionData.class), + CREATE(CreateStackRequestActionData.class), + LAB_TABLE_COMBINE(LabTableCombineRequestActionData.class), + BEACON_PAYMENT(BeaconPaymentStackRequestActionData.class), + CRAFT_RECIPE(CraftRecipeStackRequestActionData.class), + CRAFT_RECIPE_AUTO(AutoCraftRecipeStackRequestActionData.class), + CRAFT_CREATIVE(CraftCreativeStackRequestActionData.class), + CRAFT_NON_IMPLEMENTED_DEPRECATED(CraftNonImplementedStackRequestActionData.class), + CRAFT_RESULTS_DEPRECATED(CraftResultsDeprecatedStackRequestActionData.class); private static final StackRequestActionType[] VALUES = values(); + private static final Map, StackRequestActionType> CLASSES = Arrays.stream(values()) + .collect(Collectors.toMap(StackRequestActionType::getCls, v -> v)); + + private final Class cls; public static StackRequestActionType byId(int id) { if (id >= 0 && id < VALUES.length) { @@ -24,4 +53,11 @@ public static StackRequestActionType byId(int id) { } throw new UnsupportedOperationException("Unknown StackRequestActionType ID: " + id); } + + public static StackRequestActionType byClass(Class cls) { + if (CLASSES.containsKey(cls)) { + return CLASSES.get(cls); + } + throw new UnsupportedOperationException("Unknown StackRequestActionType Class: " + cls.getSimpleName()); + } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java index f3a5b7002..a3408931c 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java @@ -4,7 +4,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackActionDeprecated; +import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequestData; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestActionType; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.AutoCraftRecipeStackRequestActionData; @@ -22,6 +22,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.SwapStackRequestActionData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.TakeStackRequestActionData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.TransferStackRequestActionData; import com.nukkitx.protocol.bedrock.packet.ItemStackRequestPacket; import io.netty.buffer.ByteBuf; import lombok.AccessLevel; @@ -41,64 +42,50 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReque VarInts.writeInt(buf, requests.getRequestId()); helper.writeArray(buf, requests.getActions(), (byteBuf, action) -> { - switch (action.getType()) { - case 0: - case 1: - case 2: - byteBuf.writeByte(action.getBaseByte0()); - byteBuf.writeByte(action.getBaseByte1()); - byteBuf.writeByte(action.getBaseByte2()); - VarInts.writeInt(byteBuf, action.getVarInt0()); - byteBuf.writeByte(action.getFlagsByte0()); - byteBuf.writeByte(action.getFlagsByte1()); - VarInts.writeInt(byteBuf, action.getFlagsVarInt0()); + StackRequestActionType type = StackRequestActionType.byClass(action.getClass()); + byteBuf.writeByte(type.ordinal()); + + switch (type) { + case TAKE: + case PLACE: + case SWAP: + byteBuf.writeByte(((TransferStackRequestActionData) action).getCount()); + writeStackRequestSlotInfo(byteBuf, helper, ((TransferStackRequestActionData) action).getSource()); + writeStackRequestSlotInfo(byteBuf, helper, ((TransferStackRequestActionData) action).getDestination()); break; - case 3: - byteBuf.writeByte(action.getBaseByte0()); - byteBuf.writeByte(action.getBaseByte1()); - byteBuf.writeByte(action.getBaseByte2()); - VarInts.writeInt(byteBuf, action.getVarInt0()); - byteBuf.writeBoolean(action.isBool0()); + case DROP: + byteBuf.writeByte(((DropStackRequestActionData) action).getCount()); + writeStackRequestSlotInfo(byteBuf, helper, ((DropStackRequestActionData) action).getSource()); + byteBuf.writeBoolean(((DropStackRequestActionData) action).isRandomly()); + break; + case DESTROY: + case CONSUME: + byteBuf.writeByte(((DestroyStackRequestActionData) action).getCount()); + writeStackRequestSlotInfo(byteBuf, helper, ((DestroyStackRequestActionData) action).getSource()); break; - case 4: - case 5: - byteBuf.writeByte(action.getBaseByte0()); - byteBuf.writeByte(action.getBaseByte1()); - byteBuf.writeByte(action.getBaseByte2()); - VarInts.writeInt(byteBuf, action.getVarInt0()); + case CREATE: + byteBuf.writeByte(((CreateStackRequestActionData) action).getSlot()); break; - case 6: - byteBuf.writeByte(action.getByte0()); + case BEACON_PAYMENT: + VarInts.writeInt(byteBuf, ((BeaconPaymentStackRequestActionData) action).getPrimaryEffect()); + VarInts.writeInt(byteBuf, ((BeaconPaymentStackRequestActionData) action).getSecondaryEffect()); break; - case 8: - VarInts.writeInt(byteBuf, action.getVarInt0()); - VarInts.writeInt(byteBuf, action.getVarInt1()); + case CRAFT_RECIPE: + case CRAFT_RECIPE_AUTO: + VarInts.writeInt(byteBuf, ((CraftRecipeStackRequestActionData) action).getRecipeNetworkId()); break; - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - VarInts.writeInt(byteBuf, action.getVarInt0()); + case CRAFT_CREATIVE: + VarInts.writeInt(byteBuf, ((CraftCreativeStackRequestActionData) action).getCreativeItemNetworkId()); break; - case 17: - helper.writeArray(byteBuf, action.getItems(), helper::writeItem); + case CRAFT_RESULTS_DEPRECATED: + helper.writeArray(byteBuf, ((CraftResultsDeprecatedStackRequestActionData) action).getResultItems(), helper::writeItem); + byteBuf.writeByte(((CraftResultsDeprecatedStackRequestActionData) action).getTimesCrafted()); break; } }); }); } - public StackRequestSlotInfoData readStackRequestSlotInfo(ByteBuf buffer, BedrockPacketHelper helper) { - return new StackRequestSlotInfoData( - buffer.readByte(), - buffer.readByte(), - VarInts.readInt(buffer) - ); - } - @Override public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackRequestPacket packet) { helper.readArray(buffer, packet.getRequests(), buf -> { @@ -175,72 +162,22 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReq // Fallback return new CraftNonImplementedStackRequestActionData(); - - -// boolean bool0 = false; -// byte byte0 = 0; -// int varInt0 = 0; -// int varInt1 = 0; -// byte baseByte0 = 0; -// byte baseByte1 = 0; -// byte baseByte2 = 0; -// int baseVarInt0 = 0; -// byte flagsByte0 = 0; -// byte flagsByte1 = 0; -// int flagsVarInt0 = 0; -// List items = null; -// -// switch (type) { -// case 0: -// case 1: -// case 2: -// baseByte0 = byteBuf.readByte(); -// baseByte1 = byteBuf.readByte(); -// baseByte2 = byteBuf.readByte(); -// baseVarInt0 = VarInts.readInt(byteBuf); -// flagsByte0 = byteBuf.readByte(); -// flagsByte1 = byteBuf.readByte(); -// flagsVarInt0 = VarInts.readInt(byteBuf); -// break; -// case 3: -// baseByte0 = byteBuf.readByte(); -// baseByte1 = byteBuf.readByte(); -// baseByte2 = byteBuf.readByte(); -// baseVarInt0 = VarInts.readInt(byteBuf); -// bool0 = byteBuf.readBoolean(); -// break; -// case 4: -// case 5: -// baseByte0 = byteBuf.readByte(); -// baseByte1 = byteBuf.readByte(); -// baseByte2 = byteBuf.readByte(); -// baseVarInt0 = VarInts.readInt(byteBuf); -// break; -// case 6: -// byte0 = byteBuf.readByte(); -// break; -// case 8: -// varInt0 = VarInts.readInt(byteBuf); -// varInt1 = VarInts.readInt(byteBuf); -// break; -// case 9: -// case 10: -// case 11: -// case 12: -// case 13: -// case 14: -// case 15: -// varInt0 = VarInts.readUnsignedInt(byteBuf); -// break; -// case 17: -// items = new ArrayList<>(); -// helper.readArray(byteBuf, items, helper::readItem); -// break; -// } -// return new ItemStackActionDeprecated(type, bool0, byte0, varInt0, varInt1, baseByte0, baseByte1, baseByte2, -// baseVarInt0, flagsByte0, flagsByte1, flagsVarInt0, items); }); - return new ItemStackRequestPacket.Request(requestId, actions); + return new ItemStackRequestData(requestId, actions.toArray(new StackRequestActionData[0])); }); } + + public StackRequestSlotInfoData readStackRequestSlotInfo(ByteBuf buffer, BedrockPacketHelper helper) { + return new StackRequestSlotInfoData( + buffer.readByte(), + buffer.readByte(), + VarInts.readInt(buffer) + ); + } + + public void writeStackRequestSlotInfo(ByteBuf buffer, BedrockPacketHelper helper, StackRequestSlotInfoData data) { + buffer.writeByte(data.getContainerId()); + buffer.writeByte(data.getSlot()); + VarInts.writeInt(buffer, data.getStackNetworkId()); + } } From 186b4aeab350f85ebe8fb30deb51b31a3dbd72a9 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 19:07:32 +0800 Subject: [PATCH 50/70] Implement ItemStackResponse Packet, Serializer and Data --- .../data/inventory/ItemStackRequestData.java | 22 ---------- .../packet/ItemStackRequestPacket.java | 26 ++++++++++-- .../packet/ItemStackResponsePacket.java | 37 +++++++++++++++-- .../ItemStackRequestSerializer_v407.java | 3 +- .../ItemStackResponseSerializer_v407.java | 41 +++++++++---------- 5 files changed, 76 insertions(+), 53 deletions(-) delete mode 100644 bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java deleted file mode 100644 index 84e993fde..000000000 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/inventory/ItemStackRequestData.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nukkitx.protocol.bedrock.data.inventory; - -import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * ItemStackRequestData represents a single request present in an ItemStackRequest packet sent by the client to - * change an item in an inventory. - * Item stack requests are either approved or rejected by the server using the ItemStackResponse packet. - */ -@Getter -@AllArgsConstructor -public class ItemStackRequestData { - // requestId is a unique ID for the request. This ID is used by the server to send a response for this - // specific request in the ItemStackResponse packet. - int requestId; - - // actions is a list of actions performed by the client. The actual type of the actions depends on which - // ID was present - StackRequestActionData[] actions; -} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java index 6d1e5afbb..edec52e67 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackRequestPacket.java @@ -2,12 +2,12 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacketType; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackActionDeprecated; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequestData; +import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.StackRequestActionData; import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Value; +import lombok.Getter; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,7 @@ @Data @EqualsAndHashCode(callSuper = false) public class ItemStackRequestPacket extends BedrockPacket { - private final List requests = new ArrayList<>(); + private final List requests = new ArrayList<>(); @Override public boolean handle(BedrockPacketHandler handler) { @@ -26,4 +26,22 @@ public boolean handle(BedrockPacketHandler handler) { public BedrockPacketType getPacketType() { return BedrockPacketType.ITEM_STACK_REQUEST; } + + /** + * Request represents a single request present in an ItemStackRequest packet sent by the client to + * change an item in an inventory. + * Item stack requests are either approved or rejected by the server using the ItemStackResponse packet. + */ + @Getter + @AllArgsConstructor + public static class Request { + // requestId is a unique ID for the request. This ID is used by the server to send a response for this + // specific request in the ItemStackResponse packet. + int requestId; + + // actions is a list of actions performed by the client. The actual type of the actions depends on which + // ID was present + StackRequestActionData[] actions; + } + } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackResponsePacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackResponsePacket.java index 1092c70cc..281acc8a1 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackResponsePacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/ItemStackResponsePacket.java @@ -10,6 +10,12 @@ import java.util.ArrayList; import java.util.List; +/** + * ItemStackResponse is sent by the server in response to an ItemStackRequest packet from the client. This + * packet is used to either approve or reject ItemStackRequests from the client. If a request is approved, the + * client will simply continue as normal. If rejected, the client will undo the actions so that the inventory + * should be in sync with the server again. + */ @Data @EqualsAndHashCode(callSuper = false) public class ItemStackResponsePacket extends BedrockPacket { @@ -25,24 +31,49 @@ public BedrockPacketType getPacketType() { return BedrockPacketType.ITEM_STACK_RESPONSE; } + /** + * Response is a response to an individual ItemStackRequest. + */ @Value public static class Response { - private final boolean hasContainers; + // success specifies if the request with the requestId below was successful. If this is the case, the + // containers below will have information on what slots ended up changing. If not, the container info + // will be empty. + private final boolean success; + + // requestId is the unique ID of the request that this response is in reaction to. If rejected, the client + // will undo the actions from the request with this ID. private final int requestId; + + // containers holds information on the containers that had their contents changed as a result of the + // request. private final List containers; } + /** + * ContainerEntry holds information on what slots in a container have what item stack in them. + */ @Value public static class ContainerEntry { - private final byte windowsId; + // widowId is the window ID of the container that the slots that follow are in. For the main + // inventory, this value seems to be 0x1b. For the cursor, this value seems to be 0x3a. For the crafting + // grid, this value seems to be 0x0d. + private final byte windowId; + + // items holds information on what item stack should be present in specific slots in the container. private final List items; } + /** + * ItemEntry holds information on what item stack should be present in a specific slot. + */ @Value public static class ItemEntry { private final byte slot; private final byte hotbarSlot; private final byte count; - private final int itemStackId; + + // stackNetworkID is the network ID of the new stack at a specific slot. + private final int stackNetworkId; } } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java index a3408931c..164dd6aa0 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackRequestSerializer_v407.java @@ -4,7 +4,6 @@ import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.BedrockPacketSerializer; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequestData; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestActionType; import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData; import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.AutoCraftRecipeStackRequestActionData; @@ -163,7 +162,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackReq // Fallback return new CraftNonImplementedStackRequestActionData(); }); - return new ItemStackRequestData(requestId, actions.toArray(new StackRequestActionData[0])); + return new ItemStackRequestPacket.Request(requestId, actions.toArray(new StackRequestActionData[0])); }); } diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackResponseSerializer_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackResponseSerializer_v407.java index 5fc0e05d1..dbb7e7f44 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackResponseSerializer_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/serializer/ItemStackResponseSerializer_v407.java @@ -19,16 +19,17 @@ public class ItemStackResponseSerializer_v407 implements BedrockPacketSerializer @Override public void serialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackResponsePacket packet) { helper.writeArray(buffer, packet.getEntries(), (buf, response) -> { - buf.writeBoolean(response.isHasContainers()); + buf.writeBoolean(response.isSuccess()); + VarInts.writeInt(buffer, response.getRequestId()); helper.writeArray(buf, response.getContainers(), (buf2, containerEntry) -> { - buf2.writeByte(containerEntry.getWindowsId()); + buf2.writeByte(containerEntry.getWindowId()); helper.writeArray(buf2, containerEntry.getItems(), (byteBuf, itemEntry) -> { byteBuf.writeByte(itemEntry.getSlot()); byteBuf.writeByte(itemEntry.getHotbarSlot()); byteBuf.writeByte(itemEntry.getCount()); - VarInts.writeInt(byteBuf, itemEntry.getItemStackId()); + VarInts.writeInt(byteBuf, itemEntry.getStackNetworkId()); }); }); }); @@ -38,27 +39,23 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackRespo public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, ItemStackResponsePacket packet) { List entries = packet.getEntries(); helper.readArray(buffer, entries, buf -> { - boolean hasArray = buf.readBoolean(); + boolean success = buf.readBoolean(); int requestId = VarInts.readInt(buf); - List containerEntries = null; - if (hasArray) { - containerEntries = new ArrayList<>(); - helper.readArray(buf, containerEntries, buf2 -> { - byte windowId = buf2.readByte(); - - List itemEntries = new ArrayList<>(); - helper.readArray(buf2, itemEntries, byteBuf -> { - byte slot = byteBuf.readByte(); - byte hotbarSlot = byteBuf.readByte(); - byte count = byteBuf.readByte(); - int unknownVarint0 = VarInts.readInt(byteBuf); - return new ItemStackResponsePacket.ItemEntry(slot, hotbarSlot, count, unknownVarint0); - }); - return new ItemStackResponsePacket.ContainerEntry(windowId, itemEntries); - }); - } - return new ItemStackResponsePacket.Response(hasArray, requestId, containerEntries); + List containerEntries = new ArrayList<>(); + helper.readArray(buf, containerEntries, buf2 -> { + byte windowId = buf2.readByte(); + + List itemEntries = new ArrayList<>(); + helper.readArray(buf2, itemEntries, byteBuf -> new ItemStackResponsePacket.ItemEntry( + byteBuf.readByte(), + byteBuf.readByte(), + byteBuf.readByte(), + VarInts.readInt(byteBuf) + )); + return new ItemStackResponsePacket.ContainerEntry(windowId, itemEntries); + }); + return new ItemStackResponsePacket.Response(success, requestId, containerEntries); }); } } From 1f22ebda909548a0feadea093637de437d5f7129 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 19:18:33 +0800 Subject: [PATCH 51/70] | != + --- .../v291/BedrockPacketHelper_v291.java | 238 +++++++++--------- .../v313/BedrockPacketHelper_v313.java | 2 +- .../v332/BedrockPacketHelper_v332.java | 4 +- .../v354/BedrockPacketHelper_v354.java | 2 +- .../v361/BedrockPacketHelper_v361.java | 2 +- .../v388/BedrockPacketHelper_v388.java | 6 +- 6 files changed, 127 insertions(+), 127 deletions(-) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/BedrockPacketHelper_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/BedrockPacketHelper_v291.java index 3b39ef914..3bde34446 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/BedrockPacketHelper_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/BedrockPacketHelper_v291.java @@ -537,138 +537,138 @@ protected void registerLevelEvents() { // Sounds int sound = 1000; - this.addLevelEvent(0 | sound, LevelEventType.SOUND_CLICK); - this.addLevelEvent(1 | sound, LevelEventType.SOUND_CLICK_FAIL); - this.addLevelEvent(2 | sound, LevelEventType.SOUND_LAUNCH); - this.addLevelEvent(3 | sound, LevelEventType.SOUND_DOOR_OPEN); - this.addLevelEvent(4 | sound, LevelEventType.SOUND_FIZZ); - this.addLevelEvent(5 | sound, LevelEventType.SOUND_FUSE); - this.addLevelEvent(6 | sound, LevelEventType.SOUND_PLAY_RECORDING); - this.addLevelEvent(7 | sound, LevelEventType.SOUND_GHAST_WARNING); - this.addLevelEvent(8 | sound, LevelEventType.SOUND_GHAST_FIREBALL); - this.addLevelEvent(9 | sound, LevelEventType.SOUND_BLAZE_FIREBALL); - this.addLevelEvent(10 | sound, LevelEventType.SOUND_ZOMBIE_DOOR_BUMP); - - this.addLevelEvent(12 | sound, LevelEventType.SOUND_ZOMBIE_DOOR_CRASH); - - this.addLevelEvent(16 | sound, LevelEventType.SOUND_ZOMBIE_INFECTED); - this.addLevelEvent(17 | sound, LevelEventType.SOUND_ZOMBIE_CONVERTED); - this.addLevelEvent(18 | sound, LevelEventType.SOUND_ENDERMAN_TELEPORT); - - this.addLevelEvent(20 | sound, LevelEventType.SOUND_ANVIL_BROKEN); - this.addLevelEvent(21 | sound, LevelEventType.SOUND_ANVIL_USED); - this.addLevelEvent(22 | sound, LevelEventType.SOUND_ANVIL_LAND); - - this.addLevelEvent(30 | sound, LevelEventType.SOUND_INFINITY_ARROW_PICKUP); - - this.addLevelEvent(32 | sound, LevelEventType.SOUND_TELEPORT_ENDERPEARL); - - this.addLevelEvent(40 | sound, LevelEventType.SOUND_ITEMFRAME_ITEM_ADD); - this.addLevelEvent(41 | sound, LevelEventType.SOUND_ITEMFRAME_BREAK); - this.addLevelEvent(42 | sound, LevelEventType.SOUND_ITEMFRAME_PLACE); - this.addLevelEvent(43 | sound, LevelEventType.SOUND_ITEMFRAME_ITEM_REMOVE); - this.addLevelEvent(44 | sound, LevelEventType.SOUND_ITEMFRAME_ITEM_ROTATE); - - this.addLevelEvent(51 | sound, LevelEventType.SOUND_EXPERIENCE_ORB_PICKUP); - this.addLevelEvent(52 | sound, LevelEventType.SOUND_TOTEM_USED); - - this.addLevelEvent(60 | sound, LevelEventType.SOUND_ARMOR_STAND_BREAK); - this.addLevelEvent(61 | sound, LevelEventType.SOUND_ARMOR_STAND_HIT); - this.addLevelEvent(62 | sound, LevelEventType.SOUND_ARMOR_STAND_LAND); - this.addLevelEvent(63 | sound, LevelEventType.SOUND_ARMOR_STAND_PLACE); + this.addLevelEvent(0 + sound, LevelEventType.SOUND_CLICK); + this.addLevelEvent(1 + sound, LevelEventType.SOUND_CLICK_FAIL); + this.addLevelEvent(2 + sound, LevelEventType.SOUND_LAUNCH); + this.addLevelEvent(3 + sound, LevelEventType.SOUND_DOOR_OPEN); + this.addLevelEvent(4 + sound, LevelEventType.SOUND_FIZZ); + this.addLevelEvent(5 + sound, LevelEventType.SOUND_FUSE); + this.addLevelEvent(6 + sound, LevelEventType.SOUND_PLAY_RECORDING); + this.addLevelEvent(7 + sound, LevelEventType.SOUND_GHAST_WARNING); + this.addLevelEvent(8 + sound, LevelEventType.SOUND_GHAST_FIREBALL); + this.addLevelEvent(9 + sound, LevelEventType.SOUND_BLAZE_FIREBALL); + this.addLevelEvent(10 + sound, LevelEventType.SOUND_ZOMBIE_DOOR_BUMP); + + this.addLevelEvent(12 + sound, LevelEventType.SOUND_ZOMBIE_DOOR_CRASH); + + this.addLevelEvent(16 + sound, LevelEventType.SOUND_ZOMBIE_INFECTED); + this.addLevelEvent(17 + sound, LevelEventType.SOUND_ZOMBIE_CONVERTED); + this.addLevelEvent(18 + sound, LevelEventType.SOUND_ENDERMAN_TELEPORT); + + this.addLevelEvent(20 + sound, LevelEventType.SOUND_ANVIL_BROKEN); + this.addLevelEvent(21 + sound, LevelEventType.SOUND_ANVIL_USED); + this.addLevelEvent(22 + sound, LevelEventType.SOUND_ANVIL_LAND); + + this.addLevelEvent(30 + sound, LevelEventType.SOUND_INFINITY_ARROW_PICKUP); + + this.addLevelEvent(32 + sound, LevelEventType.SOUND_TELEPORT_ENDERPEARL); + + this.addLevelEvent(40 + sound, LevelEventType.SOUND_ITEMFRAME_ITEM_ADD); + this.addLevelEvent(41 + sound, LevelEventType.SOUND_ITEMFRAME_BREAK); + this.addLevelEvent(42 + sound, LevelEventType.SOUND_ITEMFRAME_PLACE); + this.addLevelEvent(43 + sound, LevelEventType.SOUND_ITEMFRAME_ITEM_REMOVE); + this.addLevelEvent(44 + sound, LevelEventType.SOUND_ITEMFRAME_ITEM_ROTATE); + + this.addLevelEvent(51 + sound, LevelEventType.SOUND_EXPERIENCE_ORB_PICKUP); + this.addLevelEvent(52 + sound, LevelEventType.SOUND_TOTEM_USED); + + this.addLevelEvent(60 + sound, LevelEventType.SOUND_ARMOR_STAND_BREAK); + this.addLevelEvent(61 + sound, LevelEventType.SOUND_ARMOR_STAND_HIT); + this.addLevelEvent(62 + sound, LevelEventType.SOUND_ARMOR_STAND_LAND); + this.addLevelEvent(63 + sound, LevelEventType.SOUND_ARMOR_STAND_PLACE); // Particles int particle = 2000; - this.addLevelEvent(0 | particle, LevelEventType.PARTICLE_SHOOT); - this.addLevelEvent(1 | particle, LevelEventType.PARTICLE_DESTROY_BLOCK); - this.addLevelEvent(2 | particle, LevelEventType.PARTICLE_POTION_SPLASH); - this.addLevelEvent(3 | particle, LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH); - this.addLevelEvent(4 | particle, LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); - this.addLevelEvent(5 | particle, LevelEventType.PARTICLE_CROP_GROWTH); - this.addLevelEvent(6 | particle, LevelEventType.PARTICLE_SOUND_GUARDIAN_GHOST); - this.addLevelEvent(7 | particle, LevelEventType.PARTICLE_DEATH_SMOKE); - this.addLevelEvent(8 | particle, LevelEventType.PARTICLE_DENY_BLOCK); - this.addLevelEvent(9 | particle, LevelEventType.PARTICLE_GENERIC_SPAWN); - this.addLevelEvent(10 | particle, LevelEventType.PARTICLE_DRAGON_EGG); - this.addLevelEvent(11 | particle, LevelEventType.PARTICLE_CROP_EATEN); - this.addLevelEvent(12 | particle, LevelEventType.PARTICLE_CRIT); - this.addLevelEvent(13 | particle, LevelEventType.PARTICLE_TELEPORT); - this.addLevelEvent(14 | particle, LevelEventType.PARTICLE_CRACK_BLOCK); - this.addLevelEvent(15 | particle, LevelEventType.PARTICLE_BUBBLES); - this.addLevelEvent(16 | particle, LevelEventType.PARTICLE_EVAPORATE); - this.addLevelEvent(17 | particle, LevelEventType.PARTICLE_DESTROY_ARMOR_STAND); - this.addLevelEvent(18 | particle, LevelEventType.PARTICLE_BREAKING_EGG); - this.addLevelEvent(19 | particle, LevelEventType.PARTICLE_DESTROY_EGG); - this.addLevelEvent(20 | particle, LevelEventType.PARTICLE_EVAPORATE_WATER); - this.addLevelEvent(21 | particle, LevelEventType.PARTICLE_DESTROY_BLOCK_NO_SOUND); + this.addLevelEvent(0 + particle, LevelEventType.PARTICLE_SHOOT); + this.addLevelEvent(1 + particle, LevelEventType.PARTICLE_DESTROY_BLOCK); + this.addLevelEvent(2 + particle, LevelEventType.PARTICLE_POTION_SPLASH); + this.addLevelEvent(3 + particle, LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH); + this.addLevelEvent(4 + particle, LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); + this.addLevelEvent(5 + particle, LevelEventType.PARTICLE_CROP_GROWTH); + this.addLevelEvent(6 + particle, LevelEventType.PARTICLE_SOUND_GUARDIAN_GHOST); + this.addLevelEvent(7 + particle, LevelEventType.PARTICLE_DEATH_SMOKE); + this.addLevelEvent(8 + particle, LevelEventType.PARTICLE_DENY_BLOCK); + this.addLevelEvent(9 + particle, LevelEventType.PARTICLE_GENERIC_SPAWN); + this.addLevelEvent(10 + particle, LevelEventType.PARTICLE_DRAGON_EGG); + this.addLevelEvent(11 + particle, LevelEventType.PARTICLE_CROP_EATEN); + this.addLevelEvent(12 + particle, LevelEventType.PARTICLE_CRIT); + this.addLevelEvent(13 + particle, LevelEventType.PARTICLE_TELEPORT); + this.addLevelEvent(14 + particle, LevelEventType.PARTICLE_CRACK_BLOCK); + this.addLevelEvent(15 + particle, LevelEventType.PARTICLE_BUBBLES); + this.addLevelEvent(16 + particle, LevelEventType.PARTICLE_EVAPORATE); + this.addLevelEvent(17 + particle, LevelEventType.PARTICLE_DESTROY_ARMOR_STAND); + this.addLevelEvent(18 + particle, LevelEventType.PARTICLE_BREAKING_EGG); + this.addLevelEvent(19 + particle, LevelEventType.PARTICLE_DESTROY_EGG); + this.addLevelEvent(20 + particle, LevelEventType.PARTICLE_EVAPORATE_WATER); + this.addLevelEvent(21 + particle, LevelEventType.PARTICLE_DESTROY_BLOCK_NO_SOUND); // World int world = 3000; - this.addLevelEvent(1 | world, LevelEventType.START_RAINING); - this.addLevelEvent(2 | world, LevelEventType.START_THUNDERSTORM); - this.addLevelEvent(3 | world, LevelEventType.STOP_RAINING); - this.addLevelEvent(4 | world, LevelEventType.STOP_THUNDERSTORM); - this.addLevelEvent(5 | world, LevelEventType.GLOBAL_PAUSE); - this.addLevelEvent(6 | world, LevelEventType.SIM_TIME_STEP); - this.addLevelEvent(7 | world, LevelEventType.SIM_TIME_SCALE); + this.addLevelEvent(1 + world, LevelEventType.START_RAINING); + this.addLevelEvent(2 + world, LevelEventType.START_THUNDERSTORM); + this.addLevelEvent(3 + world, LevelEventType.STOP_RAINING); + this.addLevelEvent(4 + world, LevelEventType.STOP_THUNDERSTORM); + this.addLevelEvent(5 + world, LevelEventType.GLOBAL_PAUSE); + this.addLevelEvent(6 + world, LevelEventType.SIM_TIME_STEP); + this.addLevelEvent(7 + world, LevelEventType.SIM_TIME_SCALE); // Blocks int block = 3500; - this.addLevelEvent(0 | block, LevelEventType.ACTIVATE_BLOCK); - this.addLevelEvent(1 | block, LevelEventType.CAULDRON_EXPLODE); - this.addLevelEvent(2 | block, LevelEventType.CAULDRON_DYE_ARMOR); - this.addLevelEvent(3 | block, LevelEventType.CAULDRON_CLEAN_ARMOR); - this.addLevelEvent(4 | block, LevelEventType.CAULDRON_FILL_POTION); - this.addLevelEvent(5 | block, LevelEventType.CAULDRON_TAKE_POTION); - this.addLevelEvent(6 | block, LevelEventType.CAULDRON_FILL_WATER); - this.addLevelEvent(7 | block, LevelEventType.CAULDRON_TAKE_WATER); - this.addLevelEvent(8 | block, LevelEventType.CAULDRON_ADD_DYE); - this.addLevelEvent(9 | block, LevelEventType.CAULDRON_CLEAN_BANNER); - this.addLevelEvent(10 | block, LevelEventType.CAULDRON_FLUSH); + this.addLevelEvent(0 + block, LevelEventType.ACTIVATE_BLOCK); + this.addLevelEvent(1 + block, LevelEventType.CAULDRON_EXPLODE); + this.addLevelEvent(2 + block, LevelEventType.CAULDRON_DYE_ARMOR); + this.addLevelEvent(3 + block, LevelEventType.CAULDRON_CLEAN_ARMOR); + this.addLevelEvent(4 + block, LevelEventType.CAULDRON_FILL_POTION); + this.addLevelEvent(5 + block, LevelEventType.CAULDRON_TAKE_POTION); + this.addLevelEvent(6 + block, LevelEventType.CAULDRON_FILL_WATER); + this.addLevelEvent(7 + block, LevelEventType.CAULDRON_TAKE_WATER); + this.addLevelEvent(8 + block, LevelEventType.CAULDRON_ADD_DYE); + this.addLevelEvent(9 + block, LevelEventType.CAULDRON_CLEAN_BANNER); + this.addLevelEvent(10 + block, LevelEventType.CAULDRON_FLUSH); // Legacy particles int legacy = 0x4000; - this.addLevelEvent(1 | legacy, LevelEventType.PARTICLE_BUBBLE); - this.addLevelEvent(2 | legacy, LevelEventType.PARTICLE_CRITICAL); - this.addLevelEvent(3 | legacy, LevelEventType.PARTICLE_BLOCK_FORCE_FIELD); - this.addLevelEvent(4 | legacy, LevelEventType.PARTICLE_SMOKE); - this.addLevelEvent(5 | legacy, LevelEventType.PARTICLE_EXPLODE); - this.addLevelEvent(6 | legacy, LevelEventType.PARTICLE_EVAPORATION); - this.addLevelEvent(7 | legacy, LevelEventType.PARTICLE_FLAME); - this.addLevelEvent(8 | legacy, LevelEventType.PARTICLE_LAVA); - this.addLevelEvent(9 | legacy, LevelEventType.PARTICLE_LARGE_SMOKE); - this.addLevelEvent(10 | legacy, LevelEventType.PARTICLE_REDSTONE); - this.addLevelEvent(11 | legacy, LevelEventType.PARTICLE_RISING_RED_DUST); - this.addLevelEvent(12 | legacy, LevelEventType.PARTICLE_ITEM_BREAK); - this.addLevelEvent(13 | legacy, LevelEventType.PARTICLE_SNOWBALL_POOF); - this.addLevelEvent(14 | legacy, LevelEventType.PARTICLE_HUGE_EXPLODE); - this.addLevelEvent(15 | legacy, LevelEventType.PARTICLE_HUGE_EXPLODE_SEED); - this.addLevelEvent(16 | legacy, LevelEventType.PARTICLE_MOB_FLAME); - this.addLevelEvent(17 | legacy, LevelEventType.PARTICLE_HEART); - this.addLevelEvent(18 | legacy, LevelEventType.PARTICLE_TERRAIN); - this.addLevelEvent(19 | legacy, LevelEventType.PARTICLE_TOWN_AURA); - this.addLevelEvent(20 | legacy, LevelEventType.PARTICLE_PORTAL); - this.addLevelEvent(21 | legacy, LevelEventType.PARTICLE_SPLASH); - this.addLevelEvent(22 | legacy, LevelEventType.PARTICLE_WATER_WAKE); - this.addLevelEvent(23 | legacy, LevelEventType.PARTICLE_DRIP_WATER); - this.addLevelEvent(24 | legacy, LevelEventType.PARTICLE_DRIP_LAVA); - this.addLevelEvent(25 | legacy, LevelEventType.PARTICLE_FALLING_DUST); - this.addLevelEvent(26 | legacy, LevelEventType.PARTICLE_MOB_SPELL); - this.addLevelEvent(27 | legacy, LevelEventType.PARTICLE_MOB_SPELL_AMBIENT); - this.addLevelEvent(28 | legacy, LevelEventType.PARTICLE_MOB_SPELL_INSTANTANEOUS); - this.addLevelEvent(29 | legacy, LevelEventType.PARTICLE_INK); - this.addLevelEvent(30 | legacy, LevelEventType.PARTICLE_SLIME); - this.addLevelEvent(31 | legacy, LevelEventType.PARTICLE_RAIN_SPLASH); - this.addLevelEvent(32 | legacy, LevelEventType.PARTICLE_VILLAGER_ANGRY); - this.addLevelEvent(33 | legacy, LevelEventType.PARTICLE_VILLAGER_HAPPY); - this.addLevelEvent(34 | legacy, LevelEventType.PARTICLE_ENCHANTMENT_TABLE); - this.addLevelEvent(35 | legacy, LevelEventType.PARTICLE_TRACKING_EMITTER); - this.addLevelEvent(36 | legacy, LevelEventType.PARTICLE_NOTE); - this.addLevelEvent(37 | legacy, LevelEventType.PARTICLE_WITCH_SPELL); - this.addLevelEvent(38 | legacy, LevelEventType.PARTICLE_CARROT); + this.addLevelEvent(1 + legacy, LevelEventType.PARTICLE_BUBBLE); + this.addLevelEvent(2 + legacy, LevelEventType.PARTICLE_CRITICAL); + this.addLevelEvent(3 + legacy, LevelEventType.PARTICLE_BLOCK_FORCE_FIELD); + this.addLevelEvent(4 + legacy, LevelEventType.PARTICLE_SMOKE); + this.addLevelEvent(5 + legacy, LevelEventType.PARTICLE_EXPLODE); + this.addLevelEvent(6 + legacy, LevelEventType.PARTICLE_EVAPORATION); + this.addLevelEvent(7 + legacy, LevelEventType.PARTICLE_FLAME); + this.addLevelEvent(8 + legacy, LevelEventType.PARTICLE_LAVA); + this.addLevelEvent(9 + legacy, LevelEventType.PARTICLE_LARGE_SMOKE); + this.addLevelEvent(10 + legacy, LevelEventType.PARTICLE_REDSTONE); + this.addLevelEvent(11 + legacy, LevelEventType.PARTICLE_RISING_RED_DUST); + this.addLevelEvent(12 + legacy, LevelEventType.PARTICLE_ITEM_BREAK); + this.addLevelEvent(13 + legacy, LevelEventType.PARTICLE_SNOWBALL_POOF); + this.addLevelEvent(14 + legacy, LevelEventType.PARTICLE_HUGE_EXPLODE); + this.addLevelEvent(15 + legacy, LevelEventType.PARTICLE_HUGE_EXPLODE_SEED); + this.addLevelEvent(16 + legacy, LevelEventType.PARTICLE_MOB_FLAME); + this.addLevelEvent(17 + legacy, LevelEventType.PARTICLE_HEART); + this.addLevelEvent(18 + legacy, LevelEventType.PARTICLE_TERRAIN); + this.addLevelEvent(19 + legacy, LevelEventType.PARTICLE_TOWN_AURA); + this.addLevelEvent(20 + legacy, LevelEventType.PARTICLE_PORTAL); + this.addLevelEvent(21 + legacy, LevelEventType.PARTICLE_SPLASH); + this.addLevelEvent(22 + legacy, LevelEventType.PARTICLE_WATER_WAKE); + this.addLevelEvent(23 + legacy, LevelEventType.PARTICLE_DRIP_WATER); + this.addLevelEvent(24 + legacy, LevelEventType.PARTICLE_DRIP_LAVA); + this.addLevelEvent(25 + legacy, LevelEventType.PARTICLE_FALLING_DUST); + this.addLevelEvent(26 + legacy, LevelEventType.PARTICLE_MOB_SPELL); + this.addLevelEvent(27 + legacy, LevelEventType.PARTICLE_MOB_SPELL_AMBIENT); + this.addLevelEvent(28 + legacy, LevelEventType.PARTICLE_MOB_SPELL_INSTANTANEOUS); + this.addLevelEvent(29 + legacy, LevelEventType.PARTICLE_INK); + this.addLevelEvent(30 + legacy, LevelEventType.PARTICLE_SLIME); + this.addLevelEvent(31 + legacy, LevelEventType.PARTICLE_RAIN_SPLASH); + this.addLevelEvent(32 + legacy, LevelEventType.PARTICLE_VILLAGER_ANGRY); + this.addLevelEvent(33 + legacy, LevelEventType.PARTICLE_VILLAGER_HAPPY); + this.addLevelEvent(34 + legacy, LevelEventType.PARTICLE_ENCHANTMENT_TABLE); + this.addLevelEvent(35 + legacy, LevelEventType.PARTICLE_TRACKING_EMITTER); + this.addLevelEvent(36 + legacy, LevelEventType.PARTICLE_NOTE); + this.addLevelEvent(37 + legacy, LevelEventType.PARTICLE_WITCH_SPELL); + this.addLevelEvent(38 + legacy, LevelEventType.PARTICLE_CARROT); //39 unknown - this.addLevelEvent(40 | legacy, LevelEventType.PARTICLE_END_ROD); - this.addLevelEvent(41 | legacy, LevelEventType.PARTICLE_DRAGONS_BREATH); + this.addLevelEvent(40 + legacy, LevelEventType.PARTICLE_END_ROD); + this.addLevelEvent(41 + legacy, LevelEventType.PARTICLE_DRAGONS_BREATH); } @Override diff --git a/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/BedrockPacketHelper_v313.java b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/BedrockPacketHelper_v313.java index 9ad0b7600..db5cb43bf 100644 --- a/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/BedrockPacketHelper_v313.java +++ b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/BedrockPacketHelper_v313.java @@ -79,6 +79,6 @@ protected void registerSoundEvents() { protected void registerLevelEvents() { super.registerLevelEvents(); - this.addLevelEvent(11 | 3500, LevelEventType.AGENT_SPAWN_EFFECT); + this.addLevelEvent(11 + 3500, LevelEventType.AGENT_SPAWN_EFFECT); } } diff --git a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/BedrockPacketHelper_v332.java b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/BedrockPacketHelper_v332.java index 981fbd22c..335031c75 100644 --- a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/BedrockPacketHelper_v332.java +++ b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/BedrockPacketHelper_v332.java @@ -62,8 +62,8 @@ protected void registerLevelEvents() { super.registerLevelEvents(); int block = 3500; - this.addLevelEvent(12 | block, LevelEventType.CAULDRON_FILL_LAVA); - this.addLevelEvent(13 | block, LevelEventType.CAULDRON_TAKE_LAVA); + this.addLevelEvent(12 + block, LevelEventType.CAULDRON_FILL_LAVA); + this.addLevelEvent(13 + block, LevelEventType.CAULDRON_TAKE_LAVA); } @Override diff --git a/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java b/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java index 93cc96aca..782c1aebd 100644 --- a/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java +++ b/bedrock/bedrock-v354/src/main/java/com/nukkitx/protocol/bedrock/v354/BedrockPacketHelper_v354.java @@ -70,6 +70,6 @@ protected void registerSoundEvents() { protected void registerLevelEvents() { super.registerLevelEvents(); - this.addLevelEvent(22 | 2000, LevelEventType.PARTICLE_KNOCKBACK_ROAR); + this.addLevelEvent(22 + 2000, LevelEventType.PARTICLE_KNOCKBACK_ROAR); } } diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index 6969edbde..c2c298ce4 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -55,7 +55,7 @@ protected void registerEntityFlags() { protected void registerLevelEvents() { super.registerLevelEvents(); - this.addLevelEvent(23 | 2000, LevelEventType.PARTICLE_TELEPORT_TRAIL); + this.addLevelEvent(23 + 2000, LevelEventType.PARTICLE_TELEPORT_TRAIL); } @Override diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java index 27e2fc59c..dea0a27c2 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/BedrockPacketHelper_v388.java @@ -56,9 +56,9 @@ protected void registerLevelEvents() { super.registerLevelEvents(); int particle = 2000; - this.addLevelEvent(24 | particle, LevelEventType.PARTICLE_POINT_CLOUD); - this.addLevelEvent(25 | particle, LevelEventType.PARTICLE_EXPLOSION); - this.addLevelEvent(26 | particle, LevelEventType.PARTICLE_BLOCK_EXPLOSION); + this.addLevelEvent(24 + particle, LevelEventType.PARTICLE_POINT_CLOUD); + this.addLevelEvent(25 + particle, LevelEventType.PARTICLE_EXPLOSION); + this.addLevelEvent(26 + particle, LevelEventType.PARTICLE_BLOCK_EXPLOSION); } @Override From 543056c2deec9acca232cc95f1d5e3f712605dd0 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 28 Jun 2020 19:57:56 +0800 Subject: [PATCH 52/70] Add LevelEvents for SOUND_CAMERA, BLOCK_START_BREAK, BLOCK_STOP_BREAK, BLOCK_UPDATE_BREAK, SET_DATA, ALL_PLAYER_SLEEPING --- .../bedrock/v407/BedrockPacketHelper_v407.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java index 9dfe08487..ce46bd264 100644 --- a/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java +++ b/bedrock/bedrock-v407/src/main/java/com/nukkitx/protocol/bedrock/v407/BedrockPacketHelper_v407.java @@ -2,7 +2,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.data.command.CommandParamType; +import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData; @@ -91,4 +91,18 @@ public void writeEntityLink(ByteBuf buffer, EntityLinkData entityLink) { buffer.writeBoolean(entityLink.isRiderInitiated()); } + @Override + protected void registerLevelEvents() { + super.registerLevelEvents(); + + this.addLevelEvent(1050, LevelEventType.SOUND_CAMERA); + + this.addLevelEvent(3600, LevelEventType.BLOCK_START_BREAK); + this.addLevelEvent(3601, LevelEventType.BLOCK_STOP_BREAK); + this.addLevelEvent(3602, LevelEventType.BLOCK_UPDATE_BREAK); + + this.addLevelEvent(4000, LevelEventType.SET_DATA); + + this.addLevelEvent(9800, LevelEventType.ALL_PLAYERS_SLEEPING); + } } From e9cd1f1b57eb08a93aaeff8d3c6b00a597978cc1 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 11:47:34 +0800 Subject: [PATCH 53/70] Start work on refector of MCEE --- bedrock/bedrock-v363/pom.xml | 8 +- .../v363/BedrockPacketHelper_v363.java | 35 + .../protocol/bedrock/v363/BedrockUtils.java | 1058 ----------------- .../protocol/bedrock/v363/Bedrock_v363.java | 256 ++-- .../AvailableCommandsSerializer_v363.java | 271 +---- .../serializer/PlayerListSerializer_v363.java | 48 +- .../serializer/StartGameSerializer_v363.java | 54 +- bedrock/pom.xml | 1 + 8 files changed, 215 insertions(+), 1516 deletions(-) create mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java diff --git a/bedrock/bedrock-v363/pom.xml b/bedrock/bedrock-v363/pom.xml index 9881a1dde..fb629cfae 100644 --- a/bedrock/bedrock-v363/pom.xml +++ b/bedrock/bedrock-v363/pom.xml @@ -5,19 +5,13 @@ bedrock-parent com.nukkitx.protocol - 2.5.7-SNAPSHOT + 2.6.0-SNAPSHOT 4.0.0 bedrock-v363 - - com.nukkitx.protocol - bedrock-common - ${project.version} - compile - com.nukkitx.protocol bedrock-v361 diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java new file mode 100644 index 000000000..e04dd8f21 --- /dev/null +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java @@ -0,0 +1,35 @@ +package com.nukkitx.protocol.bedrock.v363; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.nbt.stream.NBTInputStream; +import com.nukkitx.nbt.stream.NBTOutputStream; +import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.LevelEventType; +import com.nukkitx.protocol.bedrock.data.entity.EntityData; +import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap; +import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; +import com.nukkitx.protocol.bedrock.data.entity.EntityFlags; +import com.nukkitx.protocol.bedrock.data.inventory.ItemData; +import com.nukkitx.protocol.bedrock.data.structure.StructureMirror; +import com.nukkitx.protocol.bedrock.data.structure.StructureRotation; +import com.nukkitx.protocol.bedrock.data.structure.StructureSettings; +import com.nukkitx.protocol.bedrock.v354.BedrockPacketHelper_v354; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.io.IOException; +import java.util.Comparator; +import java.util.Map; +import java.util.stream.Collectors; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class BedrockPacketHelper_v363 extends BedrockPacketHelper_v354 { + +} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java deleted file mode 100644 index cca12a095..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockUtils.java +++ /dev/null @@ -1,1058 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363; - -import com.nukkitx.math.vector.Vector2f; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.nbt.CompoundTagBuilder; -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.nbt.tag.Tag; -import com.nukkitx.network.VarInts; -import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.data.*; -import com.nukkitx.protocol.bedrock.packet.ResourcePackStackPacket; -import com.nukkitx.protocol.bedrock.packet.ResourcePacksInfoPacket; -import com.nukkitx.protocol.bedrock.v361.serializer.GameRulesChangedSerializer_v361; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import io.netty.util.AsciiString; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import lombok.experimental.UtilityClass; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.function.BiConsumer; -import java.util.function.Function; - -import static com.nukkitx.protocol.bedrock.data.EntityData.*; - -@UtilityClass -public final class BedrockUtils { - private static final InternalLogger log = InternalLoggerFactory.getInstance(BedrockUtils.class); - private static final Int2ObjectBiMap METADATAS = new Int2ObjectBiMap<>(); - private static final Int2ObjectBiMap METADATA_FLAGS = new Int2ObjectBiMap<>(); - private static final Int2ObjectBiMap METADATA_TYPES = new Int2ObjectBiMap<>(9); - - static { - METADATAS.put(0, FLAGS); - METADATAS.put(1, HEALTH); - METADATAS.put(2, VARIANT); - METADATAS.put(3, COLOR); - METADATAS.put(4, NAMETAG); - METADATAS.put(5, OWNER_EID); - METADATAS.put(6, TARGET_EID); - METADATAS.put(7, AIR); - METADATAS.put(8, POTION_COLOR); - METADATAS.put(9, POTION_AMBIENT); - METADATAS.put(10, JUMP_DURATION); - METADATAS.put(11, HURT_TIME); - METADATAS.put(12, HURT_DIRECTION); - METADATAS.put(13, PADDLE_TIME_LEFT); - METADATAS.put(14, PADDLE_TIME_RIGHT); - METADATAS.put(15, EXPERIENCE_VALUE); - METADATAS.put(16, DISPLAY_ITEM); - METADATAS.put(17, DISPLAY_OFFSET); - METADATAS.put(18, HAS_DISPLAY); - METADATAS.put(22, CHARGED); - METADATAS.put(23, ENDERMAN_HELD_ITEM_ID); - METADATAS.put(24, ENTITY_AGE); - //METADATAS.put(25, WITCH_UNKNOWN); - METADATAS.put(26, CAN_START_SLEEP); - METADATAS.put(27, PLAYER_INDEX); - METADATAS.put(28, BED_RESPAWN_POS); - METADATAS.put(29, FIREBALL_POWER_X); - METADATAS.put(30, FIREBALL_POWER_Y); - METADATAS.put(31, FIREBALL_POWER_Z); - METADATAS.put(36, POTION_AUX_VALUE); - METADATAS.put(37, LEAD_HOLDER_EID); - METADATAS.put(38, SCALE); - METADATAS.put(39, HAS_NPC_COMPONENT); - METADATAS.put(40, NPC_SKIN_ID); - METADATAS.put(41, URL_TAG); - METADATAS.put(42, MAX_AIR); - METADATAS.put(43, MARK_VARIANT); - METADATAS.put(44, CONTAINER_TYPE); - METADATAS.put(45, CONTAINER_BASE_SIZE); - METADATAS.put(46, CONTAINER_EXTRA_SLOTS_PER_STRENGTH); - - METADATAS.put(47, BLOCK_TARGET); - METADATAS.put(48, WITHER_INVULNERABLE_TICKS); - METADATAS.put(49, WITHER_TARGET_1); - METADATAS.put(50, WITHER_TARGET_2); - METADATAS.put(51, WITHER_TARGET_3); - METADATAS.put(52, WITHER_AERIAL_ATTACK); - - METADATAS.put(53, BOUNDING_BOX_WIDTH); - METADATAS.put(54, BOUNDING_BOX_HEIGHT); - METADATAS.put(55, FUSE_LENGTH); - METADATAS.put(56, RIDER_SEAT_POSITION); - METADATAS.put(57, RIDER_ROTATION_LOCKED); - METADATAS.put(58, RIDER_MAX_ROTATION); - METADATAS.put(59, RIDER_MIN_ROTATION); - METADATAS.put(60, AREA_EFFECT_CLOUD_RADIUS); - METADATAS.put(61, AREA_EFFECT_CLOUD_WAITING); - METADATAS.put(62, AREA_EFFECT_CLOUD_PARTICLE_ID); - - METADATAS.put(64, SHULKER_ATTACH_FACE); - - METADATAS.put(66, SHULKER_ATTACH_POS); - METADATAS.put(67, TRADING_PLAYER_EID); - - METADATAS.put(69, COMMAND_BLOCK_ENABLED); // Unsure - METADATAS.put(70, COMMAND_BLOCK_COMMAND); - METADATAS.put(71, COMMAND_BLOCK_LAST_OUTPUT); - METADATAS.put(72, COMMAND_BLOCK_TRACK_OUTPUT); - METADATAS.put(73, CONTROLLING_RIDER_SEAT_NUMBER); - METADATAS.put(74, STRENGTH); - METADATAS.put(75, MAX_STRENGTH); - METADATAS.put(76, EVOKER_SPELL_COLOR); - METADATAS.put(77, LIMITED_LIFE); - METADATAS.put(78, ARMOR_STAND_POSE_INDEX); - METADATAS.put(79, ENDER_CRYSTAL_TIME_OFFSET); - METADATAS.put(80, ALWAYS_SHOW_NAMETAG); - METADATAS.put(81, COLOR_2); - METADATAS.put(83, SCORE_TAG); - METADATAS.put(84, BALLOON_ATTACHED_ENTITY); - METADATAS.put(85, PUFFERFISH_SIZE); - METADATAS.put(86, BOAT_BUBBLE_TIME); - METADATAS.put(87, AGENT_ID); - - - METADATAS.put(90, EAT_COUNTER); - METADATAS.put(91, FLAGS_2); - - - METADATAS.put(94, AREA_EFFECT_CLOUD_DURATION); - METADATAS.put(95, AREA_EFFECT_CLOUD_SPAWN_TIME); - METADATAS.put(96, AREA_EFFECT_CLOUD_RADIUS_PER_TICK); - METADATAS.put(97, AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP); - METADATAS.put(98, AREA_EFFECT_CLOUD_PICKUP_COUNT); - METADATAS.put(99, INTERACTIVE_TAG); - METADATAS.put(100, TRADE_TIER); - METADATAS.put(101, MAX_TRADE_TIER); - METADATAS.put(102, TRADE_XP); - METADATAS.put(103, SKIN_ID); - - METADATAS.put(105, UNKNOWN_105); - METADATAS.put(106, UNKNOWN_106); - METADATAS.put(107, UNKNOWN_107); - METADATAS.put(108, UNKNOWN_108); - METADATAS.put(109, UNKNOWN_109); - - - METADATA_FLAGS.put(0, EntityFlag.ON_FIRE); - METADATA_FLAGS.put(1, EntityFlag.SNEAKING); - METADATA_FLAGS.put(2, EntityFlag.RIDING); - METADATA_FLAGS.put(3, EntityFlag.SPRINTING); - METADATA_FLAGS.put(4, EntityFlag.USING_ITEM); - METADATA_FLAGS.put(5, EntityFlag.INVISIBLE); - METADATA_FLAGS.put(6, EntityFlag.TEMPTED); - METADATA_FLAGS.put(7, EntityFlag.IN_LOVE); - METADATA_FLAGS.put(8, EntityFlag.SADDLED); - METADATA_FLAGS.put(9, EntityFlag.POWERED); - METADATA_FLAGS.put(10, EntityFlag.IGNITED); - METADATA_FLAGS.put(11, EntityFlag.BABY); - METADATA_FLAGS.put(12, EntityFlag.CONVERTING); - METADATA_FLAGS.put(13, EntityFlag.CRITICAL); - METADATA_FLAGS.put(14, EntityFlag.CAN_SHOW_NAME); - METADATA_FLAGS.put(15, EntityFlag.ALWAYS_SHOW_NAME); - METADATA_FLAGS.put(16, EntityFlag.NO_AI); - METADATA_FLAGS.put(17, EntityFlag.SILENT); - METADATA_FLAGS.put(18, EntityFlag.WALL_CLIMBING); - METADATA_FLAGS.put(19, EntityFlag.CAN_CLIMB); - METADATA_FLAGS.put(20, EntityFlag.CAN_SWIM); - METADATA_FLAGS.put(21, EntityFlag.CAN_FLY); - METADATA_FLAGS.put(22, EntityFlag.CAN_WALK); - METADATA_FLAGS.put(23, EntityFlag.RESTING); - METADATA_FLAGS.put(24, EntityFlag.SITTING); - METADATA_FLAGS.put(25, EntityFlag.ANGRY); - METADATA_FLAGS.put(26, EntityFlag.INTERESTED); - METADATA_FLAGS.put(27, EntityFlag.CHARGED); - METADATA_FLAGS.put(28, EntityFlag.TAMED); - METADATA_FLAGS.put(29, EntityFlag.ORPHANED); - METADATA_FLAGS.put(30, EntityFlag.LEASHED); - METADATA_FLAGS.put(31, EntityFlag.SHEARED); - METADATA_FLAGS.put(32, EntityFlag.GLIDING); - METADATA_FLAGS.put(33, EntityFlag.ELDER); - METADATA_FLAGS.put(34, EntityFlag.MOVING); - METADATA_FLAGS.put(35, EntityFlag.BREATHING); - METADATA_FLAGS.put(36, EntityFlag.CHESTED); - METADATA_FLAGS.put(37, EntityFlag.STACKABLE); - METADATA_FLAGS.put(38, EntityFlag.SHOW_BOTTOM); - METADATA_FLAGS.put(39, EntityFlag.STANDING); - METADATA_FLAGS.put(40, EntityFlag.SHAKING); - METADATA_FLAGS.put(41, EntityFlag.IDLING); - METADATA_FLAGS.put(42, EntityFlag.CASTING); - METADATA_FLAGS.put(43, EntityFlag.CHARGING); - METADATA_FLAGS.put(44, EntityFlag.WASD_CONTROLLED); - METADATA_FLAGS.put(45, EntityFlag.CAN_POWER_JUMP); - METADATA_FLAGS.put(46, EntityFlag.LINGERING); - METADATA_FLAGS.put(47, EntityFlag.HAS_COLLISION); - METADATA_FLAGS.put(48, EntityFlag.HAS_GRAVITY); - METADATA_FLAGS.put(49, EntityFlag.FIRE_IMMUNE); - METADATA_FLAGS.put(50, EntityFlag.DANCING); - METADATA_FLAGS.put(51, EntityFlag.ENCHANTED); - METADATA_FLAGS.put(52, EntityFlag.RETURN_TRIDENT); - METADATA_FLAGS.put(53, EntityFlag.CONTAINER_IS_PRIVATE); - METADATA_FLAGS.put(55, EntityFlag.DAMAGE_NEARBY_MOBS); - METADATA_FLAGS.put(56, EntityFlag.SWIMMING); - METADATA_FLAGS.put(57, EntityFlag.BRIBED); - METADATA_FLAGS.put(58, EntityFlag.IS_PREGNANT); - METADATA_FLAGS.put(59, EntityFlag.LAYING_EGG); - METADATA_FLAGS.put(60, EntityFlag.RIDER_CAN_PICK); - METADATA_FLAGS.put(61, EntityFlag.TRANSITION_SITTING); - METADATA_FLAGS.put(62, EntityFlag.EATING); - METADATA_FLAGS.put(63, EntityFlag.LAYING_DOWN); - METADATA_FLAGS.put(64, EntityFlag.SNEEZING); - METADATA_FLAGS.put(65, EntityFlag.TRUSTING); - METADATA_FLAGS.put(66, EntityFlag.ROLLING); - METADATA_FLAGS.put(67, EntityFlag.SCARED); - METADATA_FLAGS.put(68, EntityFlag.IN_SCAFFOLDING); - METADATA_FLAGS.put(69, EntityFlag.OVER_SCAFFOLDING); - METADATA_FLAGS.put(70, EntityFlag.FALL_THROUGH_SCAFFOLDING); - METADATA_FLAGS.put(71, EntityFlag.BLOCKING); - METADATA_FLAGS.put(72, EntityFlag.DISABLE_BLOCKING); - METADATA_FLAGS.put(87, EntityFlag.UNKNOWN_87); - - - METADATA_FLAGS.put(75, EntityFlag.SLEEPING); - - METADATA_FLAGS.put(77, EntityFlag.TRADE_INTEREST); - METADATA_FLAGS.put(78, EntityFlag.DOOR_BREAKER); - METADATA_FLAGS.put(79, EntityFlag.BREAKING_OBSTRUCTION); - METADATA_FLAGS.put(80, EntityFlag.DOOR_OPENER); - METADATA_FLAGS.put(81, EntityFlag.ILLAGER_CAPTAIN); - METADATA_FLAGS.put(82, EntityFlag.STUNNED); - METADATA_FLAGS.put(83, EntityFlag.ROARING); - METADATA_FLAGS.put(84, EntityFlag.DELAYED_ATTACKING); - METADATA_FLAGS.put(85, EntityFlag.AVOIDING_MOBS); - - METADATA_TYPES.put(7, Type.FLAGS); - METADATA_TYPES.put(0, Type.BYTE); - METADATA_TYPES.put(1, Type.SHORT); - METADATA_TYPES.put(2, Type.INT); - METADATA_TYPES.put(3, Type.FLOAT); - METADATA_TYPES.put(4, Type.STRING); - METADATA_TYPES.put(5, Type.NBT); - METADATA_TYPES.put(6, Type.VECTOR3I); - METADATA_TYPES.put(7, Type.LONG); - METADATA_TYPES.put(8, Type.VECTOR3F); - } - - public static byte[] readByteArray(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - byte[] bytes = new byte[VarInts.readUnsignedInt(buffer)]; - buffer.readBytes(bytes); - return bytes; - } - - public static void writeByteArray(ByteBuf buffer, byte[] bytes) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(bytes, "bytes"); - VarInts.writeUnsignedInt(buffer, bytes.length); - buffer.writeBytes(bytes); - } - - public static String readString(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - return new String(readByteArray(buffer), StandardCharsets.UTF_8); - } - - public static void writeString(ByteBuf buffer, String string) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(string, "string"); - writeByteArray(buffer, string.getBytes(StandardCharsets.UTF_8)); - } - - public static AsciiString readLEAsciiString(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - int length = buffer.readIntLE(); - byte[] bytes = new byte[length]; - buffer.readBytes(bytes); - return new AsciiString(bytes); - } - - public static void writeLEAsciiString(ByteBuf buffer, AsciiString string) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(string, "string"); - buffer.writeIntLE(string.length()); - buffer.writeBytes(string.toByteArray()); - } - - public static AsciiString readVarIntAsciiString(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - int length = VarInts.readUnsignedInt(buffer); - byte[] bytes = new byte[length]; - buffer.readBytes(bytes); - return new AsciiString(bytes); - } - - public static void writeVarIntAsciiString(ByteBuf buffer, AsciiString string) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(string, "string"); - VarInts.writeUnsignedInt(buffer, string.length()); - buffer.writeBytes(string.toByteArray()); - } - - public static UUID readUuid(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - return new UUID(buffer.readLongLE(), buffer.readLongLE()); - } - - public static void writeUuid(ByteBuf buffer, UUID uuid) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(uuid, "uuid"); - buffer.writeLongLE(uuid.getMostSignificantBits()); - buffer.writeLongLE(uuid.getLeastSignificantBits()); - } - - public static Vector3f readVector3f(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - float x = buffer.readFloatLE(); - float y = buffer.readFloatLE(); - float z = buffer.readFloatLE(); - return Vector3f.from(x, y, z); - } - - public static void writeVector3f(ByteBuf buffer, Vector3f vector3f) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(vector3f, "vector3f"); - buffer.writeFloatLE(vector3f.getX()); - buffer.writeFloatLE(vector3f.getY()); - buffer.writeFloatLE(vector3f.getZ()); - } - - public static Vector2f readVector2f(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - float x = buffer.readFloatLE(); - float y = buffer.readFloatLE(); - return Vector2f.from(x, y); - } - - public static void writeVector2f(ByteBuf buffer, Vector2f vector2f) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(vector2f, "vector2f"); - buffer.writeFloatLE(vector2f.getX()); - buffer.writeFloatLE(vector2f.getY()); - } - - - public static Vector3i readVector3i(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - int x = VarInts.readInt(buffer); - int y = VarInts.readInt(buffer); - int z = VarInts.readInt(buffer); - - return Vector3i.from(x, y, z); - } - - public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(vector3i, "vector3i"); - VarInts.writeInt(buffer, vector3i.getX()); - VarInts.writeInt(buffer, vector3i.getY()); - VarInts.writeInt(buffer, vector3i.getZ()); - } - - public static Vector3i readBlockPosition(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - int x = VarInts.readInt(buffer); - int y = VarInts.readUnsignedInt(buffer); - int z = VarInts.readInt(buffer); - - return Vector3i.from(x, y, z); - } - - public static void writeBlockPosition(ByteBuf buffer, Vector3i blockPosition) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(blockPosition, "blockPosition"); - VarInts.writeInt(buffer, blockPosition.getX()); - VarInts.writeUnsignedInt(buffer, blockPosition.getY()); - VarInts.writeInt(buffer, blockPosition.getZ()); - } - - public static Vector3f readByteRotation(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - float pitch = readByteAngle(buffer); - float yaw = readByteAngle(buffer); - float roll = readByteAngle(buffer); - return Vector3f.from(pitch, yaw, roll); - } - - public static void writeByteRotation(ByteBuf buffer, Vector3f rotation) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(rotation, "rotation"); - writeByteAngle(buffer, rotation.getX()); - writeByteAngle(buffer, rotation.getY()); - writeByteAngle(buffer, rotation.getZ()); - } - - public static float readByteAngle(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - return buffer.readByte() * (360f / 256f); - } - - public static void writeByteAngle(ByteBuf buffer, float angle) { - Preconditions.checkNotNull(buffer, "buffer"); - buffer.writeByte((byte) (angle / (360f / 256f))); - } - - public static Attribute readEntityAttribute(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - String name = BedrockUtils.readString(buffer); - float min = buffer.readFloatLE(); - float max = buffer.readFloatLE(); - float val = buffer.readFloatLE(); - - return new Attribute(name, min, max, val, max); - } - - public static void writeEntityAttribute(ByteBuf buffer, Attribute attribute) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(attribute, "attribute"); - - BedrockUtils.writeString(buffer, attribute.getName()); - buffer.writeFloatLE(attribute.getMinimum()); - buffer.writeFloatLE(attribute.getMaximum()); - buffer.writeFloatLE(attribute.getValue()); - } - - public static Attribute readPlayerAttribute(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - float min = buffer.readFloatLE(); - float max = buffer.readFloatLE(); - float val = buffer.readFloatLE(); - float def = buffer.readFloatLE(); - String name = BedrockUtils.readString(buffer); - - return new Attribute(name, min, max, val, def); - } - - public static void writePlayerAttribute(ByteBuf buffer, Attribute attribute) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(attribute, "attribute"); - - buffer.writeFloatLE(attribute.getMinimum()); - buffer.writeFloatLE(attribute.getMaximum()); - buffer.writeFloatLE(attribute.getValue()); - buffer.writeFloatLE(attribute.getDefaultValue()); - BedrockUtils.writeString(buffer, attribute.getName()); - } - - public static EntityLink readEntityLink(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - long from = VarInts.readLong(buffer); - long to = VarInts.readLong(buffer); - int type = buffer.readUnsignedByte(); - boolean immediate = buffer.readBoolean(); - - return new EntityLink(from, to, EntityLink.Type.values()[type], immediate); - } - - public static void writeEntityLink(ByteBuf buffer, EntityLink entityLink) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(entityLink, "entityLink"); - - VarInts.writeLong(buffer, entityLink.getFrom()); - VarInts.writeLong(buffer, entityLink.getTo()); - buffer.writeByte(entityLink.getType().ordinal()); - buffer.writeBoolean(entityLink.isImmediate()); - } - - public static ItemData readItemData(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - int id = VarInts.readInt(buffer); - if (id == 0) { - // We don't need to read anything extra. - return ItemData.AIR; - } - int aux = VarInts.readInt(buffer); - short damage = (short) (aux >> 8); - if (damage == Short.MAX_VALUE) damage = -1; - int count = aux & 0xff; - int nbtSize = buffer.readShortLE(); - - CompoundTag compoundTag = null; - if (nbtSize > 0) { - try (NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(buffer.readSlice(nbtSize)))) { - Tag tag = reader.readTag(); - if (tag instanceof CompoundTag) { - compoundTag = (CompoundTag) tag; - } - } catch (IllegalArgumentException ignored) { - } catch (IOException e) { - throw new IllegalStateException("Unable to load NBT data", e); - } - } else if (nbtSize == -1) { - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - int nbtTagCount = VarInts.readUnsignedInt(buffer); - if (nbtTagCount == 1) { - Tag tag = reader.readTag(); - if (tag instanceof CompoundTag) { - compoundTag = (CompoundTag) tag; - } - } else { - throw new AssertionError("Expected 1 tag but got " + nbtTagCount); - } - } catch (IllegalArgumentException ignored) { - } catch (IOException e) { - throw new IllegalStateException("Unable to load NBT data", e); - } - } - - String[] canPlace = new String[VarInts.readInt(buffer)]; - for (int i = 0; i < canPlace.length; i++) { - canPlace[i] = readString(buffer); - } - - String[] canBreak = new String[VarInts.readInt(buffer)]; - for (int i = 0; i < canBreak.length; i++) { - canBreak[i] = readString(buffer); - } - - long blockingTicks = 0; - if (id == 513) { // TODO: 20/03/2019 We shouldn't be hardcoding this but it's what Microjang have made us do - blockingTicks = VarInts.readLong(buffer); - } - - return ItemData.of(id, damage, count, compoundTag, canPlace, canBreak, blockingTicks); - } - - public static void writeItemData(ByteBuf buffer, ItemData item) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(item, "item"); - - // Write id - int id = item.getId(); - if (id == 0) { - // We don't need to write anything extra. - buffer.writeByte(0); - return; - } - VarInts.writeInt(buffer, id); - - // Write damage and count - short damage = item.getDamage(); - if (damage == -1) damage = Short.MAX_VALUE; - VarInts.writeInt(buffer, (damage << 8) | (item.getCount() & 0xff)); - - if (item.getTag() != null) { - buffer.writeShort(-1); - VarInts.writeUnsignedInt(buffer, 1); // Hardcoded in current version - - try (NBTOutputStream stream = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - stream.write(item.getTag()); - } catch (IOException e) { - // This shouldn't happen (as this is backed by a Netty ByteBuf), but okay... - throw new IllegalStateException("Unable to save NBT data", e); - } - } else { - buffer.writeShortLE(0); - } - - String[] canPlace = item.getCanPlace(); - VarInts.writeInt(buffer, canPlace.length); - for (String aCanPlace : canPlace) { - BedrockUtils.writeString(buffer, aCanPlace); - } - - String[] canBreak = item.getCanBreak(); - VarInts.writeInt(buffer, canBreak.length); - for (String aCanBreak : canBreak) { - BedrockUtils.writeString(buffer, aCanBreak); - } - - if (id == 513) { // TODO: 20/03/2019 We shouldn't be hardcoding this but it's what Microjang have made us do - VarInts.writeLong(buffer, item.getBlockingTicks()); - } - } - - public static ItemData readRecipeIngredient(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - int id = VarInts.readInt(buffer); - int auxValue = 0; - int stackSize = 0; - - if (id != 0) { - auxValue = VarInts.readInt(buffer); - if (auxValue == 0x7fff) auxValue = -1; - stackSize = VarInts.readInt(buffer); - } - - return ItemData.of(id, (short) auxValue, stackSize); - } - - public static void writeRecipeIngredient(ByteBuf buffer, ItemData itemData) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(itemData, "itemData"); - - int id = itemData.getId(); - VarInts.writeInt(buffer, id); - - if (id != 0) { - int damage = itemData.getDamage(); - if (damage == -1) damage = 0x7fff; - VarInts.writeInt(buffer, damage); - VarInts.writeInt(buffer, itemData.getCount()); - } - } - - public static CommandOriginData readCommandOriginData(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - CommandOriginData.Origin origin = CommandOriginData.Origin.values()[VarInts.readUnsignedInt(buffer)]; - UUID uuid = readUuid(buffer); - String requestId = readString(buffer); - long varLong = -1; - if (origin == CommandOriginData.Origin.DEV_CONSOLE || origin == CommandOriginData.Origin.TEST) { - varLong = VarInts.readLong(buffer); - } - return new CommandOriginData(origin, uuid, requestId, varLong); - } - - public static void writeCommandOriginData(ByteBuf buffer, CommandOriginData originData) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(originData, "commandOriginData"); - VarInts.writeUnsignedInt(buffer, originData.getOrigin().ordinal()); - writeUuid(buffer, originData.getUuid()); - writeString(buffer, originData.getRequestId()); - if (originData.getOrigin() == CommandOriginData.Origin.DEV_CONSOLE || originData.getOrigin() == CommandOriginData.Origin.TEST) { - VarInts.writeLong(buffer, originData.getEvent()); - } - } - - public static CommandOutputMessage readCommandOutputMessage(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - boolean internal = buffer.readBoolean(); - String messageId = readString(buffer); - String[] parameters = new String[VarInts.readUnsignedInt(buffer)]; - for (int i = 0; i < parameters.length; i++) { - parameters[i] = BedrockUtils.readString(buffer); - } - return new CommandOutputMessage(internal, messageId, parameters); - } - - public static void writeCommandOutputMessage(ByteBuf buffer, CommandOutputMessage outputMessage) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(outputMessage, "outputMessage"); - buffer.writeBoolean(outputMessage.isInternal()); - writeString(buffer, outputMessage.getMessageId()); - writeArray(buffer, outputMessage.getParameters(), BedrockUtils::writeString); - } - - public static List readPacksInfoEntries(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - List entries = new ObjectArrayList<>(); - int length = buffer.readUnsignedShortLE(); - for (int i = 0; i < length; i++) { - String packId = readString(buffer); - String packVersion = readString(buffer); - long packSize = buffer.readLongLE(); - String encryptionKey = readString(buffer); - String subpackName = readString(buffer); - String contentId = readString(buffer); - boolean unknownBool = buffer.readBoolean(); - entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, unknownBool)); - } - return entries; - } - - public static void writePacksInfoEntries(ByteBuf buffer, Collection packInfoEntries) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(packInfoEntries, "packInfoEntries"); - buffer.writeShortLE(packInfoEntries.size()); - for (ResourcePacksInfoPacket.Entry packInfoEntry : packInfoEntries) { - writeString(buffer, packInfoEntry.getPackId().toString()); - writeString(buffer, packInfoEntry.getPackVersion()); - buffer.writeLongLE(packInfoEntry.getPackSize()); - writeString(buffer, packInfoEntry.getEncryptionKey()); - writeString(buffer, packInfoEntry.getSubpackName()); - writeString(buffer, packInfoEntry.getContentId()); - buffer.writeBoolean(packInfoEntry.isScripting()); - } - } - - public static ResourcePackStackPacket.Entry readPackInstanceEntry(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - String packId = readString(buffer); - String packVersion = readString(buffer); - String subpackName = readString(buffer); - return new ResourcePackStackPacket.Entry(packId, packVersion, subpackName); - } - - public static void writePackInstanceEntry(ByteBuf buffer, ResourcePackStackPacket.Entry packInstanceEntry) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(packInstanceEntry, "packInstanceEntry"); - - writeString(buffer, packInstanceEntry.getPackId().toString()); - writeString(buffer, packInstanceEntry.getPackVersion()); - writeString(buffer, packInstanceEntry.getSubpackName()); - } - - public static void readArray(ByteBuf buffer, Collection array, Function function) { - int length = VarInts.readUnsignedInt(buffer); - - - for (int i = 0; i < length; i++) { - array.add(function.apply(buffer)); - } - } - - public static void writeArray(ByteBuf buffer, Collection array, BiConsumer biConsumer) { - VarInts.writeUnsignedInt(buffer, array.size()); - for (T val : array) { - biConsumer.accept(buffer, val); - } - } - - public static void writeArray(ByteBuf buffer, T[] array, BiConsumer biConsumer) { - VarInts.writeUnsignedInt(buffer, array.length); - for (T val : array) { - biConsumer.accept(buffer, val); - } - } - - public static InventoryActionData readInventoryAction(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - InventorySource source = readInventorySource(buffer); - - int slot = VarInts.readUnsignedInt(buffer); - ItemData fromItem = readItemData(buffer); - ItemData toItem = readItemData(buffer); - - return new InventoryActionData(source, slot, fromItem, toItem); - } - - public static void writeInventoryAction(ByteBuf buffer, InventoryActionData action) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(action, "action"); - - writeInventorySource(buffer, action.getSource()); - - VarInts.writeUnsignedInt(buffer, action.getSlot()); - writeItemData(buffer, action.getFromItem()); - writeItemData(buffer, action.getToItem()); - } - - public static InventorySource readInventorySource(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - InventorySource.Type type = InventorySource.Type.byId(VarInts.readUnsignedInt(buffer)); - - switch (type) { - case CONTAINER: - int containerId = VarInts.readInt(buffer); - return InventorySource.fromContainerWindowId(containerId); - case GLOBAL: - return InventorySource.fromGlobalInventory(); - case WORLD_INTERACTION: - InventorySource.Flag flag = InventorySource.Flag.values()[VarInts.readUnsignedInt(buffer)]; - return InventorySource.fromWorldInteraction(flag); - case CREATIVE: - return InventorySource.fromCreativeInventory(); - case UNTRACKED_INTERACTION_UI: - containerId = VarInts.readInt(buffer); - return InventorySource.fromUntrackedInteractionUI(containerId); - case NON_IMPLEMENTED_TODO: - containerId = VarInts.readInt(buffer); - return InventorySource.fromNonImplementedTodo(containerId); - default: - return InventorySource.fromInvalid(); - } - } - - public static void writeInventorySource(ByteBuf buffer, InventorySource inventorySource) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(inventorySource, "inventorySource"); - - VarInts.writeUnsignedInt(buffer, inventorySource.getType().id()); - - switch (inventorySource.getType()) { - case CONTAINER: - case UNTRACKED_INTERACTION_UI: - case NON_IMPLEMENTED_TODO: - VarInts.writeInt(buffer, inventorySource.getContainerId()); - break; - case WORLD_INTERACTION: - VarInts.writeUnsignedInt(buffer, inventorySource.getFlag().ordinal()); - break; - } - } - - public static GameRuleData readGameRule(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - String name = BedrockUtils.readString(buffer); - int type = VarInts.readUnsignedInt(buffer); - - switch (type) { - case 1: - return new GameRuleData<>(name, buffer.readBoolean()); - case 2: - return new GameRuleData<>(name, VarInts.readUnsignedInt(buffer)); - case 3: - return new GameRuleData<>(name, buffer.readFloatLE()); - } - throw new IllegalStateException("Invalid gamerule type received"); - } - - public static void writeGameRule(ByteBuf buffer, GameRuleData gameRule) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(gameRule, "gameRule"); - - Object value = gameRule.getValue(); - int type = GameRulesChangedSerializer_v361.RULE_TYPES.get(value.getClass()); - - BedrockUtils.writeString(buffer, gameRule.getName()); - VarInts.writeUnsignedInt(buffer, type); - - switch (type) { - case 1: - buffer.writeBoolean((boolean) value); - break; - case 2: - VarInts.writeUnsignedInt(buffer, (int) value); - break; - case 3: - buffer.writeFloatLE((float) value); - break; - } - } - - public static void readEntityData(ByteBuf buffer, EntityDataMap metadataDictionary) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(metadataDictionary, "metadataDictionary"); - - int length = VarInts.readUnsignedInt(buffer); - - for (int i = 0; i < length; i++) { - int metadataInt = VarInts.readUnsignedInt(buffer); - EntityData entityData = METADATAS.get(metadataInt); - EntityData.Type type = METADATA_TYPES.get(VarInts.readUnsignedInt(buffer)); - if (entityData != null && entityData.isFlags()) { - if (type != Type.LONG) { - throw new IllegalArgumentException("Expected long value for flags, got " + type.name()); - } - type = Type.FLAGS; - } - - Object object; - switch (type) { - case BYTE: - object = buffer.readByte(); - break; - case SHORT: - object = buffer.readShortLE(); - break; - case INT: - object = VarInts.readInt(buffer); - break; - case FLOAT: - object = buffer.readFloatLE(); - break; - case STRING: - object = BedrockUtils.readString(buffer); - break; - case NBT: - CompoundTag tag; - try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { - tag = (CompoundTag) reader.readTag(); - } catch (IOException e) { - throw new IllegalStateException("Error whilst decoding NBT entity data"); - } - object = tag; - log.debug("TAG \n{}", tag); - break; - case VECTOR3I: - object = BedrockUtils.readVector3i(buffer); - break; - case FLAGS: - int index = entityData == FLAGS_2 ? 1 : 0; - metadataDictionary.getOrCreateFlags().set(VarInts.readLong(buffer), index, METADATA_FLAGS); - continue; - case LONG: - object = VarInts.readLong(buffer); - break; - case VECTOR3F: - object = BedrockUtils.readVector3f(buffer); - break; - default: - throw new IllegalArgumentException("Unknown entity data type received"); - } - if (entityData != null) { - metadataDictionary.put(entityData, object); - } else { - log.debug("Unknown entity data: {} type {} value {}", metadataInt, type, object); - } - } - } - - public static void writeEntityData(ByteBuf buffer, EntityDataMap metadataDictionary) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(metadataDictionary, "metadataDictionary"); - - VarInts.writeUnsignedInt(buffer, metadataDictionary.size()); - - for (Map.Entry entry : metadataDictionary.entrySet()) { - int index = buffer.writerIndex(); - VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey())); - Object object = entry.getValue(); - EntityData.Type type = EntityData.Type.from(object); - VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type)); - - switch (type) { - case BYTE: - buffer.writeByte((byte) object); - break; - case SHORT: - buffer.writeShortLE((short) object); - break; - case INT: - VarInts.writeInt(buffer, (int) object); - break; - case FLOAT: - buffer.writeFloatLE((float) object); - break; - case STRING: - BedrockUtils.writeString(buffer, (String) object); - break; - case NBT: - CompoundTag tag; - if (object instanceof CompoundTag) { - tag = (CompoundTag) object; - } else { - ItemData item = (ItemData) object; - tag = item.getTag(); - if (tag == null) { - tag = CompoundTagBuilder.builder().buildRootTag(); - } - } - try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) { - writer.write(tag); - } catch (IOException e) { - throw new IllegalStateException("Error whilst decoding NBT entity data"); - } - break; - case VECTOR3I: - BedrockUtils.writeVector3i(buffer, (Vector3i) object); - break; - case FLAGS: - int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0; - object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS); - case LONG: - VarInts.writeLong(buffer, (long) object); - break; - case VECTOR3F: - BedrockUtils.writeVector3f(buffer, (Vector3f) object); - break; - default: - buffer.writerIndex(index); - break; - } - } - } - - public static CommandEnumData readCommandEnumData(ByteBuf buffer, boolean soft) { - Preconditions.checkNotNull(buffer, "buffer"); - - String name = BedrockUtils.readString(buffer); - - String[] values = new String[VarInts.readUnsignedInt(buffer)]; - for (int i = 0; i < values.length; i++) { - values[i] = BedrockUtils.readString(buffer); - } - return new CommandEnumData(name, values, soft); - } - - public static void writeCommandEnumData(ByteBuf buffer, CommandEnumData enumData) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(enumData, "enumData"); - - BedrockUtils.writeString(buffer, enumData.getName()); - - String[] values = enumData.getValues(); - VarInts.writeUnsignedInt(buffer, values.length); - for (String value : values) { - BedrockUtils.writeString(buffer, value); - } - } - - public static StructureSettings readStructureSettings(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - String paletteName = BedrockUtils.readString(buffer); - boolean ignoreEntities = buffer.readBoolean(); - boolean ignoreBlocks = buffer.readBoolean(); - Vector3i structureSize = BedrockUtils.readBlockPosition(buffer); - Vector3i structureOffset = BedrockUtils.readBlockPosition(buffer); - long lastTouchedByEntityId = VarInts.readLong(buffer); - byte rotation = buffer.readByte(); - byte mirror = buffer.readByte(); - float integrityValue = buffer.readFloatLE(); - int integritySeed = VarInts.readUnsignedInt(buffer); - - return new StructureSettings(paletteName, ignoreEntities, ignoreBlocks, structureSize, structureOffset, - lastTouchedByEntityId, rotation, mirror, integrityValue, integritySeed); - } - - public static void writeStructureSettings(ByteBuf buffer, StructureSettings structureSettings) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(structureSettings, "structureSettings"); - - BedrockUtils.writeString(buffer, structureSettings.getPaletteName()); - buffer.writeBoolean(structureSettings.isIgnoreEntities()); - buffer.writeBoolean(structureSettings.isIgnoreBlocks()); - BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureSize()); - BedrockUtils.writeBlockPosition(buffer, structureSettings.getStructureOffset()); - VarInts.writeLong(buffer, structureSettings.getLastTouchedByEntityId()); - buffer.writeByte(structureSettings.getRotation()); - buffer.writeByte(structureSettings.getMirror()); - buffer.writeFloatLE(structureSettings.getIntegrityValue()); - VarInts.writeUnsignedInt(buffer, structureSettings.getIntegritySeed()); - } - - public static StructureEditorData readStructureEditorData(ByteBuf buffer) { - Preconditions.checkNotNull(buffer, "buffer"); - - String name = BedrockUtils.readString(buffer); - String structureDataField = BedrockUtils.readString(buffer); - boolean includePlayers = buffer.readBoolean(); - boolean showBoundingBox = buffer.readBoolean(); - int structureBlockType = VarInts.readInt(buffer); - StructureSettings settings = BedrockUtils.readStructureSettings(buffer); - - return new StructureEditorData(name, structureDataField, includePlayers, showBoundingBox, structureBlockType, - settings); - } - - public static void writeStructureEditorData(ByteBuf buffer, StructureEditorData structureEditorData) { - Preconditions.checkNotNull(buffer, "buffer"); - Preconditions.checkNotNull(structureEditorData, "structureEditorData"); - - BedrockUtils.writeString(buffer, structureEditorData.getName()); - BedrockUtils.writeString(buffer, structureEditorData.getStructureDataField()); - buffer.writeBoolean(structureEditorData.isIncludePlayers()); - buffer.writeBoolean(structureEditorData.isShowBoundingBox()); - VarInts.writeInt(buffer, structureEditorData.getStructureBlockType()); - BedrockUtils.writeStructureSettings(buffer, structureEditorData.getStructureSettings()); - } -} diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index 8e4c8810d..b1673978a 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -2,10 +2,13 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.protocol.bedrock.v291.serializer.*; +import com.nukkitx.protocol.bedrock.v313.serializer.*; +import com.nukkitx.protocol.bedrock.v332.serializer.*; +import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; +import com.nukkitx.protocol.bedrock.v354.serializer.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; -import com.nukkitx.protocol.bedrock.v363.serializer.AvailableCommandsSerializer_v363; -import com.nukkitx.protocol.bedrock.v363.serializer.PlayerListSerializer_v363; -import com.nukkitx.protocol.bedrock.v363.serializer.StartGameSerializer_v363; +import com.nukkitx.protocol.bedrock.v363.serializer.*; import lombok.experimental.UtilityClass; @UtilityClass @@ -13,149 +16,140 @@ public class Bedrock_v363 { public static BedrockPacketCodec V363_CODEC = BedrockPacketCodec.builder() .protocolVersion(363) .minecraftVersion("1.12.60") - .headerSerializer(PacketHeaderSerializer_v361.INSTANCE) - .registerPacket(LoginPacket.class, LoginSerializer_v361.INSTANCE, 1) - .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v361.INSTANCE, 2) - .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v361.INSTANCE, 3) - .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v361.INSTANCE, 4) - .registerPacket(DisconnectPacket.class, DisconnectSerializer_v361.INSTANCE, 5) - .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v361.INSTANCE, 6) - .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v361.INSTANCE, 7) - .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v361.INSTANCE, 8) - .registerPacket(TextPacket.class, TextSerializer_v361.INSTANCE, 9) - .registerPacket(SetTimePacket.class, SetTimeSerializer_v361.INSTANCE, 10) - .registerPacket(StartGamePacket.class, StartGameSerializer_v363.INSTANCE, 11) - .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v361.INSTANCE, 12) - .registerPacket(AddEntityPacket.class, AddEntitySerializer_v361.INSTANCE, 13) - .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v361.INSTANCE, 14) - .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v361.INSTANCE, 15) - .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v361.INSTANCE, 17) - .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v361.INSTANCE, 18) - .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v361.INSTANCE, 19) - .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v361.INSTANCE, 20) - .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v361.INSTANCE, 21) + .helper(BedrockPacketHelper_v363.INSTANCE) + .registerPacket(LoginPacket.class, LoginSerializer_v291.INSTANCE, 1) + .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v291.INSTANCE, 2) + .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v291.INSTANCE, 3) + .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v291.INSTANCE, 4) + .registerPacket(DisconnectPacket.class, DisconnectSerializer_v291.INSTANCE, 5) + .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v332.INSTANCE, 6) + .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v313.INSTANCE, 7) + .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v291.INSTANCE, 8) + .registerPacket(TextPacket.class, TextSerializer_v332.INSTANCE, 9) + .registerPacket(SetTimePacket.class, SetTimeSerializer_v291.INSTANCE, 10) + .registerPacket(StartGamePacket.class, StartGameSerializer_v361.INSTANCE, 11) + .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v291.INSTANCE, 12) + .registerPacket(AddEntityPacket.class, AddEntitySerializer_v313.INSTANCE, 13) + .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v291.INSTANCE, 14) + .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v291.INSTANCE, 15) + .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v291.INSTANCE, 17) + .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v291.INSTANCE, 18) + .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v291.INSTANCE, 19) + .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v291.INSTANCE, 20) + .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v291.INSTANCE, 21) .registerPacket(AddPaintingPacket.class, AddPaintingSerializer_v361.INSTANCE, 22) - .registerPacket(ExplodePacket.class, ExplodeSerializer_v361.INSTANCE, 23) - .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v361.INSTANCE, 24) - .registerPacket(LevelEventPacket.class, LevelEventSerializer_v361.INSTANCE, 25) - .registerPacket(BlockEventPacket.class, BlockEventSerializer_v361.INSTANCE, 26) - .registerPacket(EntityEventPacket.class, EntityEventSerializer_v361.INSTANCE, 27) - .registerPacket(MobEffectPacket.class, MobEffectSerializer_v361.INSTANCE, 28) - .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v361.INSTANCE, 29) - .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v361.INSTANCE, 30) - .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v361.INSTANCE, 31) - .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v361.INSTANCE, 32) - .registerPacket(InteractPacket.class, InteractSerializer_v361.INSTANCE, 33) - .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v361.INSTANCE, 34) - .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v361.INSTANCE, 35) - .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v361.INSTANCE, 36) - .registerPacket(EntityFallPacket.class, EntityFallSerializer_v361.INSTANCE, 37) - .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v361.INSTANCE, 38) - .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v361.INSTANCE, 39) - .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v361.INSTANCE, 40) - .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v361.INSTANCE, 41) - .registerPacket(SetHealthPacket.class, SetHealthSerializer_v361.INSTANCE, 42) - .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v361.INSTANCE, 43) - .registerPacket(AnimatePacket.class, AnimateSerializer_v361.INSTANCE, 44) - .registerPacket(RespawnPacket.class, RespawnSerializer_v361.INSTANCE, 45) - .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v361.INSTANCE, 46) - .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v361.INSTANCE, 47) - .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v361.INSTANCE, 48) - .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v361.INSTANCE, 49) - .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v361.INSTANCE, 50) - .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v361.INSTANCE, 51) + .registerPacket(ExplodePacket.class, ExplodeSerializer_v291.INSTANCE, 23) + .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v291.INSTANCE, 24) + .registerPacket(LevelEventPacket.class, LevelEventSerializer_v291.INSTANCE, 25) + .registerPacket(BlockEventPacket.class, BlockEventSerializer_v291.INSTANCE, 26) + .registerPacket(EntityEventPacket.class, EntityEventSerializer_v291.INSTANCE, 27) + .registerPacket(MobEffectPacket.class, MobEffectSerializer_v291.INSTANCE, 28) + .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v291.INSTANCE, 29) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v340.INSTANCE, 30) + .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v291.INSTANCE, 31) + .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v291.INSTANCE, 32) + .registerPacket(InteractPacket.class, InteractSerializer_v291.INSTANCE, 33) + .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v291.INSTANCE, 34) + .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v291.INSTANCE, 35) + .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v291.INSTANCE, 36) + .registerPacket(EntityFallPacket.class, EntityFallSerializer_v291.INSTANCE, 37) + .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v291.INSTANCE, 38) + .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v291.INSTANCE, 39) + .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v291.INSTANCE, 40) + .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v291.INSTANCE, 41) + .registerPacket(SetHealthPacket.class, SetHealthSerializer_v291.INSTANCE, 42) + .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v291.INSTANCE, 43) + .registerPacket(AnimatePacket.class, AnimateSerializer_v291.INSTANCE, 44) + .registerPacket(RespawnPacket.class, RespawnSerializer_v291.INSTANCE, 45) + .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v291.INSTANCE, 46) + .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v291.INSTANCE, 47) + .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v291.INSTANCE, 48) + .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v291.INSTANCE, 49) + .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v291.INSTANCE, 50) + .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v291.INSTANCE, 51) .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v361.INSTANCE, 52) - .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v361.INSTANCE, 53) - .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v361.INSTANCE, 54) - .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v361.INSTANCE, 55) - .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v361.INSTANCE, 56) - .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v361.INSTANCE, 57) + .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v291.INSTANCE, 53) + .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v291.INSTANCE, 54) + .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v291.INSTANCE, 55) + .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v291.INSTANCE, 56) + .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v291.INSTANCE, 57) .registerPacket(LevelChunkPacket.class, LevelChunkSerializer_v361.INSTANCE, 58) - .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v361.INSTANCE, 59) - .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v361.INSTANCE, 60) - .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v361.INSTANCE, 61) - .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v361.INSTANCE, 62) + .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v291.INSTANCE, 59) + .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v291.INSTANCE, 60) + .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v291.INSTANCE, 61) + .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v291.INSTANCE, 62) .registerPacket(PlayerListPacket.class, PlayerListSerializer_v363.INSTANCE, 63) - .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v361.INSTANCE, 64) - .registerPacket(EventPacket.class, EventSerializer_v361.INSTANCE, 65) - .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v361.INSTANCE, 66) - .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v361.INSTANCE, 67) - .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v361.INSTANCE, 68) - .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v361.INSTANCE, 69) - .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v361.INSTANCE, 70) - .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v361.INSTANCE, 71) - .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v361.INSTANCE, 72) - .registerPacket(CameraPacket.class, CameraSerializer_v361.INSTANCE, 73) - .registerPacket(BossEventPacket.class, BossEventSerializer_v361.INSTANCE, 74) - .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v361.INSTANCE, 75) + .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v291.INSTANCE, 64) + .registerPacket(EventPacket.class, EventSerializer_v354.INSTANCE, 65) + .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v291.INSTANCE, 66) + .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v354.INSTANCE, 67) + .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v291.INSTANCE, 68) + .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v291.INSTANCE, 69) + .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v291.INSTANCE, 70) + .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v291.INSTANCE, 71) + .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v291.INSTANCE, 72) + .registerPacket(CameraPacket.class, CameraSerializer_v291.INSTANCE, 73) + .registerPacket(BossEventPacket.class, BossEventSerializer_v291.INSTANCE, 74) + .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v291.INSTANCE, 75) .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v363.INSTANCE, 76) - .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v361.INSTANCE, 77) + .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v291.INSTANCE, 77) .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v361.INSTANCE, 78) - .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v361.INSTANCE, 79) - .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v361.INSTANCE, 80) - .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v361.INSTANCE, 81) + .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v291.INSTANCE, 79) + .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v354.INSTANCE, 80) + .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v291.INSTANCE, 81) .registerPacket(ResourcePackDataInfoPacket.class, ResourcePackDataInfoSerializer_v361.INSTANCE, 82) - .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v361.INSTANCE, 83) - .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v361.INSTANCE, 84) - .registerPacket(TransferPacket.class, TransferSerializer_v361.INSTANCE, 85) - .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v361.INSTANCE, 86) - .registerPacket(StopSoundPacket.class, StopSoundSerializer_v361.INSTANCE, 87) - .registerPacket(SetTitlePacket.class, SetTitleSerializer_v361.INSTANCE, 88) - .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v361.INSTANCE, 89) + .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v291.INSTANCE, 83) + .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v291.INSTANCE, 84) + .registerPacket(TransferPacket.class, TransferSerializer_v291.INSTANCE, 85) + .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v291.INSTANCE, 86) + .registerPacket(StopSoundPacket.class, StopSoundSerializer_v291.INSTANCE, 87) + .registerPacket(SetTitlePacket.class, SetTitleSerializer_v291.INSTANCE, 88) + .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v291.INSTANCE, 89) .registerPacket(StructureBlockUpdatePacket.class, StructureBlockUpdateSerializer_v361.INSTANCE, 90) - .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v361.INSTANCE, 91) - .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v361.INSTANCE, 92) - .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v361.INSTANCE, 93) - .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v361.INSTANCE, 94) - .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v361.INSTANCE, 95) - .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v361.INSTANCE, 96) - .registerPacket(BookEditPacket.class, BookEditSerializer_v361.INSTANCE, 97) - .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v361.INSTANCE, 98) - .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v361.INSTANCE, 99) - .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v361.INSTANCE, 100) - .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v361.INSTANCE, 101) - .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v361.INSTANCE, 102) - .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v361.INSTANCE, 103) - .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v361.INSTANCE, 104) - .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v361.INSTANCE, 105) - .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v361.INSTANCE, 106) - .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v361.INSTANCE, 107) - .registerPacket(SetScorePacket.class, SetScoreSerializer_v361.INSTANCE, 108) - .registerPacket(LabTablePacket.class, LabTableSerializer_v361.INSTANCE, 109) - .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v361.INSTANCE, 110) - .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v361.INSTANCE, 111) - .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v361.INSTANCE, 112) - .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v361.INSTANCE, 113) - .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v361.INSTANCE, 114) - .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v361.INSTANCE, 115) - .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v361.INSTANCE, 117) - .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v361.INSTANCE, 118) - .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v361.INSTANCE, 119) - .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v361.INSTANCE, 120) - .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v361.INSTANCE, 121) - .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v361.INSTANCE, 122) - .registerPacket(LevelSoundEventPacket.class, LevelSoundEvent3Serializer_v361.INSTANCE, 123) + .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v291.INSTANCE, 91) + .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v291.INSTANCE, 92) + .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v291.INSTANCE, 93) + .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v291.INSTANCE, 94) + .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v291.INSTANCE, 95) + .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v291.INSTANCE, 96) + .registerPacket(BookEditPacket.class, BookEditSerializer_v291.INSTANCE, 97) + .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v291.INSTANCE, 98) + .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v291.INSTANCE, 99) + .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v291.INSTANCE, 100) + .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v291.INSTANCE, 101) + .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v291.INSTANCE, 102) + .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v291.INSTANCE, 103) + .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v291.INSTANCE, 104) + .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v291.INSTANCE, 105) + .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v291.INSTANCE, 106) + .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v291.INSTANCE, 107) + .registerPacket(SetScorePacket.class, SetScoreSerializer_v291.INSTANCE, 108) + .registerPacket(LabTablePacket.class, LabTableSerializer_v291.INSTANCE, 109) + .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v291.INSTANCE, 110) + .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v291.INSTANCE, 111) + .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v291.INSTANCE, 112) + .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v291.INSTANCE, 113) + .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v291.INSTANCE, 114) + .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v332.INSTANCE, 115) + .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v291.INSTANCE, 117) + .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v332.INSTANCE, 118) + .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v313.INSTANCE, 119) + .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v313.INSTANCE, 120) + .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v313.INSTANCE, 121) + .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v313.INSTANCE, 122) + .registerPacket(LevelSoundEventPacket.class, LevelSoundEventSerializer_v332.INSTANCE, 123) .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v361.INSTANCE, 124) - .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v361.INSTANCE, 125) + .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v354.INSTANCE, 125) .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v361.INSTANCE, 126) // AddEntityPacket 127 // RemoveEntityPacket 128 .registerPacket(ClientCacheStatusPacket.class, ClientCacheStatusSerializer_v361.INSTANCE, 129) - .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v361.INSTANCE, 130) - .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v361.INSTANCE, 131) - .registerPacket(StructureTemplateDataExportRequestPacket.class, StructureTemplateDataExportRequestSerializer_v361.INSTANCE, 132) - .registerPacket(StructureTemplateDataExportResponsePacket.class, StructureTemplateDataExportResponseSerializer_v361.INSTANCE, 133) + .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v354.INSTANCE, 130) + .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v354.INSTANCE, 131) + .registerPacket(StructureTemplateDataRequestPacket.class, StructureTemplateDataRequestSerializer_v361.INSTANCE, 132) + .registerPacket(StructureTemplateDataResponsePacket.class, StructureTemplateDataResponseSerializer_v361.INSTANCE, 133) .registerPacket(UpdateBlockPropertiesPacket.class, UpdateBlockPropertiesSerializer_v361.INSTANCE, 134) .registerPacket(ClientCacheBlobStatusPacket.class, ClientCacheBlobStatusSerializer_v361.INSTANCE, 135) .registerPacket(ClientCacheMissResponsePacket.class, ClientCacheMissResponseSerializer_v361.INSTANCE, 136) - -// .registerPacket(EducationSettingsPacket.class, EducationSettingsSerializer_v363.INSTANCE, 137) -// .registerPacket(EmotePacket.class, EmoteSerializer_v363.INSTANCE, 138) -// .registerPacket(MultiplayerSettingsPacket.class, MultiplayerSettingsSerializer_v363.INSTANCE, 139) -// .registerPacket(SettingsCommandPacket.class, SettingsCommandSerializer_v363.INSTANCE, 140) -// .registerPacket(AnvilDamagePacket.class, AnvilDamageSerializer_v363.INSTANCE, 141) -// .registerPacket(CompletedUsingItemPacket.class, CompletedUsingItemSerializer_v363.INSTANCE, 142) -// .registerPacket(NetworkSettingsPacket.class, NetworkSettingsSerializer_v363.INSTANCE, 143) -// .registerPacket(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v363.INSTANCE, 144) .build(); } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java index 9edf8a2e1..9cc2f8c65 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java @@ -2,11 +2,13 @@ import com.nukkitx.network.VarInts; import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.CommandData; import com.nukkitx.protocol.bedrock.data.CommandEnumData; import com.nukkitx.protocol.bedrock.data.CommandParamData; import com.nukkitx.protocol.bedrock.data.CommandParamType; import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; +import com.nukkitx.protocol.bedrock.v340.serializer.AvailableCommandsSerializer_v340; import com.nukkitx.protocol.bedrock.v361.BedrockUtils; import com.nukkitx.protocol.serializer.PacketSerializer; import com.nukkitx.protocol.util.Int2ObjectBiMap; @@ -27,274 +29,7 @@ import static com.nukkitx.protocol.bedrock.data.CommandParamData.Type.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AvailableCommandsSerializer_v363 implements PacketSerializer { - private static final InternalLogger log = InternalLoggerFactory.getInstance(AvailableCommandsSerializer_v363.class); +public class AvailableCommandsSerializer_v363 extends AvailableCommandsSerializer_v340 { public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); - private static final ObjIntConsumer WRITE_BYTE = ByteBuf::writeByte; - private static final ObjIntConsumer WRITE_SHORT = ByteBuf::writeShortLE; - private static final ObjIntConsumer WRITE_INT = ByteBuf::writeIntLE; - private static final ToIntFunction READ_BYTE = ByteBuf::readUnsignedByte; - private static final ToIntFunction READ_SHORT = ByteBuf::readUnsignedShortLE; - private static final ToIntFunction READ_INT = ByteBuf::readIntLE; - private static final Int2ObjectBiMap PARAM_TYPES = new Int2ObjectBiMap<>(); - static { - PARAM_TYPES.put(1, INT); - PARAM_TYPES.put(2, FLOAT); - PARAM_TYPES.put(3, VALUE); - PARAM_TYPES.put(4, WILDCARD_INT); - PARAM_TYPES.put(5, OPERATOR); - PARAM_TYPES.put(6, TARGET); - PARAM_TYPES.put(7, WILDCARD_TARGET); - PARAM_TYPES.put(14, FILE_PATH); - PARAM_TYPES.put(18, INT_RANGE); - PARAM_TYPES.put(27, STRING); - PARAM_TYPES.put(29, POSITION); - PARAM_TYPES.put(32, MESSAGE); - PARAM_TYPES.put(34, TEXT); - PARAM_TYPES.put(37, JSON); - PARAM_TYPES.put(44, COMMAND); - } - - @Override - public void serialize(ByteBuf buffer, AvailableCommandsPacket packet) { - Set enumValuesSet = new ObjectOpenHashSet<>(); - Set postfixSet = new ObjectOpenHashSet<>(); - Set enumsSet = new ObjectOpenHashSet<>(); - Set softEnumsSet = new ObjectOpenHashSet<>(); - - // Get all enum values - for (CommandData data : packet.getCommands()) { - if (data.getAliases() != null) { - Collections.addAll(enumValuesSet, data.getAliases().getValues()); - enumsSet.add(data.getAliases()); - } - - for (CommandParamData[] overload : data.getOverloads()) { - for (CommandParamData parameter : overload) { - CommandEnumData commandEnumData = parameter.getEnumData(); - if (commandEnumData != null) { - if (commandEnumData.isSoft()) { - softEnumsSet.add(commandEnumData); - } else { - Collections.addAll(enumValuesSet, commandEnumData.getValues()); - enumsSet.add(commandEnumData); - } - } - - String postfix = parameter.getPostfix(); - if (postfix != null) { - postfixSet.add(postfix); - } - } - } - } - - List enumValues = new ObjectArrayList<>(enumValuesSet); - List postFixes = new ObjectArrayList<>(postfixSet); - List enums = new ObjectArrayList<>(enumsSet); - List softEnums = new ObjectArrayList<>(softEnumsSet); - - // Determine width of enum index - ObjIntConsumer indexWriter; - int valuesSize = enumValues.size(); - if (valuesSize < 0x100) { - indexWriter = WRITE_BYTE; - } else if (valuesSize < 0x10000) { - indexWriter = WRITE_SHORT; - } else { - indexWriter = WRITE_INT; - } - - BedrockUtils.writeArray(buffer, enumValues, BedrockUtils::writeString); - BedrockUtils.writeArray(buffer, postFixes, BedrockUtils::writeString); - - // Write enums - BedrockUtils.writeArray(buffer, enums, (buf, commandEnum) -> { - BedrockUtils.writeString(buf, commandEnum.getName()); - - VarInts.writeUnsignedInt(buffer, commandEnum.getValues().length); - for (String value : commandEnum.getValues()) { - int index = enumValues.indexOf(value); - Preconditions.checkArgument(index > -1, "Invalid enum value detected"); - indexWriter.accept(buf, index); - } - }); - - // Write command data - BedrockUtils.writeArray(buffer, packet.getCommands(), (buf, commandData) -> { - BedrockUtils.writeString(buf, commandData.getName()); - BedrockUtils.writeString(buf, commandData.getDescription()); - byte flags = 0; - if (commandData.getFlags() != null) { - for (CommandData.Flag flag : commandData.getFlags()) { - flags |= 1 << flag.ordinal(); - } - } - buf.writeByte(flags); - buf.writeByte(commandData.getPermission()); - - CommandEnumData aliases = commandData.getAliases(); - buf.writeIntLE(enums.indexOf(aliases)); - - CommandParamData[][] overloads = commandData.getOverloads(); - VarInts.writeUnsignedInt(buf, overloads.length); - for (CommandParamData[] overload : overloads) { - VarInts.writeUnsignedInt(buf, overload.length); - for (CommandParamData param : overload) { - BedrockUtils.writeString(buf, param.getName()); - - int index; - boolean postfix = false; - boolean enumData = false; - boolean softEnum = false; - if (param.getPostfix() != null) { - postfix = true; - index = postFixes.indexOf(param.getPostfix()); - } else if (param.getEnumData() != null) { - if (param.getEnumData().isSoft()) { - softEnum = true; - index = softEnums.indexOf(param.getEnumData()); - } else { - enumData = true; - index = enums.indexOf(param.getEnumData()); - } - } else if (param.getType() != null) { - index = PARAM_TYPES.get(param.getType()); - } else { - throw new IllegalStateException("No param type specified"); - } - - CommandParamType type = new CommandParamType(index, enumData, softEnum, postfix); - - buf.writeIntLE(type.serialize()); - buf.writeBoolean(param.isOptional()); - byte options = 0; - if (param.getOptions() != null) { - for (CommandParamData.Option opt : param.getOptions()) { - options |= 1 << opt.ordinal(); - } - } - buf.writeByte(options); - } - } - }); - - BedrockUtils.writeArray(buffer, softEnums, BedrockUtils::writeCommandEnumData); - } - - @Override - public void deserialize(ByteBuf buffer, AvailableCommandsPacket packet) { - List enumValues = new ObjectArrayList<>(); - List postFixes = new ObjectArrayList<>(); - List enums = new ObjectArrayList<>(); - List commands = new ObjectArrayList<>(); - List softEnums = new ObjectArrayList<>(); - - BedrockUtils.readArray(buffer, enumValues, BedrockUtils::readString); - BedrockUtils.readArray(buffer, postFixes, BedrockUtils::readString); - - // Determine width of enum index - ToIntFunction indexReader; - int valuesSize = enumValues.size(); - if (valuesSize < 0x100) { - indexReader = READ_BYTE; - } else if (valuesSize < 0x10000) { - indexReader = READ_SHORT; - } else { - indexReader = READ_INT; - } - - BedrockUtils.readArray(buffer, enums, buf -> { - String name = BedrockUtils.readString(buf); - - int length = VarInts.readUnsignedInt(buffer); - String[] values = new String[length]; - for (int i = 0; i < length; i++) { - values[i] = enumValues.get(indexReader.applyAsInt(buf)); - } - return new CommandEnumData(name, values, false); - }); - - BedrockUtils.readArray(buffer, commands, buf -> { - String name = BedrockUtils.readString(buf); - String description = BedrockUtils.readString(buf); - byte flags = buf.readByte(); - byte permissions = buf.readByte(); - int aliasesIndex = buf.readIntLE(); - - CommandParamData.Builder[][] overloads = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)][]; - for (int i = 0; i < overloads.length; i++) { - overloads[i] = new CommandParamData.Builder[VarInts.readUnsignedInt(buf)]; - for (int i2 = 0; i2 < overloads[i].length; i2++) { - String parameterName = BedrockUtils.readString(buf); - - CommandParamType type = CommandParamType.deserialize(buf.readIntLE()); - - boolean optional = buf.readBoolean(); - byte unknownByte = buf.readByte(); - - overloads[i][i2] = new CommandParamData.Builder(parameterName, type, optional, unknownByte); - } - } - return new CommandData.Builder(name, description, flags, permissions, aliasesIndex, overloads); - }); - - BedrockUtils.readArray(buffer, softEnums, buf -> BedrockUtils.readCommandEnumData(buffer, true)); - - // Generate command data - - for (CommandData.Builder command : commands) { - byte flagsByte = command.getFlags(); - List flags = new ObjectArrayList<>(); - - for (int i = 0; i < 8; i++) { - if (((flagsByte >>> i) & 0x1) != 0) { - flags.add(CommandData.Flag.values()[i]); - } - } - int aliasesIndex = command.getAliases(); - CommandEnumData aliases = aliasesIndex == -1 ? null : enums.get(aliasesIndex); - - CommandParamData.Builder[][] overloadBuilders = command.getOverloads(); - CommandParamData[][] overloads = new CommandParamData[overloadBuilders.length][]; - for (int i = 0; i < overloadBuilders.length; i++) { - overloads[i] = new CommandParamData[overloadBuilders[i].length]; - for (int i2 = 0; i2 < overloadBuilders[i].length; i2++) { - String name = overloadBuilders[i][i2].getName(); - CommandParamType type = overloadBuilders[i][i2].getType(); - boolean optional = overloadBuilders[i][i2].isOptional(); - byte optionsByte = overloadBuilders[i][i2].getOptions(); - List options = new ObjectArrayList<>(); - for (int oi = 0; oi < 8; oi++) { - if (((optionsByte >>> oi) & 0xf) != 0) { - options.add(CommandParamData.Option.values()[oi]); - } - } - - String postfix = null; - CommandEnumData enumData = null; - CommandParamData.Type paramType = null; - if (type.isPostfix()) { - postfix = postFixes.get(type.getValue()); - } else { - if (type.isCommandEnum()) { - enumData = enums.get(type.getValue()); - } else if (type.isSoftEnum()) { - enumData = softEnums.get(type.getValue()); - } else { - paramType = PARAM_TYPES.get(type.getValue()); - if (paramType == null) { - log.debug("Unknown parameter type {} from {} in {}", type.getValue(), name, command.getName()); - } - } - } - overloads[i][i2] = new CommandParamData(name, optional, enumData, paramType, postfix, options); - } - } - - packet.getCommands().add(new CommandData(command.getName(), command.getDescription(), - flags, command.getPermission(), aliases, overloads)); - } - } } \ No newline at end of file diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java index 8064e1860..7d7ceb80b 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java @@ -1,11 +1,9 @@ package com.nukkitx.protocol.bedrock.v363.serializer; import com.nukkitx.network.VarInts; -import com.nukkitx.protocol.bedrock.data.ImageData; -import com.nukkitx.protocol.bedrock.data.SerializedSkin; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; -import com.nukkitx.protocol.bedrock.v361.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.bedrock.v291.serializer.PlayerListSerializer_v291; import io.netty.buffer.ByteBuf; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -14,31 +12,31 @@ import static com.nukkitx.protocol.bedrock.packet.PlayerListPacket.Entry; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerListSerializer_v363 implements PacketSerializer { +public class PlayerListSerializer_v363 extends PlayerListSerializer_v291 { public static final PlayerListSerializer_v363 INSTANCE = new PlayerListSerializer_v363(); @Override - public void serialize(ByteBuf buffer, PlayerListPacket packet) { + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, PlayerListPacket packet) { buffer.writeByte(packet.getAction().ordinal()); VarInts.writeUnsignedInt(buffer, packet.getEntries().size()); for (Entry entry : packet.getEntries()) { - BedrockUtils.writeUuid(buffer, entry.getUuid()); + helper.writeUuid(buffer, entry.getUuid()); if (packet.getAction() == Action.ADD) { VarInts.writeLong(buffer, entry.getEntityId()); - BedrockUtils.writeString(buffer, entry.getName()); + helper.writeString(buffer, entry.getName()); SerializedSkin skin = entry.getSkin(); - BedrockUtils.writeString(buffer, skin.getSkinId()); + helper.writeString(buffer, skin.getSkinId()); skin.getSkinData().checkLegacySkinSize(); - BedrockUtils.writeByteArray(buffer, skin.getSkinData().getImage()); + helper.writeByteArray(buffer, skin.getSkinData().getImage()); skin.getCapeData().checkLegacyCapeSize(); - BedrockUtils.writeByteArray(buffer, skin.getCapeData().getImage()); - BedrockUtils.writeString(buffer, skin.getGeometryName()); - BedrockUtils.writeString(buffer, skin.getGeometryData()); - BedrockUtils.writeString(buffer, entry.getXuid()); - BedrockUtils.writeString(buffer, entry.getPlatformChatId()); + helper.writeByteArray(buffer, skin.getCapeData().getImage()); + helper.writeString(buffer, skin.getGeometryName()); + helper.writeString(buffer, skin.getGeometryData()); + helper.writeString(buffer, entry.getXuid()); + helper.writeString(buffer, entry.getPlatformChatId()); buffer.writeBoolean(entry.isTeacher()); buffer.writeBoolean(entry.isHost()); } @@ -46,25 +44,25 @@ public void serialize(ByteBuf buffer, PlayerListPacket packet) { } @Override - public void deserialize(ByteBuf buffer, PlayerListPacket packet) { + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, PlayerListPacket packet) { Action action = Action.values()[buffer.readUnsignedByte()]; packet.setAction(action); int length = VarInts.readUnsignedInt(buffer); for (int i = 0; i < length; i++) { - Entry entry = new Entry(BedrockUtils.readUuid(buffer)); + Entry entry = new Entry(helper.readUuid(buffer)); if (action == Action.ADD) { entry.setEntityId(VarInts.readLong(buffer)); - entry.setName(BedrockUtils.readString(buffer)); - String skinId = BedrockUtils.readString(buffer); - ImageData skinData = ImageData.of(BedrockUtils.readByteArray(buffer)); - ImageData capeData = ImageData.of(64, 32, BedrockUtils.readByteArray(buffer)); - String geometryName = BedrockUtils.readString(buffer); - String geometryData = BedrockUtils.readString(buffer); + entry.setName(helper.readString(buffer)); + String skinId = helper.readString(buffer); + ImageData skinData = ImageData.of(helper.readByteArray(buffer)); + ImageData capeData = ImageData.of(64, 32, helper.readByteArray(buffer)); + String geometryName = helper.readString(buffer); + String geometryData = helper.readString(buffer); entry.setSkin(SerializedSkin.of(skinId, skinData, capeData, geometryName, geometryData, false)); - entry.setXuid(BedrockUtils.readString(buffer)); - entry.setPlatformChatId(BedrockUtils.readString(buffer)); + entry.setXuid(helper.readString(buffer)); + entry.setPlatformChatId(helper.readString(buffer)); entry.setTeacher(buffer.readBoolean()); entry.setHost(buffer.readBoolean()); diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index 612de807a..ba987fcd8 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -4,11 +4,11 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.ListTag; import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; -import com.nukkitx.protocol.bedrock.v361.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; +import com.nukkitx.protocol.bedrock.v361.serializer.StartGameSerializer_v361; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.AccessLevel; @@ -17,25 +17,25 @@ import java.util.List; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StartGameSerializer_v363 implements PacketSerializer { +public class StartGameSerializer_v363 extends StartGameSerializer_v361 { public static final StartGameSerializer_v363 INSTANCE = new StartGameSerializer_v363(); private static final PlayerPermission[] PLAYER_PERMISSIONS = PlayerPermission.values(); @Override - public void serialize(ByteBuf buffer, StartGamePacket packet) { + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacket packet) { VarInts.writeLong(buffer, packet.getUniqueEntityId()); VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); VarInts.writeInt(buffer, packet.getPlayerGamemode()); - BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); - BedrockUtils.writeVector2f(buffer, packet.getRotation()); + helper.writeVector3f(buffer, packet.getPlayerPosition()); + helper.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGamemode()); VarInts.writeInt(buffer, packet.getDifficulty()); - BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); + helper.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); VarInts.writeInt(buffer, packet.getTime()); buffer.writeByte(packet.getEduEditionOffers()); @@ -53,7 +53,7 @@ public void serialize(ByteBuf buffer, StartGamePacket packet) { VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); buffer.writeBoolean(packet.isCommandsEnabled()); buffer.writeBoolean(packet.isTexturePacksRequired()); - BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); + helper.writeArray(buffer, packet.getGamerules(), helper::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); @@ -70,9 +70,9 @@ public void serialize(ByteBuf buffer, StartGamePacket packet) { buffer.writeBytes(new byte[] {0x10, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0}); // Level settings end - BedrockUtils.writeString(buffer, packet.getLevelId()); - BedrockUtils.writeString(buffer, packet.getWorldName()); - BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); + helper.writeString(buffer, packet.getLevelId()); + helper.writeString(buffer, packet.getWorldName()); + helper.writeString(buffer, packet.getPremiumWorldTemplateId()); buffer.writeBoolean(packet.isTrial()); buffer.writeLongLE(packet.getCurrentTick()); VarInts.writeInt(buffer, packet.getEnchantmentSeed()); @@ -81,28 +81,28 @@ public void serialize(ByteBuf buffer, StartGamePacket packet) { VarInts.writeUnsignedInt(buffer, palette.size()); for (CompoundTag entry : palette) { CompoundTag blockTag = entry.getCompound("block"); - BedrockUtils.writeString(buffer, blockTag.getString("name")); + helper.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); buffer.writeShortLE(entry.getShort("id")); } - BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { - BedrockUtils.writeString(buf, entry.getIdentifier()); + helper.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { + helper.writeString(buf, entry.getIdentifier()); buf.writeShortLE(entry.getId()); }); - BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); + helper.writeString(buffer, packet.getMultiplayerCorrelationId()); } @Override - public void deserialize(ByteBuf buffer, StartGamePacket packet) { + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacket packet) { packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPlayerGamemode(VarInts.readInt(buffer)); - packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); - packet.setRotation(BedrockUtils.readVector2f(buffer)); + packet.setPlayerPosition(helper.readVector3f(buffer)); + packet.setRotation(helper.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); @@ -110,7 +110,7 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGamemode(VarInts.readInt(buffer)); packet.setDifficulty(VarInts.readInt(buffer)); - packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); + packet.setDefaultSpawn(helper.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readByte()); @@ -129,7 +129,7 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setCommandsEnabled(buffer.readBoolean()); packet.setTexturePacksRequired(buffer.readBoolean()); - BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); + helper.readArray(buffer, packet.getGamerules(), helper::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); @@ -147,9 +147,9 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { buffer.readLong(); // Level settings end - packet.setLevelId(BedrockUtils.readString(buffer)); - packet.setWorldName(BedrockUtils.readString(buffer)); - packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); + packet.setLevelId(helper.readString(buffer)); + packet.setWorldName(helper.readString(buffer)); + packet.setPremiumWorldTemplateId(helper.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); packet.setEnchantmentSeed(VarInts.readInt(buffer)); @@ -159,7 +159,7 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { for (int i = 0; i < paletteLength; i++) { palette.add(CompoundTagBuilder.builder() .tag(CompoundTagBuilder.builder() - .stringTag("name", BedrockUtils.readString(buffer)) + .stringTag("name", helper.readString(buffer)) .build("block")) .shortTag("meta", buffer.readShortLE()) .shortTag("id", buffer.readShortLE()) @@ -167,12 +167,12 @@ public void deserialize(ByteBuf buffer, StartGamePacket packet) { } packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); - BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> { - String identifier = BedrockUtils.readString(buf); + helper.readArray(buffer, packet.getItemEntries(), buf -> { + String identifier = helper.readString(buf); short id = buf.readShortLE(); return new StartGamePacket.ItemEntry(identifier, id); }); - packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); + packet.setMultiplayerCorrelationId(helper.readString(buffer)); } } diff --git a/bedrock/pom.xml b/bedrock/pom.xml index 9fb517646..bde4ca632 100644 --- a/bedrock/pom.xml +++ b/bedrock/pom.xml @@ -20,6 +20,7 @@ bedrock-v340 bedrock-v354 bedrock-v361 + bedrock-v363 bedrock-v388 bedrock-v389 bedrock-v390 From 92e2b10d12a8a2206af031e2a7356a130997e952 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 12:28:10 +0800 Subject: [PATCH 54/70] Make it compile --- .../protocol/bedrock/BedrockClient.java | 13 -------- .../protocol/bedrock/v363/Bedrock_v363.java | 2 +- .../AvailableCommandsSerializer_v363.java | 24 -------------- .../serializer/PlayerListSerializer_v363.java | 2 ++ .../serializer/StartGameSerializer_v363.java | 31 +++++++++---------- 5 files changed, 18 insertions(+), 54 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockClient.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockClient.java index 7efca8c5b..db5ac5ee8 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockClient.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockClient.java @@ -81,19 +81,6 @@ public CompletableFuture connect(InetSocketAddress address return future; } - public CompletableFuture directConnect(InetSocketAddress address) { - CompletableFuture future = new CompletableFuture<>(); - - RakNetClientSession connection = this.rakNetClient.create(address); - this.session = new BedrockClientSession(connection); - BedrockRakNetSessionListener.Client listener = new BedrockRakNetSessionListener.Client(this.session, - connection, this, future); - connection.setListener(listener); - connection.connect(); - - return future; - } - public CompletableFuture ping(InetSocketAddress address) { return this.rakNetClient.ping(address, 10, TimeUnit.SECONDS).thenApply(BedrockPong::fromRakNet); } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index b1673978a..d67e68c51 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -27,7 +27,7 @@ public class Bedrock_v363 { .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v291.INSTANCE, 8) .registerPacket(TextPacket.class, TextSerializer_v332.INSTANCE, 9) .registerPacket(SetTimePacket.class, SetTimeSerializer_v291.INSTANCE, 10) - .registerPacket(StartGamePacket.class, StartGameSerializer_v361.INSTANCE, 11) + .registerPacket(StartGamePacket.class, StartGameSerializer_v363.INSTANCE, 11) .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v291.INSTANCE, 12) .registerPacket(AddEntityPacket.class, AddEntitySerializer_v313.INSTANCE, 13) .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v291.INSTANCE, 14) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java index 9cc2f8c65..9f170c018 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java @@ -1,33 +1,9 @@ package com.nukkitx.protocol.bedrock.v363.serializer; -import com.nukkitx.network.VarInts; -import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.BedrockPacketHelper; -import com.nukkitx.protocol.bedrock.data.CommandData; -import com.nukkitx.protocol.bedrock.data.CommandEnumData; -import com.nukkitx.protocol.bedrock.data.CommandParamData; -import com.nukkitx.protocol.bedrock.data.CommandParamType; -import com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket; import com.nukkitx.protocol.bedrock.v340.serializer.AvailableCommandsSerializer_v340; -import com.nukkitx.protocol.bedrock.v361.BedrockUtils; -import com.nukkitx.protocol.serializer.PacketSerializer; -import com.nukkitx.protocol.util.Int2ObjectBiMap; -import io.netty.buffer.ByteBuf; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.ObjIntConsumer; -import java.util.function.ToIntFunction; - -import static com.nukkitx.protocol.bedrock.data.CommandParamData.Type.*; - @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AvailableCommandsSerializer_v363 extends AvailableCommandsSerializer_v340 { public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java index 7d7ceb80b..420011314 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java @@ -2,6 +2,8 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.data.skin.ImageData; +import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import com.nukkitx.protocol.bedrock.v291.serializer.PlayerListSerializer_v291; import io.netty.buffer.ByteBuf; diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index ba987fcd8..4dfe7ccb8 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -6,6 +6,7 @@ import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; +import com.nukkitx.protocol.bedrock.data.GameType; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.v361.serializer.StartGameSerializer_v361; @@ -26,18 +27,18 @@ public class StartGameSerializer_v363 extends StartGameSerializer_v361 { public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacket packet) { VarInts.writeLong(buffer, packet.getUniqueEntityId()); VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); - VarInts.writeInt(buffer, packet.getPlayerGamemode()); + VarInts.writeInt(buffer, packet.getPlayerGameType().ordinal()); helper.writeVector3f(buffer, packet.getPlayerPosition()); helper.writeVector2f(buffer, packet.getRotation()); + // Level settings start - VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); - VarInts.writeInt(buffer, packet.getLevelGamemode()); + VarInts.writeInt(buffer, packet.getLevelGameType().ordinal()); VarInts.writeInt(buffer, packet.getDifficulty()); helper.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); - VarInts.writeInt(buffer, packet.getTime()); + VarInts.writeInt(buffer, packet.getDayCycleStopTime()); buffer.writeByte(packet.getEduEditionOffers()); buffer.writeBoolean(packet.isEduFeaturesEnabled()); buffer.writeFloatLE(packet.getRainLevel()); @@ -65,13 +66,12 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke buffer.writeBoolean(packet.isFromWorldTemplate()); buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); - - // Unknown - buffer.writeBytes(new byte[] {0x10, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0}); + buffer.writeIntLE(packet.getLimitedWorldWidth()); + buffer.writeIntLE(packet.getLimitedWorldHeight()); // Level settings end helper.writeString(buffer, packet.getLevelId()); - helper.writeString(buffer, packet.getWorldName()); + helper.writeString(buffer, packet.getLevelName()); helper.writeString(buffer, packet.getPremiumWorldTemplateId()); buffer.writeBoolean(packet.isTrial()); buffer.writeLongLE(packet.getCurrentTick()); @@ -100,7 +100,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); - packet.setPlayerGamemode(VarInts.readInt(buffer)); + packet.setPlayerGameType(GameType.from(VarInts.readInt(buffer))); packet.setPlayerPosition(helper.readVector3f(buffer)); packet.setRotation(helper.readVector2f(buffer)); @@ -108,18 +108,18 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setSeed(VarInts.readInt(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); - packet.setLevelGamemode(VarInts.readInt(buffer)); + packet.setLevelGameType(GameType.values()[VarInts.readInt(buffer)]); packet.setDifficulty(VarInts.readInt(buffer)); packet.setDefaultSpawn(helper.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); - packet.setTime(VarInts.readInt(buffer)); + packet.setDayCycleStopTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readByte()); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); // unknown: Mine: 0x0 - buffer.readBoolean(); + buffer.readByte(); packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); packet.setMultiplayerGame(buffer.readBoolean()); @@ -142,13 +142,12 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setFromWorldTemplate(buffer.readBoolean()); packet.setWorldTemplateOptionLocked(buffer.readBoolean()); packet.setOnlySpawningV1Villagers(buffer.readBoolean()); - - // Unknown: Mine: 0x10 0x0 0x0 0x0 0x10 0x0 0x0 0x0 - buffer.readLong(); + packet.setLimitedWorldWidth(buffer.readIntLE()); + packet.setLimitedWorldHeight(buffer.readIntLE()); // Level settings end packet.setLevelId(helper.readString(buffer)); - packet.setWorldName(helper.readString(buffer)); + packet.setLevelName(helper.readString(buffer)); packet.setPremiumWorldTemplateId(helper.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); From f43e892c6ed598c81dbbccc67f90501166d48595 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 15:50:19 +0800 Subject: [PATCH 55/70] AvailableCommandSerializer looks like it may be ok now --- .../java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index d67e68c51..eb4434910 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -5,6 +5,7 @@ import com.nukkitx.protocol.bedrock.v291.serializer.*; import com.nukkitx.protocol.bedrock.v313.serializer.*; import com.nukkitx.protocol.bedrock.v332.serializer.*; +import com.nukkitx.protocol.bedrock.v340.serializer.AvailableCommandsSerializer_v340; import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; import com.nukkitx.protocol.bedrock.v354.serializer.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; @@ -91,7 +92,7 @@ public class Bedrock_v363 { .registerPacket(CameraPacket.class, CameraSerializer_v291.INSTANCE, 73) .registerPacket(BossEventPacket.class, BossEventSerializer_v291.INSTANCE, 74) .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v291.INSTANCE, 75) - .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v363.INSTANCE, 76) + .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v340.INSTANCE, 76) .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v291.INSTANCE, 77) .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v361.INSTANCE, 78) .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v291.INSTANCE, 79) From a43d40f5c5fe614eea513bc86a020a1d482f9c85 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 16:41:16 +0800 Subject: [PATCH 56/70] Allow setting the raknetProtocolVersion on BedrockPacketCodec.Builder --- .../nukkitx/protocol/bedrock/BedrockPacketCodec.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index 39fe8f400..0c6d6dc95 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -31,6 +31,8 @@ public final class BedrockPacketCodec { private final BedrockPacketSerializer[] serializers; private final Int2ObjectBiMap> idBiMap; private final BedrockPacketHelper helper; + @Getter + private final int raknetProtocolVersion; public static Builder builder() { return new Builder(); @@ -95,6 +97,7 @@ public static class Builder { private final Int2ObjectMap> serializers = new Int2ObjectOpenHashMap<>(); private final Int2ObjectBiMap> idBiMap = new Int2ObjectBiMap<>(UnknownPacket.class); private int protocolVersion = -1; + private int raknetProtocolVersion = 10; private String minecraftVersion = null; private BedrockPacketHelper helper = null; @@ -114,6 +117,12 @@ public Builder protocolVersion(@Nonnegative int protocolVersion) { return this; } + public Builder raknetProtocolVersion(@Nonnegative int version) { + Preconditions.checkArgument(protocolVersion >= 0, "raknetProtocolVersion cannot be negative"); + this.raknetProtocolVersion = version; + return this; + } + public Builder minecraftVersion(@Nonnull String minecraftVersion) { Preconditions.checkNotNull(minecraftVersion, "minecraftVersion"); Preconditions.checkArgument(!minecraftVersion.isEmpty() && minecraftVersion.split("\\.").length > 2, "Invalid minecraftVersion"); @@ -143,7 +152,7 @@ public BedrockPacketCodec build() { for (Int2ObjectMap.Entry> entry : this.serializers.int2ObjectEntrySet()) { serializers[entry.getIntKey()] = entry.getValue(); } - return new BedrockPacketCodec(protocolVersion, minecraftVersion, serializers, idBiMap, helper); + return new BedrockPacketCodec(protocolVersion, minecraftVersion, serializers, idBiMap, helper, raknetProtocolVersion); } } } From 7201ad6555cb7b1138dee95882418b7730d40057 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 16:42:44 +0800 Subject: [PATCH 57/70] Set v363 raknetProtocolVersion to 9. --- .../java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java index eb4434910..95f9bd5c1 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java @@ -16,6 +16,7 @@ public class Bedrock_v363 { public static BedrockPacketCodec V363_CODEC = BedrockPacketCodec.builder() .protocolVersion(363) + .raknetProtocolVersion(9) .minecraftVersion("1.12.60") .helper(BedrockPacketHelper_v363.INSTANCE) .registerPacket(LoginPacket.class, LoginSerializer_v291.INSTANCE, 1) From 51cc498162abb674b0a248595fe3634e92ed582a Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 19:01:21 +0800 Subject: [PATCH 58/70] Fix AvailableCommandsSerializer_v291 --- .../AvailableCommandsSerializer_v291.java | 2 +- .../v363/BedrockPacketHelper_v363.java | 42 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java index ffd305fea..4a83fec62 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java @@ -142,7 +142,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom List options = new ObjectArrayList<>(); for (int idx = 0; idx < 8; idx++) { if ((optionsByte & (1 << idx)) != 0) { - options.add(OPTIONS[i]); + options.add(OPTIONS[idx]); } } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java index e04dd8f21..d03e1fba4 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java @@ -1,35 +1,29 @@ package com.nukkitx.protocol.bedrock.v363; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.network.VarInts; -import com.nukkitx.network.util.Preconditions; -import com.nukkitx.protocol.bedrock.data.LevelEventType; -import com.nukkitx.protocol.bedrock.data.entity.EntityData; -import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap; -import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; -import com.nukkitx.protocol.bedrock.data.entity.EntityFlags; -import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.data.structure.StructureMirror; -import com.nukkitx.protocol.bedrock.data.structure.StructureRotation; -import com.nukkitx.protocol.bedrock.data.structure.StructureSettings; import com.nukkitx.protocol.bedrock.v354.BedrockPacketHelper_v354; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import java.io.IOException; -import java.util.Comparator; -import java.util.Map; -import java.util.stream.Collectors; +import static com.nukkitx.protocol.bedrock.data.command.CommandParamType.*; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v363 extends BedrockPacketHelper_v354 { + @Override + protected void registerCommandParams() { + this.addCommandParam(1, INT); + this.addCommandParam(2, FLOAT); + this.addCommandParam(3, VALUE); + this.addCommandParam(4, WILDCARD_INT); + this.addCommandParam(5, OPERATOR); + this.addCommandParam(6, TARGET); + this.addCommandParam(7, WILDCARD_TARGET); + this.addCommandParam(14, FILE_PATH); + this.addCommandParam(27, STRING); + this.addCommandParam(29, POSITION); + this.addCommandParam(32, MESSAGE); + this.addCommandParam(34, TEXT); + this.addCommandParam(37, JSON); + this.addCommandParam(44, COMMAND); + } } From 2b57decfc287aa205b79ab39108b6e56f325bf89 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 19:18:27 +0800 Subject: [PATCH 59/70] Fix StartGamePacket --- .../v361/BedrockPacketHelper_v361.java | 2 ++ .../v363/BedrockPacketHelper_v363.java | 31 +++++++------------ .../serializer/StartGameSerializer_v363.java | 1 + 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index c2c298ce4..ac6c65a2d 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -8,6 +8,7 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.network.VarInts; import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap; @@ -31,6 +32,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v361 extends BedrockPacketHelper_v354 { + public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); @Override protected void registerEntityData() { diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java index d03e1fba4..fc0d9d3b0 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java @@ -1,29 +1,22 @@ package com.nukkitx.protocol.bedrock.v363; -import com.nukkitx.protocol.bedrock.v354.BedrockPacketHelper_v354; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.data.entity.EntityData; +import com.nukkitx.protocol.bedrock.v361.BedrockPacketHelper_v361; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import static com.nukkitx.protocol.bedrock.data.command.CommandParamType.*; - @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BedrockPacketHelper_v363 extends BedrockPacketHelper_v354 { +public class BedrockPacketHelper_v363 extends BedrockPacketHelper_v361 { + public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v363(); @Override - protected void registerCommandParams() { - this.addCommandParam(1, INT); - this.addCommandParam(2, FLOAT); - this.addCommandParam(3, VALUE); - this.addCommandParam(4, WILDCARD_INT); - this.addCommandParam(5, OPERATOR); - this.addCommandParam(6, TARGET); - this.addCommandParam(7, WILDCARD_TARGET); - this.addCommandParam(14, FILE_PATH); - this.addCommandParam(27, STRING); - this.addCommandParam(29, POSITION); - this.addCommandParam(32, MESSAGE); - this.addCommandParam(34, TEXT); - this.addCommandParam(37, JSON); - this.addCommandParam(44, COMMAND); + protected void registerEntityData() { + super.registerEntityData(); + + this.addEntityData(107, EntityData.AMBIENT_SOUND_INTERVAL); + this.addEntityData(108, EntityData.AMBIENT_SOUND_INTERVAL_RANGE); + this.addEntityData(109, EntityData.AMBIENT_SOUND_EVENT_NAME); } + } diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index 4dfe7ccb8..d96fd2e7c 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -32,6 +32,7 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke helper.writeVector2f(buffer, packet.getRotation()); // Level settings start + VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGameType().ordinal()); From 52c746361d514624af5fc68bfcef6a0cac34e891 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 19:19:38 +0800 Subject: [PATCH 60/70] Fix bugs in BedrockPacketHelper_v361, AvailableCommandsSerializer_v291 --- .../v291/serializer/AvailableCommandsSerializer_v291.java | 2 +- .../protocol/bedrock/v361/BedrockPacketHelper_v361.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java index ffd305fea..4a83fec62 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/AvailableCommandsSerializer_v291.java @@ -142,7 +142,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, AvailableCom List options = new ObjectArrayList<>(); for (int idx = 0; idx < 8; idx++) { if ((optionsByte & (1 << idx)) != 0) { - options.add(OPTIONS[i]); + options.add(OPTIONS[idx]); } } diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index c2c298ce4..fb5ccffbe 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -8,6 +8,7 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.network.VarInts; import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap; @@ -32,6 +33,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class BedrockPacketHelper_v361 extends BedrockPacketHelper_v354 { + public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); + @Override protected void registerEntityData() { super.registerEntityData(); From 898a3feb3118745f55963abce157e5fb490aace9 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 19:46:45 +0800 Subject: [PATCH 61/70] Don't print LevelChunk data --- .../com/nukkitx/protocol/bedrock/packet/LevelChunkPacket.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelChunkPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelChunkPacket.java index f86d1bdaa..1f3f589dc 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelChunkPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelChunkPacket.java @@ -7,9 +7,11 @@ import it.unimi.dsi.fastutil.longs.LongList; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.ToString; @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) +@ToString(exclude = {"data"}) // We don't really want to be printing the entire chunk public class LevelChunkPacket extends BedrockPacket { private int chunkX; private int chunkZ; From 6e9815284080d14c19a9f76c76e3766d06b51101 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 29 Jun 2020 19:47:25 +0800 Subject: [PATCH 62/70] Fix bug in LevelSoundEventSerializer_v332 --- .../com/nukkitx/protocol/bedrock/BedrockPacketHelper.java | 2 +- .../v332/serializer/LevelSoundEventSerializer_v332.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java index 2b657f99c..93495e1a4 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketHelper.java @@ -129,7 +129,7 @@ public final int getSoundEventId(SoundEvent event) { public final SoundEvent getSoundEvent(int id) { SoundEvent soundEvent = this.soundEvents.get(id); if (soundEvent == null) { - log.debug("Unknown SoundEvent {} received", id); + log.debug("Unknown SoundEvent {} received", Integer.toUnsignedLong(id)); return SoundEvent.UNDEFINED; } return soundEvent; diff --git a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/LevelSoundEventSerializer_v332.java b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/LevelSoundEventSerializer_v332.java index 1185d75a2..07b223d73 100644 --- a/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/LevelSoundEventSerializer_v332.java +++ b/bedrock/bedrock-v332/src/main/java/com/nukkitx/protocol/bedrock/v332/serializer/LevelSoundEventSerializer_v332.java @@ -14,7 +14,7 @@ public class LevelSoundEventSerializer_v332 implements BedrockPacketSerializer Date: Tue, 30 Jun 2020 08:13:21 +0800 Subject: [PATCH 63/70] Remove Duplicate --- .../nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index 191bc7e7e..ac6c65a2d 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -34,8 +34,6 @@ public class BedrockPacketHelper_v361 extends BedrockPacketHelper_v354 { public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); - public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); - @Override protected void registerEntityData() { super.registerEntityData(); From f10bc62b9b76c956d3e56ae1dc9c3681bcdd08b4 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Tue, 30 Jun 2020 08:55:07 +0800 Subject: [PATCH 64/70] Remove Duplicate --- .../nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java index 191bc7e7e..ac6c65a2d 100644 --- a/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java +++ b/bedrock/bedrock-v361/src/main/java/com/nukkitx/protocol/bedrock/v361/BedrockPacketHelper_v361.java @@ -34,8 +34,6 @@ public class BedrockPacketHelper_v361 extends BedrockPacketHelper_v354 { public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); - public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v361(); - @Override protected void registerEntityData() { super.registerEntityData(); From 77a514db575bb658883ff59c38a43ea2a2377461 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Tue, 30 Jun 2020 09:00:44 +0800 Subject: [PATCH 65/70] Add missing Container Type --- .../v291/serializer/InventoryTransactionSerializer_v291.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/InventoryTransactionSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/InventoryTransactionSerializer_v291.java index 1fa082d36..ecea755f7 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/InventoryTransactionSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/InventoryTransactionSerializer_v291.java @@ -91,6 +91,8 @@ public InventorySource readSource(ByteBuf buffer) { return InventorySource.fromWorldInteraction(flag); case CREATIVE: return InventorySource.fromCreativeInventory(); + case UNTRACKED_INTERACTION_UI: + return InventorySource.fromUntrackedInteractionUI(VarInts.readInt(buffer)); case NON_IMPLEMENTED_TODO: containerId = VarInts.readInt(buffer); return InventorySource.fromNonImplementedTodo(containerId); From 24e95d5e857054cf667fcd6668f6df8b4a3650ed Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 6 Jul 2020 04:23:03 +0800 Subject: [PATCH 66/70] Add missing InventorySource type (#52) --- .../protocol/bedrock/v313/Bedrock_v313.java | 2 +- .../InventoryTransactionSerializer_v313.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/serializer/InventoryTransactionSerializer_v313.java diff --git a/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/Bedrock_v313.java b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/Bedrock_v313.java index 02cf1c26a..e1b07ee7a 100644 --- a/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/Bedrock_v313.java +++ b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/Bedrock_v313.java @@ -41,7 +41,7 @@ public final class Bedrock_v313 { .registerPacket(EntityEventPacket.class, EntityEventSerializer_v291.INSTANCE, 27) .registerPacket(MobEffectPacket.class, MobEffectSerializer_v291.INSTANCE, 28) .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v291.INSTANCE, 29) - .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v291.INSTANCE, 30) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v313.INSTANCE, 30) .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v291.INSTANCE, 31) .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v291.INSTANCE, 32) .registerPacket(InteractPacket.class, InteractSerializer_v291.INSTANCE, 33) diff --git a/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/serializer/InventoryTransactionSerializer_v313.java b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/serializer/InventoryTransactionSerializer_v313.java new file mode 100644 index 000000000..6762c17ae --- /dev/null +++ b/bedrock/bedrock-v313/src/main/java/com/nukkitx/protocol/bedrock/v313/serializer/InventoryTransactionSerializer_v313.java @@ -0,0 +1,24 @@ +package com.nukkitx.protocol.bedrock.v313.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.data.inventory.InventorySource; +import com.nukkitx.protocol.bedrock.v291.serializer.InventoryTransactionSerializer_v291; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class InventoryTransactionSerializer_v313 extends InventoryTransactionSerializer_v291 { + public static final InventoryTransactionSerializer_v313 INSTANCE = new InventoryTransactionSerializer_v313(); + + + @Override + public InventorySource readSource(ByteBuf buffer) { + InventorySource.Type type = InventorySource.Type.byId(VarInts.readUnsignedInt(buffer.duplicate())); + + if (type == InventorySource.Type.UNTRACKED_INTERACTION_UI) { + return InventorySource.fromUntrackedInteractionUI(VarInts.readInt(buffer)); + } + return super.readSource(buffer); + } +} From 3c91ec0eb0448e85d4e934f424fdb6d9e1aca5a2 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Mon, 6 Jul 2020 08:18:43 +0800 Subject: [PATCH 67/70] Merge Fixes --- .../serializer/StartGameSerializer_v363.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index d96fd2e7c..8196b1691 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -1,8 +1,8 @@ package com.nukkitx.protocol.bedrock.v363.serializer; -import com.nukkitx.nbt.CompoundTagBuilder; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.nbt.tag.ListTag; +import com.nukkitx.nbt.NbtList; +import com.nukkitx.nbt.NbtMap; +import com.nukkitx.nbt.NbtType; import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; @@ -78,13 +78,12 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke buffer.writeLongLE(packet.getCurrentTick()); VarInts.writeInt(buffer, packet.getEnchantmentSeed()); - List palette = packet.getBlockPalette().getValue(); + NbtList palette = packet.getBlockPalette(); VarInts.writeUnsignedInt(buffer, palette.size()); - for (CompoundTag entry : palette) { - CompoundTag blockTag = entry.getCompound("block"); + for (NbtMap entry : palette) { + NbtMap blockTag = entry.getCompound("block"); helper.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); - buffer.writeShortLE(entry.getShort("id")); } helper.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { @@ -155,17 +154,16 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac packet.setEnchantmentSeed(VarInts.readInt(buffer)); int paletteLength = VarInts.readUnsignedInt(buffer); - List palette = new ObjectArrayList<>(paletteLength); + List palette = new ObjectArrayList<>(paletteLength); for (int i = 0; i < paletteLength; i++) { - palette.add(CompoundTagBuilder.builder() - .tag(CompoundTagBuilder.builder() - .stringTag("name", helper.readString(buffer)) - .build("block")) - .shortTag("meta", buffer.readShortLE()) - .shortTag("id", buffer.readShortLE()) - .buildRootTag()); + palette.add(NbtMap.builder() + .putCompound("block", NbtMap.builder() + .putString("name", helper.readString(buffer)) + .build()) + .putShort("meta", buffer.readShortLE()) + .build()); } - packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); + packet.setBlockPalette(new NbtList<>(NbtType.COMPOUND, palette)); helper.readArray(buffer, packet.getItemEntries(), buf -> { String identifier = helper.readString(buf); From c6feb685c345ac1c087d4a06425e83617a1e4537 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Tue, 7 Jul 2020 20:05:27 +0800 Subject: [PATCH 68/70] Fix StartGameSerializer_v363 as it was missing id fields in the Palette --- .../bedrock/v363/serializer/StartGameSerializer_v363.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java index 8196b1691..9d1903a82 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java @@ -84,6 +84,7 @@ public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePacke NbtMap blockTag = entry.getCompound("block"); helper.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); + buffer.writeShortLE(entry.getShort("id")); } helper.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { @@ -161,6 +162,7 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, StartGamePac .putString("name", helper.readString(buffer)) .build()) .putShort("meta", buffer.readShortLE()) + .putShort("id", buffer.readShortLE()) .build()); } packet.setBlockPalette(new NbtList<>(NbtType.COMPOUND, palette)); From 3754d354f466892285973df907c9d1c695a862cd Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 13 Aug 2020 22:11:01 +0800 Subject: [PATCH 69/70] Move Education to its own package and start implementing education-v390 --- .../protocol/bedrock/BedrockPacketCodec.java | 2 + .../packet/LevelEventGenericPacket.java | 13 ++ .../AvailableCommandsSerializer_v363.java | 11 -- .../{bedrock-v363 => education-v363}/pom.xml | 2 +- .../v363/EducationPacketHelper_v363.java} | 6 +- .../education/v363/Education_v363.java} | 8 +- .../serializer/PlayerListSerializer_v363.java | 2 +- .../serializer/StartGameSerializer_v363.java | 2 +- bedrock/education-v390/pom.xml | 22 +++ .../v390/EducationPacketHelper_v390.java | 35 ++++ .../education/v390/Education_v390.java | 168 ++++++++++++++++++ .../CraftingDataSerializer_v390.java | 116 ++++++++++++ .../serializer/StartGameSerializer_v390.java | 108 +++++++++++ bedrock/pom.xml | 3 +- pom.xml | 14 +- 15 files changed, 484 insertions(+), 28 deletions(-) delete mode 100644 bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java rename bedrock/{bedrock-v363 => education-v363}/pom.xml (94%) rename bedrock/{bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java => education-v363/src/main/java/com/nukkitx/protocol/education/v363/EducationPacketHelper_v363.java} (74%) rename bedrock/{bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java => education-v363/src/main/java/com/nukkitx/protocol/education/v363/Education_v363.java} (98%) rename bedrock/{bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock => education-v363/src/main/java/com/nukkitx/protocol/education}/v363/serializer/PlayerListSerializer_v363.java (98%) rename bedrock/{bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock => education-v363/src/main/java/com/nukkitx/protocol/education}/v363/serializer/StartGameSerializer_v363.java (99%) create mode 100644 bedrock/education-v390/pom.xml create mode 100644 bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/EducationPacketHelper_v390.java create mode 100644 bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/Education_v390.java create mode 100644 bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/serializer/CraftingDataSerializer_v390.java create mode 100644 bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/serializer/StartGameSerializer_v390.java diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java index 0c6d6dc95..5ba5174d3 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/BedrockPacketCodec.java @@ -5,6 +5,7 @@ import com.nukkitx.protocol.bedrock.packet.UnknownPacket; import com.nukkitx.protocol.util.Int2ObjectBiMap; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -61,6 +62,7 @@ public BedrockPacket tryDecode(ByteBuf buf, int id) throws PacketSerializeExcept if (log.isDebugEnabled() && buf.isReadable()) { log.debug(packet.getClass().getSimpleName() + " still has " + buf.readableBytes() + " bytes to read!"); + log.debug(ByteBufUtil.prettyHexDump(buf)); } return packet; } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelEventGenericPacket.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelEventGenericPacket.java index 6eee294e6..9a2b79936 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelEventGenericPacket.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/packet/LevelEventGenericPacket.java @@ -7,10 +7,23 @@ import lombok.Data; import lombok.EqualsAndHashCode; +/** + * LevelEventGeneric is sent by the server to send a 'generic' level event to the client. This packet sends an + * NBT serialised object and may for that reason be used for any event holding additional data. + */ @Data @EqualsAndHashCode(doNotUseGetters = true, callSuper = false) public class LevelEventGenericPacket extends BedrockPacket { private int eventId; + + /** + * SerialisedEventData is a network little endian serialised object of event data, with fields that vary + * depending on eventId. + * Unlike many other NBT structures, this data is not actually in a compound but just loosely floating + * NBT tags. To decode using the nbt package, you would need to append 0x0a00 at the start (compound id + * and name length) and add 0x00 at the end, to manually wrap it in a compound. Likewise, you would have + * to remove these bytes when encoding. + */ private NbtMap tag; @Override diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java b/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java deleted file mode 100644 index 9f170c018..000000000 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/AvailableCommandsSerializer_v363.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; - -import com.nukkitx.protocol.bedrock.v340.serializer.AvailableCommandsSerializer_v340; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AvailableCommandsSerializer_v363 extends AvailableCommandsSerializer_v340 { - public static final AvailableCommandsSerializer_v363 INSTANCE = new AvailableCommandsSerializer_v363(); - -} \ No newline at end of file diff --git a/bedrock/bedrock-v363/pom.xml b/bedrock/education-v363/pom.xml similarity index 94% rename from bedrock/bedrock-v363/pom.xml rename to bedrock/education-v363/pom.xml index fb629cfae..8c775b39c 100644 --- a/bedrock/bedrock-v363/pom.xml +++ b/bedrock/education-v363/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - bedrock-v363 + education-v363 diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/EducationPacketHelper_v363.java similarity index 74% rename from bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java rename to bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/EducationPacketHelper_v363.java index fc0d9d3b0..98c426eff 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/BedrockPacketHelper_v363.java +++ b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/EducationPacketHelper_v363.java @@ -1,4 +1,4 @@ -package com.nukkitx.protocol.bedrock.v363; +package com.nukkitx.protocol.education.v363; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; import com.nukkitx.protocol.bedrock.data.entity.EntityData; @@ -7,8 +7,8 @@ import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BedrockPacketHelper_v363 extends BedrockPacketHelper_v361 { - public static final BedrockPacketHelper INSTANCE = new BedrockPacketHelper_v363(); +public class EducationPacketHelper_v363 extends BedrockPacketHelper_v361 { + public static final BedrockPacketHelper INSTANCE = new EducationPacketHelper_v363(); @Override protected void registerEntityData() { diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/Education_v363.java similarity index 98% rename from bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java rename to bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/Education_v363.java index 95f9bd5c1..3de6f5406 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/Bedrock_v363.java +++ b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/Education_v363.java @@ -1,4 +1,4 @@ -package com.nukkitx.protocol.bedrock.v363; +package com.nukkitx.protocol.education.v363; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; @@ -9,16 +9,16 @@ import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; import com.nukkitx.protocol.bedrock.v354.serializer.*; import com.nukkitx.protocol.bedrock.v361.serializer.*; -import com.nukkitx.protocol.bedrock.v363.serializer.*; +import com.nukkitx.protocol.education.v363.serializer.*; import lombok.experimental.UtilityClass; @UtilityClass -public class Bedrock_v363 { +public class Education_v363 { public static BedrockPacketCodec V363_CODEC = BedrockPacketCodec.builder() .protocolVersion(363) .raknetProtocolVersion(9) .minecraftVersion("1.12.60") - .helper(BedrockPacketHelper_v363.INSTANCE) + .helper(EducationPacketHelper_v363.INSTANCE) .registerPacket(LoginPacket.class, LoginSerializer_v291.INSTANCE, 1) .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v291.INSTANCE, 2) .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v291.INSTANCE, 3) diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/PlayerListSerializer_v363.java similarity index 98% rename from bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java rename to bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/PlayerListSerializer_v363.java index 420011314..71f3f1283 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/PlayerListSerializer_v363.java +++ b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/PlayerListSerializer_v363.java @@ -1,4 +1,4 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; +package com.nukkitx.protocol.education.v363.serializer; import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.BedrockPacketHelper; diff --git a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/StartGameSerializer_v363.java similarity index 99% rename from bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java rename to bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/StartGameSerializer_v363.java index 9d1903a82..010b2e366 100644 --- a/bedrock/bedrock-v363/src/main/java/com/nukkitx/protocol/bedrock/v363/serializer/StartGameSerializer_v363.java +++ b/bedrock/education-v363/src/main/java/com/nukkitx/protocol/education/v363/serializer/StartGameSerializer_v363.java @@ -1,4 +1,4 @@ -package com.nukkitx.protocol.bedrock.v363.serializer; +package com.nukkitx.protocol.education.v363.serializer; import com.nukkitx.nbt.NbtList; import com.nukkitx.nbt.NbtMap; diff --git a/bedrock/education-v390/pom.xml b/bedrock/education-v390/pom.xml new file mode 100644 index 000000000..9f5890f5f --- /dev/null +++ b/bedrock/education-v390/pom.xml @@ -0,0 +1,22 @@ + + + + bedrock-parent + com.nukkitx.protocol + 2.6.0-SNAPSHOT + + 4.0.0 + + education-v390 + + + + com.nukkitx.protocol + bedrock-v388 + ${project.version} + + + + \ No newline at end of file diff --git a/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/EducationPacketHelper_v390.java b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/EducationPacketHelper_v390.java new file mode 100644 index 000000000..55fb255b4 --- /dev/null +++ b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/EducationPacketHelper_v390.java @@ -0,0 +1,35 @@ +package com.nukkitx.protocol.education.v390; + +import com.nukkitx.protocol.bedrock.v388.BedrockPacketHelper_v388; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import static com.nukkitx.protocol.bedrock.data.command.CommandParamType.*; + + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class EducationPacketHelper_v390 extends BedrockPacketHelper_v388 { + public static final EducationPacketHelper_v390 INSTANCE = new EducationPacketHelper_v390(); + + + @Override + protected void registerCommandParams() { + this.addCommandParam(1, INT); + this.addCommandParam(2, FLOAT); + this.addCommandParam(3, VALUE); + this.addCommandParam(4, WILDCARD_INT); + this.addCommandParam(5, OPERATOR); + this.addCommandParam(6, TARGET); + this.addCommandParam(7, WILDCARD_TARGET); + this.addCommandParam(14, FILE_PATH); + this.addCommandParam(29, STRING); + this.addCommandParam(37, BLOCK_POSITION); + this.addCommandParam(38, POSITION); + this.addCommandParam(41, MESSAGE); + this.addCommandParam(43, TEXT); + this.addCommandParam(47, JSON); + this.addCommandParam(54, COMMAND); + } + + +} diff --git a/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/Education_v390.java b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/Education_v390.java new file mode 100644 index 000000000..129ee3fd6 --- /dev/null +++ b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/Education_v390.java @@ -0,0 +1,168 @@ +package com.nukkitx.protocol.education.v390; + +import com.nukkitx.protocol.bedrock.BedrockPacketCodec; +import com.nukkitx.protocol.bedrock.packet.RiderJumpPacket; +import com.nukkitx.protocol.education.v390.serializer.CraftingDataSerializer_v390; +import com.nukkitx.protocol.education.v390.serializer.StartGameSerializer_v390; +import lombok.experimental.UtilityClass; + +import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.protocol.bedrock.v291.serializer.*; +import com.nukkitx.protocol.bedrock.v313.serializer.*; +import com.nukkitx.protocol.bedrock.v332.serializer.*; +import com.nukkitx.protocol.bedrock.v340.serializer.InventoryTransactionSerializer_v340; +import com.nukkitx.protocol.bedrock.v354.serializer.*; +import com.nukkitx.protocol.bedrock.v361.serializer.*; +import com.nukkitx.protocol.bedrock.v388.serializer.*; + +@UtilityClass +public class Education_v390 { + public static BedrockPacketCodec V390_CODEC = BedrockPacketCodec.builder() + .protocolVersion(390) + .raknetProtocolVersion(9) + .minecraftVersion("1.14.31") + .helper(EducationPacketHelper_v390.INSTANCE) + .registerPacket(LoginPacket.class, LoginSerializer_v291.INSTANCE, 1) + .registerPacket(PlayStatusPacket.class, PlayStatusSerializer_v291.INSTANCE, 2) + .registerPacket(ServerToClientHandshakePacket.class, ServerToClientHandshakeSerializer_v291.INSTANCE, 3) + .registerPacket(ClientToServerHandshakePacket.class, ClientToServerHandshakeSerializer_v291.INSTANCE, 4) + .registerPacket(DisconnectPacket.class, DisconnectSerializer_v291.INSTANCE, 5) + .registerPacket(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v332.INSTANCE, 6) + .registerPacket(ResourcePackStackPacket.class, ResourcePackStackSerializer_v388.INSTANCE, 7) + .registerPacket(ResourcePackClientResponsePacket.class, ResourcePackClientResponseSerializer_v291.INSTANCE, 8) + .registerPacket(TextPacket.class, TextSerializer_v332.INSTANCE, 9) + .registerPacket(SetTimePacket.class, SetTimeSerializer_v291.INSTANCE, 10) + .registerPacket(StartGamePacket.class, StartGameSerializer_v390.INSTANCE, 11) + .registerPacket(AddPlayerPacket.class, AddPlayerSerializer_v388.INSTANCE, 12) + .registerPacket(AddEntityPacket.class, AddEntitySerializer_v313.INSTANCE, 13) + .registerPacket(RemoveEntityPacket.class, RemoveEntitySerializer_v291.INSTANCE, 14) + .registerPacket(AddItemEntityPacket.class, AddItemEntitySerializer_v291.INSTANCE, 15) + .registerPacket(TakeItemEntityPacket.class, TakeItemEntitySerializer_v291.INSTANCE, 17) + .registerPacket(MoveEntityAbsolutePacket.class, MoveEntityAbsoluteSerializer_v291.INSTANCE, 18) + .registerPacket(MovePlayerPacket.class, MovePlayerSerializer_v291.INSTANCE, 19) + .registerPacket(RiderJumpPacket.class, RiderJumpSerializer_v291.INSTANCE, 20) + .registerPacket(UpdateBlockPacket.class, UpdateBlockSerializer_v291.INSTANCE, 21) + .registerPacket(AddPaintingPacket.class, AddPaintingSerializer_v361.INSTANCE, 22) + .registerPacket(TickSyncPacket.class, TickSyncSerializer_v388.INSTANCE, 23) + .registerPacket(LevelSoundEvent1Packet.class, LevelSoundEvent1Serializer_v291.INSTANCE, 24) + .registerPacket(LevelEventPacket.class, LevelEventSerializer_v291.INSTANCE, 25) + .registerPacket(BlockEventPacket.class, BlockEventSerializer_v291.INSTANCE, 26) + .registerPacket(EntityEventPacket.class, EntityEventSerializer_v291.INSTANCE, 27) + .registerPacket(MobEffectPacket.class, MobEffectSerializer_v291.INSTANCE, 28) + .registerPacket(UpdateAttributesPacket.class, UpdateAttributesSerializer_v291.INSTANCE, 29) + .registerPacket(InventoryTransactionPacket.class, InventoryTransactionSerializer_v340.INSTANCE, 30) + .registerPacket(MobEquipmentPacket.class, MobEquipmentSerializer_v291.INSTANCE, 31) + .registerPacket(MobArmorEquipmentPacket.class, MobArmorEquipmentSerializer_v291.INSTANCE, 32) + .registerPacket(InteractPacket.class, InteractSerializer_v388.INSTANCE, 33) + .registerPacket(BlockPickRequestPacket.class, BlockPickRequestSerializer_v291.INSTANCE, 34) + .registerPacket(EntityPickRequestPacket.class, EntityPickRequestSerializer_v291.INSTANCE, 35) + .registerPacket(PlayerActionPacket.class, PlayerActionSerializer_v291.INSTANCE, 36) + .registerPacket(EntityFallPacket.class, EntityFallSerializer_v291.INSTANCE, 37) + .registerPacket(HurtArmorPacket.class, HurtArmorSerializer_v291.INSTANCE, 38) + .registerPacket(SetEntityDataPacket.class, SetEntityDataSerializer_v291.INSTANCE, 39) + .registerPacket(SetEntityMotionPacket.class, SetEntityMotionSerializer_v291.INSTANCE, 40) + .registerPacket(SetEntityLinkPacket.class, SetEntityLinkSerializer_v291.INSTANCE, 41) + .registerPacket(SetHealthPacket.class, SetHealthSerializer_v291.INSTANCE, 42) + .registerPacket(SetSpawnPositionPacket.class, SetSpawnPositionSerializer_v291.INSTANCE, 43) + .registerPacket(AnimatePacket.class, AnimateSerializer_v291.INSTANCE, 44) + .registerPacket(RespawnPacket.class, RespawnSerializer_v388.INSTANCE, 45) + .registerPacket(ContainerOpenPacket.class, ContainerOpenSerializer_v291.INSTANCE, 46) + .registerPacket(ContainerClosePacket.class, ContainerCloseSerializer_v291.INSTANCE, 47) + .registerPacket(PlayerHotbarPacket.class, PlayerHotbarSerializer_v291.INSTANCE, 48) + .registerPacket(InventoryContentPacket.class, InventoryContentSerializer_v291.INSTANCE, 49) + .registerPacket(InventorySlotPacket.class, InventorySlotSerializer_v291.INSTANCE, 50) + .registerPacket(ContainerSetDataPacket.class, ContainerSetDataSerializer_v291.INSTANCE, 51) + .registerPacket(CraftingDataPacket.class, CraftingDataSerializer_v390.INSTANCE, 52) + .registerPacket(CraftingEventPacket.class, CraftingEventSerializer_v291.INSTANCE, 53) + .registerPacket(GuiDataPickItemPacket.class, GuiDataPickItemSerializer_v291.INSTANCE, 54) + .registerPacket(AdventureSettingsPacket.class, AdventureSettingsSerializer_v291.INSTANCE, 55) + .registerPacket(BlockEntityDataPacket.class, BlockEntityDataSerializer_v291.INSTANCE, 56) + .registerPacket(PlayerInputPacket.class, PlayerInputSerializer_v291.INSTANCE, 57) + .registerPacket(LevelChunkPacket.class, LevelChunkSerializer_v361.INSTANCE, 58) + .registerPacket(SetCommandsEnabledPacket.class, SetCommandsEnabledSerializer_v291.INSTANCE, 59) + .registerPacket(SetDifficultyPacket.class, SetDifficultySerializer_v291.INSTANCE, 60) + .registerPacket(ChangeDimensionPacket.class, ChangeDimensionSerializer_v291.INSTANCE, 61) + .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v291.INSTANCE, 62) + .registerPacket(PlayerListPacket.class, PlayerListSerializer_v388.INSTANCE, 63) + .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v291.INSTANCE, 64) + .registerPacket(EventPacket.class, EventSerializer_v388.INSTANCE, 65) + .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v291.INSTANCE, 66) + .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v354.INSTANCE, 67) + .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v291.INSTANCE, 68) + .registerPacket(RequestChunkRadiusPacket.class, RequestChunkRadiusSerializer_v291.INSTANCE, 69) + .registerPacket(ChunkRadiusUpdatedPacket.class, ChunkRadiusUpdatedSerializer_v291.INSTANCE, 70) + .registerPacket(ItemFrameDropItemPacket.class, ItemFrameDropItemSerializer_v291.INSTANCE, 71) + .registerPacket(GameRulesChangedPacket.class, GameRulesChangedSerializer_v291.INSTANCE, 72) + .registerPacket(CameraPacket.class, CameraSerializer_v291.INSTANCE, 73) + .registerPacket(BossEventPacket.class, BossEventSerializer_v291.INSTANCE, 74) + .registerPacket(ShowCreditsPacket.class, ShowCreditsSerializer_v291.INSTANCE, 75) + .registerPacket(AvailableCommandsPacket.class, AvailableCommandsSerializer_v388.INSTANCE, 76) + .registerPacket(CommandRequestPacket.class, CommandRequestSerializer_v291.INSTANCE, 77) + .registerPacket(CommandBlockUpdatePacket.class, CommandBlockUpdateSerializer_v361.INSTANCE, 78) + .registerPacket(CommandOutputPacket.class, CommandOutputSerializer_v291.INSTANCE, 79) + .registerPacket(UpdateTradePacket.class, UpdateTradeSerializer_v354.INSTANCE, 80) + .registerPacket(UpdateEquipPacket.class, UpdateEquipSerializer_v291.INSTANCE, 81) + .registerPacket(ResourcePackDataInfoPacket.class, ResourcePackDataInfoSerializer_v361.INSTANCE, 82) + .registerPacket(ResourcePackChunkDataPacket.class, ResourcePackChunkDataSerializer_v388.INSTANCE, 83) + .registerPacket(ResourcePackChunkRequestPacket.class, ResourcePackChunkRequestSerializer_v291.INSTANCE, 84) + .registerPacket(TransferPacket.class, TransferSerializer_v291.INSTANCE, 85) + .registerPacket(PlaySoundPacket.class, PlaySoundSerializer_v291.INSTANCE, 86) + .registerPacket(StopSoundPacket.class, StopSoundSerializer_v291.INSTANCE, 87) + .registerPacket(SetTitlePacket.class, SetTitleSerializer_v291.INSTANCE, 88) + .registerPacket(AddBehaviorTreePacket.class, AddBehaviorTreeSerializer_v291.INSTANCE, 89) + .registerPacket(StructureBlockUpdatePacket.class, StructureBlockUpdateSerializer_v388.INSTANCE, 90) + .registerPacket(ShowStoreOfferPacket.class, ShowStoreOfferSerializer_v291.INSTANCE, 91) + .registerPacket(PurchaseReceiptPacket.class, PurchaseReceiptSerializer_v291.INSTANCE, 92) + .registerPacket(PlayerSkinPacket.class, PlayerSkinSerializer_v388.INSTANCE, 93) + .registerPacket(SubClientLoginPacket.class, SubClientLoginSerializer_v291.INSTANCE, 94) + .registerPacket(AutomationClientConnectPacket.class, AutomationClientConnectSerializer_v291.INSTANCE, 95) + .registerPacket(SetLastHurtByPacket.class, SetLastHurtBySerializer_v291.INSTANCE, 96) + .registerPacket(BookEditPacket.class, BookEditSerializer_v291.INSTANCE, 97) + .registerPacket(NpcRequestPacket.class, NpcRequestSerializer_v291.INSTANCE, 98) + .registerPacket(PhotoTransferPacket.class, PhotoTransferSerializer_v291.INSTANCE, 99) + .registerPacket(ModalFormRequestPacket.class, ModalFormRequestSerializer_v291.INSTANCE, 100) + .registerPacket(ModalFormResponsePacket.class, ModalFormResponseSerializer_v291.INSTANCE, 101) + .registerPacket(ServerSettingsRequestPacket.class, ServerSettingsRequestSerializer_v291.INSTANCE, 102) + .registerPacket(ServerSettingsResponsePacket.class, ServerSettingsResponseSerializer_v291.INSTANCE, 103) + .registerPacket(ShowProfilePacket.class, ShowProfileSerializer_v291.INSTANCE, 104) + .registerPacket(SetDefaultGameTypePacket.class, SetDefaultGameTypeSerializer_v291.INSTANCE, 105) + .registerPacket(RemoveObjectivePacket.class, RemoveObjectiveSerializer_v291.INSTANCE, 106) + .registerPacket(SetDisplayObjectivePacket.class, SetDisplayObjectiveSerializer_v291.INSTANCE, 107) + .registerPacket(SetScorePacket.class, SetScoreSerializer_v291.INSTANCE, 108) + .registerPacket(LabTablePacket.class, LabTableSerializer_v291.INSTANCE, 109) + .registerPacket(UpdateBlockSyncedPacket.class, UpdateBlockSyncedSerializer_v291.INSTANCE, 110) + .registerPacket(MoveEntityDeltaPacket.class, MoveEntityDeltaSerializer_v388.INSTANCE, 111) + .registerPacket(SetScoreboardIdentityPacket.class, SetScoreboardIdentitySerializer_v291.INSTANCE, 112) + .registerPacket(SetLocalPlayerAsInitializedPacket.class, SetLocalPlayerAsInitializedSerializer_v291.INSTANCE, 113) + .registerPacket(UpdateSoftEnumPacket.class, UpdateSoftEnumSerializer_v291.INSTANCE, 114) + .registerPacket(NetworkStackLatencyPacket.class, NetworkStackLatencySerializer_v332.INSTANCE, 115) + .registerPacket(ScriptCustomEventPacket.class, ScriptCustomEventSerializer_v291.INSTANCE, 117) + .registerPacket(SpawnParticleEffectPacket.class, SpawnParticleEffectSerializer_v332.INSTANCE, 118) + .registerPacket(AvailableEntityIdentifiersPacket.class, AvailableEntityIdentifiersSerializer_v313.INSTANCE, 119) + .registerPacket(LevelSoundEvent2Packet.class, LevelSoundEvent2Serializer_v313.INSTANCE, 120) + .registerPacket(NetworkChunkPublisherUpdatePacket.class, NetworkChunkPublisherUpdateSerializer_v313.INSTANCE, 121) + .registerPacket(BiomeDefinitionListPacket.class, BiomeDefinitionListSerializer_v313.INSTANCE, 122) + .registerPacket(LevelSoundEventPacket.class, LevelSoundEventSerializer_v332.INSTANCE, 123) + .registerPacket(LevelEventGenericPacket.class, LevelEventGenericSerializer_v361.INSTANCE, 124) + .registerPacket(LecternUpdatePacket.class, LecternUpdateSerializer_v354.INSTANCE, 125) + .registerPacket(VideoStreamConnectPacket.class, VideoStreamConnectSerializer_v361.INSTANCE, 126) + // AddEntityPacket 127 + // RemoveEntityPacket 128 + .registerPacket(ClientCacheStatusPacket.class, ClientCacheStatusSerializer_v361.INSTANCE, 129) + .registerPacket(OnScreenTextureAnimationPacket.class, OnScreenTextureAnimationSerializer_v354.INSTANCE, 130) + .registerPacket(MapCreateLockedCopyPacket.class, MapCreateLockedCopySerializer_v354.INSTANCE, 131) + .registerPacket(StructureTemplateDataRequestPacket.class, StructureTemplateDataRequestSerializer_v361.INSTANCE, 132) + .registerPacket(StructureTemplateDataResponsePacket.class, StructureTemplateDataResponseSerializer_v388.INSTANCE, 133) + .registerPacket(UpdateBlockPropertiesPacket.class, UpdateBlockPropertiesSerializer_v361.INSTANCE, 134) + .registerPacket(ClientCacheBlobStatusPacket.class, ClientCacheBlobStatusSerializer_v361.INSTANCE, 135) + .registerPacket(ClientCacheMissResponsePacket.class, ClientCacheMissResponseSerializer_v361.INSTANCE, 136) + .registerPacket(EducationSettingsPacket.class, EducationSettingsSerializer_v388.INSTANCE, 137) + .registerPacket(EmotePacket.class, EmoteSerializer_v388.INSTANCE, 138) + .registerPacket(MultiplayerSettingsPacket.class, MultiplayerSettingsSerializer_v388.INSTANCE, 139) + .registerPacket(SettingsCommandPacket.class, SettingsCommandSerializer_v388.INSTANCE, 140) + .registerPacket(AnvilDamagePacket.class, AnvilDamageSerializer_v388.INSTANCE, 141) + .registerPacket(CompletedUsingItemPacket.class, CompletedUsingItemSerializer_v388.INSTANCE, 142) + .registerPacket(NetworkSettingsPacket.class, NetworkSettingsSerializer_v388.INSTANCE, 143) + .registerPacket(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v388.INSTANCE, 144) + .build(); +} diff --git a/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/serializer/CraftingDataSerializer_v390.java b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/serializer/CraftingDataSerializer_v390.java new file mode 100644 index 000000000..4a0507a04 --- /dev/null +++ b/bedrock/education-v390/src/main/java/com/nukkitx/protocol/education/v390/serializer/CraftingDataSerializer_v390.java @@ -0,0 +1,116 @@ +package com.nukkitx.protocol.education.v390.serializer; + +import com.nukkitx.network.VarInts; +import com.nukkitx.protocol.bedrock.BedrockPacketHelper; +import com.nukkitx.protocol.bedrock.data.inventory.ContainerMixData; +import com.nukkitx.protocol.bedrock.data.inventory.CraftingDataType; +import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; +import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; +import com.nukkitx.protocol.bedrock.v361.serializer.CraftingDataSerializer_v361; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CraftingDataSerializer_v390 extends CraftingDataSerializer_v361 { + public static final CraftingDataSerializer_v390 INSTANCE = new CraftingDataSerializer_v390(); + + @Override + public void serialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataPacket packet) { + helper.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { + VarInts.writeInt(buf, craftingData.getType().ordinal()); + switch (craftingData.getType()) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + this.writeShapelessRecipe(buf, helper, craftingData); + break; + case SHAPED: + case SHAPED_CHEMISTRY: + this.writeShapedRecipe(buf, helper, craftingData); + break; + case FURNACE: + case FURNACE_DATA: + this.writeFurnaceRecipe(buf, helper, craftingData); + break; + case MULTI: + this.writeMultiRecipe(buf, helper, craftingData); + break; + } + }); + + + // Potions + helper.writeArray(buffer, packet.getPotionMixData(), (buf, potionMixData) -> { + VarInts.writeInt(buf, potionMixData.getInputId()); + VarInts.writeInt(buf, potionMixData.getReagentId()); + VarInts.writeInt(buf, potionMixData.getOutputId()); + }); + + // Potion Container Change + helper.writeArray(buffer, packet.getContainerMixData(), (buf, containerMixData) -> { + VarInts.writeInt(buf, containerMixData.getInputId()); + VarInts.writeInt(buf, containerMixData.getReagentId()); + VarInts.writeInt(buf, containerMixData.getOutputId()); + }); + + // Unknown Array + buffer.writeByte(0); + + buffer.writeBoolean(packet.isCleanRecipes()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataPacket packet) { + helper.readArray(buffer, packet.getCraftingData(), buf -> { + int typeInt = VarInts.readInt(buf); + CraftingDataType type = CraftingDataType.byId(typeInt); + + switch (type) { + case SHAPELESS: + case SHAPELESS_CHEMISTRY: + case SHULKER_BOX: + return this.readShapelessRecipe(buf, helper, type); + case SHAPED: + case SHAPED_CHEMISTRY: + return this.readShapedRecipe(buf, helper, type); + case FURNACE: + case FURNACE_DATA: + return this.readFurnaceRecipe(buf, helper, type); + case MULTI: + return this.readMultiRecipe(buf, helper, type); + default: + throw new IllegalArgumentException("Unhandled crafting data type: " + type); + } + }); + + // Potions + helper.readArray(buffer, packet.getPotionMixData(), buf -> { + int fromPotionId = VarInts.readInt(buf); + int ingredient = VarInts.readInt(buf); + int toPotionId = VarInts.readInt(buf); + return new PotionMixData(fromPotionId, 0, ingredient, 0, toPotionId, 0); + }); + + // Potion Container Change + helper.readArray(buffer, packet.getContainerMixData(), buf -> { + int fromItemId = VarInts.readInt(buf); + int ingredient = VarInts.readInt(buf); + int toItemId = VarInts.readInt(buf); + return new ContainerMixData(fromItemId, ingredient, toItemId); + }); + + // I don't really know what this is but its an array{varint, array{varint, varint}} + // We'll just toss it away for now + int length = VarInts.readUnsignedInt(buffer); + for (int i=0; ibedrock-v340 bedrock-v354 bedrock-v361 - bedrock-v363 bedrock-v388 bedrock-v389 bedrock-v390 bedrock-v407 bedrock-v408 bedrock-v409 + education-v363 + education-v390 \ No newline at end of file diff --git a/pom.xml b/pom.xml index a4be334b4..d3c1b2c78 100644 --- a/pom.xml +++ b/pom.xml @@ -49,14 +49,16 @@ - releases - nukkitx-releases - https://repo.nukkitx.com/release + bundabrg-repo + + https://repo.worldguard.com.au/repository/maven-releases + - snapshots - nukkitx-snapshots - https://repo.nukkitx.com/snapshot + bundabrg-repo + + https://repo.worldguard.com.au/repository/maven-snapshots + From 13a14693c4095f31eacb792c4df9a9310ed62d73 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Thu, 13 Aug 2020 22:12:39 +0800 Subject: [PATCH 70/70] Generify EventSerializer_v291 --- .../v291/serializer/EventSerializer_v291.java | 51 +++---------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java index b0f0aabdc..f96b703c2 100644 --- a/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java +++ b/bedrock/bedrock-v291/src/main/java/com/nukkitx/protocol/bedrock/v291/serializer/EventSerializer_v291.java @@ -81,52 +81,13 @@ public void deserialize(ByteBuf buffer, BedrockPacketHelper helper, EventPacket packet.setUsePlayerId(buffer.readByte()); - EventData data; - - switch (type) { - case ACHIEVEMENT_AWARDED: - data = this.readAchievementAwarded(buffer, helper); - break; - case ENTITY_INTERACT: - data = this.readEntityInteract(buffer, helper); - break; - case PORTAL_BUILT: - data = this.readPortalBuilt(buffer, helper); - break; - case PORTAL_USED: - data = this.readPortalUsed(buffer, helper); - break; - case MOB_KILLED: - data = this.readMobKilled(buffer, helper); - break; - case CAULDRON_USED: - data = this.readCauldronUsed(buffer, helper); - break; - case PLAYER_DIED: - data = this.readPlayerDied(buffer, helper); - break; - case BOSS_KILLED: - data = this.readBossKilled(buffer, helper); - break; - case AGENT_COMMAND: - data = this.readAgentCommand(buffer, helper); - break; - case AGENT_CREATED: - data = AgentCreatedEventData.INSTANCE; - break; - case PATTERN_REMOVED: - data = this.readPatternRemoved(buffer, helper); - break; - case SLASH_COMMAND_EXECUTED: - data = this.readSlashCommandExecuted(buffer, helper); - break; - case FISH_BUCKETED: - data = this.readFishBucketed(buffer, helper); - break; - default: - throw new UnsupportedOperationException("Unknown event type " + type); + BiFunction function = this.readers.get(type); + + if (function == null) { + throw new UnsupportedOperationException("Unknown event type " + type); } - packet.setEventData(data); + + packet.setEventData(function.apply(buffer, helper)); } protected AchievementAwardedEventData readAchievementAwarded(ByteBuf buffer, BedrockPacketHelper helper) {