From 809c7e379acc24f6c8f3ceaf9f8992c1b3b79086 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 16:30:31 +0200 Subject: [PATCH 01/42] Update server_list_ping_event.h and make fields public --- include/endstone/event/server/server_list_ping_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index a01269c4c..18b84bf72 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -231,8 +231,9 @@ class ServerListPingEvent : public ServerEvent { private: std::string ping_response_; std::string remote_host_; - int remote_port_; std::string motd_; +public: + int remote_port_; int network_protocol_version_; std::string minecraft_version_network_; int num_players_; From b0757da0224aeca252f8ecbe3c7f617eb5216602 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 17:42:19 +0200 Subject: [PATCH 02/42] use proper setters --- .../event/server/server_list_ping_event.h | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index 18b84bf72..b31bcd242 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -74,6 +74,18 @@ class ServerListPingEvent : public ServerEvent { return local_port_; } + /** + * Sets the local port of the server. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setLocalPort(int port) + { + local_port_ = port; + } + /** * Get the local port of the server for IPv6 support * @@ -84,6 +96,18 @@ class ServerListPingEvent : public ServerEvent { return local_port_v6_; } + /** + * Sets the local port of the server for IPv6 support. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setLocalPortV6(int port) + { + local_port_v6_ = port; + } + /** * Get the message of the day message. * @@ -231,9 +255,8 @@ class ServerListPingEvent : public ServerEvent { private: std::string ping_response_; std::string remote_host_; - std::string motd_; -public: int remote_port_; + std::string motd_; int network_protocol_version_; std::string minecraft_version_network_; int num_players_; From 7f9f59ad54f77f5bfb0a8fd57e7a577cc196f308 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 17:46:09 +0200 Subject: [PATCH 03/42] add set guid method for ServerListPingEvent --- .../endstone/event/server/server_list_ping_event.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index b31bcd242..ae5f07bf7 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -64,6 +64,18 @@ class ServerListPingEvent : public ServerEvent { return server_guid_; } + /** + * Sets the local port of the server. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setServerGuid(std::string guid) + { + server_guid_ = guid; + } + /** * Get the local port of the server. * From c5f58c80946ae32114603e809d27e7bbb505e41d Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 3 Dec 2024 15:09:01 +0000 Subject: [PATCH 04/42] docs: update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 073aee840..ccd49fe18 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![CI](https://github.com/EndstoneMC/endstone/actions/workflows/ci.yml/badge.svg)](https://github.com/EndstoneMC/endstone/actions/workflows/ci.yml) [![Documentation](https://github.com/EndstoneMC/endstone/actions/workflows/docs.yml/badge.svg)](https://endstone.dev/) -[![Minecraft - Version](https://img.shields.io/badge/minecraft-v1.21.41_(Bedrock)-black)](https://feedback.minecraft.net/hc/en-us/articles/31222183227149-Minecraft-Bedrock-Edition-1-21-40-Bundles-of-Bravery) +[![Minecraft - Version](https://img.shields.io/badge/minecraft-v1.21.44_(Bedrock)-black)](https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs) [![PyPI - Version](https://img.shields.io/pypi/v/endstone)](https://pypi.org/project/endstone) [![Python](https://img.shields.io/pypi/pyversions/endstone?logo=python&logoColor=white)](https://www.python.org/) [![GitHub License](https://img.shields.io/github/license/endstonemc/endstone)](LICENSE) From e9491ff861b1b087a4662d3963c5ddd8f0dc45cc Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 4 Dec 2024 18:56:44 +0000 Subject: [PATCH 05/42] chore: update symbols.toml for BDS v1.21.50 Windows (not supported yet) --- python/src/endstone/__init__.py | 2 +- python/src/endstone/_internal/symbols.toml | 142 ++++++++++----------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/python/src/endstone/__init__.py b/python/src/endstone/__init__.py index 54aff736a..3c481ea5e 100644 --- a/python/src/endstone/__init__.py +++ b/python/src/endstone/__init__.py @@ -1,6 +1,6 @@ from endstone._internal.endstone_python import ColorFormat, GameMode, Logger, Player, Server, Skin from endstone._internal.version import __version__ -__minecraft_version__ = "1.21.44" +__minecraft_version__ = "1.21.50" __all__ = ["__version__", "__minecraft_version__", "ColorFormat", "GameMode", "Logger", "Player", "Server", "Skin"] diff --git a/python/src/endstone/_internal/symbols.toml b/python/src/endstone/_internal/symbols.toml index 656c644df..7a53b46fd 100644 --- a/python/src/endstone/_internal/symbols.toml +++ b/python/src/endstone/_internal/symbols.toml @@ -1,114 +1,114 @@ -timestamp = 1733146961 -version = "1.21.44" +timestamp = 1733338493 +version = "1.21.50" [windows] -"?getI18n@@YAAEAVI18n@@XZ" = 9204784 +"?getI18n@@YAAEAVI18n@@XZ" = 14120528 # Actor -"?remove@Actor@@UEAAXXZ" = 31798864 -"?teleportTo@Actor@@UEAAXAEBVVec3@@_NHH1@Z" = 31831600 +"?remove@Actor@@UEAAXXZ" = 37853696 +"?teleportTo@Actor@@UEAAXAEBVVec3@@_NHH1@Z" = 37887936 # Bedrock -"?getServerThread@Threading@Bedrock@@YAAEAVAssignedThread@12@XZ" = 54670112 +"?getServerThread@Threading@Bedrock@@YAAEAVAssignedThread@12@XZ" = 62131040 # BedrockLog -"?log_va@BedrockLog@@YAXW4LogCategory@1@V?$bitset@$02@std@@W4LogRule@1@W4LogAreaID@@IPEBDH4PEAD@Z" = 52334304 +"?log_va@BedrockLog@@YAXW4LogCategory@1@V?$bitset@$02@std@@W4LogRule@1@W4LogAreaID@@IPEBDH4PEAD@Z" = 59908992 # BlockDescriptor -"?tryGetBlockNoLogging@BlockDescriptor@@QEBAPEBVBlock@@XZ" = 34244672 +"?tryGetBlockNoLogging@BlockDescriptor@@QEBAPEBVBlock@@XZ" = 41068464 # BlockTypeRegistry -"?forEachBlock@BlockTypeRegistry@@SAXV?$function@$$A6A_NAEBVBlockLegacy@@@Z@std@@@Z" = 40987984 +"?forEachBlock@BlockTypeRegistry@@SAXV?$function@$$A6A_NAEBVBlockLegacy@@@Z@std@@@Z" = 46961872 # Command -"?getCommandName@Command@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 15467408 -"?run@Command@@QEBAXAEBVCommandOrigin@@AEAVCommandOutput@@@Z" = 15507616 +"?getCommandName@Command@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 20390816 +"?run@Command@@QEBAXAEBVCommandOrigin@@AEAVCommandOutput@@@Z" = 20430480 # CommandOriginLoader -"?load@CommandOriginLoader@@SA?AV?$unique_ptr@VCommandOrigin@@U?$default_delete@VCommandOrigin@@@std@@@std@@AEBVCompoundTag@@AEAVServerLevel@@@Z" = 15488320 +"?load@CommandOriginLoader@@SA?AV?$unique_ptr@VCommandOrigin@@U?$default_delete@VCommandOrigin@@@std@@@std@@AEBVCompoundTag@@AEAVServerLevel@@@Z" = 20412112 # CommandRegistry -"?addEnumValues@CommandRegistry@@QEAAHAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 17946016 -"?createCommand@CommandRegistry@@AEBA?AV?$unique_ptr@VCommand@@U?$default_delete@VCommand@@@std@@@std@@AEBUParseToken@1@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 17965328 -"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVCommandParameterData@@@Z" = 17967088 -"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBUSignature@1@AEBV23@AEBUOverload@1@IPEAI3@Z" = 17966512 -"?findCommand@CommandRegistry@@AEBAPEBUSignature@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z" = 17973888 -"?registerAlias@CommandRegistry@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z" = 18003792 -"?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z" = 18005840 -"?registerOverloadInternal@CommandRegistry@@AEAAXAEAUSignature@1@AEAUOverload@1@@Z" = 18008432 -"?serializeAvailableCommands@CommandRegistry@@QEBA?AVAvailableCommandsPacket@@XZ" = 18014736 +"?addEnumValues@CommandRegistry@@QEAAHAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 22482992 +"?createCommand@CommandRegistry@@AEBA?AV?$unique_ptr@VCommand@@U?$default_delete@VCommand@@@std@@@std@@AEBUParseToken@1@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 22501920 +"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVCommandParameterData@@@Z" = 22503680 +"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBUSignature@1@AEBV23@AEBUOverload@1@IPEAI3@Z" = 22503104 +"?findCommand@CommandRegistry@@AEBAPEBUSignature@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z" = 22508688 +"?registerAlias@CommandRegistry@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z" = 22539008 +"?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z" = 22541056 +"?registerOverloadInternal@CommandRegistry@@AEAAXAEAUSignature@1@AEAUOverload@1@@Z" = 22543648 +"?serializeAvailableCommands@CommandRegistry@@QEBA?AVAvailableCommandsPacket@@XZ" = 22549552 # CommandUtils -"?getActorName@CommandUtils@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVActor@@@Z" = 17661392 +"?getActorName@CommandUtils@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVActor@@@Z" = 22221424 # Common -"?getGameVersionString@Common@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 6246224 +"?getGameVersionString@Common@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 6291840 # CraftingDataPacket -"?prepareFromRecipes@CraftingDataPacket@@SA?AV?$unique_ptr@VCraftingDataPacket@@U?$default_delete@VCraftingDataPacket@@@std@@@std@@AEBVRecipes@@_N@Z" = 9681280 +"?prepareFromRecipes@CraftingDataPacket@@SA?AV?$unique_ptr@VCraftingDataPacket@@U?$default_delete@VCraftingDataPacket@@@std@@@std@@AEBVRecipes@@_N@Z" = 16545120 # FurnaceBlockActor -"?getBurnDuration@FurnaceBlockActor@@SAMAEBVItemStackBase@@M@Z" = 42530768 +"?getBurnDuration@FurnaceBlockActor@@SAMAEBVItemStackBase@@M@Z" = 50047168 # GameMode -"?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z" = 31200336 -"?interact@GameMode@@UEAA_NAEAVActor@@AEBVVec3@@@Z" = 31211696 -"?useItemOn@GameMode@@UEAA?AVInteractionResult@@AEAVItemStack@@AEBVBlockPos@@EAEBVVec3@@PEBVBlock@@_N@Z" = 31241696 +"?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z" = 36328896 +"?interact@GameMode@@UEAA_NAEAVActor@@AEBVVec3@@@Z" = 36359280 +"?useItemOn@GameMode@@UEAA?AVInteractionResult@@AEAVItemStack@@AEBVBlockPos@@EAEBVVec3@@PEBVBlock@@_N@Z" = 36388512 # Item -"?_sendTryPlaceBlockEvent@Item@@IEBA?AW4CoordinatorResult@@AEBVBlock@@AEBVBlockSource@@AEBVActor@@AEBVBlockPos@@EAEBVVec3@@@Z" = 35716800 +"?_sendTryPlaceBlockEvent@Item@@IEBA?AW4CoordinatorResult@@AEBVBlock@@AEBVBlockSource@@AEBVActor@@AEBVBlockPos@@EAEBVVec3@@@Z" = 40218656 # ItemStack -"??0ItemStack@@QEAA@XZ" = 33714320 -"??0ItemStack@@QEAA@AEBV0@@Z" = 33713728 -"??0ItemStack@@QEAA@AEBVItem@@HHPEBVCompoundTag@@@Z" = 33713952 +"??0ItemStack@@QEAA@XZ" = 40190640 +"??0ItemStack@@QEAA@AEBV0@@Z" = 40190144 +"??0ItemStack@@QEAA@AEBVItem@@HHPEBVCompoundTag@@@Z" = 40190368 # Level -"?tick@Level@@UEAAXXZ" = 33034384 +"?tick@Level@@UEAAXXZ" = 39489328 # LevelEventCoordinator -"?_postReloadActorAdded@LevelEventCoordinator@@AEAAXAEAVActor@@W4ActorInitializationMethod@@@Z" = 30324464 +"?_postReloadActorAdded@LevelEventCoordinator@@AEAAXAEAVActor@@W4ActorInitializationMethod@@@Z" = 36309440 # MinecraftCommands -"?compileCommand@MinecraftCommands@@QEAAPEAVCommand@@AEBVHashedString@@AEAVCommandOrigin@@W4CurrentCmdVersion@@V?$function@$$A6AXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@std@@@Z" = 17596992 -"?executeCommand@MinecraftCommands@@QEBA?AUMCRESULT@@AEAVCommandContext@@_N@Z" = 17657792 +"?compileCommand@MinecraftCommands@@QEAAPEAVCommand@@AEBVHashedString@@AEAVCommandOrigin@@W4CurrentCmdVersion@@V?$function@$$A6AXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@std@@@Z" = 22148496 +"?executeCommand@MinecraftCommands@@QEBA?AUMCRESULT@@AEAVCommandContext@@_N@Z" = 22217824 # MinecraftPackets -"?createPacket@MinecraftPackets@@SA?AV?$shared_ptr@VPacket@@@std@@W4MinecraftPacketIds@@@Z" = 8985776 +"?createPacket@MinecraftPackets@@SA?AV?$shared_ptr@VPacket@@@std@@W4MinecraftPacketIds@@@Z" = 13909120 # Mob -"?die@Mob@@UEAAXAEBVActorDamageSource@@@Z" = 30936992 -"?knockback@Mob@@UEAAXPEAVActor@@HMMMMM@Z" = 30977456 +"?die@Mob@@UEAAXAEBVActorDamageSource@@@Z" = 37552064 +"?knockback@Mob@@UEAAXPEAVActor@@HMMMMM@Z" = 37598352 # Pack -"?createPack@Pack@@SA?AV?$unique_ptr@VPack@@U?$default_delete@VPack@@@std@@@std@@AEBVResourceLocation@@W4PackType@@W4PackOrigin@@AEAVIPackManifestFactory@@AEBV?$not_null@V?$NonOwnerPointer@$$CBVIContentKeyProvider@@@Bedrock@@@gsl@@PEAVPackSourceReport@@AEBVPath@Core@@@Z" = 10238928 +"?createPack@Pack@@SA?AV?$unique_ptr@VPack@@U?$default_delete@VPack@@@std@@@std@@AEBVResourceLocation@@W4PackType@@W4PackOrigin@@AEAVIPackManifestFactory@@AEBV?$not_null@V?$NonOwnerPointer@$$CBVIContentKeyProvider@@@Bedrock@@@gsl@@PEAVPackSourceReport@@AEBVPath@Core@@@Z" = 15310816 # Player -"?getInventory@Player@@QEAAAEAVContainer@@XZ" = 31914480 -"?getName@Player@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 31916352 -"?setPermissions@Player@@QEAAXW4CommandPermissionLevel@@@Z" = 31953456 -"?teleportTo@Player@@UEAAXAEBVVec3@@_NHH1@Z" = 31969136 +"?getInventory@Player@@QEAAAEAVContainer@@XZ" = 37971760 +"?getName@Player@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" = 37973648 +"?setPermissions@Player@@QEAAXW4CommandPermissionLevel@@@Z" = 38013904 +"?teleportTo@Player@@UEAAXAEBVVec3@@_NHH1@Z" = 38032432 # PlayerEventCoordinator -"?sendEvent@PlayerEventCoordinator@@QEAAXAEBV?$EventRef@U?$PlayerGameplayEvent@X@@@@@Z" = 30412896 +"?sendEvent@PlayerEventCoordinator@@QEAAXAEBV?$EventRef@U?$PlayerGameplayEvent@X@@@@@Z" = 36373312 # RakNet -"?Send_Windows_Linux_360NoVDP@RNS2_Windows_Linux_360@RakNet@@KAHHPEAURNS2_SendParameters@2@PEBDI@Z" = 44992352 -"?ToString@SystemAddress@RakNet@@QEBAX_NPEADD@Z" = 44839280 +"?Send_Windows_Linux_360NoVDP@RNS2_Windows_Linux_360@RakNet@@KAHHPEAURNS2_SendParameters@2@PEBDI@Z" = 51374320 +"?ToString@SystemAddress@RakNet@@QEBAX_NPEADD@Z" = 51221232 # RakPeerHelper -"?peerStartup@RakPeerHelper@@QEAA?AW4StartupResult@RakNet@@PEAVRakPeerInterface@3@AEBUConnectionDefinition@@W4PeerPurpose@1@@Z" = 9040016 +"?peerStartup@RakPeerHelper@@QEAA?AW4StartupResult@RakNet@@PEAVRakPeerInterface@3@AEBUConnectionDefinition@@W4PeerPurpose@1@@Z" = 13945120 # ResourcePackRepository -"?_initializePackSource@ResourcePackRepository@@AEAAXXZ" = 10402864 +"?_initializePackSource@ResourcePackRepository@@AEAAXXZ" = 15659648 # ResourcePackStack -"?deserialize@ResourcePackStack@@SA?AV?$unique_ptr@VResourcePackStack@@U?$default_delete@VResourcePackStack@@@std@@@std@@AEAV?$basic_istream@DU?$char_traits@D@std@@@3@AEBV?$not_null@V?$NonOwnerPointer@$$CBVIResourcePackRepository@@@Bedrock@@@gsl@@@Z" = 10590384 +"?deserialize@ResourcePackStack@@SA?AV?$unique_ptr@VResourcePackStack@@U?$default_delete@VResourcePackStack@@@std@@@std@@AEAV?$basic_istream@DU?$char_traits@D@std@@@3@AEBV?$not_null@V?$NonOwnerPointer@$$CBVIResourcePackRepository@@@Bedrock@@@gsl@@@Z" = 15500912 # SayCommand -"?_sendMessage@SayCommand@@CAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@0AEBUCommandOriginIdentity@@AEAVLevel@@@Z" = 27721296 +"?_sendMessage@SayCommand@@CAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@0AEBUCommandOriginIdentity@@AEAVLevel@@@Z" = 34977872 # Scoreboard -"?resetPlayerScore@Scoreboard@@QEAA_NAEBUScoreboardId@@AEAVObjective@@@Z" = 44746976 +"?resetPlayerScore@Scoreboard@@QEAA_NAEBUScoreboardId@@AEAVObjective@@@Z" = 48536832 # ScriptingEventCoordinator -"?sendEvent@ScriptingEventCoordinator@@QEAA?AW4CoordinatorResult@@V?$EventRef@U?$ScriptingGameplayEvent@W4CoordinatorResult@@@@@@@Z" = 30413520 +"?sendEvent@ScriptingEventCoordinator@@QEAA?AW4CoordinatorResult@@V?$EventRef@U?$ScriptingGameplayEvent@W4CoordinatorResult@@@@@@@Z" = 36373936 # ScriptLevelGameplayHandler -"?handleEvent@ScriptLevelGameplayHandler@@UEAA?AU?$GameplayHandlerResult@W4CoordinatorResult@@@@AEAULevelWeatherChangedEvent@@@Z" = 17265504 +"?handleEvent@ScriptLevelGameplayHandler@@UEAA?AU?$GameplayHandlerResult@W4CoordinatorResult@@@@AEAULevelWeatherChangedEvent@@@Z" = 21865632 # ScriptModuleMinecraft::ScriptBlockUtils -"?createBlockDescriptor@ScriptBlockUtils@ScriptModuleMinecraft@@YA?AVBlockDescriptor@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$variant@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@2@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$variant@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@2@@std@@@2@@std@@@5@@Z" = 26938832 +"?createBlockDescriptor@ScriptBlockUtils@ScriptModuleMinecraft@@YA?AVBlockDescriptor@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$variant@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@2@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$variant@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@2@@std@@@2@@std@@@5@@Z" = 24454288 # ServerInstanceEventCoordinator -"?sendServerInitializeStart@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 30417584 -"?sendServerThreadStarted@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 30417920 -"?sendServerThreadStopped@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 30417968 +"?sendServerInitializeStart@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 36377152 +"?sendServerThreadStarted@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 36377328 +"?sendServerThreadStopped@ServerInstanceEventCoordinator@@QEAAXAEAVServerInstance@@@Z" = 36377376 # ServerNetworkHandler -"?disconnectClient@ServerNetworkHandler@@QEAAXAEBVNetworkIdentifier@@W4SubClientId@@W4DisconnectFailReason@Connection@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@7@_N@Z" = 9610240 -"?trytLoadPlayer@ServerNetworkHandler@@QEAA_NAEAVServerPlayer@@AEBVConnectionRequest@@@Z" = 9697328 -"?updateServerAnnouncement@ServerNetworkHandler@@QEAAXXZ" = 9698880 -"?_createNewPlayer@ServerNetworkHandler@@AEAAAEAVServerPlayer@@AEBVNetworkIdentifier@@AEBVSubClientConnectionRequest@@W4SubClientId@@@Z" = 9502832 -"?_displayGameMessage@ServerNetworkHandler@@AEAAXAEBVPlayer@@AEAUChatEvent@@@Z" = 9507552 -"?_isServerTextEnabled@ServerNetworkHandler@@AEBA_NAEBW4ServerTextEvent@@@Z" = 9515344 +"?disconnectClient@ServerNetworkHandler@@QEAAXAEBVNetworkIdentifier@@W4SubClientId@@W4DisconnectFailReason@Connection@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@7@_N@Z" = 14360864 +"?trytLoadPlayer@ServerNetworkHandler@@QEAA_NAEAVServerPlayer@@AEBVConnectionRequest@@@Z" = 14436512 +"?updateServerAnnouncement@ServerNetworkHandler@@QEAAXXZ" = 14438928 +"?_createNewPlayer@ServerNetworkHandler@@AEAAAEAVServerPlayer@@AEBVNetworkIdentifier@@AEBVSubClientConnectionRequest@@W4SubClientId@@@Z" = 14291952 +"?_displayGameMessage@ServerNetworkHandler@@AEAAXAEBVPlayer@@AEAUChatEvent@@@Z" = 14296736 +"?_isServerTextEnabled@ServerNetworkHandler@@AEBA_NAEBW4ServerTextEvent@@@Z" = 14311280 # ServerPlayer -"?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z" = 15453040 -"?disconnect@ServerPlayer@@QEAAXXZ" = 15453200 -"?setLocalPlayerAsInitialized@ServerPlayer@@QEAAXXZ" = 15526128 +"?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z" = 20376160 +"?disconnect@ServerPlayer@@QEAAXXZ" = 20376320 +"?setLocalPlayerAsInitialized@ServerPlayer@@QEAAXXZ" = 20449488 # ServerScoreboard -"??0ServerScoreboard@@QEAA@VCommandSoftEnumRegistry@@PEAVLevelStorage@@V?$not_null@V?$NonOwnerPointer@VGameplayUserManager@@@Bedrock@@@gsl@@@Z" = 44716688 +"??0ServerScoreboard@@QEAA@VCommandSoftEnumRegistry@@PEAVLevelStorage@@V?$not_null@V?$NonOwnerPointer@VGameplayUserManager@@@Bedrock@@@gsl@@@Z" = 51136848 # StartGamePacket -"?write@StartGamePacket@@UEBAXAEAVBinaryStream@@@Z" = 11521840 +"?write@StartGamePacket@@UEBAXAEAVBinaryStream@@@Z" = 15195216 # TeleportCommand -"?applyTarget@TeleportCommand@@SAXAEAVActor@@VTeleportTarget@@_N@Z" = 28487984 -"?computeTarget@TeleportCommand@@SA?AVTeleportTarget@@AEAVActor@@VVec3@@PEAV4@V?$AutomaticID@VDimension@@H@@AEBV?$optional@VRotationData@RotationCommandUtils@@@std@@H@Z" = 28488480 +"?applyTarget@TeleportCommand@@SAXAEAVActor@@VTeleportTarget@@_N@Z" = 34991456 +"?computeTarget@TeleportCommand@@SA?AVTeleportTarget@@AEAVActor@@VVec3@@PEAV4@V?$AutomaticID@VDimension@@H@@AEBV?$optional@VRotationData@RotationCommandUtils@@@std@@H@Z" = 34991952 [linux] "_Z7getI18nv" = 75064256 From 99b3437118e5f6493b0bf12142bfa902403492d7 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 09:25:12 +0000 Subject: [PATCH 06/42] fix: add missing virtual functions in IResourcePackRepository --- .../bedrock/resources/resource_pack_repository_interface.h | 4 +++- .../bedrock/world/events/server_instance_event_coordinator.h | 1 - src/endstone_core/packs/endstone_pack_source.cpp | 1 - src/endstone_core/server.cpp | 3 +++ .../world/events/server_instance_event_coordinator.cpp | 3 --- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/bedrock/resources/resource_pack_repository_interface.h b/include/bedrock/resources/resource_pack_repository_interface.h index 7c939fa4f..ae0fec8ae 100644 --- a/include/bedrock/resources/resource_pack_repository_interface.h +++ b/include/bedrock/resources/resource_pack_repository_interface.h @@ -22,7 +22,8 @@ class IResourcePackRepository : public Bedrock::EnableNonOwnerReferences { public: virtual void getResourcePacksByPackId(std::vector const &, std::vector &) const = 0; [[nodiscard]] virtual ResourcePack *getResourcePackForPackId(PackIdVersion const &) const = 0; - [[nodiscard]] virtual ResourcePack *getResourcePackForPackIdInPath(PackIdVersion const &,Core::Path const &) const = 0; + [[nodiscard]] virtual ResourcePack *getResourcePackForPackIdInPath(PackIdVersion const &, + Core::Path const &) const = 0; [[nodiscard]] virtual ResourcePack *getResourcePackByUUID(mce::UUID const &) const = 0; [[nodiscard]] virtual ResourcePack *getResourcePackForPackIdOwned(PackIdVersion const &) const = 0; [[nodiscard]] virtual ResourcePack *getResourcePackSatisfiesPackId(PackIdVersion const &, bool) const = 0; @@ -39,6 +40,7 @@ class IResourcePackRepository : public Bedrock::EnableNonOwnerReferences { virtual void addCachedResourcePacks(ContentKeyMap const *) = 0; virtual void addWorldResourcePacks(Core::Path const &) = 0; virtual void addPremiumWorldTemplateResourcePacks(Core::Path const &, ContentIdentity const &) = 0; + virtual void addTempWorldTemplateResourcePacks(mce::UUID const &) = 0; virtual void removePacksLoadedFromCache() = 0; virtual void removePacksLoadedFromWorld() = 0; [[nodiscard]] virtual Core::HeapPathBuffer getResourcePacksPath() const = 0; diff --git a/include/bedrock/world/events/server_instance_event_coordinator.h b/include/bedrock/world/events/server_instance_event_coordinator.h index 6f2b4e660..1b7f4f496 100644 --- a/include/bedrock/world/events/server_instance_event_coordinator.h +++ b/include/bedrock/world/events/server_instance_event_coordinator.h @@ -24,5 +24,4 @@ class ServerInstanceEventCoordinator : public EventCoordinatorPimpl -#include "endstone/color_format.h" #include "endstone/detail/server.h" namespace fs = std::filesystem; diff --git a/src/endstone_core/server.cpp b/src/endstone_core/server.cpp index b97b74e28..d434c36ba 100644 --- a/src/endstone_core/server.cpp +++ b/src/endstone_core/server.cpp @@ -39,6 +39,7 @@ namespace fs = std::filesystem; #include "endstone/detail/permissions/default_permissions.h" #include "endstone/detail/plugin/cpp_plugin_loader.h" #include "endstone/detail/plugin/python_plugin_loader.h" +#include "endstone/detail/signal_handler.h" #include "endstone/detail/util/error.h" #include "endstone/event/server/broadcast_message_event.h" #include "endstone/event/server/server_load_event.h" @@ -52,6 +53,8 @@ namespace endstone::detail { EndstoneServer::EndstoneServer() : logger_(LoggerFactory::getLogger("Server")) { + register_signal_handler(); + player_ban_list_ = std::make_unique("banned-players.json"); language_ = std::make_unique(); plugin_manager_ = std::make_unique(*this); diff --git a/src/endstone_runtime/bedrock/world/events/server_instance_event_coordinator.cpp b/src/endstone_runtime/bedrock/world/events/server_instance_event_coordinator.cpp index 0e5d0042e..2fa9e6602 100644 --- a/src/endstone_runtime/bedrock/world/events/server_instance_event_coordinator.cpp +++ b/src/endstone_runtime/bedrock/world/events/server_instance_event_coordinator.cpp @@ -20,7 +20,6 @@ #include "bedrock/world/level/level.h" #include "endstone/detail/hook.h" #include "endstone/detail/level/level.h" -#include "endstone/detail/plugin/python_plugin_loader.h" #include "endstone/detail/scoreboard/scoreboard.h" #include "endstone/detail/server.h" #include "endstone/detail/signal_handler.h" @@ -34,11 +33,9 @@ using endstone::ServerLoadEvent; using endstone::detail::EndstoneLevel; using endstone::detail::EndstoneScoreboard; using endstone::detail::EndstoneServer; -using endstone::detail::PythonPluginLoader; void ServerInstanceEventCoordinator::sendServerInitializeStart(ServerInstance &instance) { - endstone::detail::register_signal_handler(); auto &server = entt::locator::value_or(); server.init(instance); server.loadPlugins(); From 6d719a902dc681910b9c629635f4a0ae72b56594 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 10:06:47 +0000 Subject: [PATCH 07/42] fix: ScriptingGameplayEvent variants --- include/bedrock/world/events/event_variant.h | 5 +- .../bedrock/world/events/scripting_events.h | 13 +++-- include/bedrock/world/level/level.h | 10 ++++ include/bedrock/world/level/level_interface.h | 15 ++---- src/endstone_core/server.cpp | 2 +- .../events/scripting_event_coordinator.cpp | 48 ++++++++++--------- 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/include/bedrock/world/events/event_variant.h b/include/bedrock/world/events/event_variant.h index f0f99861c..fe6ec1c2b 100644 --- a/include/bedrock/world/events/event_variant.h +++ b/include/bedrock/world/events/event_variant.h @@ -61,9 +61,8 @@ struct EventVariantImpl { EventVariantImpl(EventVariantImpl const &) = default; EventVariantImpl(EventVariantImpl &&) = default; - template - EventVariantImpl(std::reference_wrapper event) - : variant{std::in_place_type>, event} + template + EventVariantImpl(std::reference_wrapper event) : variant{std::in_place_type>, event} { } diff --git a/include/bedrock/world/events/scripting_events.h b/include/bedrock/world/events/scripting_events.h index fd20c2b2c..c5d5666c3 100644 --- a/include/bedrock/world/events/scripting_events.h +++ b/include/bedrock/world/events/scripting_events.h @@ -17,14 +17,15 @@ #include #include -#include - #include "bedrock/gameplayhandlers/coordinator_result.h" #include "bedrock/world/actor/actor_unique_id.h" #include "bedrock/world/events/event_variant.h" #include "bedrock/world/level/block_pos.h" #include "bedrock/world/level/block_source.h" +struct ScriptModuleStartupEvent {}; +struct ScriptModuleShutdownEvent {}; + struct BlockObject { gsl::not_null region; BlockPos pos; @@ -39,10 +40,12 @@ struct ScriptCommandMessageEvent { std::optional initiator; }; -template +template struct ScriptingGameplayEvent; template <> -struct ScriptingGameplayEvent : ConstEventVariant { - using ConstEventVariant::ConstEventVariant; +struct ScriptingGameplayEvent + : ConstEventVariant { + using ConstEventVariant::ConstEventVariant; }; diff --git a/include/bedrock/world/level/level.h b/include/bedrock/world/level/level.h index 48e4e272f..89ad87432 100644 --- a/include/bedrock/world/level/level.h +++ b/include/bedrock/world/level/level.h @@ -25,8 +25,18 @@ class Level : public ILevel { public: ENDSTONE_HOOK void tick() override; +#ifdef __linux__ // wtf mojang + virtual void onSourceCreated(BlockSource &) = 0; + virtual void onSourceDestroyed(BlockSource &) = 0; +#endif + +protected: + virtual void _subTick() = 0; + +public: static bool isUsableLevel(const ILevel &level); protected: + virtual void _initializeMapDataManager() = 0; friend class endstone::detail::EndstoneServer; }; diff --git a/include/bedrock/world/level/level_interface.h b/include/bedrock/world/level/level_interface.h index a3e5c2bf7..5c2029f52 100644 --- a/include/bedrock/world/level/level_interface.h +++ b/include/bedrock/world/level/level_interface.h @@ -320,7 +320,6 @@ class ILevel : public Bedrock::EnableNonOwnerReferences { virtual void upgradeStorageVersion(StorageVersion) = 0; virtual void suspendAndSave() = 0; virtual Particle *addParticle(ParticleType, Vec3 const &, Vec3 const &, int, CompoundTag const *, bool) = 0; - virtual void _destroyEffect(BlockPos const &, Block const &, int) = 0; virtual void addParticleEffect(HashedString const &, Vec3 const &, MolangVariableMap const &) = 0; virtual void addTerrainParticleEffect(BlockPos const &, Block const &, Vec3 const &, float, float, float) = 0; virtual void addTerrainSlideEffect(BlockPos const &, Block const &, Vec3 const &, float, float, float) = 0; @@ -383,7 +382,6 @@ class ILevel : public Bedrock::EnableNonOwnerReferences { virtual void initializeBlockDefinitionGroup() = 0; virtual Bedrock::NonOwnerPointer getUnknownBlockTypeRegistry() = 0; [[nodiscard]] virtual bool isClientSide() const = 0; - virtual std::unordered_map &getPlayerList() = 0; [[nodiscard]] virtual std::unordered_map const &getPlayerList() const = 0; [[nodiscard]] virtual std::string const &getPlayerXUID(mce::UUID const &) const = 0; [[nodiscard]] virtual std::string const &getPlayerPlatformOnlineId(mce::UUID const &) const = 0; @@ -458,20 +456,13 @@ class ILevel : public Bedrock::EnableNonOwnerReferences { [[nodiscard]] virtual ItemRegistryRef getItemRegistry() const = 0; [[nodiscard]] virtual std::weak_ptr getBlockRegistry() const = 0; virtual void pauseAndFlushTaskGroups() = 0; - - virtual PlayerDeathManager *_getPlayerDeathManager() = 0; // Endstone: private -> public + virtual void *cerealContext() = 0; + virtual PlayerDeathManager *_getPlayerDeathManager() = 0; // Endstone: protected -> public private: virtual MapDataManager &_getMapDataManager() = 0; virtual void *getArmorTrimUnloader() = 0; [[nodiscard]] virtual void *getPlayerSleepManager() const = 0; virtual void *getPlayerSleepManager() = 0; -#ifdef __linux__ // wtf mojang - virtual void onSourceCreated(BlockSource &) = 0; - virtual void onSourceDestroyed(BlockSource &) = 0; -#endif - -protected: - virtual void _subTick() = 0; - virtual void _initializeMapDataManager() = 0; + virtual void *_cerealContext(); }; diff --git a/src/endstone_core/server.cpp b/src/endstone_core/server.cpp index d434c36ba..1a945c7ee 100644 --- a/src/endstone_core/server.cpp +++ b/src/endstone_core/server.cpp @@ -220,7 +220,7 @@ Scheduler &EndstoneServer::getScheduler() const Level *EndstoneServer::getLevel() const { - return level_.get(); + return level_ ? level_.get() : nullptr; } void EndstoneServer::setLevel(std::unique_ptr level) diff --git a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp index ab58a5d6e..5551556b1 100644 --- a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp +++ b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp @@ -17,38 +17,40 @@ #include #include "endstone/detail/hook.h" -#include "endstone/detail/level/level.h" #include "endstone/detail/server.h" #include "endstone/event/server/script_message_event.h" -using endstone::detail::EndstoneLevel; using endstone::detail::EndstoneServer; CoordinatorResult ScriptingEventCoordinator::sendEvent(EventRef> ref) { auto &server = entt::locator::value(); - auto &level = static_cast(server.getLevel())->getHandle(); - - return std::visit(endstone::overloaded{[&](const Details::ValueOrRef &arg) { - const auto &event = arg.value(); - endstone::CommandSender *sender = nullptr; - if (event.source_actor.has_value()) { - if (auto *actor = level.fetchEntity(event.source_actor.value(), false); actor) { - sender = &actor->getEndstoneActor(); + return std::visit(endstone::overloaded{ + [&](const Details::ValueOrRef &arg) { + const auto &event = arg.value(); + const endstone::CommandSender *sender = nullptr; + if (event.source_actor.has_value()) { + if (auto *actor = event.level.fetchEntity(event.source_actor.value(), false); actor) { + sender = &actor->getEndstoneActor(); + } + } + // TODO(command): add support for BlockCommandSender + if (!sender) { + sender = &server.getCommandSender(); } - } - // TODO(command): add support for BlockCommandSender - if (!sender) { - sender = &server.getCommandSender(); - } - endstone::ScriptMessageEvent e{event.message_id, event.message_value, *sender}; - server.getPluginManager().callEvent(e); + endstone::ScriptMessageEvent e{event.message_id, event.message_value, *sender}; + server.getPluginManager().callEvent(e); - // fix: wtf mojang devs - the original function accesses the pointer without checking - if (!scripting_event_handler_) { - return CoordinatorResult::Continue; - } - return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); - }}, + // fix: wtf mojang devs - the original function accesses the pointer without checking + if (!scripting_event_handler_) { + return CoordinatorResult::Continue; + } + return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); + }, + [&](auto &&arg) -> CoordinatorResult { + const auto &event = arg.value(); + return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); + }, + }, ref.get().variant); } From b05c77a44b6fcf432d85648d8f4fe49d6ca3b5c1 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 10:31:42 +0000 Subject: [PATCH 08/42] fix: Dimension class members --- include/bedrock/forward.h | 1 + .../bedrock/world/level/dimension/dimension.h | 48 ++++++++++++------- .../levelgen/v2/providers/constant_int.h | 24 ++++++++++ .../levelgen/v2/providers/int_provider.h | 26 ++++++++++ .../levelgen/v2/providers/int_provider_type.h | 19 ++++++++ .../level/levelgen/v2/providers/uniform_int.h | 25 ++++++++++ 6 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 include/bedrock/world/level/levelgen/v2/providers/constant_int.h create mode 100644 include/bedrock/world/level/levelgen/v2/providers/int_provider.h create mode 100644 include/bedrock/world/level/levelgen/v2/providers/int_provider_type.h create mode 100644 include/bedrock/world/level/levelgen/v2/providers/uniform_int.h diff --git a/include/bedrock/forward.h b/include/bedrock/forward.h index bc6498c7f..e106fb636 100644 --- a/include/bedrock/forward.h +++ b/include/bedrock/forward.h @@ -93,6 +93,7 @@ class IContentTierManager; class IFoodItemComponent; class IGameModuleShared; class ILevelRandom; +class ILevelStorageManagerConnector; class IMinecraftEventing; class INpcDialogueData; class IUnknownBlockTypeRegistry; diff --git a/include/bedrock/world/level/dimension/dimension.h b/include/bedrock/world/level/dimension/dimension.h index bcfca794d..1e4240550 100644 --- a/include/bedrock/world/level/dimension/dimension.h +++ b/include/bedrock/world/level/dimension/dimension.h @@ -19,13 +19,16 @@ #include #include "bedrock/core/utility/automatic_id.h" -#include "bedrock/core/utility/non_owner_pointer.h" #include "bedrock/entity/gamerefs_entity/gamerefs_entity.h" #include "bedrock/forward.h" #include "bedrock/gamerefs/owner_ptr.h" +#include "bedrock/network/packet.h" +#include "bedrock/world/actor/actor_unique_id.h" +#include "bedrock/world/level/biome/registry/biome_registry.h" #include "bedrock/world/level/block_source.h" #include "bedrock/world/level/dimension/dimension_height_range.h" #include "bedrock/world/level/level_listener.h" +#include "bedrock/world/level/levelgen/v2/providers/int_provider.h" #include "bedrock/world/level/saveddata/saved_data.h" #include "endstone/level/dimension.h" @@ -35,8 +38,16 @@ class IDimension { public: virtual ~IDimension() = 0; [[nodiscard]] virtual bool isNaturalDimension() const = 0; - [[nodiscard]] virtual DimensionType getDimensionId() const = 0; - // ... + virtual AutomaticID getDimensionId() = 0; + virtual void sendPacketForPosition(BlockPos const &, Packet const &, Player const *) = 0; + virtual void sendPacketForEntity(Actor const &, Packet const &, Player const *) = 0; + virtual void flushLevelChunkGarbageCollector() = 0; + virtual void initializeWithLevelStorageManagerConnector(ILevelStorageManagerConnector &) = 0; + virtual BiomeRegistry &getBiomeRegistry() = 0; + [[nodiscard]] virtual BiomeRegistry const &getBiomeRegistry() const = 0; + virtual Vec3 translatePosAcrossDimension(Vec3 const &, AutomaticID) = 0; + virtual void forEachPlayer(std::function) = 0; + virtual Actor *fetchEntity(ActorUniqueID, bool) = 0; }; class Dimension : public IDimension, @@ -53,20 +64,23 @@ class Dimension : public IDimension, [[nodiscard]] endstone::Dimension &getEndstoneDimension() const; // Endstone private: - std::vector actor_chunk_transfer_queue_; // +104 (+96) + std::vector actor_chunk_transfer_queue_; // +104 std::unordered_map> // - actor_unloaded_chunk_transfer_queue_; // +128 (+120) - Level *level_; // +192 (+160) - DimensionHeightRange height_range_; // +200 (+168) - OwnerPtr block_source_; // +208 (+176) - float mobs_per_chunk_surface_[7]; // +224 - float mobs_per_chunk_underground_[7]; // +252 - BrightnessPair default_brightness_; // +280 - std::unique_ptr base_light_texture_image_builder_; // +288 - std::unique_ptr dimension_brightness_ramp_; // +296 - std::shared_ptr target_metadata_; // +304 - std::unique_ptr runtime_lighting_manager_; // +320 - std::string name_; // +328 (+296) - DimensionType id_; // +360 (+320) + actor_unloaded_chunk_transfer_queue_; // +128 + Level *level_; // +192 + DimensionHeightRange height_range_; // +200 + std::int16_t sea_level_; // +204 + std::uint8_t monster_spawn_block_light_limit_; // +206 + IntProvider monster_spawn_light_test_; // +208 + OwnerPtr block_source_; // +240 + float mobs_per_chunk_surface_[7]; // +256 + float mobs_per_chunk_underground_[7]; // +284 + BrightnessPair default_brightness_; // +312 + std::unique_ptr base_light_texture_image_builder_; // +320 + std::unique_ptr dimension_brightness_ramp_; // +328 + std::shared_ptr target_metadata_; // +344 + std::unique_ptr runtime_lighting_manager_; // +352 + std::string name_; // +360 + DimensionType id_; // +392 // ... }; diff --git a/include/bedrock/world/level/levelgen/v2/providers/constant_int.h b/include/bedrock/world/level/levelgen/v2/providers/constant_int.h new file mode 100644 index 000000000..009ff0435 --- /dev/null +++ b/include/bedrock/world/level/levelgen/v2/providers/constant_int.h @@ -0,0 +1,24 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "bedrock/world/level/levelgen/v2/providers/int_provider_type.h" + +struct ConstantInt : IntProviderType { +private: + int constant_; +}; diff --git a/include/bedrock/world/level/levelgen/v2/providers/int_provider.h b/include/bedrock/world/level/levelgen/v2/providers/int_provider.h new file mode 100644 index 000000000..0d39ae743 --- /dev/null +++ b/include/bedrock/world/level/levelgen/v2/providers/int_provider.h @@ -0,0 +1,26 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "bedrock/world/level/levelgen/v2/providers/constant_int.h" +#include "bedrock/world/level/levelgen/v2/providers/int_provider_type.h" +#include "bedrock/world/level/levelgen/v2/providers/uniform_int.h" + +struct IntProvider : IntProviderType { +private: + std::variant provider_; +}; diff --git a/include/bedrock/world/level/levelgen/v2/providers/int_provider_type.h b/include/bedrock/world/level/levelgen/v2/providers/int_provider_type.h new file mode 100644 index 000000000..3e69b49f4 --- /dev/null +++ b/include/bedrock/world/level/levelgen/v2/providers/int_provider_type.h @@ -0,0 +1,19 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +struct IntProviderType { + virtual ~IntProviderType() = 0; +}; diff --git a/include/bedrock/world/level/levelgen/v2/providers/uniform_int.h b/include/bedrock/world/level/levelgen/v2/providers/uniform_int.h new file mode 100644 index 000000000..9a71966b5 --- /dev/null +++ b/include/bedrock/world/level/levelgen/v2/providers/uniform_int.h @@ -0,0 +1,25 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "bedrock/world/level/levelgen/v2/providers/int_provider_type.h" + +struct UniformInt : IntProviderType { +private: + int min_inclusive_; + int max_inclusive_; +}; From f088952b8712d77d81f2ba91883feeddc568d1a9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 10:36:57 +0000 Subject: [PATCH 09/42] fix: PlayerGameplayEvent variants --- include/bedrock/world/events/player_events.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/bedrock/world/events/player_events.h b/include/bedrock/world/events/player_events.h index eb350ba22..c73a95d0f 100644 --- a/include/bedrock/world/events/player_events.h +++ b/include/bedrock/world/events/player_events.h @@ -59,6 +59,7 @@ struct PlayerOpenContainerEvent {}; struct PlayerShootArrowEvent {}; struct PlayerRespawnEvent {}; struct PlayerStopLoadingEvent {}; +struct PlayerInputModeChangeEvent {}; struct PlayerUpdateInteractionEvent {}; struct PlayerSelectedItemChangedEvent {}; struct PlayerDimensionChangeBeforeEvent {}; @@ -75,6 +76,7 @@ struct PlayerInteractWithBlockAfterEvent { bool is_first_event; }; struct PlayerEmoteEvent {}; +struct PlayerScriptInputEvent {}; struct PlayerInputPermissionCategoryChangeEvent {}; template <> @@ -82,12 +84,12 @@ struct PlayerGameplayEvent : ConstEventVariant { -}; + PlayerInteractWithBlockAfterEvent, PlayerEmoteEvent, PlayerScriptInputEvent, + PlayerInputPermissionCategoryChangeEvent> {}; BEDROCK_STATIC_ASSERT_SIZE(PlayerGameplayEvent, 384, 384); struct PlayerSayCommandEvent {}; From 1d2df090d0007fd651bd24005479d36453ea2e92 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 10:43:30 +0000 Subject: [PATCH 10/42] fix: update enums --- include/bedrock/network/disconnection_request_info.h | 2 +- include/bedrock/network/packet.h | 5 +++-- include/bedrock/platform/build_platform.h | 2 +- include/bedrock/world/actor/actor_types.h | 1 + src/endstone_core/player.cpp | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/bedrock/network/disconnection_request_info.h b/include/bedrock/network/disconnection_request_info.h index b57aae16d..1ff6df01b 100644 --- a/include/bedrock/network/disconnection_request_info.h +++ b/include/bedrock/network/disconnection_request_info.h @@ -83,7 +83,7 @@ class Connection { BlockMismatch = 63, InvalidHeights = 64, InvalidWidths = 65, - ConnectionLost = 66, + ConnectionLost_DEPRECATED = 66, ZombieConnection = 67, Shutdown = 68, ReasonNotSet_DEPRECATED = 69, diff --git a/include/bedrock/network/packet.h b/include/bedrock/network/packet.h index 159188567..91b055e7d 100644 --- a/include/bedrock/network/packet.h +++ b/include/bedrock/network/packet.h @@ -19,7 +19,7 @@ #include "bedrock/network/network_peer.h" #include "bedrock/platform/result.h" -enum class MinecraftPacketIds { +enum class MinecraftPacketIds : int { KeepAlive = 0, Login = 1, PlayStatus = 2, @@ -242,7 +242,8 @@ enum class MinecraftPacketIds { ContainerRegistryCleanup = 317, MovementEffect = 318, SetMovementAuthorityMode = 319, - EndId, + CameraAimAssistPresets = 320, + EndId = 321, }; class Packet { diff --git a/include/bedrock/platform/build_platform.h b/include/bedrock/platform/build_platform.h index 11a6f290c..4331c9e03 100644 --- a/include/bedrock/platform/build_platform.h +++ b/include/bedrock/platform/build_platform.h @@ -20,7 +20,7 @@ enum class BuildPlatform { iOS = 2, OSX = 3, Amazon = 4, - GearVR = 5, + GearVR_Deprecated = 5, UWP = 7, Win32 = 8, Dedicated = 9, diff --git a/include/bedrock/world/actor/actor_types.h b/include/bedrock/world/actor/actor_types.h index d8f30d79d..521debc76 100644 --- a/include/bedrock/world/actor/actor_types.h +++ b/include/bedrock/world/actor/actor_types.h @@ -166,5 +166,6 @@ enum class ActorType : int { WindChargeProjectile = 143 | Projectile, Bogged = 144 | SkeletonMonster, OminousItemSpawner = 145, + Creaking = 146 | Monster, _entt_enum_as_bitmask }; diff --git a/src/endstone_core/player.cpp b/src/endstone_core/player.cpp index 2eb0e5344..f1710fdb9 100644 --- a/src/endstone_core/player.cpp +++ b/src/endstone_core/player.cpp @@ -729,7 +729,7 @@ void EndstonePlayer::initFromConnectionRequest( case BuildPlatform::OSX: device_os_ = "macOS"; break; - case BuildPlatform::GearVR: + case BuildPlatform::GearVR_Deprecated: device_os_ = "Gear VR"; break; case BuildPlatform::UWP: From a1c6b008253ccf89cbcacac20c538ac1dfe0312d Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 12:05:05 +0000 Subject: [PATCH 11/42] fix: Block and BlockLegacy --- include/bedrock/forward.h | 2 +- include/bedrock/locale/i18n.h | 1 - include/bedrock/world/level/block/block.h | 29 +-- .../bedrock/world/level/block/block_legacy.h | 200 +++++++----------- .../components/block_component_direct_data.h | 42 ++-- .../components/block_component_storage.h | 18 +- .../world/level/block/detection_rule.h | 39 ++++ src/endstone_devtools/vanilla_data.cpp | 2 +- .../world/level/block/block_legacy.cpp | 69 ++++++ 9 files changed, 236 insertions(+), 166 deletions(-) create mode 100644 include/bedrock/world/level/block/detection_rule.h create mode 100644 src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp diff --git a/include/bedrock/forward.h b/include/bedrock/forward.h index e106fb636..f4aae3523 100644 --- a/include/bedrock/forward.h +++ b/include/bedrock/forward.h @@ -186,7 +186,7 @@ enum class ArmorSlot; enum class ArmorTextureType; enum class BedSleepingResult; enum class BlockActorType; -enum class BlockRenderLayer; +enum class BlockRenderLayer : std::uint8_t; enum class BlockSupportType; enum class BlockTintType; enum class BurnOdds; diff --git a/include/bedrock/locale/i18n.h b/include/bedrock/locale/i18n.h index 38b155670..37bb0cd36 100644 --- a/include/bedrock/locale/i18n.h +++ b/include/bedrock/locale/i18n.h @@ -49,7 +49,6 @@ class I18n { virtual void appendAdditionalTranslations(std::unordered_map const &, std::string const &) = 0; virtual void appendLanguageStrings(PackAccessStrategy *) = 0; - virtual void appendTranslations(std::string const &, std::unordered_map const &) = 0; virtual void addI18nObserver(I18nObserver &) = 0; virtual void chooseLanguage(std::string const &) = 0; virtual std::string get(std::string const &, std::vector const &, std::shared_ptr) = 0; diff --git a/include/bedrock/world/level/block/block.h b/include/bedrock/world/level/block/block.h index 3582f4937..006a6a600 100644 --- a/include/bedrock/world/level/block/block.h +++ b/include/bedrock/world/level/block/block.h @@ -47,8 +47,10 @@ struct CachedComponentData { BlockOcclusionType occlusion_type; // +4 }; -class Block : public BlockComponentStorage { +class Block { public: + virtual ~Block() = default; + [[nodiscard]] bool canDropWithAnyTool() const { return legacy_block_->canDropWithAnyTool(); @@ -61,7 +63,7 @@ class Block : public BlockComponentStorage { [[nodiscard]] BlockRuntimeId getRuntimeId() const { - return runtime_id_; + return network_id_; } [[nodiscard]] BurnOdds getBurnOdds() const @@ -157,15 +159,16 @@ class Block : public BlockComponentStorage { private: friend class ItemStackBase; - DataID data_; // +40 (+36) - gsl::not_null legacy_block_; // +48 (+40) - CachedComponentData cached_component_data_; // +56 (+48) - BlockComponentDirectData direct_data_; // +64 - std::vector tags_; // +160 - BlockSerializationId serialization_id_; // +184 - HashType64 serialization_id_hash_; // +208 - std::uint32_t raw_serialization_id_hash_for_network_; // +216 - BlockRuntimeId runtime_id_; // +220 - bool has_runtime_id_; // +224 + BlockComponentStorage components_; // +8 + DataID data_; // +112 + gsl::not_null legacy_block_; // +120 + CachedComponentData cached_component_data_; // + BlockComponentDirectData direct_data_; // + std::vector tags_; // + BlockSerializationId serialization_id_; // + HashType64 serialization_id_hash_; // + std::uint32_t serialization_id_hash_for_network_; // + BlockRuntimeId network_id_; // +300 + bool has_runtime_id_; // }; -BEDROCK_STATIC_ASSERT_SIZE(Block, 232, 232); +BEDROCK_STATIC_ASSERT_SIZE(Block, 312, 312); diff --git a/include/bedrock/world/level/block/block_legacy.h b/include/bedrock/world/level/block/block_legacy.h index 8585d984e..d164f5f6a 100644 --- a/include/bedrock/world/level/block/block_legacy.h +++ b/include/bedrock/world/level/block/block_legacy.h @@ -97,7 +97,7 @@ enum class BlockProperty : std::uint64_t { _entt_enum_as_bitmask }; -class BlockLegacy : public BlockComponentStorage { +class BlockLegacy { struct NameInfo { HashedString raw_name; // +0 std::string namespace_name; // +48 @@ -106,7 +106,7 @@ class BlockLegacy : public BlockComponentStorage { }; public: - ~BlockLegacy() override = 0; + virtual ~BlockLegacy() = 0; [[nodiscard]] virtual std::shared_ptr newBlockEntity(BlockPos const &, Block const &) const = 0; [[nodiscard]] virtual Block const *getNextBlockPermutation(Block const &) const = 0; [[nodiscard]] virtual bool hasTag(BlockSource &, BlockPos const &, Block const &, std::string const &) const = 0; @@ -170,9 +170,6 @@ class BlockLegacy : public BlockComponentStorage { [[nodiscard]] virtual Block const &sanitizeFillBlock(Block const &) const = 0; virtual void onFillBlock(BlockSource &, BlockPos const &, Block const &) const = 0; [[nodiscard]] virtual int getDirectSignal(BlockSource &, BlockPos const &, int dir) const = 0; - [[nodiscard]] virtual bool canBeDestroyedByWaterSpread() const = 0; - [[nodiscard]] virtual bool waterSpreadCausesSpawn() const = 0; - [[nodiscard]] virtual bool canContainLiquid() const = 0; [[nodiscard]] virtual std::optional getRequiredMedium() const = 0; [[nodiscard]] virtual bool shouldConnectToRedstone(BlockSource &, BlockPos const &, Direction::Type) const = 0; virtual void handlePrecipitation(BlockSource &, BlockPos const &, float, float) const = 0; @@ -278,125 +275,84 @@ class BlockLegacy : public BlockComponentStorage { virtual void _onHitByActivatingAttack(BlockSource &, BlockPos const &, Actor *) const = 0; virtual void entityInside(BlockSource &, BlockPos const &, Actor &) const = 0; - [[nodiscard]] bool canDropWithAnyTool() const - { - return can_drop_with_any_tool_; - } + [[nodiscard]] bool canDropWithAnyTool() const; + [[nodiscard]] float getThickness() const; + [[nodiscard]] const Material &getMaterial() const; + [[nodiscard]] const std::vector &getTags() const; + [[nodiscard]] const std::string &getDescriptionId() const; + [[nodiscard]] const std::string &getFullNameId() const; + [[nodiscard]] const std::string &getRawNameId() const; + [[nodiscard]] const std::string &getNamespace() const; + [[nodiscard]] const Block *getDefaultState() const; + void forEachBlockPermutation(std::function callback) const; - [[nodiscard]] float getThickness() const - { - return thickness_; - } - - [[nodiscard]] const Material &getMaterial() const - { - return *material_; - } - - [[nodiscard]] const std::vector &getTags() const - { - return tags_; - } - - [[nodiscard]] const std::string &getDescriptionId() const - { - return description_id_; - } - - [[nodiscard]] const std::string &getFullNameId() const - { - return name_info_.full_name.getString(); - } - - [[nodiscard]] const std::string &getRawNameId() const - { - return name_info_.raw_name.getString(); - } - - [[nodiscard]] const std::string &getNamespace() const - { - return name_info_.namespace_name; - } - - [[nodiscard]] const Block *getDefaultState() const - { - return default_state_; - } - - void forEachBlockPermutation(std::function callback) const - { - for (const auto &block_permutation : block_permutations_) { - if (block_permutation) { - callback(*block_permutation); - } - } - } + std::string description_id_; // +8 private: - std::string description_id_; // +40 - NameInfo name_info_; // +72 (+64) - BlockProperty properties_; // +248 (+208) - bool fancy_; // +256 (+216) - BlockRenderLayer render_layer_; // +260 (+220) - bool render_layer_can_render_as_opaque_; // +264 (+224) - BlockActorType block_entity_type_; // +268 (+228) - bool animated_texture_; // +272 (+232) - float brightness_gamma_; // +276 (+236) - float thickness_; // +280 (+240) - bool can_slide_; // +284 (+244) - bool can_react_to_neighbors_during_instatick_; // +285 (+245) - bool is_interaction_; // +286 (+246) - float gravity_; // +288 (+248) - Material *material_; // +296 (+256) - bool falling_; // +304 (+264) - float particle_quantity_scalar_; // +308 (+268) - CreativeItemCategory creative_item_category_; // +312 (+272) - std::string creative_group_; // +320 (+280) - bool is_hidden_in_commands_; // +352 (+304) - bool allows_runes_; // +353 (+305) - bool can_be_broken_from_falling_; // +354 (+306) - bool can_be_original_surface_; // +355 (+307) - bool solid_; // +356 (+308) - bool pushes_out_items_; // +357 (+309) - bool ignore_block_for_inside_cube_renderer_; // +358 (+310) - bool is_trapdoor_; // +359 (+311) - bool is_door_; // +360 (+312) - bool is_opaque_full_block_; // +361 (+313) - float translucency_; // +364 (+316) - bool should_random_tick_; // +368 (+320) - bool should_random_tick_extra_layer_; // +369 (+321) - bool is_mob_piece_; // +370 (+322) - bool can_be_extra_block_; // +371 (+323) - bool can_propagate_brightness_; // +372 (+324) - Brightness light_block_; // +373 (+325) - Brightness light_emission_; // +374 (+326) - FlameOdds flame_odds_; // +376 (+328) - BurnOdds burn_odds_; // +380 (+332) - LavaFlammable lava_flammable_; // +384 (+336) - mce::Color map_color_; // +388 - float friction_; // +404 - BlockTintType block_tint_type_; // +408 - bool return_default_block_on_unidentified_block_state_; // +412 - BlockColorLogic color_logic_; // +416 - NewBlockID id_; // +420 - BaseGameVersion min_required_game_version_; // +424 - bool is_vanilla_; // +544 - std::vector tags_; // +552 - std::unordered_map event_handlers_; // +576 void* = DefinitionEvent - bool data_driven_vanilla_blocks_and_items_enabled_; // +640 - AABB visual_shape_; // +644 - std::int32_t bits_used_; // +672 - std::int32_t total_bits_used_; // +676 - std::map states_; // +680 - std::unordered_map state_name_map_; // +696 - std::size_t creative_enum_state_; // +760 - std::vector> block_permutations_; // +768 - Block *default_state_; // +792 - std::vector> get_placement_block_callbacks_; // +800 - Core::Cache legacy_data_lookup_table_; // +824 - std::unique_ptr block_state_group_; // +896 void* = BlockStateGroup - std::unique_ptr resource_drops_strategy_; // +904 void* = IResourceDropsStrategy - IntRange experience_drop_; // +912 - bool can_drop_with_any_tool_; // +920 + BlockComponentStorage components_; // +40 + NameInfo name_info_; // +144 + BlockProperty properties_; // + bool fancy_; // + BlockRenderLayer render_layer_; // + bool render_layer_can_render_as_opaque_; // + BlockActorType block_entity_type_; // + bool animated_texture_; // + float brightness_gamma_; // + float thickness_; // + bool can_slide_; // + bool can_react_to_neighbors_during_instatick_; // + bool is_interaction_; // + float gravity_; // + Material *material_; // +360 + bool falling_; // + float particle_quantity_scalar_; // + CreativeItemCategory creative_item_category_; // + std::string creative_group_; // + bool is_hidden_in_commands_; // + bool allows_runes_; // + bool can_be_broken_from_falling_; // + bool can_be_original_surface_; // + bool solid_; // + bool pushes_out_items_; // + bool ignore_block_for_inside_cube_renderer_; // + bool is_trapdoor_; // + bool is_door_; // + bool is_opaque_full_block_; // + float translucency_; // + bool should_random_tick_; // + bool should_random_tick_extra_layer_; // + bool is_mob_piece_; // + bool can_be_extra_block_; // + bool can_propagate_brightness_; // + Brightness light_block_; // + Brightness light_emission_; // + FlameOdds flame_odds_; // + BurnOdds burn_odds_; // + LavaFlammable lava_flammable_; // + mce::Color map_color_; // + float friction_; // + BlockTintType block_tint_type_; // + bool return_default_block_on_unidentified_block_state_; // + BlockColorLogic color_logic_; // + NewBlockID id_; // + BaseGameVersion min_required_game_version_; // + bool is_vanilla_; // + std::vector tags_; // + std::unordered_map event_handlers_; // + bool data_driven_vanilla_blocks_and_items_enabled_; // + AABB visual_shape_; // + std::int32_t bits_used_; // + std::int32_t total_bits_used_; // + std::map states_; // + std::unordered_map state_name_map_; // + std::size_t creative_enum_state_; // + std::vector> block_permutations_; // + Block *default_state_; // + std::vector> get_placement_block_callbacks_; // + Core::Cache legacy_data_lookup_table_; // + std::unique_ptr block_state_group_; // + std::unique_ptr resource_drops_strategy_; // + IntRange experience_drop_; // + bool can_drop_with_any_tool_; // // ... }; diff --git a/include/bedrock/world/level/block/components/block_component_direct_data.h b/include/bedrock/world/level/block/components/block_component_direct_data.h index 673b073f0..d377c968c 100644 --- a/include/bedrock/world/level/block/components/block_component_direct_data.h +++ b/include/bedrock/world/level/block/components/block_component_direct_data.h @@ -16,6 +16,8 @@ #include +#include "bedrock/world/level/block/detection_rule.h" + struct BlockComponentDirectData { enum LayerBitMask : std::uint32_t { NONE = 0x0, @@ -23,23 +25,25 @@ struct BlockComponentDirectData { RENDERING = 0x2, }; - class BlockTransformationComponent const *block_transformation_component; // +0 - class BlockCollisionBoxComponent const *block_collision_box_component; // +8 - class BlockSelectionBoxComponent const *block_selection_box_component; // +16 - class BlockRedstoneComponent const *block_redstone_component; // +24 - class BlockGeometryComponent const *block_geometry_component; // +32 - class BlockBakedMaterialDataComponent const *block_baked_material_data_component; // +40 - bool is_full_block_geometry; // +48 - bool use_new_tessellation; // +49 - bool needs_legacy_top_rotation; // +50 - bool is_opaque_full_block; // +51 - Brightness light_emission; // +52 - Brightness light; // +53 - float explosion_resistance; // +56 - BurnOdds burn_odds; // +60 - FlameOdds flame_odds; // +64 - float friction; // +68 - float destroy_speed; // +72 - class BlockDestructibleByMiningComponent const *destructible_by_mining_component; // +80 - LayerBitMask finalized; // +88 + class BlockTransformationComponent const *block_transformation_component; // + class BlockCollisionBoxComponent const *block_collision_box_component; // + class BlockSelectionBoxComponent const *block_selection_box_component; // + class BlockRedstoneComponent const *block_redstone_component; // + class BlockGeometryComponent const *block_geometry_component; // + class BlockBakedMaterialDataComponent const *block_baked_material_data_component; // + class BlockItemVisualComponent const *block_item_visual_component; // + bool is_full_block_geometry; // + bool use_new_tessellation; // + bool needs_legacy_top_rotation; // + bool is_opaque_full_block; // + Brightness light_emission; // + Brightness light; // + float explosion_resistance; // + BurnOdds burn_odds; // + FlameOdds flame_odds; // + float friction; // + float destroy_speed; // + DetectionRule water_detection_rule; // + LayerBitMask finalized; // + class BlockDestructibleByMiningComponent const *destructible_by_mining_component; // }; diff --git a/include/bedrock/world/level/block/components/block_component_storage.h b/include/bedrock/world/level/block/components/block_component_storage.h index fb7a241be..a0520bb0e 100644 --- a/include/bedrock/world/level/block/components/block_component_storage.h +++ b/include/bedrock/world/level/block/components/block_component_storage.h @@ -14,21 +14,21 @@ #pragma once -#include #include -#include + +#include +#include #include "bedrock/core/utility/type_id.h" -#include "bedrock/world/level/block/components/block_component_base.h" class BlockComponentStorage { public: - virtual ~BlockComponentStorage() = 0; + class ComponentBase {}; private: - std::vector, std::unique_ptr>> components_; // +8 - bool allow_adding_components_; // +32 - bool allow_replacement_components_; // +33 - bool allow_try_get_components_before_finalization_; // +34 + std::size_t padding_[12]; // +0 + bool allow_adding_components_; // +96 + bool allow_replacement_components_; // +97 + bool allow_try_get_components_before_finalization_; // +98 }; -BEDROCK_STATIC_ASSERT_SIZE(BlockComponentStorage, 40, 40); +BEDROCK_STATIC_ASSERT_SIZE(BlockComponentStorage, 104, 104); diff --git a/include/bedrock/world/level/block/detection_rule.h b/include/bedrock/world/level/block/detection_rule.h new file mode 100644 index 000000000..2ecd002ce --- /dev/null +++ b/include/bedrock/world/level/block/detection_rule.h @@ -0,0 +1,39 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +enum LiquidType : std::uint8_t { + WATER = 0, +}; + +enum LiquidReaction : std::uint8_t { + BROKEN = 0, + POPPED = 1, + BLOCKING = 2, + NOREACTION = 3, +}; + +struct BlockedDirections { + std::uint8_t stops_flow_directions_mask; +}; + +struct DetectionRule { + bool can_contain_liquid; + BlockedDirections stop_flow_directions; + LiquidReaction on_liquid_touches; + LiquidType liquid_type; +}; diff --git a/src/endstone_devtools/vanilla_data.cpp b/src/endstone_devtools/vanilla_data.cpp index 982af5b75..48ca8d6a5 100644 --- a/src/endstone_devtools/vanilla_data.cpp +++ b/src/endstone_devtools/vanilla_data.cpp @@ -118,7 +118,7 @@ void dumpBlockData(VanillaData &data, ::Level &level) {"explosionResistance", round(block.getExplosionResistance())}, {"friction", round(block.getFriction())}, {"hardness", round(block.getDestroySpeed())}, - {"canContainLiquid", block.getLegacyBlock().canContainLiquid()}, + // {"canContainLiquid", block.getLegacyBlock().canContainLiquid()}, // {"canDropWithAnyTool", block.canDropWithAnyTool()}, {"mapColor", map_color.toHexString()}, {"collisionShape", diff --git a/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp new file mode 100644 index 000000000..9abf485c1 --- /dev/null +++ b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bedrock/world/level/block/block_legacy.h" + +bool BlockLegacy::canDropWithAnyTool() const +{ + return can_drop_with_any_tool_; +} + +float BlockLegacy::getThickness() const +{ + return thickness_; +} + +const Material &BlockLegacy::getMaterial() const +{ + return *material_; +} + +const std::vector &BlockLegacy::getTags() const +{ + return tags_; +} + +const std::string &BlockLegacy::getDescriptionId() const +{ + return description_id_; +} + +const std::string &BlockLegacy::getFullNameId() const +{ + return name_info_.full_name.getString(); +} + +const std::string &BlockLegacy::getRawNameId() const +{ + return name_info_.raw_name.getString(); +} + +const std::string &BlockLegacy::getNamespace() const +{ + return name_info_.namespace_name; +} + +const Block *BlockLegacy::getDefaultState() const +{ + return default_state_; +} + +void BlockLegacy::forEachBlockPermutation(std::function callback) const +{ + for (const auto &block_permutation : block_permutations_) { + if (block_permutation) { + callback(*block_permutation); + } + } +} From 408e17b705dd84a2b9115b7e61163f29fe0bad21 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 12:32:59 +0000 Subject: [PATCH 12/42] fix: Item and ItemRegistry --- include/bedrock/world/item/item.h | 7 +-- .../world/item/registry/item_registry.h | 51 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/bedrock/world/item/item.h b/include/bedrock/world/item/item.h index 14b3cbb77..06feaa653 100644 --- a/include/bedrock/world/item/item.h +++ b/include/bedrock/world/item/item.h @@ -128,8 +128,9 @@ class Item { virtual void hurtActor(ItemStack &, Actor &, Mob &) const = 0; virtual void hitActor(ItemStack &, Actor &, Mob &) const = 0; virtual void hitBlock(ItemStack &, Block const &, BlockPos const &, Mob &) const = 0; - // virtual bool mineBlock(ItemStack &, Block const &, int x, int y, int z, Actor *) const = 0; virtual std::string buildDescriptionName(ItemStackBase const &) const = 0; + // virtual Bedrock::Safety::RedactableString const buildRedactedDescriptionName + virtual void const buildRedactedDescriptionName(ItemStackBase const &) const = 0; virtual std::string buildDescriptionId(ItemDescriptor const &, CompoundTag const *) const = 0; virtual std::string buildEffectDescriptionName(ItemStackBase const &) const = 0; virtual void readUserData(ItemStackBase &, IDataInput &, ReadOnlyBinaryStream &) const = 0; @@ -191,12 +192,12 @@ class Item { return furnace_burn_interval_modifier_; } -private: +protected: std::string texture_atlas_file_; // +8 int frame_count_; // +40 bool animates_in_toolbar_; // +44 bool is_mirrored_art_; // +45 - std::uint16_t use_anim_; // +46 + std::uint8_t use_anim_; // +46 std::string hover_text_color_format_; // +48 int icon_frame_; // +80 int atlas_frame_; // +84 diff --git a/include/bedrock/world/item/registry/item_registry.h b/include/bedrock/world/item/registry/item_registry.h index 3e45dc5c7..89a24b8b3 100644 --- a/include/bedrock/world/item/registry/item_registry.h +++ b/include/bedrock/world/item/registry/item_registry.h @@ -49,29 +49,30 @@ class ItemRegistry : public std::enable_shared_from_this { friend ItemRegistryRef; using ItemRegistryMap = std::vector>; - ItemRegistryMap item_registry_; // +16 - std::unordered_map> id_to_item_map_; // +40 - std::unordered_map> name_to_item_map_; // +104 (+80) - std::unordered_map> tile_namespace_to_item_map_; // +168 (+120) - std::unordered_map> tile_item_name_to_item_map_; // +232 (+160) - std::unordered_map item_alias_lookup_map_; // +296 - std::unordered_map reverse_alias_lookup_map_; // +360 - std::unordered_map reverse_full_name_alias_lookup_map_; // +424 - std::unordered_map complex_alias_lookup_map_; // +488 - std::unordered_map legacy_id_to_name_map_; // +552 - std::int16_t max_item_id_; // +616 - std::vector attachable_definitions_; // +624 - std::unordered_map> tag_to_items_map_; // +648 - std::unordered_set const empty_item_set_; // +712 - bool server_initializing_creative_items_; // +776 - bool is_initialized_; // +777 - std::function extra_item_init_callback_; // +784 - Bedrock::PubSub::PublisherPtr - finished_init_publisher_; // +848 - std::shared_ptr> can_update_tags_; // +856 - ItemRegistryMap dead_item_registry_; // +872 - BaseGameVersion world_base_game_version_; // +896 - bool check_for_item_world_compatibility_; // +1016 - std::shared_ptr compatibility_check_mutex_; // +1024 - std::unique_ptr creative_item_registry_; // +1040 + std::unique_ptr cereal_context_; // +16 + ItemRegistryMap item_registry_; // +24 + std::unordered_map> id_to_item_map_; // + std::unordered_map> name_to_item_map_; // + std::unordered_map> tile_namespace_to_item_map_; // + std::unordered_map> tile_item_name_to_item_map_; // + std::unordered_map item_alias_lookup_map_; // + std::unordered_map reverse_alias_lookup_map_; // + std::unordered_map reverse_full_name_alias_lookup_map_; // + std::unordered_map complex_alias_lookup_map_; // + std::unordered_map legacy_id_to_name_map_; // + std::int16_t max_item_id_; // + std::vector attachable_definitions_; // + std::unordered_map> tag_to_items_map_; // + std::unordered_set const empty_item_set_; // + bool server_initializing_creative_items_; // + bool is_initialized_; // + std::function extra_item_init_callback_; // + std::unique_ptr> + finished_init_publisher_; // + std::shared_ptr> can_update_tags_; // + ItemRegistryMap dead_item_registry_; // + BaseGameVersion world_base_game_version_; // + bool check_for_item_world_compatibility_; // + std::shared_ptr compatibility_check_mutex_; // + std::unique_ptr creative_item_registry_; // }; From f76cf4ad2868f6f7e89e578a16fc224be7300fe4 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 13:10:28 +0000 Subject: [PATCH 13/42] fix: Actor class --- include/bedrock/forward.h | 1 - include/bedrock/util/variant_parameter_list.h | 46 +++++++++++ include/bedrock/world/actor/actor.h | 82 +++++++++++++------ 3 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 include/bedrock/util/variant_parameter_list.h diff --git a/include/bedrock/forward.h b/include/bedrock/forward.h index f4aae3523..ea1ee1627 100644 --- a/include/bedrock/forward.h +++ b/include/bedrock/forward.h @@ -176,7 +176,6 @@ class TrackedPacketDataContainer; class TrimMaterialRegistry; class TrimPatternRegistry; class UpdateEntityAfterFallOnInterface; -class VariantParameterList; class WeakEntityRef; class _TickPtr; // NOLINT diff --git a/include/bedrock/util/variant_parameter_list.h b/include/bedrock/util/variant_parameter_list.h new file mode 100644 index 000000000..a65c56722 --- /dev/null +++ b/include/bedrock/util/variant_parameter_list.h @@ -0,0 +1,46 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +class Actor; +class Player; +class Mob; +class BlockPos; + +struct VariantParameterListConst { + Actor const *self; + Actor const *other; + Player const *player; + Actor const *target; + Actor const *parent; + Mob const *baby; + BlockPos const *block; + Actor const *damager; + Actor const *holder; +}; + +struct VariantParameterList { + Actor *self; + Actor *other; + Player *player; + Actor *target; + Actor *parent; + Mob *baby; + BlockPos *block; + Actor *damager; + Actor *holder; +}; diff --git a/include/bedrock/world/actor/actor.h b/include/bedrock/world/actor/actor.h index 38e7e9a4e..9f25de4e3 100644 --- a/include/bedrock/world/actor/actor.h +++ b/include/bedrock/world/actor/actor.h @@ -37,6 +37,7 @@ #include "bedrock/network/spatial_actor_network_data.h" #include "bedrock/platform/uuid.h" #include "bedrock/server/commands/command_permission_level.h" +#include "bedrock/util/variant_parameter_list.h" #include "bedrock/world/actor/actor_category.h" #include "bedrock/world/actor/actor_damage_source.h" #include "bedrock/world/actor/actor_flags.h" @@ -141,7 +142,7 @@ class Actor { [[nodiscard]] virtual bool isOnFire() const = 0; [[nodiscard]] virtual bool isSurfaceMob() const = 0; [[nodiscard]] virtual bool isTargetable() const = 0; - virtual bool canAttack(Actor *, bool) const = 0; + // virtual bool canAttack(Actor *, bool) const = 0; virtual void setTarget(Actor *) = 0; virtual bool isValidTarget(Actor *) const = 0; virtual bool attack(Actor &, ActorDamageCause const &) = 0; @@ -280,30 +281,61 @@ class Actor { static Actor *tryGetFromEntity(EntityContext const &, bool include_removed); -protected: - EntityContext entity_context_; // +8 - std::array init_params_; // +32 - std::string custom_init_event_name_; // +192 - ActorInitializationMethod init_method_; // +224 - bool force_init_method_to_spawn_on_reload_; // +225 - bool added_; // +226 - int send_rate_counter_; // +228 - ActorDefinitionGroup *definitions_; // +232 - std::unique_ptr current_description_; // +240 - std::shared_ptr leash_rope_system_; // +248 - std::string alias_; // +264 - std::optional previous_render_transform_; // +296 - int last_hurt_by_player_time_; // +364 - std::map>> previous_bone_matrices_; // +368 - SynchedActorDataEntityWrapper entity_data_; // +384 - std::unique_ptr network_data_; // +432 - Vec3 sent_delta_; // +440 - char unknown11_[92]; // +452 - WeakRef dimension_; // +544 - Level *level_; // +560 - HashedString actor_renderer_id_; // +568 - ActorCategory categories_; // +616 - BuiltInActorComponents built_in_components_; // +624 +private: + EntityContext entity_context_; // +8 + VariantParameterList init_params_; + std::string custom_init_event_name_; + ActorInitializationMethod init_method_; + bool force_init_method_to_spawn_on_reload_; + +public: + bool added; + int send_rate_counter; + ActorDefinitionGroup *definitions; + std::unique_ptr current_description; + std::shared_ptr leash_rope_system; + std::string alias; + std::optional previous_render_transform; + int last_hurt_by_player_time; + std::map>> previous_bone_matrices; + SynchedActorDataEntityWrapper entity_data; + std::unique_ptr network_data; + Vec3 sent_delta; + float scale; + float scale_prev; + bool ignore_lighting; + bool filter_lighting; + float step_sound_volume; + float step_sound_pitch; + AABB *last_hit_bb; + HashType64 name_tag_hash; + float shadow_offset; + float pushthrough; + int tick_count; + int invulnerable_time; + int last_health; + bool hurt_marked; + bool was_hurt_last_frame; + bool invulnerable; + int flame_tex_frame_index; + float flame_frame_increment_time; + bool always_fire_immune; + bool inherit_rotation_when_riding; + bool forced_loading; + bool force_send_motion_packet; + bool highlighted_this_frame; + bool initialized; + bool processed_on_chunk_discard; + float sound_volume; + int shake_time; + ActorUniqueID legacy_unique_id; + +private: + WeakRef dimension_; // +456 + Level *level_; // +472 + HashedString actor_renderer_id_; // + ActorCategory categories_; // + BuiltInActorComponents built_in_components_; // // ... endstone::detail::EndstoneActor &getEndstoneActor0() const; From 1a32ec86416614d890245ac5ed697f2b80b3f20a Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 13:42:25 +0000 Subject: [PATCH 14/42] fix: BlockSource and BinaryStream --- include/bedrock/core/utility/binary_stream.h | 15 +++++++++------ include/bedrock/world/level/block_source.h | 10 ++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/bedrock/core/utility/binary_stream.h b/include/bedrock/core/utility/binary_stream.h index 19ec18f9e..9fb109877 100644 --- a/include/bedrock/core/utility/binary_stream.h +++ b/include/bedrock/core/utility/binary_stream.h @@ -21,12 +21,15 @@ class ReadOnlyBinaryStream { virtual ~ReadOnlyBinaryStream(); virtual Bedrock::Result read(void *, std::uint64_t); +protected: + std::string owned_buffer_; // +8 + std::string_view view_; // +40 + private: - std::size_t read_pointer_; // +8 - bool has_overflowed_; // +16 - std::string owned_buffer_; // +24 - std::string *buffer_; // +56 + std::size_t read_pointer_; // +56 + bool has_overflowed_; // +64 }; +BEDROCK_STATIC_ASSERT_SIZE(ReadOnlyBinaryStream, 72, 64); class BinaryStream : public ReadOnlyBinaryStream { public: @@ -42,6 +45,6 @@ class BinaryStream : public ReadOnlyBinaryStream { void writeFloat(float value); private: - std::string owned_buffer_; // +64 - std::string *buffer_; // +96 + std::string *buffer_; // +72 }; +BEDROCK_STATIC_ASSERT_SIZE(BinaryStream, 80, 72); diff --git a/include/bedrock/world/level/block_source.h b/include/bedrock/world/level/block_source.h index aecab0791..8fa17117a 100644 --- a/include/bedrock/world/level/block_source.h +++ b/include/bedrock/world/level/block_source.h @@ -24,6 +24,7 @@ #include "bedrock/world/level/block/block_legacy.h" #include "bedrock/world/level/block_source_interface.h" #include "bedrock/world/level/chunk/level_chunk.h" +#include "bedrock/world/level/level_seed.h" #include "bedrock/world/level/material/material.h" #include "bedrock/world/level/material/material_type.h" @@ -42,7 +43,6 @@ class IConstBlockSource { [[nodiscard]] virtual Block const &getExtraBlock(BlockPos const &) const = 0; [[nodiscard]] virtual Block const &getLiquidBlock(BlockPos const &) const = 0; [[nodiscard]] virtual bool hasBlock(BlockPos const &) const = 0; - virtual bool removeBlock(BlockPos const &) = 0; [[nodiscard]] virtual bool containsAnyLiquid(AABB const &) const = 0; [[nodiscard]] virtual bool containsMaterial(AABB const &, MaterialType) const = 0; [[nodiscard]] virtual bool isUnderWater(Vec3 const &, Block const &) const = 0; @@ -62,7 +62,6 @@ class IConstBlockSource { virtual AABB getTallestCollisionShape(AABB const &, float *, bool, optional_ref) const = 0; [[nodiscard]] virtual float getBrightness(BlockPos const &) const = 0; - virtual void postGameEvent(Actor *, GameEvent const &, BlockPos const &, Block const *) = 0; }; class IBlockSource : public IConstBlockSource { @@ -88,6 +87,11 @@ class IBlockSource : public IConstBlockSource { [[nodiscard]] virtual LevelChunk *getChunk(ChunkPos const &) const = 0; virtual Level &getLevel() = 0; [[nodiscard]] virtual ILevel &getILevel() const = 0; + [[nodiscard]] virtual LevelSeed64 getLevelSeed64() const = 0; + [[nodiscard]] virtual std::uint16_t getAboveTopSolidBlock(int, int, bool, bool) const = 0; + [[nodiscard]] virtual std::uint16_t getHeight(std::function const &, + BlockPos const &) const = 0; + [[nodiscard]] virtual std::uint16_t getHeight(std::function const &, int, int) const = 0; virtual std::vector &fetchAABBs(AABB const &, bool) = 0; virtual std::vector &fetchCollisionShapes(AABB const &, bool, std::optional, std::vector *) = 0; @@ -102,6 +106,8 @@ class IBlockSource : public IConstBlockSource { [[nodiscard]] virtual bool isInstaticking(BlockPos const &) const = 0; virtual void updateCheckForValidityState(bool) = 0; virtual bool checkBlockPermissions(Actor &, BlockPos const &, FacingID, ItemStackBase const &, bool) = 0; + virtual bool removeBlock(BlockPos const &) = 0; + virtual void postGameEvent(Actor *, GameEvent const &, BlockPos const &, Block const *) = 0; }; class BlockSource : public IBlockSource, From facfb51aee008b5359316ad5346df79ad721b831 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 13:56:02 +0000 Subject: [PATCH 15/42] fix: correct size assertion for Block class --- include/bedrock/world/level/block/block.h | 2 +- .../world/level/block/components/block_component_storage.h | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/bedrock/world/level/block/block.h b/include/bedrock/world/level/block/block.h index 006a6a600..97ebd1b55 100644 --- a/include/bedrock/world/level/block/block.h +++ b/include/bedrock/world/level/block/block.h @@ -171,4 +171,4 @@ class Block { BlockRuntimeId network_id_; // +300 bool has_runtime_id_; // }; -BEDROCK_STATIC_ASSERT_SIZE(Block, 312, 312); +BEDROCK_STATIC_ASSERT_SIZE(Block, 312, 320); diff --git a/include/bedrock/world/level/block/components/block_component_storage.h b/include/bedrock/world/level/block/components/block_component_storage.h index a0520bb0e..5149c9545 100644 --- a/include/bedrock/world/level/block/components/block_component_storage.h +++ b/include/bedrock/world/level/block/components/block_component_storage.h @@ -14,12 +14,9 @@ #pragma once -#include +#include -#include -#include - -#include "bedrock/core/utility/type_id.h" +#include "bedrock/bedrock.h" class BlockComponentStorage { public: From 4e6c8f30bc5fffb81fdcf4792348c2abadf51b38 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 17:08:50 +0000 Subject: [PATCH 16/42] fix: prevent server crash when comments are present in `world_resource_packs.json` Fix #100 --- src/endstone_core/level/level.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/endstone_core/level/level.cpp b/src/endstone_core/level/level.cpp index 3d8156d1e..5910a06fe 100644 --- a/src/endstone_core/level/level.cpp +++ b/src/endstone_core/level/level.cpp @@ -122,8 +122,13 @@ void EndstoneLevel::loadResourcePacks() fs::path file_path = fs::current_path() / "worlds" / level_.getLevelId() / "world_resource_packs.json"; if (exists(file_path)) { - std::ifstream file(file_path); - file >> json; + try { + std::ifstream file(file_path); + json = nlohmann::json::parse(file, nullptr, true, true); + } + catch (std::exception &e) { + server_.getLogger().error("Failed to load from {}", file_path); + } } // Append loaded packs to the stack From 1e68d72e208b85327251903f9e8c380e8dbcd338 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 5 Dec 2024 17:23:40 +0000 Subject: [PATCH 17/42] feat: improve error logging to include exception details when JSON loading fails --- src/endstone_core/level/level.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endstone_core/level/level.cpp b/src/endstone_core/level/level.cpp index 5910a06fe..c5f3490f3 100644 --- a/src/endstone_core/level/level.cpp +++ b/src/endstone_core/level/level.cpp @@ -127,7 +127,7 @@ void EndstoneLevel::loadResourcePacks() json = nlohmann::json::parse(file, nullptr, true, true); } catch (std::exception &e) { - server_.getLogger().error("Failed to load from {}", file_path); + server_.getLogger().error("Failed to load from {}: {}", file_path, e.what()); } } From b9501c69a6349cc0ccbf0d645639cb045f998452 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 07:17:28 +0000 Subject: [PATCH 18/42] chore: update symbols.toml for BDS v1.21.50 Linux --- python/src/endstone/_internal/symbols.toml | 140 ++++++++++----------- src/endstone_core/server.cpp | 2 +- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/python/src/endstone/_internal/symbols.toml b/python/src/endstone/_internal/symbols.toml index 7a53b46fd..efb02e8bc 100644 --- a/python/src/endstone/_internal/symbols.toml +++ b/python/src/endstone/_internal/symbols.toml @@ -1,4 +1,4 @@ -timestamp = 1733338493 +timestamp = 1733469382 version = "1.21.50" [windows] @@ -111,110 +111,110 @@ version = "1.21.50" "?computeTarget@TeleportCommand@@SA?AVTeleportTarget@@AEAVActor@@VVec3@@PEAV4@V?$AutomaticID@VDimension@@H@@AEBV?$optional@VRotationData@RotationCommandUtils@@@std@@H@Z" = 34991952 [linux] -"_Z7getI18nv" = 75064256 +"_Z7getI18nv" = 91294352 # Actor -"_ZN5Actor6removeEv" = 114177056 -"_ZN5Actor10teleportToERK4Vec3biib" = 114203520 +"_ZN5Actor6removeEv" = 121537872 +"_ZN5Actor10teleportToERK4Vec3biib" = 121564592 # Bedrock -"_ZN7Bedrock9Threading15getServerThreadEv" = 149214896 +"_ZN7Bedrock9Threading15getServerThreadEv" = 164283584 # BedrockLog -"_ZN10BedrockLog6log_vaENS_11LogCategoryENSt3__16bitsetILm3EEENS_7LogRuleE9LogAreaIDjPKciS7_P13__va_list_tag" = 145785968 +"_ZN10BedrockLog6log_vaENS_11LogCategoryENSt3__16bitsetILm3EEENS_7LogRuleE9LogAreaIDjPKciS7_P13__va_list_tag" = 160989088 # BlockDescriptor -"_ZNK15BlockDescriptor20tryGetBlockNoLoggingEv" = 124516672 +"_ZNK15BlockDescriptor20tryGetBlockNoLoggingEv" = 129885728 # BlockTypeRegistry -"_ZN17BlockTypeRegistry12forEachBlockENSt3__18functionIFbRK11BlockLegacyEEE" = 129703616 +"_ZN17BlockTypeRegistry12forEachBlockENSt3__18functionIFbRK11BlockLegacyEEE" = 139876944 # Command -"_ZNK7Command14getCommandNameEv" = 97224928 -"_ZNK7Command3runERK13CommandOriginR13CommandOutput" = 97225040 +"_ZNK7Command14getCommandNameEv" = 103695968 +"_ZNK7Command3runERK13CommandOriginR13CommandOutput" = 103696080 # CommandOriginLoader -"_ZN19CommandOriginLoader4loadERK11CompoundTagR11ServerLevel" = 97275696 +"_ZN19CommandOriginLoader4loadERK11CompoundTagR11ServerLevel" = 103746608 # CommandRegistry -"_ZN15CommandRegistry13addEnumValuesERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS0_6vectorIS6_NS4_IS6_EEEE" = 93186960 -"_ZNK15CommandRegistry13createCommandERKNS_10ParseTokenERK13CommandOriginiRNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEERNS6_6vectorISC_NSA_ISC_EEEE" = 93076352 -"_ZNK15CommandRegistry8describeERK20CommandParameterData" = 93265424 -"_ZNK15CommandRegistry8describeERKNS_9SignatureERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEERKNS_8OverloadEjPjSF_" = 93267216 -"_ZNK15CommandRegistry11findCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE" = 93085168 -"_ZN15CommandRegistry13registerAliasENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES6_" = 93195344 -"_ZN15CommandRegistry15registerCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEPKc22CommandPermissionLevel11CommandFlagSC_" = 93189568 -"_ZN15CommandRegistry24registerOverloadInternalERNS_9SignatureERNS_8OverloadE" = 93206896 -"_ZNK15CommandRegistry26serializeAvailableCommandsEv" = 93284688 +"_ZN15CommandRegistry13addEnumValuesERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS0_6vectorIS6_NS4_IS6_EEEE" = 93541776 +"_ZNK15CommandRegistry13createCommandERKNS_10ParseTokenERK13CommandOriginiRNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEERNS6_6vectorISC_NSA_ISC_EEEE" = 93432368 +"_ZNK15CommandRegistry8describeERK20CommandParameterData" = 93620240 +"_ZNK15CommandRegistry8describeERKNS_9SignatureERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEERKNS_8OverloadEjPjSF_" = 93622032 +"_ZNK15CommandRegistry11findCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE" = 93441184 +"_ZN15CommandRegistry13registerAliasENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES6_" = 93550160 +"_ZN15CommandRegistry15registerCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEPKc22CommandPermissionLevel11CommandFlagSC_" = 93544384 +"_ZN15CommandRegistry24registerOverloadInternalERNS_9SignatureERNS_8OverloadE" = 93561712 +"_ZNK15CommandRegistry26serializeAvailableCommandsEv" = 93639504 # CommandUtils -"_ZN12CommandUtils12getActorNameERK5Actor" = 81686912 +"_ZN12CommandUtils12getActorNameERK5Actor" = 113599856 # Common -"_ZN6Common20getGameVersionStringEv" = 66439872 +"_ZN6Common20getGameVersionStringEv" = 81754400 # CraftingDataPacket -"_ZN18CraftingDataPacket18prepareFromRecipesERK7Recipesb" = 80363616 +"_ZN18CraftingDataPacket18prepareFromRecipesERK7Recipesb" = 88352736 # FurnaceBlockActor -"_ZN17FurnaceBlockActor15getBurnDurationERK13ItemStackBasef" = 133854048 +"_ZN17FurnaceBlockActor15getBurnDurationERK13ItemStackBasef" = 146244016 # GameMode -"_ZN8GameMode12destroyBlockERK8BlockPosh" = 114441200 -"_ZN8GameMode8interactER5ActorRK4Vec3" = 114436912 -"_ZN8GameMode9useItemOnER9ItemStackRK8BlockPoshRK4Vec3PK5Blockb" = 114449872 +"_ZN8GameMode12destroyBlockERK8BlockPosh" = 129314240 +"_ZN8GameMode8interactER5ActorRK4Vec3" = 129309872 +"_ZN8GameMode9useItemOnER9ItemStackRK8BlockPoshRK4Vec3PK5Blockb" = 129322896 # Item -"_ZNK4Item23_sendTryPlaceBlockEventERK5BlockRK11BlockSourceRK5ActorRK8BlockPoshRK4Vec3" = 123477152 +"_ZNK4Item23_sendTryPlaceBlockEventERK5BlockRK11BlockSourceRK5ActorRK8BlockPoshRK4Vec3" = 137794752 # ItemStack -"_ZN9ItemStackC2Ev" = 124133024 -"_ZN9ItemStackC2ERKS_" = 124134928 -"_ZN9ItemStackC2ERK4ItemiiPK11CompoundTag" = 124133216 +"_ZN9ItemStackC2Ev" = 137837680 +"_ZN9ItemStackC2ERKS_" = 137838128 +"_ZN9ItemStackC2ERK4ItemiiPK11CompoundTag" = 137837872 # Level -"_ZN5Level4tickEv" = 123832128 +"_ZN5Level4tickEv" = 130259312 # LevelEventCoordinator -"_ZN21LevelEventCoordinator21_postReloadActorAddedER5Actor25ActorInitializationMethod" = 115976288 +"_ZN21LevelEventCoordinator21_postReloadActorAddedER5Actor25ActorInitializationMethod" = 129209008 # MinecraftCommands -"_ZN17MinecraftCommands14compileCommandERK12HashedStringR13CommandOrigin17CurrentCmdVersionNSt3__18functionIFvRKNS6_12basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEEEEE" = 81714448 -"_ZNK17MinecraftCommands14executeCommandER14CommandContextb" = 81711152 +"_ZN17MinecraftCommands14compileCommandERK12HashedStringR13CommandOrigin17CurrentCmdVersionNSt3__18functionIFvRKNS6_12basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEEEEE" = 113630544 +"_ZNK17MinecraftCommands14executeCommandER14CommandContextb" = 113627248 # MinecraftPackets -"_ZN16MinecraftPackets12createPacketE18MinecraftPacketIds" = 78435792 +"_ZN16MinecraftPackets12createPacketE18MinecraftPacketIds" = 91844144 # Mob -"_ZN3Mob3dieERK17ActorDamageSource" = 107993520 -"_ZN3Mob9knockbackEP5Actorifffff" = 107992752 +"_ZN3Mob3dieERK17ActorDamageSource" = 120610640 +"_ZN3Mob9knockbackEP5Actorifffff" = 120609872 # Pack -"_ZN4Pack10createPackERK16ResourceLocation8PackType10PackOriginR20IPackManifestFactoryRKN3gsl8not_nullIN7Bedrock15NonOwnerPointerIK19IContentKeyProviderEEEEP16PackSourceReportRKN4Core4PathE" = 75716064 +"_ZN4Pack10createPackERK16ResourceLocation8PackType10PackOriginR20IPackManifestFactoryRKN3gsl8not_nullIN7Bedrock15NonOwnerPointerIK19IContentKeyProviderEEEEP16PackSourceReportRKN4Core4PathE" = 90720896 # Player -"_ZN6Player12getInventoryEv" = 113318768 -"_ZNK6Player7getNameEv" = 113240336 -"_ZN6Player14setPermissionsE22CommandPermissionLevel" = 113265232 -"_ZN6Player10teleportToERK4Vec3biib" = 113229936 +"_ZN6Player12getInventoryEv" = 128862032 +"_ZNK6Player7getNameEv" = 128778416 +"_ZN6Player14setPermissionsE22CommandPermissionLevel" = 128802864 +"_ZN6Player10teleportToERK4Vec3biib" = 128767968 # PlayerEventCoordinator -"_ZN22PlayerEventCoordinator9sendEventERK8EventRefI19PlayerGameplayEventIvEE" = 115978464 +"_ZN22PlayerEventCoordinator9sendEventERK8EventRefI19PlayerGameplayEventIvEE" = 129211184 # RakNet -"_ZN6RakNet22RNS2_Windows_Linux_36027Send_Windows_Linux_360NoVDPEiPNS_19RNS2_SendParametersEPKcj" = 135909808 -"_ZNK6RakNet13SystemAddress8ToStringEbPcc" = 135943120 +"_ZN6RakNet22RNS2_Windows_Linux_36027Send_Windows_Linux_360NoVDPEiPNS_19RNS2_SendParametersEPKcj" = 149421424 +"_ZNK6RakNet13SystemAddress8ToStringEbPcc" = 149455664 # RakPeerHelper -"_ZN13RakPeerHelper11peerStartupEPN6RakNet16RakPeerInterfaceERK20ConnectionDefinitionNS_11PeerPurposeE" = 78507456 +"_ZN13RakPeerHelper11peerStartupEPN6RakNet16RakPeerInterfaceERK20ConnectionDefinitionNS_11PeerPurposeE" = 91912080 # ResourcePackRepository -"_ZN22ResourcePackRepository21_initializePackSourceEv" = 80990416 +"_ZN22ResourcePackRepository21_initializePackSourceEv" = 93260080 # ResourcePackStack -"_ZN17ResourcePackStack11deserializeERNSt3__113basic_istreamIcNS0_11char_traitsIcEEEERKN3gsl8not_nullIN7Bedrock15NonOwnerPointerIK23IResourcePackRepositoryEEEE" = 76539408 +"_ZN17ResourcePackStack11deserializeERNSt3__113basic_istreamIcNS0_11char_traitsIcEEEERKN3gsl8not_nullIN7Bedrock15NonOwnerPointerIK23IResourcePackRepositoryEEEE" = 92997664 # SayCommand -"_ZN10SayCommand12_sendMessageERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS0_8optionalIS6_EES8_RK21CommandOriginIdentityR5Level" = 82887872 +"_ZN10SayCommand12_sendMessageERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS0_8optionalIS6_EES8_RK21CommandOriginIdentityR5Level" = 103166880 # Scoreboard -"_ZN10Scoreboard16resetPlayerScoreERK12ScoreboardIdR9Objective" = 135188608 +"_ZN10Scoreboard16resetPlayerScoreERK12ScoreboardIdR9Objective" = 147989168 # ScriptingEventCoordinator -"_ZN25ScriptingEventCoordinator9sendEventE8EventRefI22ScriptingGameplayEventI17CoordinatorResultEE" = 115987584 +"_ZN25ScriptingEventCoordinator9sendEventE8EventRefI22ScriptingGameplayEventI17CoordinatorResultEE" = 129220304 # ScriptLevelGameplayHandler -"_ZN26ScriptLevelGameplayHandler11handleEventER24LevelWeatherChangedEvent" = 101911248 +"_ZN26ScriptLevelGameplayHandler11handleEventER24LevelWeatherChangedEvent" = 111598320 # ScriptModuleMinecraft::ScriptBlockUtils -"_ZN21ScriptModuleMinecraft16ScriptBlockUtils21createBlockDescriptorENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_8optionalINS1_13unordered_mapIS7_NS1_7variantIJiS7_bEEENS1_4hashIS7_EENS1_8equal_toIS7_EENS5_INS1_4pairIKS7_SB_EEEEEEEE" = 93735296 +"_ZN21ScriptModuleMinecraft16ScriptBlockUtils21createBlockDescriptorENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS1_8optionalINS1_13unordered_mapIS7_NS1_7variantIJiS7_bEEENS1_4hashIS7_EENS1_8equal_toIS7_EENS5_INS1_4pairIKS7_SB_EEEEEEEE" = 95970720 # ServerInstanceEventCoordinator -"_ZN30ServerInstanceEventCoordinator25sendServerInitializeStartER14ServerInstance" = 115987664 -"_ZN30ServerInstanceEventCoordinator23sendServerThreadStartedER14ServerInstance" = 115988816 -"_ZN30ServerInstanceEventCoordinator23sendServerThreadStoppedER14ServerInstance" = 115988960 +"_ZN30ServerInstanceEventCoordinator25sendServerInitializeStartER14ServerInstance" = 129220384 +"_ZN30ServerInstanceEventCoordinator23sendServerThreadStartedER14ServerInstance" = 129221536 +"_ZN30ServerInstanceEventCoordinator23sendServerThreadStoppedER14ServerInstance" = 129221680 # ServerNetworkHandler -"_ZN20ServerNetworkHandler16disconnectClientERK17NetworkIdentifier11SubClientIdN10Connection20DisconnectFailReasonERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEENS6_8optionalISC_EEb" = 80251632 -"_ZN20ServerNetworkHandler14trytLoadPlayerER12ServerPlayerRK17ConnectionRequest" = 80323520 -"_ZN20ServerNetworkHandler24updateServerAnnouncementEv" = 80278896 -"_ZN20ServerNetworkHandler16_createNewPlayerERK17NetworkIdentifierRK26SubClientConnectionRequest11SubClientId" = 80367184 -"_ZN20ServerNetworkHandler19_displayGameMessageERK6PlayerR9ChatEvent" = 80241696 -"_ZNK20ServerNetworkHandler20_isServerTextEnabledERK15ServerTextEvent" = 80279840 +"_ZN20ServerNetworkHandler16disconnectClientERK17NetworkIdentifier11SubClientIdN10Connection20DisconnectFailReasonERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEENS6_8optionalISC_EEb" = 91556800 +"_ZN20ServerNetworkHandler14trytLoadPlayerER12ServerPlayerRK17ConnectionRequest" = 91630384 +"_ZN20ServerNetworkHandler24updateServerAnnouncementEv" = 91583744 +"_ZN20ServerNetworkHandler16_createNewPlayerERK17NetworkIdentifierRK26SubClientConnectionRequest11SubClientId" = 91671520 +"_ZN20ServerNetworkHandler19_displayGameMessageERK6PlayerR9ChatEvent" = 91546832 +"_ZNK20ServerNetworkHandler20_isServerTextEnabledERK15ServerTextEvent" = 91584688 # ServerPlayer -"_ZN12ServerPlayer3dieERK17ActorDamageSource" = 97160176 -"_ZN12ServerPlayer10disconnectEv" = 97179392 -"_ZN12ServerPlayer27setLocalPlayerAsInitializedEv" = 97185712 +"_ZN12ServerPlayer3dieERK17ActorDamageSource" = 103631264 +"_ZN12ServerPlayer10disconnectEv" = 103650656 +"_ZN12ServerPlayer27setLocalPlayerAsInitializedEv" = 103657312 # ServerScoreboard -"_ZN16ServerScoreboardC2E23CommandSoftEnumRegistryP12LevelStorageN3gsl8not_nullIN7Bedrock15NonOwnerPointerI19GameplayUserManagerEEEE" = 135198704 +"_ZN16ServerScoreboardC2E23CommandSoftEnumRegistryP12LevelStorageN3gsl8not_nullIN7Bedrock15NonOwnerPointerI19GameplayUserManagerEEEE" = 144814368 # StartGamePacket -"_ZNK15StartGamePacket5writeER12BinaryStream" = 79753776 +"_ZNK15StartGamePacket5writeER12BinaryStream" = 92457792 # TeleportCommand -"_ZN15TeleportCommand11applyTargetER5Actor14TeleportTargetb" = 82277280 -"_ZN15TeleportCommand13computeTargetER5Actor4Vec3PS2_11AutomaticIDI9DimensioniERKNSt3__18optionalIN20RotationCommandUtils12RotationDataEEEi" = 82277664 +"_ZN15TeleportCommand11applyTargetER5Actor14TeleportTargetb" = 103348896 +"_ZN15TeleportCommand13computeTargetER5Actor4Vec3PS2_11AutomaticIDI9DimensioniERKNSt3__18optionalIN20RotationCommandUtils12RotationDataEEEi" = 103349280 diff --git a/src/endstone_core/server.cpp b/src/endstone_core/server.cpp index 1a945c7ee..d434c36ba 100644 --- a/src/endstone_core/server.cpp +++ b/src/endstone_core/server.cpp @@ -220,7 +220,7 @@ Scheduler &EndstoneServer::getScheduler() const Level *EndstoneServer::getLevel() const { - return level_ ? level_.get() : nullptr; + return level_.get(); } void EndstoneServer::setLevel(std::unique_ptr level) From cb950eaa8bb3a31cc92544884bb9cebd7473b5bd Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 07:29:40 +0000 Subject: [PATCH 19/42] fix: make Level::_cerealContext() a pure virtual function. --- include/bedrock/world/level/level_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bedrock/world/level/level_interface.h b/include/bedrock/world/level/level_interface.h index 5c2029f52..50d4bb737 100644 --- a/include/bedrock/world/level/level_interface.h +++ b/include/bedrock/world/level/level_interface.h @@ -464,5 +464,5 @@ class ILevel : public Bedrock::EnableNonOwnerReferences { virtual void *getArmorTrimUnloader() = 0; [[nodiscard]] virtual void *getPlayerSleepManager() const = 0; virtual void *getPlayerSleepManager() = 0; - virtual void *_cerealContext(); + virtual void *_cerealContext() = 0; }; From c860482003f85f6a49ce708fab60aa778a7da049 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 07:58:46 +0000 Subject: [PATCH 20/42] docs: update CHANGELOG.md --- CHANGELOG.md | 27 +++++++++++++++++++++++++-- README.md | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be37b9579..c7a0e1e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,32 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## 0.5.6 - Unreleased +## 0.5.7 - Unreleased -[Compare with 0.5.5](https://github.com/EndstoneMC/endstone/compare/v0.5.5...HEAD) +[Compare with 0.5.6](https://github.com/EndstoneMC/endstone/compare/v0.5.6...HEAD) + +## [0.5.6](https://github.com/EndstoneMC/endstone/releases/tag/v0.5.6) - 2024-12-06 + +[Compare with 0.5.5](https://github.com/EndstoneMC/endstone/compare/v0.5.5...v0.5.6) + +### Added + +- Added support for Minecraft v1.21.50 (The Garden Awakens). +- Added `Inventory::getItem` and `Inventory::setItem` methods to manipulate a player's inventory. +- Added `Inventory::getContents` method to retrieve all items in an inventory. +- Added `/ban` and `/unban` commands to add or remove players from the deny list. +- Added `/banlist [ips|players]` command to list all banned players and/or IPs. +- Added `PluginManager::loadPlugin` to allow third-party plugin loaders to load plugins from single files instead of + directories. [#98](https://github.com/EndstoneMC/endstone/issues/98) + +### Fixed + +- Fixed an issue where `block_palette.nbt` was dumped twice in the DevTools. + +### Changed + +- Added support for loading a mixture of folder packs listed in `world_resource_packs.json` (the conventional method) + and zipped packs in `.zip` or `.mcpack` format placed under `resource_packs`. ## [0.5.5](https://github.com/EndstoneMC/endstone/releases/tag/v0.5.5) - 2024-10-26 diff --git a/README.md b/README.md index ccd49fe18..b4aa82540 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![CI](https://github.com/EndstoneMC/endstone/actions/workflows/ci.yml/badge.svg)](https://github.com/EndstoneMC/endstone/actions/workflows/ci.yml) [![Documentation](https://github.com/EndstoneMC/endstone/actions/workflows/docs.yml/badge.svg)](https://endstone.dev/) -[![Minecraft - Version](https://img.shields.io/badge/minecraft-v1.21.44_(Bedrock)-black)](https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs) +[![Minecraft - Version](https://img.shields.io/badge/minecraft-v1.21.50_(Bedrock)-black)](https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs) [![PyPI - Version](https://img.shields.io/pypi/v/endstone)](https://pypi.org/project/endstone) [![Python](https://img.shields.io/pypi/pyversions/endstone?logo=python&logoColor=white)](https://www.python.org/) [![GitHub License](https://img.shields.io/github/license/endstonemc/endstone)](LICENSE) From 01a3ac66f0aa74aa60be0d70bf655fbd65334556 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 11:15:17 +0000 Subject: [PATCH 21/42] deps: switch to FetchContent for funchook --- .github/workflows/ci.yml | 1 - .github/workflows/coverage.yml | 1 - CMakeLists.txt | 63 ++---------- CONTRIBUTING.md | 8 +- README.md | 1 - pyproject.toml | 6 +- src/endstone_runtime/CMakeLists.txt | 145 ++++++++++++++++++++++++++++ src/endstone_runtime/hook.cpp | 3 +- 8 files changed, 157 insertions(+), 71 deletions(-) create mode 100644 src/endstone_runtime/CMakeLists.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b97eeadff..f379dd0d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,6 @@ jobs: python -m pip install --upgrade pip pip install conan conan profile detect --force - conan export third_party/funchook --version 1.1.3 - name: Build with Conan (Linux) if: runner.os == 'Linux' diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 80c56f351..4eb17caed 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -49,7 +49,6 @@ jobs: python -m pip install --upgrade pip pip install conan conan profile detect --force - conan export third_party/funchook --version 1.1.3 conan install . --build=missing -s compiler.cppstd=17 -s compiler.libcxx=libc++ -s build_type=Debug -c tools.cmake.cmaketoolchain:generator=Ninja - name: Build with CMake diff --git a/CMakeLists.txt b/CMakeLists.txt index 509b2d1aa..5af80a9a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,33 +31,12 @@ if (ENDSTONE_DEVTOOLS_ENABLED) add_compile_definitions(ENDSTONE_DEVTOOLS) endif () -# ======== -# packages -# ======== -find_package(base64 CONFIG REQUIRED) -find_package(Boost CONFIG REQUIRED) -find_package(concurrentqueue CONFIG REQUIRED) -find_package(cpptrace CONFIG REQUIRED) -find_package(EnTT CONFIG REQUIRED) -find_package(expected-lite REQUIRED) -find_package(fmt CONFIG REQUIRED) -find_package(funchook CONFIG REQUIRED) -find_package(glm CONFIG REQUIRED) -find_package(magic_enum CONFIG REQUIRED) -find_package(Microsoft.GSL CONFIG REQUIRED) -find_package(nlohmann_json CONFIG REQUIRED) -find_package(spdlog CONFIG REQUIRED) -find_package(tomlplusplus CONFIG REQUIRED) -if (UNIX) - find_package(libelf CONFIG REQUIRED) -endif () - -find_package(GTest CONFIG REQUIRED) - - # ================= # endstone::headers # ================= +find_package(fmt REQUIRED) +find_package(expected-lite REQUIRED) + add_library(endstone_headers INTERFACE) add_library(endstone::headers ALIAS endstone_headers) target_include_directories(endstone_headers INTERFACE include) @@ -66,7 +45,6 @@ target_link_libraries(endstone_headers INTERFACE fmt::fmt nonstd::expected-lite) include(GNUInstallDirs) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - # ================ # endstone::python # ================ @@ -103,43 +81,14 @@ endif () # ================= # endstone::runtime # ================= -file(GLOB_RECURSE ENDSTONE_RUNTIME_SOURCE_FILES CONFIGURE_DEPENDS "src/endstone_runtime/*.cpp") -add_library(endstone_runtime SHARED ${ENDSTONE_RUNTIME_SOURCE_FILES}) -add_library(endstone::runtime ALIAS endstone_runtime) -target_link_libraries(endstone_runtime PRIVATE endstone::core funchook::funchook) -if (ENDSTONE_DEVTOOLS_ENABLED) - target_link_libraries(endstone_runtime PRIVATE endstone::devtools) -endif () -if (WIN32) - target_link_libraries(endstone_runtime PRIVATE dbghelp.lib ws2_32.lib) - target_link_options(endstone_runtime PRIVATE "/INCREMENTAL:NO") -endif () -if (UNIX) - target_link_libraries(endstone_runtime PRIVATE libelf::libelf) - target_link_options(endstone_runtime PRIVATE "-Wl,--exclude-libs,ALL") - target_compile_options(endstone_runtime PRIVATE "-fvisibility=hidden" "-fms-extensions") -endif () - -include(GNUInstallDirs) -install(TARGETS endstone_runtime - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(TARGETS endstone_runtime DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) -if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND MSVC) - install(FILES $ DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) -endif () - -if (WIN32) - add_library(endstone_runtime_loader SHARED "src/endstone_runtime/loader.cpp") - target_compile_definitions(endstone_runtime_loader PRIVATE _CRT_SECURE_NO_WARNINGS ENDSTONE_RUNTIME_LOADER) - install(TARGETS endstone_runtime_loader DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) -endif () +add_subdirectory(src/endstone_runtime) # ===== # tests # ===== if (NOT BUILD_TESTING STREQUAL OFF) + find_package(GTest REQUIRED) + add_library(test_plugin SHARED tests/plugin/test_plugin.cpp) target_link_libraries(test_plugin PRIVATE endstone::headers) set_target_properties(test_plugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "plugins") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6514ff4b7..9a783652b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,13 +36,7 @@ conan profile detect ### Install dependencies -First of all, add the `funchook/1.1.3` recipe to your conan local repository. - -```shell -conan export third_party/funchook --version 1.1.3 -``` - -Then, run the following commands: +First of all, run the following commands to install dependencies of this project: === ":fontawesome-brands-windows: Command Prompt" ```shell diff --git a/README.md b/README.md index b4aa82540..dd00fa14c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ [![Python](https://img.shields.io/pypi/pyversions/endstone?logo=python&logoColor=white)](https://www.python.org/) [![GitHub License](https://img.shields.io/github/license/endstonemc/endstone)](LICENSE) [![Codacy Badge](https://img.shields.io/codacy/grade/8877402fc70b40f5a8c4b325d890e3f7?logo=codacy)](https://app.codacy.com/gh/EndstoneMC/endstone/dashboard) -[![Code style: black](https://img.shields.io/badge/code_style-black-000000.svg)](https://github.com/psf/black) [![Discord](https://img.shields.io/discord/1230982180742631457?logo=discord&logoColor=white&color=5865F2)](https://discord.gg/xxgPuc2XN9) [![Ko-Fi](https://img.shields.io/badge/Buy_Me_a_Coffee-f37574?logo=kofi&logoColor=white)](https://ko-fi.com/EndstoneMC) diff --git a/pyproject.toml b/pyproject.toml index c776ab574..3e1bad361 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,9 +66,9 @@ sdist.include = ["python/src/endstone/_internal/version.py"] [tool.scikit-build-core-conan] config = ["tools.cmake.cmaketoolchain:generator=Ninja"] -[[tool.scikit-build-core-conan.local-recipes]] -path = "third_party/funchook" -version = "1.1.3" +# [[tool.scikit-build-core-conan.local-recipes]] +# path = "third_party/funchook" +# version = "1.1.3" [[tool.scikit-build-core-conan.overrides]] if.platform-system = "win32" diff --git a/src/endstone_runtime/CMakeLists.txt b/src/endstone_runtime/CMakeLists.txt new file mode 100644 index 000000000..7e5d30287 --- /dev/null +++ b/src/endstone_runtime/CMakeLists.txt @@ -0,0 +1,145 @@ +cmake_minimum_required(VERSION 3.15) +project(endstone_runtime LANGUAGES CXX) + +include(FetchContent) +FetchContent_Declare( + funchook + GIT_REPOSITORY https://github.com/kubo/funchook.git + GIT_TAG v1.1.3 + GIT_SHALLOW 1 +) +set(FUNCHOOK_BUILD_SHARED OFF) +set(FUNCHOOK_BUILD_TESTS OFF) +set(FUNCHOOK_DISASM capstone) + +FetchContent_MakeAvailable(funchook) +add_library(funchook::funchook ALIAS funchook-static) + +add_library(endstone_runtime SHARED + bedrock/shared_constants.cpp + bedrock/certificates/certificate.cpp + bedrock/certificates/extended_certificate.cpp + bedrock/config/player_capabilities.cpp + bedrock/core/debug/bedrock_event_logger.cpp + bedrock/core/file/path.cpp + bedrock/core/math/color.cpp + bedrock/core/resource/resource_helper.cpp + bedrock/core/sem_ver/sem_version.cpp + bedrock/core/string/string_hash.cpp + bedrock/core/utility/binary_stream.cpp + bedrock/deps/json/value.cpp + bedrock/deps/raknet/get_time.cpp + bedrock/deps/raknet/raknet_socket2.cpp + bedrock/deps/raknet/raknet_types.cpp + bedrock/entity/gamerefs_entity/entity_registry.cpp + bedrock/entity/gamerefs_entity/stack_result_storage_entity.cpp + bedrock/entity/gamerefs_entity/weak_storage_entity.cpp + bedrock/locale/i18n.cpp + bedrock/locale/localization.cpp + bedrock/nbt/compound_tag.cpp + bedrock/nbt/nbt_io.cpp + bedrock/nbt/tag.cpp + bedrock/network/network_identifier.cpp + bedrock/network/packet.cpp + bedrock/network/rak_peer_helper.cpp + bedrock/network/server_network_handler.cpp + bedrock/network/packet/crafting_data_packet.cpp + bedrock/network/packet/start_game_packet.cpp + bedrock/platform/assigned_thread.cpp + bedrock/platform/uuid.cpp + bedrock/resources/pack.cpp + bedrock/resources/pack_error.cpp + bedrock/resources/pack_manifest.cpp + bedrock/resources/pack_source.cpp + bedrock/resources/resource_pack.cpp + bedrock/resources/resource_pack_manager.cpp + bedrock/resources/resource_pack_repository.cpp + bedrock/resources/resource_pack_stack.cpp + bedrock/scripting/event_handlers/script_level_gameplay_handler.cpp + bedrock/server/server_instance.cpp + bedrock/server/server_level.cpp + bedrock/server/server_player.cpp + bedrock/server/commands/command.cpp + bedrock/server/commands/command_origin.cpp + bedrock/server/commands/command_origin_loader.cpp + bedrock/server/commands/command_output.cpp + bedrock/server/commands/command_registry.cpp + bedrock/server/commands/command_utils.cpp + bedrock/server/commands/minecraft_commands.cpp + bedrock/server/commands/standard/say_command.cpp + bedrock/server/commands/standard/teleport_command.cpp + bedrock/util/data_io.cpp + bedrock/util/index_set.cpp + bedrock/util/string_byte_output.cpp + bedrock/world/game_session.cpp + bedrock/world/minecraft.cpp + bedrock/world/actor/actor.cpp + bedrock/world/actor/mob.cpp + bedrock/world/actor/player/abilities.cpp + bedrock/world/actor/player/player.cpp + bedrock/world/attribute/attribute_instance.cpp + bedrock/world/attribute/attribute_map.cpp + bedrock/world/events/level_event_coordinator.cpp + bedrock/world/events/player_event_coordinator.cpp + bedrock/world/events/scripting_event_coordinator.cpp + bedrock/world/events/server_instance_event_coordinator.cpp + bedrock/world/gamemode/game_mode.cpp + bedrock/world/item/item.cpp + bedrock/world/item/item_stack.cpp + bedrock/world/item/item_stack_base.cpp + bedrock/world/item/registry/creative_item_entry.cpp + bedrock/world/item/registry/creative_item_registry.cpp + bedrock/world/item/registry/item_registry.cpp + bedrock/world/item/registry/item_registry_manager.cpp + bedrock/world/item/registry/item_registry_ref.cpp + bedrock/world/level/level.cpp + bedrock/world/level/biome/registry/biome_registry.cpp + bedrock/world/level/block/block_descriptor.cpp + bedrock/world/level/block/block_legacy.cpp + bedrock/world/level/block/actor/furnace_block_actor.cpp + bedrock/world/level/block/registry/block_type_registry.cpp + bedrock/world/level/dimension/dimension.cpp + bedrock/world/scores/objective.cpp + bedrock/world/scores/scoreboard.cpp + bedrock/world/scores/scoreboard_id.cpp + bedrock/world/scores/server_scoreboard.cpp + linux/hook.cpp + linux/os.cpp + linux/signal_handler.cpp + windows/hook.cpp + windows/os.cpp + windows/signal_handler.cpp + hook.cpp + loader.cpp + main.cpp +) +add_library(endstone::runtime ALIAS endstone_runtime) +target_link_libraries(endstone_runtime PRIVATE endstone::core funchook::funchook) +if (ENDSTONE_DEVTOOLS_ENABLED) + target_link_libraries(endstone_runtime PRIVATE endstone::devtools) +endif () +if (WIN32) + target_link_libraries(endstone_runtime PRIVATE dbghelp.lib ws2_32.lib) + target_link_options(endstone_runtime PRIVATE "/INCREMENTAL:NO") +endif () +if (UNIX) + target_link_libraries(endstone_runtime PRIVATE libelf::libelf) + target_link_options(endstone_runtime PRIVATE "-Wl,--exclude-libs,ALL") + target_compile_options(endstone_runtime PRIVATE "-fvisibility=hidden" "-fms-extensions") +endif () + +include(GNUInstallDirs) +install(TARGETS endstone_runtime + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS endstone_runtime DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) +if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND MSVC) + install(FILES $ DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) +endif () + +if (WIN32) + add_library(endstone_runtime_loader SHARED "loader.cpp") + target_compile_definitions(endstone_runtime_loader PRIVATE _CRT_SECURE_NO_WARNINGS ENDSTONE_RUNTIME_LOADER) + install(TARGETS endstone_runtime_loader DESTINATION "endstone/_internal/" COMPONENT endstone_wheel OPTIONAL) +endif () \ No newline at end of file diff --git a/src/endstone_runtime/hook.cpp b/src/endstone_runtime/hook.cpp index 1c2b4404b..f336fb108 100644 --- a/src/endstone_runtime/hook.cpp +++ b/src/endstone_runtime/hook.cpp @@ -14,11 +14,12 @@ #include "endstone/detail/hook.h" +#include + #include #include #include -#include #include namespace endstone::detail::hook { From ccd918ed6e5adee7b05925332458c388073af0dd Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 15:41:08 +0000 Subject: [PATCH 22/42] fix(event): ensure ScriptMessageEvent is invoked correctly --- .../events/scripting_event_coordinator.cpp | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp index 5551556b1..f49740838 100644 --- a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp +++ b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp @@ -14,8 +14,12 @@ #include "bedrock/world/events/scripting_event_coordinator.h" +#include #include +#include "bedrock/gameplayhandlers/coordinator_result.h" +#include "bedrock/world/events/event_variant.h" +#include "bedrock/world/events/scripting_events.h" #include "endstone/detail/hook.h" #include "endstone/detail/server.h" #include "endstone/event/server/script_message_event.h" @@ -24,33 +28,41 @@ using endstone::detail::EndstoneServer; CoordinatorResult ScriptingEventCoordinator::sendEvent(EventRef> ref) { - auto &server = entt::locator::value(); - return std::visit(endstone::overloaded{ - [&](const Details::ValueOrRef &arg) { - const auto &event = arg.value(); - const endstone::CommandSender *sender = nullptr; - if (event.source_actor.has_value()) { - if (auto *actor = event.level.fetchEntity(event.source_actor.value(), false); actor) { - sender = &actor->getEndstoneActor(); - } - } - // TODO(command): add support for BlockCommandSender - if (!sender) { - sender = &server.getCommandSender(); - } - endstone::ScriptMessageEvent e{event.message_id, event.message_value, *sender}; - server.getPluginManager().callEvent(e); - - // fix: wtf mojang devs - the original function accesses the pointer without checking - if (!scripting_event_handler_) { - return CoordinatorResult::Continue; - } - return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); - }, - [&](auto &&arg) -> CoordinatorResult { - const auto &event = arg.value(); - return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); - }, - }, - ref.get().variant); + const auto &server = entt::locator::value(); + + auto visitor = [&](auto &&arg) -> CoordinatorResult { + using T = std::decay_t; + + if constexpr (std::is_same_v>) { + const auto &event = arg.value(); + const endstone::CommandSender *sender = nullptr; + if (event.source_actor.has_value()) { + if (auto *actor = event.level.fetchEntity(event.source_actor.value(), false); actor) { + sender = &actor->getEndstoneActor(); + } + } + // TODO(command): add support for BlockCommandSender + if (!sender) { + sender = &server.getCommandSender(); + } + endstone::ScriptMessageEvent e{event.message_id, event.message_value, *sender}; + server.getPluginManager().callEvent(e); + + // fix: wtf mojang devs - the original function accesses the pointer without checking + if (!scripting_event_handler_) { + return CoordinatorResult::Continue; + } + return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); + } + else if constexpr (std::is_same_v> || + std::is_same_v>) { + const auto &event = arg.value(); + return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); + } + else { + static_assert(boost::mpl::false_::value, "non-exhaustive visitor!"); + } + }; + + return std::visit(visitor, ref.get().variant); } From dc44a7270dcbc43827729d2e380e9fb1ad224de4 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 15:48:17 +0000 Subject: [PATCH 23/42] fix: remove funchook in conanfile.py --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 527a42ad1..e530a6f95 100644 --- a/conanfile.py +++ b/conanfile.py @@ -117,7 +117,7 @@ def requirements(self): self.requires("entt/3.14.0") self.requires("expected-lite/0.8.0") self.requires("fmt/[~10]", transitive_headers=True, transitive_libs=True) - self.requires("funchook/1.1.3") + # self.requires("funchook/1.1.3") self.requires("glm/1.0.1") self.requires("magic_enum/0.9.5") self.requires("ms-gsl/4.0.0") From c95504e878ac2d3af056b2c8532d651b63b39916 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 15:54:45 +0000 Subject: [PATCH 24/42] fix: add missing dependencies in CMakeLists.txt --- src/endstone_runtime/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/endstone_runtime/CMakeLists.txt b/src/endstone_runtime/CMakeLists.txt index 7e5d30287..863bef7e9 100644 --- a/src/endstone_runtime/CMakeLists.txt +++ b/src/endstone_runtime/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.15) project(endstone_runtime LANGUAGES CXX) +if (UNIX) + find_package(libelf REQUIRED) +endif () + include(FetchContent) FetchContent_Declare( funchook From 4abe7d51ce0e2482a9fbd2e085933845a780047b Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 17:18:11 +0000 Subject: [PATCH 25/42] fix: compilation error in ScriptingEventCoordinator --- .../world/events/scripting_event_coordinator.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp index f49740838..0d99e7f84 100644 --- a/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp +++ b/src/endstone_runtime/bedrock/world/events/scripting_event_coordinator.cpp @@ -52,16 +52,10 @@ CoordinatorResult ScriptingEventCoordinator::sendEvent(EventRef> || - std::is_same_v>) { - const auto &event = arg.value(); - return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); - } - else { - static_assert(boost::mpl::false_::value, "non-exhaustive visitor!"); } + + const auto &event = arg.value(); + return ENDSTONE_HOOK_CALL_ORIGINAL(&ScriptingEventCoordinator::sendEvent, this, event); }; return std::visit(visitor, ref.get().variant); From b6a78473aef733d02aa99fe960ea3ffee6e52486 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 6 Dec 2024 18:33:02 +0000 Subject: [PATCH 26/42] fix: remove funchook from conanfile.py --- conanfile.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/conanfile.py b/conanfile.py index e530a6f95..5e0ce37e7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -205,10 +205,7 @@ def package_info(self): self.cpp_info.components["runtime"].libs = ["endstone_runtime"] self.cpp_info.components["runtime"].set_property("cmake_target_name", "endstone::runtime") - self.cpp_info.components["runtime"].requires = [ - "core", - "funchook::funchook", - ] + self.cpp_info.components["runtime"].requires = ["core"] if self._devtools_enabled: self.cpp_info.components["runtime"].requires.extend(["devtools"]) if self.settings.os == "Windows": From 692278cdf5b46b6fea4a155187b7b3c10a223152 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Sun, 15 Dec 2024 00:07:14 +0800 Subject: [PATCH 27/42] feat: add `Block::canContainLiquid` (#107) --- include/bedrock/world/level/block/block.h | 5 +++++ src/endstone_devtools/vanilla_data.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/bedrock/world/level/block/block.h b/include/bedrock/world/level/block/block.h index 97ebd1b55..49da6bbbc 100644 --- a/include/bedrock/world/level/block/block.h +++ b/include/bedrock/world/level/block/block.h @@ -56,6 +56,11 @@ class Block { return legacy_block_->canDropWithAnyTool(); } + [[nodiscard]] bool canContainLiquid() const + { + return direct_data_.water_detection_rule.can_contain_liquid; + } + [[nodiscard]] const CompoundTag &getSerializationId() const { return serialization_id_; diff --git a/src/endstone_devtools/vanilla_data.cpp b/src/endstone_devtools/vanilla_data.cpp index 48ca8d6a5..84aa58877 100644 --- a/src/endstone_devtools/vanilla_data.cpp +++ b/src/endstone_devtools/vanilla_data.cpp @@ -118,7 +118,7 @@ void dumpBlockData(VanillaData &data, ::Level &level) {"explosionResistance", round(block.getExplosionResistance())}, {"friction", round(block.getFriction())}, {"hardness", round(block.getDestroySpeed())}, - // {"canContainLiquid", block.getLegacyBlock().canContainLiquid()}, + {"canContainLiquid", block.canContainLiquid()}, // {"canDropWithAnyTool", block.canDropWithAnyTool()}, {"mapColor", map_color.toHexString()}, {"collisionShape", From a749b61c6d6c29c94d84837debf36800fdca0352 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Mon, 16 Dec 2024 22:42:56 +0800 Subject: [PATCH 28/42] refactor(devtools): remove deprecated material (#109) * fix: fix material.h and material_type.h * refactor: rename canDropWithAnyTool to requiresCorrectToolForDrops * refactor: remove material related things since these things are unused * docs: add a FIXME notice to biome.h --- include/bedrock/world/actor/actor.h | 1 - include/bedrock/world/level/biome/biome.h | 1 + include/bedrock/world/level/block/block.h | 19 +++-- .../bedrock/world/level/block/block_legacy.h | 10 ++- include/bedrock/world/level/block_source.h | 4 +- .../bedrock/world/level/material/material.h | 81 ------------------- .../world/level/material/material_type.h | 76 ----------------- .../endstone/detail/devtools/vanilla_data.h | 2 +- src/endstone_devtools/devtools.cpp | 9 --- src/endstone_devtools/vanilla_data.cpp | 32 ++------ .../world/level/block/block_legacy.cpp | 13 ++- 11 files changed, 36 insertions(+), 212 deletions(-) delete mode 100644 include/bedrock/world/level/material/material.h delete mode 100644 include/bedrock/world/level/material/material_type.h diff --git a/include/bedrock/world/actor/actor.h b/include/bedrock/world/actor/actor.h index 9f25de4e3..82afbe315 100644 --- a/include/bedrock/world/actor/actor.h +++ b/include/bedrock/world/actor/actor.h @@ -47,7 +47,6 @@ #include "bedrock/world/actor/actor_unique_id.h" #include "bedrock/world/actor/synched_actor_data_entity_wrapper.h" #include "bedrock/world/level/dimension/dimension.h" -#include "bedrock/world/level/material/material_type.h" #include "endstone/detail/actor/actor.h" class Player; diff --git a/include/bedrock/world/level/biome/biome.h b/include/bedrock/world/level/biome/biome.h index d159ec123..f99c954f7 100644 --- a/include/bedrock/world/level/biome/biome.h +++ b/include/bedrock/world/level/biome/biome.h @@ -51,6 +51,7 @@ class Biome { } private: + // FIXME: structure needs to be updated HashedString hash_; // +0 float temperature_; // +56 float downfall_; // +60 diff --git a/include/bedrock/world/level/block/block.h b/include/bedrock/world/level/block/block.h index 49da6bbbc..85295ab13 100644 --- a/include/bedrock/world/level/block/block.h +++ b/include/bedrock/world/level/block/block.h @@ -51,9 +51,9 @@ class Block { public: virtual ~Block() = default; - [[nodiscard]] bool canDropWithAnyTool() const + [[nodiscard]] bool requiresCorrectToolForDrops() const { - return legacy_block_->canDropWithAnyTool(); + return legacy_block_->requiresCorrectToolForDrops(); } [[nodiscard]] bool canContainLiquid() const @@ -61,6 +61,11 @@ class Block { return direct_data_.water_detection_rule.can_contain_liquid; } + [[nodiscard]] bool isSolid() const + { + return legacy_block_->isSolid(); + } + [[nodiscard]] const CompoundTag &getSerializationId() const { return serialization_id_; @@ -106,11 +111,6 @@ class Block { return direct_data_.light_emission; } - [[nodiscard]] const Material &getMaterial() const - { - return legacy_block_->getMaterial(); - } - [[nodiscard]] const std::vector &getTags() const { if (!tags_.empty()) { @@ -124,6 +124,11 @@ class Block { return legacy_block_->getThickness(); } + [[nodiscard]] float getTranslucency() const + { + return legacy_block_->getTranslucency(); + } + [[nodiscard]] const BlockLegacy &getLegacyBlock() const { return *legacy_block_; diff --git a/include/bedrock/world/level/block/block_legacy.h b/include/bedrock/world/level/block/block_legacy.h index d164f5f6a..fccad92f8 100644 --- a/include/bedrock/world/level/block/block_legacy.h +++ b/include/bedrock/world/level/block/block_legacy.h @@ -32,7 +32,6 @@ #include "bedrock/world/level/block/block_state_instance.h" #include "bedrock/world/level/block/components/block_component_storage.h" #include "bedrock/world/level/block_pos.h" -#include "bedrock/world/level/material/material.h" #include "bedrock/world/phys/aabb.h" class Actor; @@ -44,6 +43,8 @@ class IConstBlockSource; class ItemStack; class ItemInstance; class Player; +class Material; +class MaterialType; enum class BlockProperty : std::uint64_t { None = 0x0, @@ -275,9 +276,10 @@ class BlockLegacy { virtual void _onHitByActivatingAttack(BlockSource &, BlockPos const &, Actor *) const = 0; virtual void entityInside(BlockSource &, BlockPos const &, Actor &) const = 0; - [[nodiscard]] bool canDropWithAnyTool() const; + [[nodiscard]] bool requiresCorrectToolForDrops() const; + [[nodiscard]] bool isSolid() const; [[nodiscard]] float getThickness() const; - [[nodiscard]] const Material &getMaterial() const; + [[nodiscard]] float getTranslucency() const; [[nodiscard]] const std::vector &getTags() const; [[nodiscard]] const std::string &getDescriptionId() const; [[nodiscard]] const std::string &getFullNameId() const; @@ -353,6 +355,6 @@ class BlockLegacy { std::unique_ptr block_state_group_; // std::unique_ptr resource_drops_strategy_; // IntRange experience_drop_; // - bool can_drop_with_any_tool_; // + bool requires_correct_tool_for_drops; // // ... }; diff --git a/include/bedrock/world/level/block_source.h b/include/bedrock/world/level/block_source.h index 8fa17117a..c76dbe304 100644 --- a/include/bedrock/world/level/block_source.h +++ b/include/bedrock/world/level/block_source.h @@ -25,11 +25,11 @@ #include "bedrock/world/level/block_source_interface.h" #include "bedrock/world/level/chunk/level_chunk.h" #include "bedrock/world/level/level_seed.h" -#include "bedrock/world/level/material/material.h" -#include "bedrock/world/level/material/material_type.h" class ILevel; class Level; +class Material; +class MaterialType; using ActorSpan = gsl::span>; diff --git a/include/bedrock/world/level/material/material.h b/include/bedrock/world/level/material/material.h deleted file mode 100644 index afc322e9a..000000000 --- a/include/bedrock/world/level/material/material.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include "bedrock/world/level/material/material_type.h" - -class Material { -public: - [[nodiscard]] MaterialType getType() const - { - return type_; - } - - [[nodiscard]] bool isNeverBuildable() const - { - return never_buildable_; - } - - [[nodiscard]] bool isAlwaysDestroyable() const - { - return always_destroyable_; - } - - [[nodiscard]] bool isLiquid() const - { - return is_liquid_; - } - - [[nodiscard]] float getTranslucency() const - { - return translucency_; - } - - [[nodiscard]] bool getBlocksMotion() const - { - return blocks_motion_; - } - - [[nodiscard]] bool getBlocksPrecipitation() const - { - return blocks_precipitation_; - } - - [[nodiscard]] bool isSolid() const - { - return solid_; - } - - [[nodiscard]] bool isSuperHot() const - { - return super_hot_; - } - - [[nodiscard]] bool isSolidBlocking() const - { - return !never_buildable_ && blocks_motion_; - } - -private: - MaterialType type_; // +0 - bool never_buildable_; // +4 - bool always_destroyable_; // +5 - bool is_liquid_; // +6 - float translucency_; // +8 - bool blocks_motion_; // +12 - bool blocks_precipitation_; // +13 - bool solid_; // +14 - bool super_hot_; // +15 -}; diff --git a/include/bedrock/world/level/material/material_type.h b/include/bedrock/world/level/material/material_type.h deleted file mode 100644 index a48fee2a4..000000000 --- a/include/bedrock/world/level/material/material_type.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -/** - * Material type from StringFromMaterialType - */ -enum class MaterialType { - Air = 0, - Dirt = 1, - Wood = 2, - Stone = 3, - Metal = 4, - Water = 5, - Lava = 6, - Leaves = 7, - Plant = 8, - SolidPlant = 9, - Sponge = 10, - Cloth = 11, - Bed = 12, - Fire = 13, - Sand = 14, - Decoration = 15, - Glass = 16, - Explosive = 17, - Ice = 18, - PackedIce = 19, - TopSnow = 20, - Snow = 21, - PowderSnow = 22, - Amethyst = 23, - Cactus = 24, - Clay = 25, - Vegetable = 26, - Portal = 27, - Cake = 28, - Web = 29, - RedstoneWire = 30, - Carpet = 31, - BuildableGlass = 32, - Slime = 33, - Piston = 34, - Allow = 35, - Deny = 36, - Netherwart = 37, - StoneDecoration = 38, - Bubble = 39, - Egg = 40, - SoftEgg = 41, - Barrier = 42, - Coral = 43, - DecorationSolid = 44, - Dripstone = 45, - ReinforcedStone = 46, - Sculk = 47, - SculkVein = 48, - ClientRequestPlaceholder = 49, - StructureVoid = 50, - Root = 51, - Shulker = 52, - SurfaceTypeTotal = 53, - Any = 54, -}; diff --git a/include/endstone/detail/devtools/vanilla_data.h b/include/endstone/detail/devtools/vanilla_data.h index bff648add..0b8696228 100644 --- a/include/endstone/detail/devtools/vanilla_data.h +++ b/include/endstone/detail/devtools/vanilla_data.h @@ -25,7 +25,7 @@ struct VanillaData { nlohmann::json block_states; nlohmann::json block_tags; ::ListTag block_palette; - nlohmann::json materials; + // nlohmann::json materials; nlohmann::json items; ::ListTag creative_items; nlohmann::json item_tags; diff --git a/src/endstone_devtools/devtools.cpp b/src/endstone_devtools/devtools.cpp index c81fd68fa..c621fe591 100644 --- a/src/endstone_devtools/devtools.cpp +++ b/src/endstone_devtools/devtools.cpp @@ -196,10 +196,6 @@ void render() file_to_save = data->block_tags; openFileBrowser("Save Block Tags", "block_tags.json"); } - if (ImGui::MenuItem("Materials")) { - file_to_save = data->materials; - openFileBrowser("Save Materials", "materials.json"); - } if (ImGui::MenuItem("Items")) { file_to_save = data->items; openFileBrowser("Save Items", "items.json"); @@ -388,10 +384,6 @@ void showBlockWindow(bool *open) ImGui::Json(data->block_tags); } - if (ImGui::CollapsingHeader(fmt::format("{} Materials", data->materials.size()).c_str())) { - ImGui::Json(data->materials); - } - if (ImGui::CollapsingHeader("Block Palette")) { ImGui::Json(NbtIo::toJson(data->block_palette)); } @@ -538,7 +530,6 @@ void exportAll(const std::filesystem::path &base_path, const VanillaData *data) save_json_to_file(data->block_types, "block_types.json"); save_json_to_file(data->block_states, "block_states.json"); save_json_to_file(data->block_tags, "block_tags.json"); - save_json_to_file(data->materials, "materials.json"); save_json_to_file(data->items, "items.json"); save_json_to_file(data->item_tags, "item_tags.json"); save_json_to_file(data->biomes, "biomes.json"); diff --git a/src/endstone_devtools/vanilla_data.cpp b/src/endstone_devtools/vanilla_data.cpp index 84aa58877..f75714404 100644 --- a/src/endstone_devtools/vanilla_data.cpp +++ b/src/endstone_devtools/vanilla_data.cpp @@ -50,21 +50,8 @@ void dumpBlockData(VanillaData &data, ::Level &level) auto item_registry = level.getItemRegistry(); BlockTypeRegistry::forEachBlock([&](const BlockLegacy &block_legacy) { - const auto &material = block_legacy.getMaterial(); - auto material_name = magic_enum::enum_name(material.getType()); - data.materials[material_name] = { - {"isNeverBuildable", material.isNeverBuildable()}, - {"isAlwaysDestroyable", material.isAlwaysDestroyable()}, - {"isLiquid", material.isLiquid()}, - {"translucency", round(material.getTranslucency())}, - {"blocksMotion", material.getBlocksMotion()}, - {"blocksPrecipitation", material.getBlocksPrecipitation()}, - {"isSolid", material.isSolid()}, - {"isSuperHot", material.isSuperHot()}, - {"isSolidBlocking", material.isSolidBlocking()}, - }; - const auto &name = block_legacy.getFullNameId(); + nlohmann::json tags; for (const auto &tag : block_legacy.getTags()) { auto tag_name = tag.getString(); @@ -79,22 +66,11 @@ void dumpBlockData(VanillaData &data, ::Level &level) data.block_tags[tag_name].push_back(name); } - data.block_types[name] = {{"material", magic_enum::enum_name(material.getType())}}; + data.block_types[name] = {{"defaultBlockStateHash", block_legacy.getDefaultState()->getRuntimeId()}}; if (!tags.is_null()) { data.block_types[name]["tags"] = tags; } - nlohmann::json special_tools; - for (const auto &[key, item] : item_registry.getNameToItemMap()) { - if (item->canDestroySpecial(*block_legacy.getDefaultState())) { - special_tools.push_back(item->getFullItemName()); - } - } - if (!special_tools.is_null()) { - data.block_types[name]["specialTools"] = special_tools; - } - data.block_types[name]["defaultBlockStateHash"] = block_legacy.getDefaultState()->getRuntimeId(); - block_legacy.forEachBlockPermutation([&](const ::Block &block) { AABB collision_shape; AABB outline_shape; @@ -119,7 +95,9 @@ void dumpBlockData(VanillaData &data, ::Level &level) {"friction", round(block.getFriction())}, {"hardness", round(block.getDestroySpeed())}, {"canContainLiquid", block.canContainLiquid()}, - // {"canDropWithAnyTool", block.canDropWithAnyTool()}, + {"requiresCorrectToolForDrops", block.requiresCorrectToolForDrops()}, + {"isSolid", block.isSolid()}, + {"translucency", block.getTranslucency()}, {"mapColor", map_color.toHexString()}, {"collisionShape", { diff --git a/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp index 9abf485c1..d2558aad0 100644 --- a/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp +++ b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp @@ -14,9 +14,14 @@ #include "bedrock/world/level/block/block_legacy.h" -bool BlockLegacy::canDropWithAnyTool() const +bool BlockLegacy::requiresCorrectToolForDrops() const { - return can_drop_with_any_tool_; + return requires_correct_tool_for_drops; +} + +bool BlockLegacy::isSolid() const +{ + return solid_; } float BlockLegacy::getThickness() const @@ -24,9 +29,9 @@ float BlockLegacy::getThickness() const return thickness_; } -const Material &BlockLegacy::getMaterial() const +float BlockLegacy::getTranslucency() const { - return *material_; + return translucency_; } const std::vector &BlockLegacy::getTags() const From 7561b70c35218f2b146aaaf1079aa2accce762fe Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 16 Dec 2024 14:54:07 +0000 Subject: [PATCH 29/42] fix: update Biome class members --- include/bedrock/common_types.h | 9 ++ include/bedrock/world/level/biome/biome.h | 87 ++++++++++--------- .../biome/components/biome_component_base.h | 21 +++++ .../components/biome_component_storage.h | 26 ++++++ .../world/level/biome/mob_spawner_data.h | 17 ++++ 5 files changed, 118 insertions(+), 42 deletions(-) create mode 100644 include/bedrock/world/level/biome/components/biome_component_base.h create mode 100644 include/bedrock/world/level/biome/components/biome_component_storage.h create mode 100644 include/bedrock/world/level/biome/mob_spawner_data.h diff --git a/include/bedrock/common_types.h b/include/bedrock/common_types.h index e5b07cf7a..16feed581 100644 --- a/include/bedrock/common_types.h +++ b/include/bedrock/common_types.h @@ -20,6 +20,9 @@ #include "bedrock/util/new_type.h" using ActorList = std::vector; +using BlockActorList = std::vector; +using MobList = std::vector>; +using MobCategoryMap = std::array>, 8UL>; enum class SubClientId : std::uint8_t { PrimaryClient = 0, @@ -31,13 +34,19 @@ enum class SubClientId : std::uint8_t { }; using BlockRuntimeId = std::uint32_t; +using BiomeIdType = std::uint16_t; + struct NewBlockID : NewType {}; +static_assert(sizeof(NewBlockID) == 2); struct Brightness : NewType {}; +static_assert(sizeof(Brightness) == 1); + struct BrightnessPair { Brightness sky; Brightness block; }; +static_assert(sizeof(BrightnessPair) == 2); using DataID = std::uint16_t; using FacingID = std::uint8_t; diff --git a/include/bedrock/world/level/biome/biome.h b/include/bedrock/world/level/biome/biome.h index f99c954f7..84a055adb 100644 --- a/include/bedrock/world/level/biome/biome.h +++ b/include/bedrock/world/level/biome/biome.h @@ -16,61 +16,64 @@ #include -#include "bedrock/core/math/color.h" -#include "bedrock/forward.h" -#include "bedrock/gamerefs/weak_ref.h" +#include "bedrock/common_types.h" +#include "bedrock/world/level/biome/components/biome_component_storage.h" +#include "bedrock/world/level/biome/mob_spawner_data.h" -class Biome { - enum class OceanTempCategory : std::int32_t { - COLD = 0, - WARM = 1, - }; - - struct CachedClientComponentData { - bool has_noise_based_color_palette; - bool is_roofed_forest; - }; +enum class OceanTempCategory { + COLD = 0, + WARM = 1, +}; - struct OceanRuinConfiguration { - OceanTempCategory type; - float large_probability; - float cluster_probability; - }; +struct OceanRuinConfiguration { + OceanTempCategory type; + float large_probability; + float cluster_probability; +}; +class Biome { public: virtual ~Biome() = 0; [[nodiscard]] const std::string &getName() const { - return hash_.getString(); + return hash.getString(); } - [[nodiscard]] int getId() const + [[nodiscard]] BiomeIdType getId() const { return id_; } + HashedString hash; // +8 + float temperature; // +56 + float downfall; // +60 + float red_spore_density; // +64 + float blue_spore_density; // +68 + float ash_density; // +72 + float white_ash_density; // +76 + float snow_accumulation; // +80 + float foliage_snow; // +84 + float min_snow_level; // +88 + float max_snow_level; // +92 + float depth; // +96 + float scale; // +100 + int map_water_color; // +104 + float water_transparency; // +108 + bool rain; // +112 + OceanRuinConfiguration ocean_ruin_config; // +116 + +protected: + MobList mobs_; // +128 + MobCategoryMap mobs_map_; // +152 + struct CachedClientComponentData { + bool has_noise_based_color_palette; + bool is_roofed_forest; + }; + static_assert(sizeof(CachedClientComponentData) == 2); + CachedClientComponentData cached_client_component_data_; // +344 + private: - // FIXME: structure needs to be updated - HashedString hash_; // +0 - float temperature_; // +56 - float downfall_; // +60 - float red_spore_density_; // +64 - float blue_spore_density_; // +68 - float ash_density_; // +72 - float white_ash_density_; // +76 - float snow_accumulation_; // +80 - float foliage_snow_; // +84 - float min_snow_level_; // +88 - float max_snow_level_; // +92 - float depth_; // +96 - float scale_; // +100 - mce::Color water_color_; // +104 - float water_transparency_; // +120 - bool rain_; // +124 - OceanRuinConfiguration ocean_ruin_config_; // +128 - std::vector> mobs_; // +144 void* = MobSpawnerData - CachedClientComponentData cached_client_component_data_; // +168 - std::uint16_t id_; // +170 - // BiomeComponentStorage biome_component_storage_; + BiomeIdType id_; // +346 + BiomeComponentStorage biome_component_storage_; // +352 }; diff --git a/include/bedrock/world/level/biome/components/biome_component_base.h b/include/bedrock/world/level/biome/components/biome_component_base.h new file mode 100644 index 000000000..7ffbeb6a3 --- /dev/null +++ b/include/bedrock/world/level/biome/components/biome_component_base.h @@ -0,0 +1,21 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +struct BiomeComponentBase { + virtual ~BiomeComponentBase(); +}; +static_assert(sizeof(BiomeComponentBase) == 8); + diff --git a/include/bedrock/world/level/biome/components/biome_component_storage.h b/include/bedrock/world/level/biome/components/biome_component_storage.h new file mode 100644 index 000000000..51133d693 --- /dev/null +++ b/include/bedrock/world/level/biome/components/biome_component_storage.h @@ -0,0 +1,26 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "bedrock/core/utility/type_id.h" +#include "bedrock/world/level/biome/components/biome_component_base.h" + +class BiomeComponentStorage { +public: +private: + std::vector, std::unique_ptr>> component_list_; // +0 + bool allow_adding_components_; // +24 +}; +static_assert(sizeof(BiomeComponentStorage) == 32); diff --git a/include/bedrock/world/level/biome/mob_spawner_data.h b/include/bedrock/world/level/biome/mob_spawner_data.h new file mode 100644 index 000000000..ebbd0c86b --- /dev/null +++ b/include/bedrock/world/level/biome/mob_spawner_data.h @@ -0,0 +1,17 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +class MobSpawnerData {}; From 6f646e0a0cc86deaa40675451cb0e9f6c925d2e6 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 16 Dec 2024 15:49:29 +0000 Subject: [PATCH 30/42] ci: fix static_assert macros for class size checks --- .../world/level/biome/components/biome_component_base.h | 3 +-- .../world/level/biome/components/biome_component_storage.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/bedrock/world/level/biome/components/biome_component_base.h b/include/bedrock/world/level/biome/components/biome_component_base.h index 7ffbeb6a3..fa2c7c2f2 100644 --- a/include/bedrock/world/level/biome/components/biome_component_base.h +++ b/include/bedrock/world/level/biome/components/biome_component_base.h @@ -17,5 +17,4 @@ struct BiomeComponentBase { virtual ~BiomeComponentBase(); }; -static_assert(sizeof(BiomeComponentBase) == 8); - +BEDROCK_STATIC_ASSERT_SIZE(BiomeComponentBase, 8, 8); diff --git a/include/bedrock/world/level/biome/components/biome_component_storage.h b/include/bedrock/world/level/biome/components/biome_component_storage.h index 51133d693..4c6119337 100644 --- a/include/bedrock/world/level/biome/components/biome_component_storage.h +++ b/include/bedrock/world/level/biome/components/biome_component_storage.h @@ -23,4 +23,4 @@ class BiomeComponentStorage { std::vector, std::unique_ptr>> component_list_; // +0 bool allow_adding_components_; // +24 }; -static_assert(sizeof(BiomeComponentStorage) == 32); +BEDROCK_STATIC_ASSERT_SIZE(BiomeComponentStorage, 32, 32); From 8dd9acfc5c114edf5ee1e14d050e02863231bb24 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 16 Dec 2024 15:55:20 +0000 Subject: [PATCH 31/42] fix: player inventory not being updated after calling `clear` close #108 --- src/endstone_core/inventory/player_inventory.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/endstone_core/inventory/player_inventory.cpp b/src/endstone_core/inventory/player_inventory.cpp index 990c88287..d223fc80f 100644 --- a/src/endstone_core/inventory/player_inventory.cpp +++ b/src/endstone_core/inventory/player_inventory.cpp @@ -40,6 +40,7 @@ void EndstonePlayerInventory::setItem(int index, std::shared_ptr item void EndstonePlayerInventory::addItem(ItemStack &item) { EndstoneInventory::addItem(item); + holder_.sendInventory(false); } std::vector> EndstonePlayerInventory::getContents() const @@ -60,6 +61,7 @@ bool EndstonePlayerInventory::isEmpty() const void EndstonePlayerInventory::clear() { EndstoneInventory::clear(); + holder_.sendInventory(false); } } // namespace endstone::detail From e5bf28afca0c350ff8555217d53cec24926243a0 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 18:36:53 +0000 Subject: [PATCH 32/42] refactor: correct headers --- .../{application => }/app_platform_listener.h | 0 include/bedrock/certificates/certificate.h | 8 ++++---- include/bedrock/certificates/web_token.h | 16 +++++++++------ include/bedrock/network/connection_request.h | 2 +- .../network/sub_client_connection_request.h | 2 +- include/bedrock/server/server_instance.h | 2 +- src/endstone_runtime/CMakeLists.txt | 1 + .../bedrock/certificates/certificate.cpp | 4 ++-- .../bedrock/certificates/web_token.cpp | 20 +++++++++++++++++++ 9 files changed, 40 insertions(+), 15 deletions(-) rename include/bedrock/{application => }/app_platform_listener.h (100%) create mode 100644 src/endstone_runtime/bedrock/certificates/web_token.cpp diff --git a/include/bedrock/application/app_platform_listener.h b/include/bedrock/app_platform_listener.h similarity index 100% rename from include/bedrock/application/app_platform_listener.h rename to include/bedrock/app_platform_listener.h diff --git a/include/bedrock/certificates/certificate.h b/include/bedrock/certificates/certificate.h index 6962ab2da..b2cd8dee8 100644 --- a/include/bedrock/certificates/certificate.h +++ b/include/bedrock/certificates/certificate.h @@ -32,8 +32,8 @@ class Certificate { [[nodiscard]] bool isSelfSigned() const; private: - UnverifiedCertificate unverified_certificate_; // +0 - std::unique_ptr parent_; // +136 - bool valid_; // +144 - bool self_signed_; // +145 + UnverifiedCertificate unverified_certificate_; // +0 + std::unique_ptr parent_certificate_; // +136 + bool is_valid_; // +144 + bool is_self_signed_; // +145 }; diff --git a/include/bedrock/certificates/web_token.h b/include/bedrock/certificates/web_token.h index b465e8af2..3d711679e 100644 --- a/include/bedrock/certificates/web_token.h +++ b/include/bedrock/certificates/web_token.h @@ -16,10 +16,14 @@ #include "bedrock/deps/json/value.h" -struct WebToken { - std::string header; // +0 - Json::Value header_info; // +32 - std::string data; // +48 - Json::Value data_info; // +80 - std::string signature; // +96 +class WebToken { +public: + Json::Value const &getData() const; + +private: + std::string header_; // +0 + Json::Value header_info_; // +32 + std::string data_; // +48 + Json::Value data_info_; // +80 + std::string signature_; // +96 }; diff --git a/include/bedrock/network/connection_request.h b/include/bedrock/network/connection_request.h index 3775753fd..a5323d2bc 100644 --- a/include/bedrock/network/connection_request.h +++ b/include/bedrock/network/connection_request.h @@ -27,7 +27,7 @@ class ConnectionRequest { [[nodiscard]] Json::Value getData(const std::string &key) const { if (certificate_ && raw_token_) { - return raw_token_->data_info.get(key, Json::nullValue); + return raw_token_->getData().get(key, Json::nullValue); } return Json::nullValue; } diff --git a/include/bedrock/network/sub_client_connection_request.h b/include/bedrock/network/sub_client_connection_request.h index 027ece2a5..858127a31 100644 --- a/include/bedrock/network/sub_client_connection_request.h +++ b/include/bedrock/network/sub_client_connection_request.h @@ -26,7 +26,7 @@ class SubClientConnectionRequest { [[nodiscard]] Json::Value getData(const std::string &key) const { if (certificate_ && raw_token_) { - return raw_token_->data_info.get(key, Json::nullValue); + return raw_token_->getData().get(key, Json::nullValue); } return Json::nullValue; } diff --git a/include/bedrock/server/server_instance.h b/include/bedrock/server/server_instance.h index 613293971..1fe1e663e 100644 --- a/include/bedrock/server/server_instance.h +++ b/include/bedrock/server/server_instance.h @@ -14,7 +14,7 @@ #pragma once -#include "bedrock/application/app_platform_listener.h" +#include "bedrock/app_platform_listener.h" #include "bedrock/core/file/storage_area_state_listener.h" #include "bedrock/world/game_callbacks.h" #include "bedrock/world/minecraft.h" diff --git a/src/endstone_runtime/CMakeLists.txt b/src/endstone_runtime/CMakeLists.txt index 863bef7e9..e3aa0a947 100644 --- a/src/endstone_runtime/CMakeLists.txt +++ b/src/endstone_runtime/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(endstone_runtime SHARED bedrock/shared_constants.cpp bedrock/certificates/certificate.cpp bedrock/certificates/extended_certificate.cpp + bedrock/certificates/web_token.cpp bedrock/config/player_capabilities.cpp bedrock/core/debug/bedrock_event_logger.cpp bedrock/core/file/path.cpp diff --git a/src/endstone_runtime/bedrock/certificates/certificate.cpp b/src/endstone_runtime/bedrock/certificates/certificate.cpp index d66813a33..aee27a021 100644 --- a/src/endstone_runtime/bedrock/certificates/certificate.cpp +++ b/src/endstone_runtime/bedrock/certificates/certificate.cpp @@ -22,10 +22,10 @@ Json::Value Certificate::getExtraData(const std::string &key, const Json::Value bool Certificate::isValid() const { - return valid_; + return is_valid_; } bool Certificate::isSelfSigned() const { - return self_signed_; + return is_self_signed_; } diff --git a/src/endstone_runtime/bedrock/certificates/web_token.cpp b/src/endstone_runtime/bedrock/certificates/web_token.cpp new file mode 100644 index 000000000..da1b7951d --- /dev/null +++ b/src/endstone_runtime/bedrock/certificates/web_token.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bedrock/certificates/web_token.h" + +Json::Value const &WebToken::getData() const +{ + return data_info; +} From 5113f6bbf613cfb4641f38deb9600e9556436577 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 18:37:34 +0000 Subject: [PATCH 33/42] feat: add an overload for `/ban` command for player name auto-completion --- src/endstone_core/command/defaults/ban_command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endstone_core/command/defaults/ban_command.cpp b/src/endstone_core/command/defaults/ban_command.cpp index 175fbbe58..b6186f746 100644 --- a/src/endstone_core/command/defaults/ban_command.cpp +++ b/src/endstone_core/command/defaults/ban_command.cpp @@ -24,7 +24,7 @@ namespace endstone::detail { BanCommand::BanCommand() : EndstoneCommand("ban") { setDescription("commands.ban.description"); - setUsages("/ban [reason: message]"); + setUsages("/ban [reason: message]", "/ban [reason: message]"); setPermissions("endstone.command.ban"); } From 14a484627cd35321fdf266dc50ce743dc493b6e6 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 20:57:17 +0000 Subject: [PATCH 34/42] refactor: update members in CommandRegistry --- include/bedrock/certificates/web_token.h | 2 +- include/bedrock/server/commands/command.h | 2 +- .../server/commands/command_registry.h | 301 +++++++++++------- include/endstone/detail/command/command_map.h | 1 + src/endstone_core/command/command_map.cpp | 55 ++-- .../bedrock/certificates/certificate.cpp | 2 +- .../bedrock/certificates/web_token.cpp | 2 +- 7 files changed, 218 insertions(+), 147 deletions(-) diff --git a/include/bedrock/certificates/web_token.h b/include/bedrock/certificates/web_token.h index 3d711679e..882e23dc4 100644 --- a/include/bedrock/certificates/web_token.h +++ b/include/bedrock/certificates/web_token.h @@ -18,7 +18,7 @@ class WebToken { public: - Json::Value const &getData() const; + [[nodiscard]] Json::Value const &getData() const; private: std::string header_; // +0 diff --git a/include/bedrock/server/commands/command.h b/include/bedrock/server/commands/command.h index 62a261baf..b6d8a6437 100644 --- a/include/bedrock/server/commands/command.h +++ b/include/bedrock/server/commands/command.h @@ -48,6 +48,6 @@ class Command { CommandRegistry *registry_{nullptr}; // +16 CommandRegistry::Symbol command_symbol_; // +24 CommandPermissionLevel permission_level_ = CommandPermissionLevel::Internal; // +28 - CommandFlag flags_{0}; // +30 + CommandFlag flags_; // +30 }; BEDROCK_STATIC_ASSERT_SIZE(Command, 32, 32); diff --git a/include/bedrock/server/commands/command_registry.h b/include/bedrock/server/commands/command_registry.h index efd477bf9..ee5f9d2ee 100644 --- a/include/bedrock/server/commands/command_registry.h +++ b/include/bedrock/server/commands/command_registry.h @@ -32,16 +32,47 @@ #include "bedrock/server/commands/command_permission_level.h" #include "bedrock/server/commands/command_version.h" -enum SemanticConstraint : std::uint8_t; - class Command; +class CommandRunStats; class CommandParameterData; +enum class SemanticConstraint; + +namespace endstone::detail { +class EndstoneCommandMap; +} + +enum class CommandParameterDataType : int { + Basic = 0, + Enum = 1, + SoftEnum = 2, + Postfix = 3, + ChainedSubcommand = 4, +}; class CommandRegistry { + friend class CommandParameterData; + +public: + ENDSTONE_HOOK int addEnumValues(const std::string &name, const std::vector &values); + + ENDSTONE_HOOK void registerCommand(const std::string &name, char const *description, CommandPermissionLevel level, + CommandFlag flag1, CommandFlag flag2); + ENDSTONE_HOOK void registerAlias(std::string name, std::string alias); + +private: + using CommandOverrideFunctor = std::function; + public: - static constexpr int NonTerminalBit = 0x100000; - static constexpr int FirstNonTerminal = 0x100001; - enum class HardNonTerminal : std::uint32_t { + [[nodiscard]] ENDSTONE_HOOK AvailableCommandsPacket serializeAvailableCommands() const; + +private: + using ScoreboardScoreAccessor = std::function; + +public: + static const int NonTerminalBit = 0x100000; + static const int FirstNonTerminal = 0x100001; + + enum class HardNonTerminal { // Endstone: private -> public Epsilon = NonTerminalBit, Int = 0x100001, Float = 0x100002, @@ -137,64 +168,64 @@ class CommandRegistry { }; class Symbol { - static constexpr int EnumBit = 0x200000; - static constexpr int OptionalBit = 0x400000; - static constexpr int FactorizationBit = 0x800000; - static constexpr int PostfixBit = 0x1000000; - static constexpr int EnumValueBit = 0x2000000; - static constexpr int SoftEnumBit = 0x4000000; - static constexpr int ChainedSubcommandBit = 0x8000000; - static constexpr int ChainedSubcommandValueBit = 0x10000000; - public: - explicit Symbol(std::uint32_t value = 0) : value_(value){}; - explicit Symbol(HardNonTerminal value) : value_(static_cast(value)){}; + Symbol() = default; + Symbol(size_t value) : value_(static_cast(value)){}; + Symbol(HardNonTerminal value) : value_(static_cast(value)){}; - [[nodiscard]] std::uint32_t value() const + [[nodiscard]] int value() const { return value_; } - [[nodiscard]] std::uint64_t toIndex() const + [[nodiscard]] std::size_t toIndex() const { return value_ & 0xE00FFFFF; } private: - std::uint32_t value_; + static const int EnumBit = 0x200000; + static const int OptionalBit = 0x400000; + static const int FactorizationBit = 0x800000; + static const int PostfixBit = 0x1000000; + static const int EnumValueBit = 0x2000000; + static const int SoftEnumBit = 0x4000000; + static const int ChainedSubcommandBit = 0x8000000; + static const int ChainedSubcommandValueBit = 0x10000000; + int value_{-1}; }; + using NonTerminal = Symbol; + using Terminal = Symbol; + struct Overload { using AllocFunction = std::unique_ptr (*)(); - Overload(const CommandVersion &version, AllocFunction alloc) : version(version), alloc(alloc) {} CommandVersion version; // +0 AllocFunction alloc; // +8 std::vector params; // +16 std::int32_t version_offset{-1}; // +40 - bool chaining{false}; // +44 + bool is_chaining{false}; // +44 std::vector params_symbol; // +48 }; - struct Signature { - std::string name; // +0 - std::string description; // +32 - std::vector overloads; // +64 - std::vector chained_subcommand_indexes_values; // +88 - CommandPermissionLevel permission_level; // +112 - Symbol command_symbol; // +116 - Symbol command_alias_symbol; // +120 - CommandFlag flags; // +124 - int first_rule; // +128 - int first_factorization; // +132 - int first_optional; // +136 - bool runnable; // +140 - bool has_chained_subcommands; // +141 - bool finalized_chained_subcommands_subcommands; // +142 - std::int64_t rule_counter_; // +144 + std::string name; // +0 + std::string description; // +32 + std::vector overloads; // +64 + std::vector chained_subcommand_indexes; // +88 + CommandPermissionLevel permission_level; // +112 + Symbol command_symbol; // +116 + Symbol command_alias_enum; // +120 + CommandFlag flags; // +124 + int first_rule; // +128 + int first_factorization; // +132 + int first_optional; // +136 + bool runnable; // +140 + bool has_chained_subcommands; // +141 + bool finalized_chained_subcommands; // +142 + std::int64_t rule_counter; // +144 }; - struct ParseToken { std::unique_ptr child; // +0 std::unique_ptr next; // +8 @@ -204,34 +235,63 @@ class CommandRegistry { Symbol type; // +36 }; BEDROCK_STATIC_ASSERT_SIZE(CommandRegistry::ParseToken, 40, 40); - + friend struct fmt::formatter; + struct ParseRule; + struct OptionalParameterChain; + struct Factorization; using ParseFunction = bool (CommandRegistry::*)(void *, const ParseToken &, const CommandOrigin &, int, std::string &, std::vector &) const; - using CommandOverrideFunctor = std::function; - - template - bool parse(void *value, const ParseToken &parse_token, const CommandOrigin &, int, std::string &, - std::vector &) const; - - class ParseTable; struct Enum { std::string name; // +0 Bedrock::typeid_t type; // +32 ParseFunction parse; // +40 - std::vector> values; // +48 + std::vector> values; // +48 }; - class SoftEnum; - class OptionalParameterChain; - class ConstrainedValue; - class RegistryState; struct ChainedSubcommand; - struct Factorization; + struct SoftEnum; + struct ConstrainedValue; + struct ParamSymbols { + Terminal x; // +0 + Terminal y; // +4 + Terminal z; // +8 + Terminal dx; // +12 + Terminal dy; // +16 + Terminal dz; // +20 + Terminal r; // +24 + Terminal rm; // +28 + Terminal rx; // +32 + Terminal rxm; // +36 + Terminal ry; // +40 + Terminal rym; // +44 + Terminal l; // +48 + Terminal lm; // +52 + Terminal c; // +56 + Terminal m; // +60 + Terminal name; // +64 + Terminal type; // +68 + Terminal family; // +72 + Terminal score; // +76 + Terminal tag; // +80 + Terminal hasitem; // +84 + Terminal haspermission; // +88 + Terminal hasproperty; // +92 + Terminal codebuilder; // +96 + }; + BEDROCK_STATIC_ASSERT_SIZE(ParamSymbols, 100, 100); - ENDSTONE_HOOK void registerCommand(const std::string &name, char const *description, CommandPermissionLevel level, - CommandFlag flag1, CommandFlag flag2); - ENDSTONE_HOOK void registerAlias(std::string name, std::string alias); - ENDSTONE_HOOK int addEnumValues(const std::string &name, const std::vector &values); - [[nodiscard]] ENDSTONE_HOOK AvailableCommandsPacket serializeAvailableCommands() const; +public: + struct RegistryState; + + // Endstone begins + friend class endstone::detail::EndstoneCommandMap; + std::string describe(const Signature &signature, const Overload &overload) + { + return describe(signature, signature.name, overload, 0, nullptr, nullptr); + } + + template + bool parse(void *value, const ParseToken &parse_token, const CommandOrigin &, int, std::string &, + std::vector &) const; template static std::unique_ptr allocateCommand() @@ -254,45 +314,11 @@ class CommandRegistry { registerOverloadInternal(*signature, overload); return &signature->overloads.back(); } - - std::string describe(const Signature &signature, const Overload &overload) - { - return describe(signature, signature.name, overload, 0, nullptr, nullptr); - } - - std::function network_update_callback; // +0 - std::function get_score_for_objective; // +56 - bool edu_mode; // +128 - std::vector rules; // +136 - std::map parse_tables; // +160 - std::vector optionals; // +176 - std::vector enum_values; // +200 - std::vector enums; // +224 - std::vector chained_subcommand_values; // +248 - std::vector chained_subcommands; // +272 - std::vector factorizations; // +296 - std::vector postfixes; // +320 - std::map enum_lookup; // +344 - std::map enum_value_lookup; // +360 - std::map chained_subcommand_lookup; // +376 - std::map chained_subcommand_value_lookup; // +392 - std::vector command_symbols; // +408 - std::map signatures; // +432 - std::map, std::int32_t> type_lookup; // +448 - std::map aliases; // +464 - std::vector semantic_constraints; // +480 - std::map semantic_constraint_lookup; // +504 - std::vector constrained_values; // +520 - std::map, std::uint32_t> constrained_value_lookup; // +544 - std::vector soft_enums; // +560 - std::map soft_enum_lookup; // +584 - std::vector state_stack; // +600 - char param_symbols[100]; // +624 - std::unordered_set skip_on_eps_autocomplete_symbols; // +728 - std::unordered_set allow_empty_symbols; // +792 - CommandOverrideFunctor command_override_functor; + // Endstone ends private: + struct ParseTable; + [[nodiscard]] ENDSTONE_HOOK const Signature *findCommand(const std::string &name) const; [[nodiscard]] ENDSTONE_HOOK std::unique_ptr createCommand(const ParseToken &parse_token, const CommandOrigin &origin, int version, @@ -302,15 +328,41 @@ class CommandRegistry { [[nodiscard]] ENDSTONE_HOOK std::string describe(const Signature &signature, const std::string &name, const Overload &overload, unsigned int a4, unsigned int *a5, unsigned int *a6) const; - ENDSTONE_HOOK void registerOverloadInternal(Signature &signature, Overload &overload); -}; -enum class CommandParameterDataType : int { - Basic = 0, - Enum = 1, - SoftEnum = 2, - Postfix = 3 + std::function network_update_callback_; // +0 + ScoreboardScoreAccessor get_score_for_objective_; // +56 + bool is_edu_mode_; // +128 + std::vector rules_; // +136 + using ParseTableMap = std::map; // + ParseTableMap parse_tables_; // +160 + std::vector optionals_; // +176 + std::vector enum_values_; // +200 + std::vector enums_; // +224 + std::vector chained_subcommand_values_; // +248 + std::vector chained_subcommands_; // +272 + std::vector factorizations_; // +296 + std::vector postfixes_; // +320 + std::map enum_lookup_; // +344 + std::map enum_value_lookup_; // +360 + std::map chained_subcommand_lookup_; // +376 + std::map chained_subcommand_value_lookup_; // +392 + std::vector command_symbols_; // +408 + std::map signatures_; // +432 + std::map, std::int32_t> type_lookup_; // +448 + std::map aliases_; // +464 + std::vector semantic_constraints_; // +480 + std::map semantic_constraint_lookup_; // +504 + std::vector constrained_values_; // +520 + std::map, std::uint32_t> constrained_value_lookup_; // +544 + std::vector soft_enums_; // +560 + std::map soft_enum_lookup_; // +584 + std::vector state_stack_; // +600 + ParamSymbols args_; // +624 + std::unordered_set skip_on_eps_autocomplete_symbols_; // +728 + std::unordered_set allow_empty_symbols_; // +792 + CommandOverrideFunctor command_override_functor_; + std::unique_ptr command_run_stats_; }; enum class CommandParameterOption : std::uint8_t { @@ -320,32 +372,43 @@ enum class CommandParameterOption : std::uint8_t { EnumAsChainedCommand = 4 }; +enum class SemanticConstraint { + None = 0, + RequiresCheatsEnabled = 1, + RequiresElevatedPermissions = 2, + RequiresHostPermissions = 4, + RequiresAllowAliases = 8, + VALUE_MASK = 15, +}; + class CommandParameterData { + using ParseFunction = CommandRegistry::ParseFunction; + public: - CommandParameterData(Bedrock::typeid_t type, CommandRegistry::ParseFunction parse, - char const *name, CommandParameterDataType param_type, char const *enum_name, - char const *fallback_typename, int offset, bool is_optional, int set_offset) - : type(type), parse(parse), name(name), enum_name(enum_name), fallback_typename(fallback_typename), - param_type(param_type), offset(offset), set_offset(set_offset), is_optional(is_optional) + CommandParameterData(Bedrock::typeid_t type_index, ParseFunction parse, char const *name, + CommandParameterDataType param_type, char const *enum_name_or_postfix, + char const *chained_subcommand, int offset, bool is_optional, int set_offset) + : type_index(type_index), parse(parse), name(name), enum_name_or_postfix(enum_name_or_postfix), + chained_subcommand(chained_subcommand), param_type(param_type), offset(offset), set_offset(set_offset), + is_optional(is_optional) { } - Bedrock::typeid_t type; // +0 - CommandRegistry::ParseFunction parse; // +8 - std::string name; // +16 - const char *enum_name; // +48 - CommandRegistry::Symbol enum_symbol{static_cast(-1)}; // +56 - const char *fallback_typename; // +64 - CommandRegistry::Symbol fallback_symbol{static_cast(-1)}; // +72 - CommandParameterDataType param_type; // +76 - int offset; // +80 - int set_offset; // +84 - bool is_optional; // +88 - CommandParameterOption options{CommandParameterOption::None}; // +89 + Bedrock::typeid_t type_index; // +0 + ParseFunction parse; // +8 + std::string name; // +16 + const char *enum_name_or_postfix; // +48 + int enum_or_postfix_symbol{-1}; // +56 + const char *chained_subcommand; // +64 + int chained_subcommand_symbol{-1}; // +72 + CommandParameterDataType param_type; // +76 + int offset; // +80 + int set_offset; // +84 + bool is_optional; // +88 + CommandParameterOption options{CommandParameterOption::None}; // +89 }; namespace fmt { - template <> struct formatter : formatter { using Type = CommandRegistry::ParseToken; diff --git a/include/endstone/detail/command/command_map.h b/include/endstone/detail/command/command_map.h index 2b891e906..2b8599253 100644 --- a/include/endstone/detail/command/command_map.h +++ b/include/endstone/detail/command/command_map.h @@ -38,6 +38,7 @@ class EndstoneCommandMap : public CommandMap { void setMinecraftCommands(); void setPluginCommands(); + void patchCommandRegistry(); void saveCommandRegistryState() const; void restoreCommandRegistryState() const; diff --git a/src/endstone_core/command/command_map.cpp b/src/endstone_core/command/command_map.cpp index dad912c62..2685fa0a9 100644 --- a/src/endstone_core/command/command_map.cpp +++ b/src/endstone_core/command/command_map.cpp @@ -42,6 +42,7 @@ namespace endstone::detail { EndstoneCommandMap::EndstoneCommandMap(EndstoneServer &server) : server_(server) { + patchCommandRegistry(); saveCommandRegistryState(); setMinecraftCommands(); setDefaultCommands(); @@ -116,11 +117,8 @@ void EndstoneCommandMap::setMinecraftCommands() { auto ®istry = server_.getMinecraftCommands().getRegistry(); - // Override commands - registry.signatures.erase("reload"); - std::unordered_map> command_aliases; - for (const auto &[alias, command_name] : registry.aliases) { + for (const auto &[alias, command_name] : registry.aliases_) { auto it = command_aliases.emplace(command_name, std::vector()).first; it->second.push_back(alias); } @@ -130,7 +128,7 @@ void EndstoneCommandMap::setMinecraftCommands() auto *parent = DefaultPermissions::registerPermission( root->getName() + ".command", root, "Gives the user the ability to use all vanilla minecraft commands"); - for (const auto &[command_name, signature] : registry.signatures) { + for (const auto &[command_name, signature] : registry.signatures_) { auto description = getI18n().get(signature.description, {}, nullptr); std::vector usages; @@ -260,7 +258,7 @@ bool EndstoneCommandMap::registerCommand(std::shared_ptr command) // Add suffix if the enum already exists std::string enum_name_final = enum_name; int i = 0; - while (registry.enum_lookup.find(enum_name_final) != registry.enum_lookup.end()) { + while (registry.enum_lookup_.find(enum_name_final) != registry.enum_lookup_.end()) { enum_name_final = fmt::format("{}_{}", enum_name, ++i); } if (enum_name_final != enum_name) { @@ -269,30 +267,30 @@ bool EndstoneCommandMap::registerCommand(std::shared_ptr command) } // Add enum - auto symbol = static_cast(registry.addEnumValues(enum_name_final, parameter.values)); + auto symbol = registry.addEnumValues(enum_name_final, parameter.values); // Check if the enum has been added - auto it = registry.enum_lookup.find(enum_name_final); - if (it == registry.enum_lookup.end()) { + auto it = registry.enum_lookup_.find(enum_name_final); + if (it == registry.enum_lookup_.end()) { server_.getLogger().error("Unable to register enum '{}'.", enum_name_final); throw std::runtime_error("Unreachable"); } data.param_type = CommandParameterDataType::Enum; - data.enum_name = it->first.c_str(); - data.enum_symbol = CommandRegistry::Symbol{symbol}; + data.enum_name_or_postfix = it->first.c_str(); + data.enum_or_postfix_symbol = symbol; data.options = CommandParameterOption::EnumAutocompleteExpansion; } else if (parameter.type == "bool") { static auto symbol = static_cast(registry.addEnumValues("Boolean", {})); data.param_type = CommandParameterDataType::Enum; - data.enum_name = "Boolean"; - data.enum_symbol = CommandRegistry::Symbol{symbol}; + data.enum_name_or_postfix = "Boolean"; + data.enum_or_postfix_symbol = symbol; } else if (parameter.type == "block") { static auto symbol = static_cast(registry.addEnumValues("Block", {})); data.param_type = CommandParameterDataType::Enum; - data.enum_name = "Block"; - data.enum_symbol = CommandRegistry::Symbol{symbol}; + data.enum_name_or_postfix = "Block"; + data.enum_or_postfix_symbol = symbol; } else { auto it = gTypeSymbols.find(std::string(parameter.type)); @@ -303,7 +301,7 @@ bool EndstoneCommandMap::registerCommand(std::shared_ptr command) success = false; break; // early stop if any of the param in the usage is invalid } - data.fallback_symbol = CommandRegistry::Symbol{it->second}; + data.chained_subcommand_symbol = static_cast(it->second); } param_data.push_back(data); } @@ -348,22 +346,31 @@ struct { } gCommandRegistryState; } // namespace +void EndstoneCommandMap::patchCommandRegistry() +{ + std::lock_guard lock(mutex_); + auto ®istry = server_.getMinecraftCommands().getRegistry(); + + // remove the vanilla `/reload` command (to be replaced by ours) + registry.signatures_.erase("reload"); +} + void EndstoneCommandMap::saveCommandRegistryState() const { auto ®istry = server_.getMinecraftCommands().getRegistry(); - gCommandRegistryState.enums = registry.enums; - gCommandRegistryState.enum_lookup = registry.enum_lookup; - gCommandRegistryState.signatures = registry.signatures; - gCommandRegistryState.aliases = registry.aliases; + gCommandRegistryState.enums = registry.enums_; + gCommandRegistryState.enum_lookup = registry.enum_lookup_; + gCommandRegistryState.signatures = registry.signatures_; + gCommandRegistryState.aliases = registry.aliases_; } void EndstoneCommandMap::restoreCommandRegistryState() const { auto ®istry = server_.getMinecraftCommands().getRegistry(); - registry.enums = gCommandRegistryState.enums; - registry.enum_lookup = gCommandRegistryState.enum_lookup; - registry.signatures = gCommandRegistryState.signatures; - registry.aliases = gCommandRegistryState.aliases; + registry.enums_ = gCommandRegistryState.enums; + registry.enum_lookup_ = gCommandRegistryState.enum_lookup; + registry.signatures_ = gCommandRegistryState.signatures; + registry.aliases_ = gCommandRegistryState.aliases; } } // namespace endstone::detail diff --git a/src/endstone_runtime/bedrock/certificates/certificate.cpp b/src/endstone_runtime/bedrock/certificates/certificate.cpp index aee27a021..bea445e40 100644 --- a/src/endstone_runtime/bedrock/certificates/certificate.cpp +++ b/src/endstone_runtime/bedrock/certificates/certificate.cpp @@ -16,7 +16,7 @@ Json::Value Certificate::getExtraData(const std::string &key, const Json::Value &default_value) const { - const auto extra_data = unverified_certificate_.raw_token_.data_info.get("extraData", {}); + const auto extra_data = unverified_certificate_.raw_token_.getData().get("extraData", {}); return extra_data.get(key, default_value); } diff --git a/src/endstone_runtime/bedrock/certificates/web_token.cpp b/src/endstone_runtime/bedrock/certificates/web_token.cpp index da1b7951d..c63dd4c3c 100644 --- a/src/endstone_runtime/bedrock/certificates/web_token.cpp +++ b/src/endstone_runtime/bedrock/certificates/web_token.cpp @@ -16,5 +16,5 @@ Json::Value const &WebToken::getData() const { - return data_info; + return data_info_; } From 9821ee56fd2296edbc15fc270be8015a8d627854 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 21:39:39 +0000 Subject: [PATCH 35/42] chore(deps): bump scikit-build-core-conan version in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3e1bad361..b23c6a31f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["scikit-build-core-conan"] +requires = ["scikit-build-core-conan>=0.5.3"] build-backend = "scikit_build_core_conan.build" [project] From bb56db715b6c6725dfa7f8d6be6beb2323fbb1d0 Mon Sep 17 00:00:00 2001 From: engsr6982 <109733049+engsr6982@users.noreply.github.com> Date: Thu, 19 Dec 2024 06:15:30 +0800 Subject: [PATCH 36/42] fix: ensure the correct plugin loader is selected when loading from file (#110) * fix: fix EndstonePluginManager::loadPlugin #98 * refactor: improve plugin loading logic in EndstonePluginManager * refactor: revert back to range-based loop for plugin loading --------- Co-authored-by: Vincent --- src/endstone_core/plugin/plugin_manager.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/endstone_core/plugin/plugin_manager.cpp b/src/endstone_core/plugin/plugin_manager.cpp index a5e872d53..3cd89b6c4 100644 --- a/src/endstone_core/plugin/plugin_manager.cpp +++ b/src/endstone_core/plugin/plugin_manager.cpp @@ -87,11 +87,15 @@ Plugin *EndstonePluginManager::loadPlugin(std::string file) { Plugin *result = nullptr; for (const auto &loader : plugin_loaders_) { - if (auto *plugin = loader->loadPlugin(file); plugin) { - if (initPlugin(*plugin, *loader, fs::path(file).parent_path())) { - result = plugin; + for (const auto &pattern : loader->getPluginFileFilters()) { + if (std::regex r(pattern); std::regex_search(file, r)) { + if (auto *plugin = loader->loadPlugin(file); plugin) { + if (initPlugin(*plugin, *loader, fs::path(file).parent_path())) { + result = plugin; + } + break; + } } - break; } } return result; @@ -104,7 +108,7 @@ std::vector EndstonePluginManager::loadPlugins(std::string directory) // TODO(plugin): handling logic for depend, soft_depend, load_before and provides for (const auto &loader : plugin_loaders_) { auto plugins = loader->loadPlugins(directory); - for (const auto &plugin : plugins) { + for (auto *plugin : plugins) { if (!plugin) { continue; } From 8ce11d7738948ca29978da2c841164b641f437f7 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 16:30:31 +0200 Subject: [PATCH 37/42] Update server_list_ping_event.h and make fields public --- include/endstone/event/server/server_list_ping_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index a01269c4c..18b84bf72 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -231,8 +231,9 @@ class ServerListPingEvent : public ServerEvent { private: std::string ping_response_; std::string remote_host_; - int remote_port_; std::string motd_; +public: + int remote_port_; int network_protocol_version_; std::string minecraft_version_network_; int num_players_; From fd09f6a735dcd33d5e31eabc46155ea193971b8e Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 17:42:19 +0200 Subject: [PATCH 38/42] use proper setters --- .../event/server/server_list_ping_event.h | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index 18b84bf72..b31bcd242 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -74,6 +74,18 @@ class ServerListPingEvent : public ServerEvent { return local_port_; } + /** + * Sets the local port of the server. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setLocalPort(int port) + { + local_port_ = port; + } + /** * Get the local port of the server for IPv6 support * @@ -84,6 +96,18 @@ class ServerListPingEvent : public ServerEvent { return local_port_v6_; } + /** + * Sets the local port of the server for IPv6 support. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setLocalPortV6(int port) + { + local_port_v6_ = port; + } + /** * Get the message of the day message. * @@ -231,9 +255,8 @@ class ServerListPingEvent : public ServerEvent { private: std::string ping_response_; std::string remote_host_; - std::string motd_; -public: int remote_port_; + std::string motd_; int network_protocol_version_; std::string minecraft_version_network_; int num_players_; From 9404248098430f13ec3fd126d0e9015e47276731 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 11 Oct 2024 17:46:09 +0200 Subject: [PATCH 39/42] add set guid method for ServerListPingEvent --- .../endstone/event/server/server_list_ping_event.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index b31bcd242..ae5f07bf7 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -64,6 +64,18 @@ class ServerListPingEvent : public ServerEvent { return server_guid_; } + /** + * Sets the local port of the server. + * This can be usefull when dealing with proxies + * to avoid a port missmatch. + * + * @param port the port that should be set + */ + void setServerGuid(std::string guid) + { + server_guid_ = guid; + } + /** * Get the local port of the server. * From bc386b383b62481d05dbae3613d1c107d5841aa1 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 22:18:03 +0000 Subject: [PATCH 40/42] docs: fix documentation for the setters --- .../event/server/server_list_ping_event.h | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index ae5f07bf7..29473dd37 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -65,15 +65,13 @@ class ServerListPingEvent : public ServerEvent { } /** - * Sets the local port of the server. - * This can be usefull when dealing with proxies - * to avoid a port missmatch. - * - * @param port the port that should be set + * Set the unique identifier of the server. + * + * @param guid the server guid to be set */ void setServerGuid(std::string guid) { - server_guid_ = guid; + server_guid_ = std::move(guid); } /** @@ -87,10 +85,8 @@ class ServerListPingEvent : public ServerEvent { } /** - * Sets the local port of the server. - * This can be usefull when dealing with proxies - * to avoid a port missmatch. - * + * Set the local port of the server. + * * @param port the port that should be set */ void setLocalPort(int port) @@ -109,11 +105,9 @@ class ServerListPingEvent : public ServerEvent { } /** - * Sets the local port of the server for IPv6 support. - * This can be usefull when dealing with proxies - * to avoid a port missmatch. - * - * @param port the port that should be set + * Set the local port of the server for IPv6 support. + * + * @param port the local port for IPv6 */ void setLocalPortV6(int port) { From a613f885129f70a87f5f974f7dbd784c21f4d070 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 22:18:30 +0000 Subject: [PATCH 41/42] feat: add python bindings for the setters in `ServerListPingEvent` --- python/src/endstone/_internal/endstone_python.pyi | 15 ++++++++++++--- src/endstone_python/event.cpp | 11 ++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/python/src/endstone/_internal/endstone_python.pyi b/python/src/endstone/_internal/endstone_python.pyi index b5ddce077..476259c2e 100644 --- a/python/src/endstone/_internal/endstone_python.pyi +++ b/python/src/endstone/_internal/endstone_python.pyi @@ -2899,13 +2899,19 @@ class ServerListPingEvent(Event): @property def local_port(self) -> int: """ - Get the local port of the server. + Get or set the local port of the server. """ + @local_port.setter + def local_port(self, arg1: int) -> None: + ... @property def local_port_v6(self) -> int: """ - Get the local port of the server for IPv6 support + Get or set the local port of the server for IPv6 support """ + @local_port_v6.setter + def local_port_v6(self, arg1: int) -> None: + ... @property def max_players(self) -> int: """ @@ -2956,8 +2962,11 @@ class ServerListPingEvent(Event): @property def server_guid(self) -> str: """ - Get the unique identifier of the server. + Get or set the unique identifier of the server. """ + @server_guid.setter + def server_guid(self, arg1: str) -> None: + ... class ServerLoadEvent(Event): """ Called when either the server startup or reload has completed. diff --git a/src/endstone_python/event.cpp b/src/endstone_python/event.cpp index 155b6a3d5..78da6b319 100644 --- a/src/endstone_python/event.cpp +++ b/src/endstone_python/event.cpp @@ -193,11 +193,12 @@ void init_event(py::module_ &m, py::class_ &event, py::enum_ Date: Wed, 18 Dec 2024 22:25:29 +0000 Subject: [PATCH 42/42] docs: update documentation to improve consistency --- include/endstone/event/server/server_list_ping_event.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/endstone/event/server/server_list_ping_event.h b/include/endstone/event/server/server_list_ping_event.h index 29473dd37..d340b7c73 100644 --- a/include/endstone/event/server/server_list_ping_event.h +++ b/include/endstone/event/server/server_list_ping_event.h @@ -67,7 +67,7 @@ class ServerListPingEvent : public ServerEvent { /** * Set the unique identifier of the server. * - * @param guid the server guid to be set + * @param guid the server guid */ void setServerGuid(std::string guid) { @@ -87,7 +87,7 @@ class ServerListPingEvent : public ServerEvent { /** * Set the local port of the server. * - * @param port the port that should be set + * @param port the local port */ void setLocalPort(int port) {