From cf5300149ff5acbfbaf6039265607c22c8d9e86c Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:56:06 +1000 Subject: [PATCH 1/6] Add NotifyAction CPE --- src/Menus.c | 7 ++++++- src/Protocol.c | 16 ++++++++++++++-- src/Protocol.h | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Menus.c b/src/Menus.c index 7454169be..298c63e0a 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -36,6 +36,7 @@ #include "SystemFonts.h" #include "Lighting.h" #include "InputHandler.h" +#include "Protocol.h" /*########################################################################################################################* *--------------------------------------------------------Menu base--------------------------------------------------------* @@ -1408,11 +1409,15 @@ static void SaveLevelScreen_Save(void* screen, void* widget) { SaveLevelScreen_RemoveOverwrites(s); if ((res = SaveLevelScreen_SaveMap(&path))) return; Chat_Add1("&eSaved map to: %s", &path); + CPE_SendNotifyAction(0, 0); } static void SaveLevelScreen_UploadCallback(const cc_string* path) { cc_result res = SaveLevelScreen_SaveMap(path); - if (!res) Chat_Add1("&eSaved map to: %s", path); + if (!res) { + Chat_Add1("&eSaved map to: %s", path); + CPE_SendNotifyAction(0, 0); + } } static void SaveLevelScreen_File(void* screen, void* b) { diff --git a/src/Protocol.c b/src/Protocol.c index 0a8383d4d..f239b8fed 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -92,7 +92,8 @@ static struct CpeExt pluginMessages_Ext = { "PluginMessages", 1 }, extTeleport_Ext = { "ExtEntityTeleport", 1 }, lightingMode_Ext = { "LightingMode", 1 }, - cinematicGui_Ext = { "CinematicGui", 1 }, + cinematicGui_Ext = { "CinematicGui", 1 }, + notifyAction_Ext = { "NotifyAction", 1 }, extTextures_Ext = { "ExtendedTextures", 1 }, extBlocks_Ext = { "ExtendedBlocks", 1 }; @@ -102,7 +103,7 @@ static struct CpeExt* cpe_clientExtensions[] = { &messageTypes_Ext, &hackControl_Ext, &playerClick_Ext, &fullCP437_Ext, &longerMessages_Ext, &blockDefs_Ext, &blockDefsExt_Ext, &bulkBlockUpdate_Ext, &textColors_Ext, &envMapAspect_Ext, &entityProperty_Ext, &extEntityPos_Ext, &twoWayPing_Ext, &invOrder_Ext, &instantMOTD_Ext, &fastMap_Ext, &setHotbar_Ext, &setSpawnpoint_Ext, &velControl_Ext, - &customParticles_Ext, &pluginMessages_Ext, &extTeleport_Ext, &lightingMode_Ext, &cinematicGui_Ext, + &customParticles_Ext, &pluginMessages_Ext, &extTeleport_Ext, &lightingMode_Ext, &cinematicGui_Ext, ¬ifyAction_Ext, #ifdef CUSTOM_MODELS &customModels_Ext, #endif @@ -896,6 +897,17 @@ void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data) { Server.SendData(buffer, 66); } +void CPE_SendNotifyAction(int action, int value) { + cc_uint8 data[4]; + + data[0] = OPCODE_NOTIFY_ACTION; + { + data[1] = action; + data[2] = value; + } + Server.SendData(data, 4); +} + static void CPE_SendExtInfo(int extsCount) { cc_uint8 data[67]; data[0] = OPCODE_EXT_INFO; diff --git a/src/Protocol.h b/src/Protocol.h index ccaa6e417..44fd62635 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -39,7 +39,7 @@ enum OPCODE_ { OPCODE_DEFINE_EFFECT, OPCODE_SPAWN_EFFECT, OPCODE_DEFINE_MODEL, OPCODE_DEFINE_MODEL_PART, OPCODE_UNDEFINE_MODEL, OPCODE_PLUGIN_MESSAGE, OPCODE_ENTITY_TELEPORT_EXT, - OPCODE_LIGHTING_MODE, OPCODE_CINEMATIC_GUI, + OPCODE_LIGHTING_MODE, OPCODE_CINEMATIC_GUI, OPCODE_NOTIFY_ACTION, OPCODE_COUNT }; @@ -71,6 +71,7 @@ void Classic_SendChat(const cc_string* text, cc_bool partial);\ void Classic_SendSetBlock(int x, int y, int z, cc_bool place, BlockID block); void Classic_SendLogin(void); void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct RayTracer* t); +void CPE_SendNotifyAction(int button, int value); /* Send a PluginMessage to the server; data must contain 64 bytes. */ CC_API void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data); From 9889eca356351c8bf2a028a5ae453e0515dcb4e7 Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Tue, 31 Dec 2024 07:58:19 +1000 Subject: [PATCH 2/6] Use cc_uint32 for NotifyAction value --- src/Protocol.c | 10 +++++----- src/Protocol.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Protocol.c b/src/Protocol.c index f239b8fed..7915117b7 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -897,15 +897,15 @@ void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data) { Server.SendData(buffer, 66); } -void CPE_SendNotifyAction(int action, int value) { - cc_uint8 data[4]; +void CPE_SendNotifyAction(int action, cc_uint32 value) { + cc_uint8 data[8]; data[0] = OPCODE_NOTIFY_ACTION; { - data[1] = action; - data[2] = value; + Stream_SetU16_BE(data + 1, action); + Stream_SetU32_BE(data + 3, value); } - Server.SendData(data, 4); + Server.SendData(data, 8); } static void CPE_SendExtInfo(int extsCount) { diff --git a/src/Protocol.h b/src/Protocol.h index 44fd62635..bb57aea91 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -71,7 +71,7 @@ void Classic_SendChat(const cc_string* text, cc_bool partial);\ void Classic_SendSetBlock(int x, int y, int z, cc_bool place, BlockID block); void Classic_SendLogin(void); void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct RayTracer* t); -void CPE_SendNotifyAction(int button, int value); +void CPE_SendNotifyAction(int action, cc_uint32 value); /* Send a PluginMessage to the server; data must contain 64 bytes. */ CC_API void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data); From ce409304c45f8100b594253fb08226163ac67b46 Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Thu, 2 Jan 2025 09:44:30 +1000 Subject: [PATCH 3/6] Add more NotifyAction types BlockListSelected, BlockListToggled, LevelSaved, Respawned, SpawnUpdated, TexturePackChanged, TexturePromptResponded --- src/Entity.c | 5 +++++ src/Inventory.c | 2 ++ src/Menus.c | 12 ++++++++++-- src/Screens.c | 9 ++++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index a63754660..1cb146130 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -22,6 +22,7 @@ #include "Errors.h" #include "Utils.h" #include "EntityRenderers.h" +#include "Protocol.h" const char* const NameMode_Names[NAME_MODE_COUNT] = { "None", "Hovered", "All", "AllHovered", "AllUnscaled" }; const char* const ShadowMode_Names[SHADOW_MODE_COUNT] = { "None", "SnapToBlock", "Circle", "CircleAll" }; @@ -844,6 +845,8 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { Entity_GetBounds(&p->Base, &bb); bb.Min.y -= 0.01f; bb.Max.y = bb.Min.y; p->Base.OnGround = Entity_TouchesAny(&bb, LocalPlayer_IsSolidCollide); + + CPE_SendNotifyAction(3, 0); } static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { @@ -884,6 +887,8 @@ static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { p->SpawnYaw = p->Base.Yaw; if (!Game_ClassicMode) p->SpawnPitch = p->Base.Pitch; + + CPE_SendNotifyAction(4, 0); } return LocalPlayer_HandleRespawn(key, device); } diff --git a/src/Inventory.c b/src/Inventory.c index a7f00c13f..188433be2 100644 --- a/src/Inventory.c +++ b/src/Inventory.c @@ -4,6 +4,7 @@ #include "Block.h" #include "Event.h" #include "Chat.h" +#include "Protocol.h" struct _InventoryData Inventory; @@ -45,6 +46,7 @@ void Inventory_SetSelectedBlock(BlockID block) { Inventory_Set(Inventory.SelectedIndex, block); Event_RaiseVoid(&UserEvents.HeldBlockChanged); + CPE_SendNotifyAction(0, block); } void Inventory_PickBlock(BlockID block) { diff --git a/src/Menus.c b/src/Menus.c index 298c63e0a..25f117daa 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -1409,14 +1409,14 @@ static void SaveLevelScreen_Save(void* screen, void* widget) { SaveLevelScreen_RemoveOverwrites(s); if ((res = SaveLevelScreen_SaveMap(&path))) return; Chat_Add1("&eSaved map to: %s", &path); - CPE_SendNotifyAction(0, 0); + CPE_SendNotifyAction(2, 0); } static void SaveLevelScreen_UploadCallback(const cc_string* path) { cc_result res = SaveLevelScreen_SaveMap(path); if (!res) { Chat_Add1("&eSaved map to: %s", path); - CPE_SendNotifyAction(0, 0); + CPE_SendNotifyAction(2, 0); } } @@ -1562,6 +1562,8 @@ static void TexturePackScreen_EntryClick(void* screen, void* widget) { TexturePack_Url.length = 0; res = TexturePack_ExtractCurrent(true); + CPE_SendNotifyAction(5, 0); + /* FileNotFound error may be because user deleted .zips from disc */ if (res != ReturnCode_FileNotFound) return; Chat_AddRaw("&eReloading texture pack list as it may be out of date"); @@ -2739,6 +2741,9 @@ static void TexPackOverlay_YesClick(void* screen, void* widget) { TexturePack_Extract(&s->url); if (TexPackOverlay_IsAlways(s, widget)) TextureCache_Accept(&s->url); Gui_Remove((struct Screen*)s); + + if (TexPackOverlay_IsAlways(s, widget)) CPE_SendNotifyAction(6, 3); + else CPE_SendNotifyAction(6, 2); } static void TexPackOverlay_NoClick(void* screen, void* widget) { @@ -2752,6 +2757,9 @@ static void TexPackOverlay_ConfirmNoClick(void* screen, void* b) { struct TexPackOverlay* s = (struct TexPackOverlay*)screen; if (s->alwaysDeny) TextureCache_Deny(&s->url); Gui_Remove((struct Screen*)s); + + if (s->alwaysDeny) CPE_SendNotifyAction(6, 0); + else CPE_SendNotifyAction(6, 1); } static void TexPackOverlay_GoBackClick(void* screen, void* b) { diff --git a/src/Screens.c b/src/Screens.c index ff022e506..8d5a9481d 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -23,6 +23,7 @@ #include "Utils.h" #include "Options.h" #include "InputHandler.h" +#include "Protocol.h" #define CHAT_MAX_STATUS Array_Elems(Chat_Status) #define CHAT_MAX_BOTTOMRIGHT Array_Elems(Chat_BottomRight) @@ -1731,9 +1732,11 @@ static int InventoryScreen_KeyDown(void* screen, int key, struct InputDevice* de /* Accuracy: Original classic doesn't close inventory menu when B is pressed */ if (InputBind_Claims(BIND_INVENTORY, key, device) && s->releasedInv && !Game_ClassicMode) { Gui_Remove((struct Screen*)s); + CPE_SendNotifyAction(1, 0); } else if (InputDevice_IsEnter(key, device) && table->selectedIndex != -1) { Inventory_SetSelectedBlock(table->blocks[table->selectedIndex]); Gui_Remove((struct Screen*)s); + CPE_SendNotifyAction(1, 0); } else if (Elem_HandlesKeyDown(table, key, device)) { } else { return Elem_HandlesKeyDown(&HUDScreen_Instance.hotbar, key, device); @@ -1763,7 +1766,10 @@ static int InventoryScreen_PointerDown(void* screen, int id, int x, int y) { if (!handled || table->pendingClose) { hotbar = Input_IsCtrlPressed() || Input_IsShiftPressed(); - if (!hotbar) Gui_Remove((struct Screen*)s); + if (!hotbar) { + Gui_Remove((struct Screen*)s); + CPE_SendNotifyAction(1, 0); + } } return TOUCH_TYPE_GUI; } @@ -1807,6 +1813,7 @@ void InventoryScreen_Show(void) { s->VTABLE = &InventoryScreen_VTABLE; Gui_Add((struct Screen*)s, GUI_PRIORITY_INVENTORY); + CPE_SendNotifyAction(1, 1); } From 6a51ab921515aa0fa008753c2433ac91c150abce Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Fri, 3 Jan 2025 18:21:51 +1000 Subject: [PATCH 4/6] Add NotifyPositionAction CPE packet After some reflection, I think having a separate packet for position actions would be more useful than packing the data into one cc_uint16 value. --- src/Entity.c | 8 +++++--- src/Protocol.c | 23 +++++++++++++++++++---- src/Protocol.h | 4 +++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 1cb146130..ed03bb638 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -801,6 +801,7 @@ static void LocalPlayers_OnNewMap(void) { } static cc_bool LocalPlayer_IsSolidCollide(BlockID b) { return Blocks.Collide[b] == COLLIDE_SOLID; } + static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { struct LocationUpdate update; struct AABB bb; @@ -830,6 +831,9 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { } } + struct EntityLocation* prev = &p->Base.prev; + CPE_SendNotifyPositionAction(3, prev->pos.x, prev->pos.y, prev->pos.z); + /* Adjust the position to be slightly above the ground, so that */ /* it's obvious to the player that they are being respawned */ spawn.y += 2.0f/16.0f; @@ -845,8 +849,6 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { Entity_GetBounds(&p->Base, &bb); bb.Min.y -= 0.01f; bb.Max.y = bb.Min.y; p->Base.OnGround = Entity_TouchesAny(&bb, LocalPlayer_IsSolidCollide); - - CPE_SendNotifyAction(3, 0); } static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { @@ -888,7 +890,7 @@ static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { p->SpawnYaw = p->Base.Yaw; if (!Game_ClassicMode) p->SpawnPitch = p->Base.Pitch; - CPE_SendNotifyAction(4, 0); + CPE_SendNotifyPositionAction(4, p->Spawn.x, p->Spawn.y, p->Spawn.z); } return LocalPlayer_HandleRespawn(key, device); } diff --git a/src/Protocol.c b/src/Protocol.c index 7915117b7..d61f6c848 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -94,6 +94,7 @@ static struct CpeExt lightingMode_Ext = { "LightingMode", 1 }, cinematicGui_Ext = { "CinematicGui", 1 }, notifyAction_Ext = { "NotifyAction", 1 }, + notifyPositionAction_Ext = { "NotifyPositionAction", 1 }, extTextures_Ext = { "ExtendedTextures", 1 }, extBlocks_Ext = { "ExtendedBlocks", 1 }; @@ -104,6 +105,7 @@ static struct CpeExt* cpe_clientExtensions[] = { &blockDefsExt_Ext, &bulkBlockUpdate_Ext, &textColors_Ext, &envMapAspect_Ext, &entityProperty_Ext, &extEntityPos_Ext, &twoWayPing_Ext, &invOrder_Ext, &instantMOTD_Ext, &fastMap_Ext, &setHotbar_Ext, &setSpawnpoint_Ext, &velControl_Ext, &customParticles_Ext, &pluginMessages_Ext, &extTeleport_Ext, &lightingMode_Ext, &cinematicGui_Ext, ¬ifyAction_Ext, + ¬ifyPositionAction_Ext, #ifdef CUSTOM_MODELS &customModels_Ext, #endif @@ -897,15 +899,28 @@ void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data) { Server.SendData(buffer, 66); } -void CPE_SendNotifyAction(int action, cc_uint32 value) { - cc_uint8 data[8]; +void CPE_SendNotifyAction(int action, cc_uint16 value) { + cc_uint8 data[5]; data[0] = OPCODE_NOTIFY_ACTION; { Stream_SetU16_BE(data + 1, action); - Stream_SetU32_BE(data + 3, value); + Stream_SetU16_BE(data + 3, value); } - Server.SendData(data, 8); + Server.SendData(data, 5); +} + +void CPE_SendNotifyPositionAction(int action, int x, int y, int z) { + cc_uint8 data[9]; + + data[0] = OPCODE_NOTIFY_POSITION_ACTION; + { + Stream_SetU16_BE(data + 1, action); + Stream_SetU16_BE(data + 3, x); + Stream_SetU16_BE(data + 5, y); + Stream_SetU16_BE(data + 7, z); + } + Server.SendData(data, 9); } static void CPE_SendExtInfo(int extsCount) { diff --git a/src/Protocol.h b/src/Protocol.h index bb57aea91..fb97ab2b0 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -40,6 +40,7 @@ enum OPCODE_ { OPCODE_DEFINE_MODEL, OPCODE_DEFINE_MODEL_PART, OPCODE_UNDEFINE_MODEL, OPCODE_PLUGIN_MESSAGE, OPCODE_ENTITY_TELEPORT_EXT, OPCODE_LIGHTING_MODE, OPCODE_CINEMATIC_GUI, OPCODE_NOTIFY_ACTION, + OPCODE_NOTIFY_POSITION_ACTION, OPCODE_COUNT }; @@ -71,7 +72,8 @@ void Classic_SendChat(const cc_string* text, cc_bool partial);\ void Classic_SendSetBlock(int x, int y, int z, cc_bool place, BlockID block); void Classic_SendLogin(void); void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct RayTracer* t); -void CPE_SendNotifyAction(int action, cc_uint32 value); +void CPE_SendNotifyAction(int action, cc_uint16 value); +void CPE_SendNotifyPositionAction(int action, int x, int y, int z); /* Send a PluginMessage to the server; data must contain 64 bytes. */ CC_API void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data); From 90533038256e9c3d8b634f657806cb63fac7baf9 Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Fri, 3 Jan 2025 18:35:33 +1000 Subject: [PATCH 5/6] Add ThirdPersonChanged NotifyAction type --- src/Camera.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Camera.c b/src/Camera.c index 1925eb4fe..879cd9fe2 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -12,6 +12,7 @@ #include "Options.h" #include "Picking.h" #include "Platform.h" +#include "Protocol.h" struct _CameraData Camera; static struct RayTracer cameraClipPos; @@ -302,6 +303,12 @@ void Camera_CycleActive(void) { } cam_isForwardThird = Camera.Active == &cam_ForwardThird; + int cycle = 0; + if (Camera.Active == &cam_FirstPerson) cycle = 0; + else if (Camera.Active == &cam_ThirdPerson) cycle = 1; + else if (cam_isForwardThird) cycle = 2; + CPE_SendNotifyAction(7, cycle); + /* reset rotation offset when changing cameras */ cam_rotOffset.x = 0.0f; cam_rotOffset.y = 0.0f; Camera_UpdateProjection(); From 06cab0a5a17863ea5d2d76f7c226817db45e0abd Mon Sep 17 00:00:00 2001 From: Derek <19647340+ddinan@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:41:59 +1000 Subject: [PATCH 6/6] Use an enum for notify action types --- src/Camera.c | 2 +- src/Inventory.c | 2 +- src/Menus.c | 14 +++++++------- src/Protocol.h | 5 +++++ src/Screens.c | 8 ++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Camera.c b/src/Camera.c index 879cd9fe2..0d957f3f9 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -307,7 +307,7 @@ void Camera_CycleActive(void) { if (Camera.Active == &cam_FirstPerson) cycle = 0; else if (Camera.Active == &cam_ThirdPerson) cycle = 1; else if (cam_isForwardThird) cycle = 2; - CPE_SendNotifyAction(7, cycle); + CPE_SendNotifyAction(NOTIFY_ACTION_THIRD_PERSON_CHANGED, cycle); /* reset rotation offset when changing cameras */ cam_rotOffset.x = 0.0f; cam_rotOffset.y = 0.0f; diff --git a/src/Inventory.c b/src/Inventory.c index 188433be2..817a0b725 100644 --- a/src/Inventory.c +++ b/src/Inventory.c @@ -46,7 +46,7 @@ void Inventory_SetSelectedBlock(BlockID block) { Inventory_Set(Inventory.SelectedIndex, block); Event_RaiseVoid(&UserEvents.HeldBlockChanged); - CPE_SendNotifyAction(0, block); + CPE_SendNotifyAction(NOTIFY_ACTION_BLOCK_LIST_SELECTED, block); } void Inventory_PickBlock(BlockID block) { diff --git a/src/Menus.c b/src/Menus.c index 25f117daa..f01696b4e 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -1409,14 +1409,14 @@ static void SaveLevelScreen_Save(void* screen, void* widget) { SaveLevelScreen_RemoveOverwrites(s); if ((res = SaveLevelScreen_SaveMap(&path))) return; Chat_Add1("&eSaved map to: %s", &path); - CPE_SendNotifyAction(2, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_LEVEL_SAVED, 0); } static void SaveLevelScreen_UploadCallback(const cc_string* path) { cc_result res = SaveLevelScreen_SaveMap(path); if (!res) { Chat_Add1("&eSaved map to: %s", path); - CPE_SendNotifyAction(2, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_LEVEL_SAVED, 0); } } @@ -1562,7 +1562,7 @@ static void TexturePackScreen_EntryClick(void* screen, void* widget) { TexturePack_Url.length = 0; res = TexturePack_ExtractCurrent(true); - CPE_SendNotifyAction(5, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PACK_CHANGED, 0); /* FileNotFound error may be because user deleted .zips from disc */ if (res != ReturnCode_FileNotFound) return; @@ -2742,8 +2742,8 @@ static void TexPackOverlay_YesClick(void* screen, void* widget) { if (TexPackOverlay_IsAlways(s, widget)) TextureCache_Accept(&s->url); Gui_Remove((struct Screen*)s); - if (TexPackOverlay_IsAlways(s, widget)) CPE_SendNotifyAction(6, 3); - else CPE_SendNotifyAction(6, 2); + if (TexPackOverlay_IsAlways(s, widget)) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 3); + else CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 2); } static void TexPackOverlay_NoClick(void* screen, void* widget) { @@ -2758,8 +2758,8 @@ static void TexPackOverlay_ConfirmNoClick(void* screen, void* b) { if (s->alwaysDeny) TextureCache_Deny(&s->url); Gui_Remove((struct Screen*)s); - if (s->alwaysDeny) CPE_SendNotifyAction(6, 0); - else CPE_SendNotifyAction(6, 1); + if (s->alwaysDeny) CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 0); + else CPE_SendNotifyAction(NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED, 1); } static void TexPackOverlay_GoBackClick(void* screen, void* b) { diff --git a/src/Protocol.h b/src/Protocol.h index fb97ab2b0..a85b36b9f 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -50,6 +50,11 @@ enum PROTOCOL_VERSION_ { PROTOCOL_0020 = 6, PROTOCOL_0030 = 7, }; +enum NOTIFY_ACTION_TYPE { + NOTIFY_ACTION_BLOCK_LIST_SELECTED = 0, NOTIFY_ACTION_BLOCK_LIST_TOGGLED = 1, NOTIFY_ACTION_LEVEL_SAVED = 2, + NOTIFY_ACTION_RESPAWNED = 3, NOTIFY_ACTION_SPAWN_UPDATED = 4, NOTIFY_ACTION_TEXTURE_PACK_CHANGED = 5, + NOTIFY_ACTION_TEXTURE_PROMPT_RESPONDED = 6, NOTIFY_ACTION_THIRD_PERSON_CHANGED = 7 +}; typedef void (*Net_Handler)(cc_uint8* data); #define Net_Set(opcode, handler, size) Protocol.Handlers[opcode] = handler; Protocol.Sizes[opcode] = size; diff --git a/src/Screens.c b/src/Screens.c index 8d5a9481d..213fe7052 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1732,11 +1732,11 @@ static int InventoryScreen_KeyDown(void* screen, int key, struct InputDevice* de /* Accuracy: Original classic doesn't close inventory menu when B is pressed */ if (InputBind_Claims(BIND_INVENTORY, key, device) && s->releasedInv && !Game_ClassicMode) { Gui_Remove((struct Screen*)s); - CPE_SendNotifyAction(1, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_BLOCK_LIST_TOGGLED, 0); } else if (InputDevice_IsEnter(key, device) && table->selectedIndex != -1) { Inventory_SetSelectedBlock(table->blocks[table->selectedIndex]); Gui_Remove((struct Screen*)s); - CPE_SendNotifyAction(1, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_BLOCK_LIST_TOGGLED, 0); } else if (Elem_HandlesKeyDown(table, key, device)) { } else { return Elem_HandlesKeyDown(&HUDScreen_Instance.hotbar, key, device); @@ -1768,7 +1768,7 @@ static int InventoryScreen_PointerDown(void* screen, int id, int x, int y) { hotbar = Input_IsCtrlPressed() || Input_IsShiftPressed(); if (!hotbar) { Gui_Remove((struct Screen*)s); - CPE_SendNotifyAction(1, 0); + CPE_SendNotifyAction(NOTIFY_ACTION_BLOCK_LIST_TOGGLED, 0); } } return TOUCH_TYPE_GUI; @@ -1813,7 +1813,7 @@ void InventoryScreen_Show(void) { s->VTABLE = &InventoryScreen_VTABLE; Gui_Add((struct Screen*)s, GUI_PRIORITY_INVENTORY); - CPE_SendNotifyAction(1, 1); + CPE_SendNotifyAction(NOTIFY_ACTION_BLOCK_LIST_TOGGLED, 1); }