### Installation Instructions for Example Packs Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/wiki/guide/download-packs.md This snippet shows the typical installation path for behavior packs on Windows 10/11. Note that the exact path may vary depending on your platform. ```text // Note: The path here may vary depending on the actual installation platform. // Windows 10/11 default path: %localappdata%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang ``` -------------------------------- ### Install MCSM Panel and Start Daemon on Self-Owned Machine Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程10:使用Spigot开服/15-通过MCSM面板管理服务器.md Installs the MCSM panel and its associated services on a self-owned machine using a setup script. It starts both the daemon service for process control and the web service for user management and web access. ```bash # Ensure root login with sudo privileges sudo su -c "wget -qO- https://script.mcsmanager.com/setup_cn.sh | bash" # Start the panel daemon first. # This is for process control and terminal management. systemctl start mcsm-daemon.service # Then start the panel Web service. # This is for web access and user management. systemctl start mcsm-web.service # The following commands are listed (take them if needed) # Restart panel command systemctl restart mcsm-daemon.service systemctl restart mcsm-web.service # Stop panel command systemctl stop mcsm-web.service systemctl stop mcsm-daemon.service ``` -------------------------------- ### Get Service Configuration Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Retrieves the configuration for a specific service. This configuration corresponds to the settings found under 'servicelist' in the common configuration. The example output shows typical service configuration details. ```python import service.netgameApi as netServiceApi serviceConf = netServiceApi.GetServiceConfig() print serviceConf # 结果实例如下: # { # "app_type": "service", # "app_version": "1.15.0.release20191128", # "http_port": 8520, # "ip": "127.0.0.1", # "mods": "service", # "module_names": [ # "netease_salog_0", # "netease_salog_1", # "netease_uniqueid", # "netease_stats_log_0", # "netease_stats_log_1", # "netease_stats_monitor" # ], # "serverid": 11, # "type": "service" # } ``` -------------------------------- ### Install mc-netease-sdk for a specific Python path Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/13-模组SDK编程/2-Python脚本开发/0-脚本开发入门.md Install the mc-netease-sdk completion library to a specific Python installation by providing the full path to the python.exe executable. ```bash C:\xxx\python.exe -m pip install mc-netease-sdk ``` -------------------------------- ### Get Client System Instance Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/通用/System.md Retrieve an instance of a registered client-side system by its namespace and name. Returns None if the system is not found. This example also shows how to get the base class and define a new system. ```python import mod.client.extraClientApi as clientApi ClientSystem = clientApi.GetClientSystemCls() class FpsClientSystem(ClientSystem): def __init__(self, namespace, systemName): ClientSystem.__init__(self, namespace, systemName) self.tutorialSystem = clientApi.GetSystem("TutorialMod", "TutorialClientSystem") ``` -------------------------------- ### Install mc-netease-sdk using pip Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/13-模组SDK编程/2-Python脚本开发/0-脚本开发入门.md Use pip to install the latest version of the mc-netease-sdk completion library. This command installs the library for the default Python interpreter. ```bash python -m pip install mc-netease-sdk ``` -------------------------------- ### Install a specific version of mc-netease-sdk Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/13-模组SDK编程/2-Python脚本开发/0-脚本开发入门.md Install a particular version of the mc-netease-sdk completion library by specifying the version number. Check PyPI for available versions. ```bash python -m pip install mc-netease-sdk==要安装的版本号 ``` -------------------------------- ### Example ServiceMod Structure (neteaseDailyService) Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/30-网络服插件教程/3-插件知识进阶/3-插件文件夹结构.md An example demonstrating the folder structure for a 'neteaseDailyService' service mod, highlighting its server-centric components. ```plaintext neteaseDailyService developer_mods ——服务器mod,不会被传输到客户端 neteaseDailyDev ——服务器mod根目录 mod.json ——插件的配置文件和基本信息 neteaseDailyScript ——服务端脚本 mod.sql ——数据表创建的SQL语句 readme.txt ——插件介绍 ``` -------------------------------- ### Get Common Configuration Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Retrieves the common server configuration, which includes settings for all servers and databases. Access specific configurations like 'serverlist' or 'log_debug_level' using dictionary keys. ```python import service.netgameApi as netServiceApi conf = netServiceApi.GetCommonConfig() serverlist = conf['serverlist'] #获取serverlist配置 serverlist = conf['log_debug_level'] #获取日志等级配置 ``` -------------------------------- ### Start and Stop Event Recording Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Initiates and stops the statistical recording of script event send/receive packets between the lobby/game server and the function server. Call StopRecordEvent() after StartRecordEvent() to get statistics for the interval. The results provide counts and sizes for sent events and requests. ```python import service.netgameApi as netServiceApi suc = netServiceApi.StartRecordEvent() # 之后通过计时器或者其他触发方式调用StopRecordEvent result = netServiceApi.StopRecordEvent() # sendEvent对应的value保存了功能服主动发送给大厅服/游戏服、甚至客户端的事件统计 for eventName, data in result["sendEvent"].iteritems(): print "sendEvent event[{}] send={} sendSize={}".format(eventName, data["send_num"], data["send_size"]) # sendRequest对应的value保存了功能服发送给其他的功能服事件,以及对应的功能服返回结果的事件 for eventName, data in result["sendRequest"].iteritems(): print "sendRequest event[{}] request={} requestSize={} response={} responseSize={}".format(eventName, data["request_num"], data["request_size"], data["response_num"], data["response_size"]) ``` -------------------------------- ### 起床战争:增加开局逻辑 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程6:模板教学/第2节:小游戏服模板简介.md 在 `startLogicServerSystem.py` 中,增加了开局逻辑的处理。这部分代码定义了游戏开始时的初始化操作。 ```python def StartLogic(self, playerList, matchId): # 增加开局逻辑 pass ``` -------------------------------- ### Get Fog Range Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/世界/渲染.md Retrieves the fog's start and end range. Returns a tuple of two floats representing the start and end values. ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateFog(levelId) start,end = comp.GetFogLength() ``` -------------------------------- ### Initialize Server System and Listen for Events Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/15-玩法组件教程/12-开始自定义方块实体/4-挑战:制作一个自定义箱子(无法储藏版).md Sets up the server system, listens for block placement and removal events, and binds them to corresponding callback functions. ```python from mod.server.system.serverSystem import ServerSystem from mod.common.minecraftEnum import Facing import mod.server.extraServerApi as serverApi class Main(ServerSystem): def __init__(self, namespace, system_name): ServerSystem.__init__(self, namespace, system_name) namespace = serverApi.GetEngineNamespace() system_name = serverApi.GetEngineSystemName() self.ListenForEvent(namespace, system_name, 'ServerEntityTryPlaceBlockEvent', self, self.on_try_placed) self.ListenForEvent(namespace, system_name, 'EntityPlaceBlockAfterServerEvent', self, self.on_placed) # 监听引擎系统的BlockRemoveServerEvent事件,方块被移除时触发,用于大箱子被破坏了一个方块时将剩余的那个箱子复原,绑定block_removed回调 self.ListenForEvent(namespace, system_name, 'BlockRemoveServerEvent', self, self.block_removed) ``` -------------------------------- ### Initialize Server System and Listen for Block Use Events Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第04章:发挥创意构建场景/课程03.规划可轻微变动区域.md Sets up the server system, listens for block use events, and adds blocks to a whitelist to trigger these events. This is crucial for custom block interactions. ```python from mod.server.system.serverSystem import ServerSystem from mod.common.minecraftEnum import ItemPosType import mod.server.extraServerApi as serverApi class Main(ServerSystem): def __init__(self, namespace, system_name): # 继承父类 ServerSystem.__init__(self, namespace, system_name) namespace = serverApi.GetEngineNamespace() system_name = serverApi.GetEngineSystemName() # 监听交互方块事件 self.ListenForEvent(namespace, system_name, 'ServerBlockUseEvent', self, self.using_item) # 根据文档描述,原版方块需要通过添加进交互方块的白名单内才能触发ServerBlockUseEvent block_comp = serverApi.GetEngineCompFactory().CreateBlockUseEventWhiteList(serverApi.GetLevelId()) # 在地图的方块结构里,一共受到锄头影响的两种地形方块是 self.blocked_list = ["minecraft:grass", "minecraft:grass_path"] for block_name in self.blocked_list: # 加入白名单 block_comp.AddBlockItemListenForUseEvent(block_name) # 非常重要!告示牌的方块实体ID是 minecraft:standing_sign而不是 minecraft:sign block_comp.AddBlockItemListenForUseEvent('minecraft:standing_sign:*') # 储存资源点坐标 self.resources_pos = [ (73, 64, 57), (51, 63, 101), (82, 68, 136), (198, 65, 102), (82, 68, 136) ] # 结构名称 self.resource_identifier = 'design:resource' # 添加一个60秒重置资源点的定时任务 game_comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId()) game_comp.AddRepeatedTimer(60.0, self.resource_placed) ``` -------------------------------- ### Create Instance on MCSM Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程10:使用Spigot开服/15-通过MCSM面板管理服务器.md Demonstrates how to create a new server instance within the MCSM panel, allowing for migration of existing servers or creation of new ones by specifying server directory, type, and startup commands. ```bash # If you need to migrate NetEase machine's screen to MCSM, use 'Direct Creation'. # Configure the server directory, instance type, and startup command, and the migration will be successful. ``` -------------------------------- ### UI Creation and Layering Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程5:插件教学/第1节:官网插件规范.md Demonstrates how to register, create, set the layer, and control the visibility of a UI element using the client API. ```python import client.extraClientApi as clientApi clientApi.RegisterUI("neteaseAppear","shop","neteaseAppearScript.appearShopUi.ShopScreen","netease_appear_shopUI.main") clientApi.CreateUI("neteaseAppear", "shop", {"isHud" : 1}) shopUI = clientApi.GetUI("neteaseAppear", "shop") shopUI.SetLayer("", clientApi.GetMinecraftEnum().UiBaseLayer.PopUpLv1) shopUI.SetScreenVisible(False) ``` -------------------------------- ### Python Client Initialization and Event Handling Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程10:使用Spigot开服/21-Spigot服与客户端python通信原理简介.md This Python code shows how to initialize a client system, register it with the API, listen for server events, and send events to the Spigot server. It includes registering a system, setting up an event listener, and sending a notification. ```python # modMain.py @Mod.InitClient() def InitClient(self): clientApi.RegisterSystem("MyMod", "MySystemClient", client_system_class_path) # clientSystem class MySystemClient(ClientSystem): def __init__(self, namespace, systemName): ClientSystem.__init__(self, namespace, systemName) # 注册事件,在回调函数中打印参数 self.ListenForEvent("MyMod", "MySystemServer", "serverEvent", self, self.onEvent) # 给spigot发一个事件 self.NotifyToServer("clientEvent", {'a': 1}) def onEvent(self, data): # 可以在客户端日志中看到onEvent {"a": 1} print 'onEvent', data ``` -------------------------------- ### GetEntityLinksTag Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/Api索引表.md Gets entities linked to the current entity. For example, if the entity ID is a horse, it will return information about the rider. ```APIDOC ## GetEntityLinksTag ### Description Gets entities linked to the current entity. For example, if the entity ID is a horse, it will return information about the rider. ### Method Server-side ### Endpoint 实体/属性.md#getentitylinkstag ``` -------------------------------- ### Example Symbolic Link Creation Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/wiki/meta/version-control.md An example demonstrating how to create a symbolic link for a Resource Pack named 'demoRP'. Ensure the target path correctly points to your development_resource_packs folder. ```bash mklink /J demo_RP "C:/Users/Steve/AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/development_resource_packs/demoRP" ``` -------------------------------- ### Start Script Event Recording Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/通用/调试.md Starts recording script event send/receive statistics between server and client. Call StopRecordEvent to get the statistics. This is only supported in leased server and Apollo network server environments, not in standalone mode. ```python import mod.server.extraServerApi as serverApi suc = serverApi.StartRecordEvent() # After a timer or other trigger, call StopRecordEvent result = serverApi.StopRecordEvent() for eventName, data in result.iteritems(): print "event[{}] send={} sendSize={} recv={} recvSize={}".format(eventName, data["send_num"], data["send_size"], data["recv_num"], data["recv_size"]) ``` -------------------------------- ### Get Client Entity Type Name Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/实体/实体类型.md Retrieves the string name of an entity's type on the client, for example, 'minecraft:husk'. ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateEngineType(entityId) strType = comp.GetEngineTypeStr() ``` -------------------------------- ### Initialize UI and Listen for Shop Creation Events Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第05章:设置NPC的基本状态和交易表/课程03.给NPC添加对应的交易表.md Client-side system to initialize the UI and listen for events to create the shop interface. It registers a new UI screen and handles the 'create_shop_ui' event. ```python class FarmClientSystem(ClientSystem): def __init__(self, namespace, systemName): super(FarmClientSystem, self).__init__(namespace, systemName) namespace = clientApi.GetEngineNamespace() system_name = clientApi.GetEngineSystemName() self.ListenForEvent(namespace, system_name, 'UiInitFinished', self, self.ui_init) self.ListenForEvent("FarmMod", "ServerSystem", "create_shop_ui", self, self.Create_Shop_UI) def Create_Shop_UI(self,event): self.ui = clientApi.PushScreen("Farm","new_shop") def ui_init(self,args): clientApi.RegisterUI("Farm","new_shop","Script_NeteaseModw7ijjGNn.uiscreen.FarmUIScreen","new_shop.main") ``` -------------------------------- ### Get Server ID Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Fetches the server ID, which corresponds to the 'serverid' in the common configuration. Refer to the GetCommonConfig documentation for details on the common configuration. ```python import service.netgameApi as netServiceApi serverId = netServiceApi.GetServerId() ``` -------------------------------- ### Corner Transition Biome Setup Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/wiki/world-generation/biomes.md Example of target values for a transition biome positioned 'in front of' the target biome's extreme values. ```json "target_temperature": 0.8, "target_humidity": -0.8 ``` -------------------------------- ### Function File Syntax Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/15-玩法组件教程/3-了解我的世界原版命令/2-使用命令的方法.md Commands within a .mcfunction file are listed one per line and do not use the leading slash '/'. Comments start with '#'. ```minecraft-functions # This is a comment give @s iron_ingot ``` -------------------------------- ### Define Entity Locators Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/15-自定义游戏内容/3-自定义生物/01-自定义基础生物.md Adds specific points (locators) to an entity's geometry, often used for attaching other elements like guides. The 'lead' locator is shown as an example. ```json "locators": { "lead": { "head": [ 0.0, 14.0, -6.0 ] } } ``` -------------------------------- ### Client Initialization for PartBase Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/14-预设玩法编程/13-PresetAPI/预设对象/零件/零件PartBase.md Entry point for initializing a client-side PartBase object. ```python self.InitClient() ``` -------------------------------- ### Initialize ServerSystem and Listen for Block Use Events Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第04章:发挥创意构建场景/课程03.规划可轻微变动区域.md Sets up the ServerSystem, listens for player block interactions, and adds specific blocks to a whitelist to trigger the ServerBlockUseEvent. This is crucial for detecting when players interact with designated areas or objects. ```python from mod.server.system.serverSystem import ServerSystem from mod.common.minecraftEnum import ItemPosType import mod.server.extraServerApi as serverApi class Main(ServerSystem): def __init__(self, namespace, system_name): # 继承父类 ServerSystem.__init__(self, namespace, system_name) namespace = serverApi.GetEngineNamespace() system_name = serverApi.GetEngineSystemName() # 监听交互方块事件 self.ListenForEvent(namespace, system_name, 'ServerBlockUseEvent', self, self.using_item) # 根据文档描述,原版方块需要通过添加进交互方块的白名单内才能触发ServerBlockUseEvent block_comp = serverApi.GetEngineCompFactory().CreateBlockUseEventWhiteList(serverApi.GetLevelId()) # 在地图的方块结构里,一共受到锄头影响的两种地形方块是 self.blocked_list = ["minecraft:grass", "minecraft:grass_path"] for block_name in self.blocked_list: # 加入白名单 block_comp.AddBlockItemListenForUseEvent(block_name) # 非常重要!告示牌的方块实体ID是 minecraft:standing_sign而不是minecraft:sign block_comp.AddBlockItemListenForUseEvent("minecraft:standing_sign:*") # 储存资源点坐标 self.resources_pos = [ (73, 64, 57), (51, 63, 101), (82, 68, 136), (198, 65, 102), (82, 68, 136) ] # 结构名称 self.resource_identifier = 'design:resource' # 添加一个60秒重置资源点的定时任务 game_comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId()) game_comp.AddRepeatedTimer(60.0, self.resource_placed) ``` -------------------------------- ### Get Server Loaded Mods by ID Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Retrieves the list of mods loaded by a specific server, identified by its server ID. A server ID of 0 indicates the master server. ```python import service.netgameApi as netServiceApi #返回的一个示例:["neteaseAnnounce", "neteaseAuth", "neteaseShop"] mods = netServiceApi.GetServerLoadedModsById(4000) ``` -------------------------------- ### TextBoardMgr Initialization and Timer Setup Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程5:插件教学/第4节:地图插件调整(中).md Initializes TextBoardMgr with player ID and offset, loads floating text configurations from server data, and sets up a repeated timer to check for text board creation. ```python class TextBoardMgr(object): # 创建对象时,初始化参数为玩家自己的entityId,以及逻辑视野(当浮空文字距离玩家小于多少时,便会被创建) def __init__(self, playerId, offset=5.0): ... self.mCheckOffset = offset def Init(self, configData): # 通过服务端自定义事件【ServerEvent.LoginResponse】中的浮空文字配置信息,生成等待创建的浮空文字字典。 textWithPlaceList = configData.get("text_with_place_list", None) ... # 注册每3秒钟执行一次的timer,触发检查是否有浮空文字需要被创建 self.mAddTimer = comp.AddRepeatedTimer(3.0, self.CheckAddTextBoard) ``` -------------------------------- ### StartRecordEvent Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/通用/调试.md Starts recording statistics for script event sending and receiving between server and client. Call StopRecordEvent to get statistics. Only supported in Rental Server and Apollo Network Server environments. ```APIDOC ## StartRecordEvent ### Description Starts recording statistics for script event sending and receiving between server and client. Call StopRecordEvent to get statistics for script events between two function calls. Only supported in Rental Server and Apollo Network Server environments (not supported in standalone environment). ### Method serverApi.StartRecordEvent() ### Parameters None ### Return Value - **bool**: Execution result ### Example ```python import mod.server.extraServerApi as serverApi suc = serverApi.StartRecordEvent() # Call StopRecordEvent later via a timer or other trigger result = serverApi.StopRecordEvent() for eventName, data in result.iteritems(): print "event[{}] send={} sendSize={} recv={} recvSize={}".format(eventName, data["send_num"], data["send_size"], data["recv_num"], data["recv_size"]) ``` ``` -------------------------------- ### 注册服务端系统 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/15-玩法组件教程/10-模组SDK初步/4-监听事件并创建组件逻辑.md 在主模组文件中注册服务端系统,以便在游戏中启用其逻辑。此函数应在 `@Mod.InitServer()` 装饰器下。 ```python serverApi.RegisterSystem("DemoTutorialMod", "Server", "Script_DemoTutorialMod.DemoTutorialServerSystem.DemoTutorialServerSystem") ``` -------------------------------- ### Get Base UI Control Path Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/自定义UI/UI控件.md Retrieves the relative path of a UI control, starting from the canvas node. This path is used to uniquely identify the control within the UI hierarchy. ```python text2Path = "/panel/text2" baseUIControl = uiNode.GetBaseUIControl(text2Path) path = baseUIControl.GetPath() ``` -------------------------------- ### Full Animation with Particle and Sound Effects Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/wiki/visuals/animation-effects.md A comprehensive example of an entity animation including particle and sound effects, bone transformations, and animation timing. This demonstrates a complete animation setup. ```json { "format_version" : "1.8.0", "animations" : { "animation.sheep.grazing" : { "animation_length" : 2.0, "loop" : true, "particle_effects": { "0.0": { "effect": "flames", "locator": "body" } }, "sound_effects": { "0.0": { "effect": "meow" } }, "bones" : { "head" : { "position" : { "0" : [ 0.0, 0.0, 0.0 ], "0.2" : [ 0.0, -9.0, 0.0 ], "1.8" : [ 0.0, -9.0, 0.0 ], "2" : [ 0.0, 0.0, 0.0 ] }, "rotation" : { "0.2" : { "post" : [ "180.0 * (0.2 + 0.07 * math.sin(q.key_frame_lerp_time * 1644.39))", 0.0, 0.0 ], "pre" : [ 36.0, 0.0, 0.0 ] }, "1.8" : { "post" : [ 36.0, 0.0, 0.0 ], "pre" : [ "180.0 * (0.2 + 0.07 * math.sin(q.key_frame_lerp_time * 1644.39))", 0.0, 0.0 ] } } } } } } } ``` -------------------------------- ### Initialize Farm Server System and Listen for Events Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第08章:在开头添加引导关卡/课程02.实现资源收集和玩法规则的小游戏.md Sets up the server system to listen for player attacks on entities and item usage on blocks. It also initializes variables for NPC interaction, dialogue progression, and item management. ```python leveldatacomp = serverApi.GetEngineCompFactory().CreateExtraData(serverApi.GetLevelId()) class FarmServerSystem(ServerSystem): def __init__(self, namespace, systemName): ServerSystem.__init__(self, namespace, systemName) # 监听PlayerAttackEntityEvent事件 self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "PlayerAttackEntityEvent", self, self.PlayerAttack) # 监听ItemUseOnAfterServerEvent事件 self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "ItemUseOnAfterServerEvent", self, self.Item_Use) # 提前获取到的NPCid self.guide_id = "-481036336358" # 创建一个控制对话阶段的变量 self.guide_dialogue = {} # 存储物品的变量 self.guide_itemDict = [ { 'name': 'minecraft:farmland', 'aux': 0 }, { 'itemName': 'farm:spinach_seed', 'count': 1, 'enchantData': '', 'auxValue': 0, 'customTips': '', 'extraId': '', 'userData': {}, } ] ``` -------------------------------- ### Get Server Loaded Mods by Type Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/5-功能服API.md Fetches the list of mods loaded by servers of a specific type. If multiple servers of the same type have different mods, one of the mod lists will be returned. ```python import service.netgameApi as netServiceApi #返回的一个示例:["neteaseAnnounce", "neteaseAuth", "neteaseShop"] mods = netServiceApi.GetServerLoadedModsByType("survivalGame") ``` -------------------------------- ### Get Grid Item by Position Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/自定义UI/UI控件.md Retrieves a specific UI element from a grid control based on its X and Y coordinates. Note that detailed usage for grid items can be found in the 'Development Guide - Interface and Interaction - UI Description Document'. ```python # we want to get element positioned at (0, 0) gridPath = "/grid1" gridUIControl = uiNode.GetBaseUIControl(gridPath).asGrid() gridItem_0 = gridUIControl.GetGridItem(0, 0) if gridItem_0: print gridItem_0.GetSize() ``` -------------------------------- ### Server Initialization for PartBase Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/14-预设玩法编程/13-PresetAPI/预设对象/零件/零件PartBase.md Entry point for initializing a server-side PartBase object. ```python self.InitServer() ``` -------------------------------- ### Get Entities In Square Area (Server) Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/世界/地图.md Retrieves a list of entity IDs within a square area defined by start and end positions in a specific dimension. The entityId parameter is deprecated. Collision detection uses the Separating Axis Theorem, and coordinates refer to vertex positions. ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateGame(levelId) comp.GetEntitiesInSquareArea(None, (0,0,0), (100,100,100), 0) ``` -------------------------------- ### 客户端启动协程 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/通用/工具.md 使用`StartCoroutine`在客户端开启协程。可以传入一个生成器函数或一个生成器对象。协程执行完毕后会调用回调函数。可以使用`AddTimer`来停止协程,并在之后从停止点继续执行。 ```python import client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateGame(clientApi.GetLevelId()) def callback(): print "callback" def coroutineTest(): for i in xrange(1000): print i yield generator = clientApi.StartCoroutine(coroutineTest, callback) #执行1秒后停止协程 comp.AddTimer(1.0, clientApi.StopCoroutine, generator) #执行5秒后传入StartCoroutine返回的生成器,则函数将从停止位置继续执行 comp.AddTimer(5.0, clientApi.StartCoroutine, generator, callback) ``` ```python import client.extraClientApi as clientApi def callback(): print "callback" def coroutineTest(): for i in xrange(1000): print i yield #传入函数,函数将从头开始执行 clientApi.StartCoroutine(coroutineTest, callback) ``` -------------------------------- ### Feature Rule Configuration Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/20-玩法开发/15-自定义游戏内容/4-自定义维度/4-自定义特征.md This JSON defines a feature rule for placing custom structures. It specifies conditions for biome and placement pass, and details the distribution logic including iteration count, coordinate evaluation order, and scatter chance. The 'y' coordinate uses a query to get the height at the specified x and z. ```json { "format_version": "1.14.0", // 格式版本为1.14.0 "minecraft:feature_rules": { "description": { "identifier": "custombiomes:overworld_pumpkins_feature", // 该feature_rule的identifier "places_feature": "custombiomes:netease_pumpkins_structure_feature" // 该feature_rule所放置的feature的identifier }, "conditions": { // 设置feature生成条件 "placement_pass": "surface_pass", "minecraft:biome_filter": [ // 设置feature会在哪些生物群系中生成 { "all_of": [ { "any_of": [ { "test": "has_biome_tag", "operator": "==", "value": "dm4" // 自定义维度4 }, { "test": "has_biome_tag", "operator": "==", "value": "dm5" // 自定义维度5 }, { "test": "has_biome_tag", "operator": "==", "value": "the_end" // 末地 } ] } ] } ] }, "distribution": { // featuer放置规则 "iterations": "math.mod(variable.originx - 48, 96) == 0 && math.mod(variable.originz - 48, 96) == 0 && query.is_biome(variable.originx - 17, variable.originz - 17, 0, 1, 2, 9, 12, 46)?3:0", // 迭代放置次数,本句含义为X、Z方向每隔96个方块(6个区块)且尝试放置三次。variable.originx为准备放置feature的区块内最小的x坐标,variable.originz同理 "coordinate_eval_order": "xzy", // 放置feature的坐标决定顺序,下文最终y坐标与x、z坐标存在依赖,故顺序为xzy "scatter_chance": 100.0, // 放置featuer概率,应满足0 < scatter_chance ≤ 100 "x": { "distribution": "uniform", // 在一定范围内随机选取一个整数值 "extent": [ 0, 16 ] // 选取范围,不包括最大值 }, "y": "query.get_height_at(variable.worldx, variable.worldz)", // variable.worldx为最终放置feature的x坐标,variable.worldz同理 "z": { "distribution": "uniform", "extent": [ 0, 16 ] } } } } ``` -------------------------------- ### Get Entities In Square Area (Client) Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/世界/地图.md Retrieves a list of entity IDs within a square area defined by start and end positions. The entityId parameter is deprecated. This operates within the player's current dimension. Collision detection uses the Separating Axis Theorem, and coordinates refer to vertex positions. ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateGame(levelId) comp.GetEntitiesInSquareArea(None, (0,0,0), (100,100,100)) ``` -------------------------------- ### 服务端启动协程 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/1-ModAPI/接口/通用/工具.md 使用`StartCoroutine`在服务端开启协程。可以传入一个生成器函数或一个生成器对象。协程执行完毕后会调用回调函数。可以使用`AddTimer`来停止协程,并在之后从停止点继续执行。 ```python import server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId()) def callback(): print "callback" def coroutineTest(): for i in xrange(1000): print i yield generator = serverApi.StartCoroutine(coroutineTest, callback) #执行1秒后停止协程 comp.AddTimer(1.0, serverApi.StopCoroutine, generator) #5秒后传入StartCoroutine返回的生成器,则函数将从停止位置继续执行 comp.AddTimer(5.0, serverApi.StartCoroutine, generator, callback) ``` ```python import server.extraServerApi as serverApi def callback(): print "callback" def coroutineTest(): for i in xrange(1000): print i yield #传入函数,函数将从头开始执行 serverApi.StartCoroutine(coroutineTest, callback) ``` -------------------------------- ### Teleport Players Below a Certain Height Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/10-addon教程/第05章:MCSTUDIO功能简介/课程07.简易教学②:制作一条跑酷赛道.md This command block setup teleports players within a specified bounding box (excluding creative mode) to a designated coordinate if they fall below a certain height. It's crucial for preventing players from getting stuck or losing progress after falling off the course. Use gamerule commandblockoutput and sendcommandfeedback to false to hide execution messages. ```command_block /tp @a[x=-13,dx=26,y=0,dy=40,z=0,dz=100,m=!c] 0 47 8 ``` -------------------------------- ### 起床战争:设置游戏规则接口 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程6:模板教学/第2节:小游戏服模板简介.md 在 `worldServerSystem.py` (位于 `neteaseBedwar` 和 `neteaseBedwarBehavior` 目录下) 中,设置游戏规则的接口已更改为 `SetGameRulesInfoServer`。这用于配置起床战争的游戏规则。 ```python self.SetGameRulesInfoServer(gameRuleInfo) ``` -------------------------------- ### 注册自定义MOD客户端与服务端系统 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第04章:发挥创意构建场景/课程03.规划可轻微变动区域.md 在modMain.py文件中注册自定义MOD的客户端和服务器端系统。使用@Mod.InitClient()和@Mod.InitServer()装饰器来挂载系统。 ```python # -*- coding: UTF-8 -*- from mod.common.mod import Mod import mod.server.extraServerApi as serverApi import mod.client.extraClientApi as clientApi @Mod.Binding(name="NeteaseModw7ijjGNn", version="0.1") class NeteaseModw7ijjGNn(object): def __init__(self): pass @Mod.InitClient() def NeteaseModw7ijjGNnClientInit(self): # type: () -> None """Mod被挂载时,在这里注册自定义MOD客户端系统""" pass @Mod.InitServer() def NeteaseModw7ijjGNnServerInit(self): # type: () -> None """Mod被挂载时,在这里注册自定义MOD服务端系统""" serverApi.RegisterSystem("FarmMod", "ServerBlockListenerServer", "Script_NeteaseModw7ijjGNn.server.blockListener.Main") pass @Mod.DestroyClient() def NeteaseModw7ijjGNnClientDestroy(self): # type: () -> None """Mod被卸下时,销毁自定义MOD客户端系统""" pass @Mod.DestroyServer() def NeteaseModw7ijjGNnServerDestroy(self): # type: () -> None """Mod被卸下时,销毁自定义MOD客户端系统""" pass ``` -------------------------------- ### Registering a Screen Proxy Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/18-界面与交互/61-原生界面修改文档.md This example demonstrates how to register a custom proxy class for a native screen. The proxy will be instantiated when the specified native screen is created, allowing for custom logic to be injected. ```APIDOC ## RegisterScreenProxy ### Description Registers a delegate class for the corresponding native screen. After successful registration, a delegate will be created and obtain the ScreenNode instance of the native screen each time the native screen is created, and the delegate will be destroyed upon closing. ### Parameters | Parameter Name | Data Type | Description | | :--- | :--- | :--- | | screenName | str | The full name of the screen (including native and custom screens), generally composed of the namespace + "." + canvas name, such as "UIDemo.main". Refer to the explanation above for other ways to obtain this. | | proxyClassName | str | The module path of the custom proxy class that inherits from CustomUIScreenProxy. | ### Return Value | Data Type | Description | | :--- | :--- | | bool | Whether the registration was successful. Returns failure if the same proxy class is registered repeatedly, the class cannot be found, or it does not inherit from CustomUIScreenProxy. | ### Example ```python import client.extraClientApi as clientApi ClientSystem = clientApi.GetClientSystemCls() NativeScreenManager = clientApi.GetNativeScreenManagerCls() class TutorialClientSystem(ClientSystem): def __init__(self, namespace, systemName): ClientSystem.__init__(self, namespace, systemName) # Register a delegate for the pause screen, class is tutorialScripts.proxys.PauseScreenProxy.PauseScreenProxy NativeScreenManager.instance().RegisterScreenProxy( "pause.pause_screen", "tutorialScripts.proxys.PauseScreenProxy.PauseScreenProxy" ) ``` ``` -------------------------------- ### Install Black Formatter for Python 2.7 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/90-知识库获奖教程/4-SDK实用技巧/4-vscode安装Python2.7开发环境.md Install an older version of the 'black' formatter compatible with Python 2.7 using pip. Note that this command should be run with python3's pip, as Python 2.7 cannot install 'black'. Verify the installation by checking the version. ```shell python3 -m pip install black[python2]==21.12b0 ``` ```shell black --version ``` -------------------------------- ### Server System Initialization and Event Listening Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/15-玩法组件教程/12-开始自定义方块实体/4-挑战:制作一个自定义箱子(无法储藏版).md Initializes the server system and sets up listeners for block placement events. It listens for `ServerEntityTryPlaceBlockEvent` to validate placements and `EntityPlaceBlockAfterServerEvent` to handle post-placement logic. ```python from mod.server.system.serverSystem import ServerSystem from mod.common.minecraftEnum import Facing import mod.server.extraServerApi as serverApi class Main(ServerSystem): def __init__(self, namespace, system_name): ServerSystem.__init__(self, namespace, system_name) namespace = serverApi.GetEngineNamespace() system_name = serverApi.GetEngineSystemName() # 监听引擎系统的ServerEntityTryPlaceBlockEvent事件,玩家尝试放置时就会触发,用于阻止一些我们不需要的放置情形,绑定on_try_placed回调 self.ListenForEvent(namespace, system_name, 'ServerEntityTryPlaceBlockEvent', self, self.on_try_placed) # 监听引擎系统的EntityPlaceBlockAfterServerEvent事件,方块放置后立马触发,用于在方块被放置后迅速更新方块的各种状态,绑定on_placed回调 self.ListenForEvent(namespace, system_name, 'EntityPlaceBlockAfterServerEvent', self, self.on_placed) ``` -------------------------------- ### 服务端系统文件示例 Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/15-玩法组件教程/10-模组SDK初步/4-监听事件并创建组件逻辑.md 展示了 `DemoTutorialServerSystem.py` 的完整代码,包括事件监听、回调函数实现以及 `Destroy` 方法中取消事件监听。 ```python # -*- coding: utf-8 -*- import mod.server.extraServerApi as serverApi ServerSystem = serverApi.GetServerSystemCls() class DemoTutorialServerSystem(ServerSystem): def __init__(self, namespace, systemName): ServerSystem.__init__(self, namespace, systemName) self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "ActorHurtServerEvent", self, self.OnActorHurtServer) def OnActorHurtServer(self, args): comp = serverApi.GetEngineCompFactory().CreateAction(args["entityId"]) comp.SetMobKnockback(0.1, 0.1, 10.0, 1.0, 1.0) # ScriptTickServerEvent的回调函数,会在引擎tick的时候调用,1秒30帧(被调用30次) def OnTickServer(self): """ Driven by event, One tick way """ pass # 这个Update函数是基类的方法,同样会在引擎tick的时候被调用,1秒30帧(被调用30次) def Update(self): """ Driven by system manager, Two tick way """ pass def Destroy(self): self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "ActorHurtServerEvent", self, self.OnActorHurtServer) ``` -------------------------------- ### Async Redis Get Operation Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcdocs/2-Apollo/4-SDK/7-公共API.md Executes a Redis operation to get the value of a key, equivalent to the Redis 'GET key' command. A callback function can be provided to handle the returned value. ```python import apolloCommon.extraRedisPool as extraRedisPool def Cb1(t): print "cb", t extraRedisPool.InitDB('extra_redis1', 30) #建立连接池 extraRedisPool.AsyncGet('extra_redis1','player_123', Cb1) extraRedisPool.Finish() ``` -------------------------------- ### finPlayerOrder Response Example Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mcguide/27-手机网络游戏/课程10:使用Spigot开服/30-Spigot服Demo详解/3-商城Demo详解.md Example JSON response structure for the `finPlayerOrder` interface. ```APIDOC ## finPlayerOrder Response Example ### Description Sample JSON response for the `finPlayerOrder` method. ### Response Structure ```json { "code": 0, // 0 for success, otherwise an error code "message": "Successful response", "details": "", "entities": [] } ``` ``` -------------------------------- ### Service Plugin Entry Point (modMain.py) Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/30-网络服插件教程/4-插件制作/5-插件编写——制作篇(中).md Implement the main entry point for a Service plugin. This script registers the service system and includes basic initialization and destruction print statements. ```python # coding=utf-8 from mod.common.mod import Mod import mod.server.extraServiceApi as serviceApi from soldierLotteryScripts.consts import ModName, ModVersion, ServiceSystemName, ServiceSystemClsPath @Mod.Binding(name=ModName, version=ModVersion) class SoldierLotteryService(object): @Mod.InitService() def InitService(self): serviceApi.RegisterSystem(ModName, ServiceSystemName, ServiceSystemClsPath) print "SoldierLotteryService启动" @Mod.DestroyService() def DestroyService(self): print "SoldierLotteryService卸载" ``` -------------------------------- ### Client-Side UI Initialization for Shop Source: https://github.com/easecation/netease-modsdk-wiki/blob/main/docs/mconline/20-玩法地图教程/第06章:实现玩家的计数类型和数据读写/课程01.为计分板添加计数类型.md Initializes the shop UI on the client when a 'create_shop_ui' event is received from the server. Sets up UI elements and displays player currency. Requires `clientApi`. ```python class FarmClientSystem(ClientSystem): def __init__(self, namespace, systemName): super(FarmClientSystem, self).__init__(namespace, systemName) # 监听由ServerSystem发送的事件 self.ListenForEvent("FarmMod", "ServerSystem", "create_shop_ui",self, self.Create_Shop_UI) # 提前获取到的商人id self.animal_shop_id = "-120259084268" def Create_Shop_UI(self,event): if event["entityid"] == self.animal_shop_id: # 创建交易表UI self.ui = clientApi.PushScreen("Farm","new_shop") # 通过UI实例修改变量(商品) self.ui.item_button_text = self.animal_shop_item_button_text # 将事件传送过来的玩家钱数设置到ui里 self.ui.coin = event["player_coin"] ```