### Attack Animation Timer Setup (Python) Source: https://mcwiki.easecation.net/mconline/60-%E6%88%91%E7%9A%84%E4%B8%96%E7%95%8C%E5%88%9B%E9%80%A0%E8%90%A5%E6%95%99%E7%A8%8B/SDK%E5%A4%A7%E5%B8%88%E6%95%99%E7%A8%8B/2-%E6%AD%A6%E5%99%A8%E5%92%8C%E8%A3%85%E5%A4%87%E5%88%B6%E4%BD%9C/3-%E6%9E%AA%E6%A2%B0%E5%88%B6%E4%BD%9C.html This Python snippet demonstrates setting up timers for custom gun attack animations on the server. It calculates the fire time based on animation frames and duration, then schedules events for the attack's start, fire, and end states, as well as a separate timer for refreshing ammo. ```python fireTime = config.CustomGunAttackAnimAttackFrame / float(config.CustomGunAttackAnimDuration) * float(animTotalTime) gameComp.AddTimer(0, self._SetAttackStateAndSyncToOtherClients, 'start') gameComp.AddTimer(fireTime, self._SetAttackStateAndSyncToOtherClients, 'fire') gameComp.AddTimer(animTotalTime, self._SetAttackStateAndSyncToOtherClients, 'end') # 刷新背包的子弹数 gameComp.AddTimer(animTotalTime, self._FreshBagBullet) def _SetAttackStateAndSyncToOtherClients(self, state): # 设置本地自定义变量 self.mQueryVariableComp.Set(config.CustomGunAttackVarName, 1.0 if state in ['start', 'fire'] else 0.0) # 通知其他客户端 self.mClientSystem.NotifyToServer('SyncCustomGunAttackStateEvent', {'state': state, 'playerId': self.mPlayerId}) ``` -------------------------------- ### Offset Animation Example Source: https://mcwiki.easecation.net/mcguide/18-%E7%95%8C%E9%9D%A2%E4%B8%8E%E4%BA%A4%E4%BA%92/19-%E6%8E%A7%E4%BB%B6%E5%B1%9E%E6%80%A7%E5%8A%A8%E7%94%BB.html Provides an example of an offset animation for a control, moving it relative to its parent. The 'offset' attribute is animated, defining start and end positions. ```json { "offsetImg" : { "offset" : "@offset_ani", "texture" : "textures/netease/common/image/default", "type" : "image", "visible" : true }, "offset_ani": { "anim_type" : "offset", "duration" : 1.0, "from" : [0, 0], "to" : [0, 50] } } ``` -------------------------------- ### Initialize Database Host from Configuration Source: https://mcwiki.easecation.net/mcguide/28-%E7%94%B5%E8%84%91%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B4%EF%BC%9A%E5%B8%B8%E8%A7%81%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%95%99%E7%A8%8B/31-TabooLib/1-%E5%9F%BA%E7%A1%80%E6%8A%80%E6%9C%AF/8-%E6%95%B0%E6%8D%AE%E5%BA%93.html Demonstrates how to initialize a database host connection using a configuration file. This is the first step in establishing a database connection within the module. ```kotlin config.getHost("database") ``` ```yaml database: host: 127.0.0.1 port: 3306 user: root password: 123456 database: fengxi666 ``` -------------------------------- ### Implement PCustom Widget Examples Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/14-%E9%A2%84%E8%AE%BE%E7%8E%A9%E6%B3%95%E7%BC%96%E7%A8%8B/12-%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E9%9B%B6%E4%BB%B6/1-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7%E9%9D%A2%E6%9D%BF.html Demonstrates the initialization of various PCustom widgets for different data types like MCEnum, MCBlock, and MCResource within a properties dictionary. ```python PROPERTIES = { "MCEnum": PCustom(sort=0, text="MCEnum", group="custom", editAttribute="MCEnum", customFunc=updateMCEnum), "MCBlock": PCustom(editAttribute="MCBlock", default=('dirt', 0), group="custom", sort=1), 'MCBlockName': PCustom(sort=2, editAttribute="MCBlockName", group="custom"), "SelectItemWidget": PCustom(sort=3, editAttribute="SelectItemWidget", group="custom"), "MCEnumEx": PCustom(sort=4, editAttribute="MCEnumEx", customFunc=updateMCEnum, group="custom"), "MCCustomCreature": PCustom(sort=5, editAttribute="MCCustomCreature", group="custom"), 'MCItems': PCustom( sort=6, editAttribute='MCItems', default=('minecraft:apple', 0), withNamespace=False, withAuxValue=True, isBlock=None, itemCategory=8, categoryList=[8, 31], group="custom" ), 'MCResource': PCustom( sort=7, tip='背包格子中该物品显示的贴图。', editAttribute="MCResource", baseFolder=["textures"], relativePath=['items'], extension='.png', default='textures/items/apple', description='image', withExtension=True, group="custom" ), 'MCTipWidget': PCustom( group="custom", sort=8, editAttribute="MCTipWidget", text="MCTipWidget", content="说明内容:", linkText="链接文本>>", linkUrl="https://www.baidu.com") } ``` -------------------------------- ### Getting NukkitMaster Instance Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B11%EF%BC%9A%E4%BD%BF%E7%94%A8Nukkit%E5%BC%80%E6%9C%8D/1-NukkitMasterAPI%E6%96%87%E6%A1%A3.html Example code for obtaining an instance of the NukkitMaster API. ```APIDOC ## Getting NukkitMaster Instance ### Description This code snippet demonstrates how to get an instance of the NukkitMaster API within your plugin. ### Language Java ### Code Example ```java import com.neteasemc.nukkitmaster.NukkitMaster; import cn.nukkit.plugin.PluginBase; public final class App extends PluginBase { NukkitMaster nukkitMaster; @Override public void onEnable() { // Get instance directly nukkitMaster = NukkitMaster.getInstance(); // Or get via plugin manager // nukkitMaster = (NukkitMaster) getServer().getPluginManager().getPlugin("NukkitMaster"); } } ``` ``` -------------------------------- ### UI Interface Initialization Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B5%EF%BC%9A%E6%8F%92%E4%BB%B6%E6%95%99%E5%AD%A6/%E7%AC%AC1%E8%8A%82%EF%BC%9A%E5%AE%98%E7%BD%91%E6%8F%92%E4%BB%B6%E8%A7%84%E8%8C%83.html Demonstrates how to register, create, set the layer, and toggle visibility for a custom UI screen. ```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) ``` -------------------------------- ### Get Component Classes - Python Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/15-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B8%E6%88%8F%E5%86%85%E5%AE%B9/5-%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC/05-%E5%B8%B8%E7%94%A8%E8%84%9A%E6%9C%AC%E5%AF%B9%E8%B1%A1.html Retrieves predefined component classes used for building book interfaces. These functions follow the pattern 'Get' + ComponentName + 'Cls' and take no arguments. Examples include getting TextComp and ImageComp classes. ```python import mod.client.extraClientApi as clientApi bookManager = clientApi.GetBookManager() bcf = bookManager.GetBookConfig() TitlePage = bookManager.GetTitlePageCls() TextComp = bookManager.GetTextCompCls() ImageComp = bookManager.GetImageCompCls() class MyTitlePage(TitlePage): def __init__(self, size = None, position = None): TitlePage.__init__(self, size, position) self.content1 = TextComp(bcf.TextAlign.Left) self.image = ImageComp() self.content2 = TextComp(bcf.TextAlign.Left) self.AddComps(self.content1, self.image, self.content2) ``` -------------------------------- ### Mod Entry Point Script Structure Source: https://mcwiki.easecation.net/mconline/15-%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6%E6%95%99%E7%A8%8B/10-%E6%A8%A1%E7%BB%84SDK%E5%88%9D%E6%AD%A5/1-%E4%BA%86%E8%A7%A3%E6%A8%A1%E7%BB%84SDK%E6%A1%86%E6%9E%B6%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95.html This example demonstrates the basic structure of a mod's entry point script (`modMain.py`), including initialization and registration of server and client systems. ```APIDOC ## modMain.py - Mod Entry Point ### Description This file serves as the entry point for Python scripts in the Minecraft China Version Modding SDK. The engine identifies this file as the initial execution point for a mod. The filename must be `modMain.py`. ### Method N/A (Script Entry Point) ### Endpoint N/A (Script File) ### Parameters N/A ### Request Example ```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 = "TutorialMod", version = "0.0.1") class TutorialMod(object): def __init__(self): print "===== init tutorial mod ======" @Mod.InitServer() def TutorialServerInit(self): print "===== init tutorial server ====" serverApi.RegisterSystem("TutorialMod", "TutorialServerSystem", "tutorialScripts.tutorialServerSystem.TutorialServerSystem") @Mod.DestroyServer() def TutorialServerDestroy(self): print "===== destroy tutorial server ====" @Mod.InitClient() def TutorialClientInit(self): print "===== init hugo fps client ====" clientApi.RegisterSystem("TutorialMod", "TutorialClientSystem", "tutorialScripts.tutorialClientSystem.TutorialClientSystem") @Mod.DestroyClient() def TutorialClientDestroy(self): print "===== destroy hugo fps client ====" ``` ### Response N/A (Script Execution) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Teleport Falling Players to Start Source: https://mcwiki.easecation.net/mconline/10-addon%E6%95%99%E7%A8%8B/%E7%AC%AC05%E7%AB%A0%EF%BC%9AMCSTUDIO%E5%8A%9F%E8%83%BD%E7%AE%80%E4%BB%8B/%E8%AF%BE%E7%A8%8B07.%E7%AE%80%E6%98%93%E6%95%99%E5%AD%A6%E2%91%A1%EF%BC%9A%E5%88%B6%E4%BD%9C%E4%B8%80%E6%9D%A1%E8%B7%91%E9%85%B7%E8%B5%9B%E9%81%93.html A repeating command block setup that detects players falling below a certain height within a defined area and teleports them back to the start point. ```Minecraft Command /tp @a[x=-13,dx=26,y=0,dy=40,z=0,dz=100,m=!c] 0 47 8 ``` -------------------------------- ### Python Mod Initialization and Registration (Client/Server) Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B2%EF%BC%9AApollo%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/%E7%AC%AC6%E8%8A%82%EF%BC%9A%E4%BB%8EMod%E5%88%B0%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8FMod.html Demonstrates how to initialize and register client and server systems for a Mod using Python. It shows the use of decorators like @Mod.InitClient() and @Mod.DestroyClient() for client-side logic, and commented-out examples for server-side logic. ```python @Mod.Binding(name = "TutorialMod", version = "0.0.1") class TutorialMod(object): # 的列化入化关数 def __init__(self): print "===== init tutorial mod ======" # InitServer的癶合关数作为服务端脚本初始化的入口关数最常用于注册服务端系统system和组件component # @Mod.InitServer() # def TutorialServerInit(self): # print "===== init tutorial server ======" # # 关数可以将System注册到服务端引擎中实例的创建和关闭由引擎处理第一个参数是MOD名称第二个是System名称第三个是自定义MOD System类的路径 # # 取名名称尽量个性化不能与其他人的MOD冲突可以使用英文拼音下划线这三种 # serverApi.RegisterSystem("TutorialMod", "TutorialServerSystem", "tutorialScripts.tutorialServerSystem.TutorialServerSystem") # # # DestroyServer的癶合关数作为脐服务端脚本退出时执行的初始化关数通常用于反注册一些内容可为空 # @Mod.DestroyServer() # def TutorialServerDestroy(self): # print "===== destroy tutorial server ======" # InitClient的癶合关数作为可用户端脚本初始化的入口关数通常用于注册可用户系统system和组件component @Mod.InitClient() def TutorialClientInit(self): print "===== init hugo fps client ====" # 关数可以将System注册到可用户引擎中实例的创建和关闭由引擎处理第一个参数是MOD名称第二个是System名称第三个是自定义MOD System类的路径 # 取名名称尽量个性化不能与其他人的MOD冲突可以使用英文拼音下划线这三种 clientApi.RegisterSystem("TutorialMod", "TutorialClientSystem", "tutorialScripts.tutorialClientSystem.TutorialClientSystem") # DestroyClient的癶合关数作为可用户端脚本退出时执行的初始化关数通常用于反注册一些内容可为空 @Mod.DestroyClient() def TutorialClientDestroy(self): print "===== destroy hugo fps client ====" ``` -------------------------------- ### POST StartNavTo Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E7%8E%A9%E5%AE%B6/%E5%AF%BC%E8%88%AA.html Starts an automated navigation system that guides the player using visual sequence frames. ```APIDOC ## POST StartNavTo ### Description Initiates a navigation system that displays visual markers (sequence frames) leading to the target. Automatically re-navigates if the player deviates. ### Method POST ### Endpoint mod.client.extraClientApi.StartNavTo ### Parameters - **pos** (tuple(float,float,float)) - Required - Target coordinates - **sfxPath** (str) - Required - Path to the sequence frame asset - **callback** (function) - Required - Function called upon reaching the destination - **sfxIntl** (float) - Optional - Interval between markers (default: 2) - **sfxMaxNum** (int) - Optional - Max concurrent markers (default: 16) ### Request Example { "pos": [100.0, 64.0, 100.0], "sfxPath": "textures/arrow.png", "callback": "myCallback" } ### Response #### Success Response (200) - **status** (int) - 0 for success, negative values for errors ``` -------------------------------- ### Initialize Client and Server System Base Classes Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/13-%E6%A8%A1%E7%BB%84SDK%E7%BC%96%E7%A8%8B/2-Python%E8%84%9A%E6%9C%AC%E5%BC%80%E5%8F%91/4-%E7%B3%BB%E7%BB%9F%E7%AE%80%E4%BB%8B.html This snippet demonstrates how to import the Easecation API and retrieve the base classes for ClientSystem and ServerSystem. These classes are required for creating custom systems within the game environment. ```python import client.extraClientApi as clientApi ClientSystem = clientApi.GetClientSystemCls() import server.extraServerApi as serverApi ServerSystem = serverApi.GetServerSystemCls() ``` -------------------------------- ### Get UI Node Example Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/15-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B8%E6%88%8F%E5%86%85%E5%AE%B9/5-%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC/02-%E8%84%9A%E6%9C%AC%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC.html Demonstrates how to retrieve a UI node for a book screen using client API. ```APIDOC ## Get UI Node Example ### Description This snippet shows how to get a specific UI node, in this case, the book screen, using the client API. ### Method `clientApi.GetUI(nameSpace, uiKey)` ### Endpoint N/A (Client-side API call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import mod.client.extraClientApi as clientApi # Where nameSpace = "BookMod", uiKey = "book_screen.main" node = clientApi.GetUI("BookMod", "book_screen.main") print node ``` ### Response #### Success Response (200) - **node** (object) - The UI node object for the book screen. #### Response Example ```json { "node": "" } ``` ``` -------------------------------- ### Example Plugin Directory Structure Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B5%EF%BC%9A%E6%8F%92%E4%BB%B6%E6%95%99%E5%AD%A6/%E7%AC%AC1%E8%8A%82%EF%BC%9A%E5%AE%98%E7%BD%91%E6%8F%92%E4%BB%B6%E8%A7%84%E8%8C%83.html Demonstrates the required root directory structure for a plugin involving master, service, and lobby components. ```text ├─lovecraftGuildMaster ├─lovecraftGuild ├─lovecraftGuildService ``` -------------------------------- ### Get Custom Entity Variable Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E5%AE%9E%E4%BD%93/molang.html Retrieves the value of a registered entity calculation node. The variable name must start with 'query.mod.'. ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateQueryVariable(entityId) result = comp.Get('query.mod.state') ``` -------------------------------- ### Initialize Portal System Source: https://mcwiki.easecation.net/mconline/15-%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6%E6%95%99%E7%A8%8B/14-%E5%88%9B%E9%80%A0%E6%96%B0%E7%9A%84%E4%B8%96%E7%95%8C/2-%E8%AE%BE%E8%AE%A1%E7%BB%B4%E5%BA%A6%E4%BC%A0%E9%80%81%E9%97%A8.html Sets up the portal system constants, including dimension IDs, block names, and the structural pattern of the portal. It also registers necessary event listeners for portal interaction. ```python class Main(ServerSystem): def __init__(self, namespace, system): ServerSystem.__init__(self, namespace, system) self.TARGET_DIMENSION_ID = 1688560817 self.telePortBlockName = 'tutorial_demo:custom_dim_gate' self.backPortBlockName = 'tutorial_demo:custom_dim_gate_back' self.pattern = ['####', '#**#', '#**#', '####'] self.defines = {'#': 'minecraft:glowstone', '*': 'minecraft:air'} self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'ServerItemUseOnEvent', self, self.OnServerItemUseOnEvent) ``` -------------------------------- ### Size Animation Example Source: https://mcwiki.easecation.net/mcguide/18-%E7%95%8C%E9%9D%A2%E4%B8%8E%E4%BA%A4%E4%BA%92/19-%E6%8E%A7%E4%BB%B6%E5%B1%9E%E6%80%A7%E5%8A%A8%E7%94%BB.html Illustrates a size animation for a control, changing its dimensions over time. The 'size' attribute is animated, specifying the start and end dimensions. ```json { "sizeImg" : { "size" : "@size_ani", "texture" : "textures/netease/common/image/default", "type" : "image", "visible" : true }, "size_ani": { "anim_type" : "size", "duration" : 1.0, "from" : [100, 100], "to" : [150, 150] } } ``` -------------------------------- ### Alpha Animation Example Source: https://mcwiki.easecation.net/mcguide/18-%E7%95%8C%E9%9D%A2%E4%B8%8E%E4%BA%A4%E4%BA%92/19-%E6%8E%A7%E4%BB%B6%E5%B1%9E%E6%80%A7%E5%8A%A8%E7%94%BB.html Demonstrates an alpha animation for an image control, changing its transparency over time. It requires the 'alpha' attribute and defines start, end, and intermediate states. ```json { "alphaImg" : { "alpha" : "@show_alpha_ani", "texture" : "textures/netease/common/image/default", "type" : "image", "visible" : true }, "show_alpha_ani": { "anim_type" : "alpha", "duration" : 0.30, "from" : 0.0, "next" : "@hold_alpha_ani", "to" : 1.0 }, "hold_alpha_ani" : { "anim_type" : "alpha", "duration" : 1, "from" : 1.0, "next" : "@hide_alpha_ani", "to" : 1.0 }, "hide_alpha_ani" : { "anim_type" : "alpha", "duration" : 0.30, "from" : 1.0, "to" : 0.0 } } ``` -------------------------------- ### Initialize ButtonComp Component Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/15-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B8%E6%88%8F%E5%86%85%E5%AE%B9/5-%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC/03-%E7%BB%84%E4%BB%B6API.html Demonstrates how to retrieve the ButtonComp class from the book manager and instantiate a new button component. ```python import mod.client.extraClientApi as clientApi # 获取书本管理对象,详细用法见“05-常见脚本对象” bookManager = clientApi.GetBookManager() # 获取预设组件类 ButtonComp ButtonComp = bookManager.GetButtonCompCls() # 创建ButtonComp实例 buttonComp = ButtonComp() ``` -------------------------------- ### Get Fog Length (Python) Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E4%B8%96%E7%95%8C/%E6%B8%B2%E6%9F%93.html Retrieves the fog's start and end range. This function is part of the fog component client and returns a tuple of two floats. ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateFog(levelId) start,end = comp.GetFogLength() ``` -------------------------------- ### Initialize Server System and Listen for Block Use Events (Python) Source: https://mcwiki.easecation.net/mconline/20-%E7%8E%A9%E6%B3%95%E5%9C%B0%E5%9B%BE%E6%95%99%E7%A8%8B/%E7%AC%AC04%E7%AB%A0%EF%BC%9A%E5%8F%91%E6%8C%A5%E5%88%9B%E6%84%8F%E6%9E%84%E5%BB%BA%E5%9C%BA%E6%99%AF/%E8%AF%BE%E7%A8%8B03.%E8%A7%84%E5%88%92%E5%8F%AF%E8%BD%BB%E5%BE%AE%E5%8F%98%E5%8A%A8%E5%8C%BA%E5%9F%9F.html Initializes the ServerSystem, registers a listener for 'ServerBlockUseEvent', and configures a whitelist for blocks that should trigger this event. It specifically adds grass, grass path, and standing signs to the whitelist. It also sets up a list of resource positions and a repeated timer for respawning resources. ```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) ``` -------------------------------- ### GetPath: Get BaseUIControl Relative Path (Python) Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E8%87%AA%E5%AE%9A%E4%B9%89UI/UI%E6%8E%A7%E4%BB%B6.html Returns the relative path of the current control, starting from the canvas node. The path is a string representing the control's location within the UI hierarchy. ```python text2Path = "/panel/text2" baseUIControl = uiNode.GetBaseUIControl(text2Path) path = baseUIControl.GetPath() ``` -------------------------------- ### Initialize UI and Listen for Server Events (Python) Source: https://mcwiki.easecation.net/mconline/20-%E7%8E%A9%E6%B3%95%E5%9C%B0%E5%9B%BE%E6%95%99%E7%A8%8B/%E7%AC%AC05%E7%AB%A0%EF%BC%9A%E8%AE%BE%E7%BD%AENPC%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%8A%B6%E6%80%81%E5%92%8C%E4%BA%A4%E6%98%93%E8%A1%A8/%E8%AF%BE%E7%A8%8B03.%E7%BB%99NPC%E6%B7%BB%E5%8A%A0%E5%AF%B9%E5%BA%94%E7%9A%84%E4%BA%A4%E6%98%93%E8%A1%A8.html This Python client-side script initializes the UI and listens for a 'create_shop_ui' event from the server. It registers a UI screen and defines a callback function to push the shop screen when the event is received. Dependencies include the clientApi. ```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") ``` -------------------------------- ### Start Navigation with Visual Cues Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E7%8E%A9%E5%AE%B6/%E5%AF%BC%E8%88%AA.html Implements a navigation system based on GetNavPath, guiding the player using a sequence of sprites along the calculated path. It automatically re-navigates if the player deviates. Developers can customize sprite appearance, timing, and behavior. ```description method in mod.client.extraClientApi Parameters: pos (tuple(float,float,float)): Target coordinates. sfxPath (str): Path to the sprite assets for the navigation trail. callback (function): Function called upon reaching the destination (receives a bool). sfxIntl (float): Interval between sprites. Defaults to 2. sfxMaxNum (int): Max concurrent sprites. Defaults to 16. sfxScale (tuple(float,float)): Scale of sprites. Defaults to (0.5, 0.5). maxIteration (int): Max A* search iterations. Defaults to 800. isSwimmer (bool): Whether the target is in water. Defaults to False. fps (int): Sprite frame rate. Defaults to 20 (max 30). playIntl (int): Interval between sprite animations. Defaults to 8 frames. duration (int): Duration of a single sprite frame. Defaults to 60 frames (min 10). oneTurnDuration (int): Interval between animation cycles. Defaults to 90 frames (min 1.5 * duration). sfxDepthTest (bool): Whether sprites enable depth testing. Defaults to False. Returns: int: 0 for success, -1 for player unreachable, 1 for invalid params, 2 for chunk not loaded, 3 for solid target block. ``` -------------------------------- ### SpigotMaster Plugin Initialization Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B10%EF%BC%9A%E4%BD%BF%E7%94%A8Spigot%E5%BC%80%E6%9C%8D/81-SpigotMasterAPI%E6%96%87%E6%A1%A3.html Shows how to obtain an instance of the SpigotMaster plugin. ```APIDOC ## SpigotMaster Plugin Initialization ### Description This snippet demonstrates how to get an instance of the SpigotMaster plugin, which is necessary for using other API methods. ### Method Java (Bukkit Plugin Manager) ### Endpoint N/A (In-game Java code) ### Request Example ```java import com.neteasemc.spigotmaster.SpigotMaster; // Get the SpigotMaster plugin instance SpigotMaster spigotMaster = (SpigotMaster) Bukkit.getPluginManager().getPlugin("SpigotMaster"); // Now you can use spigotMaster to call other API methods. ``` ### Response N/A ``` -------------------------------- ### Get Engine Packet Statistics Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B8%EF%BC%9A%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/%E7%AC%AC1%E8%8A%82%EF%BC%9A%E6%8F%92%E4%BB%B6%E8%B0%83%E8%AF%95%E5%B0%8F%E6%8A%80%E5%B7%A7.html This section details how to use the StartRecordPacket and StopRecordPacket APIs to capture and analyze engine-level network packet statistics. It also provides a Python code example demonstrating how to integrate these functions and interpret the results, along with an explanation of the log output. ```APIDOC ## Get Engine Packet Statistics ### Description Use the `StartRecordPacket` and `StopRecordPacket` APIs to obtain engine-level send/receive packet statistics. Be aware that packet statistics collection has a significant overhead and is not recommended for long-term use on production servers. As these APIs currently require explicit calls, you may need to wrap them in operational commands for real-time monitoring. ### Method This is a conceptual API usage, not tied to a specific HTTP method. The functions `StartRecordPacket` and `StopRecordPacket` are called programmatically. ### Endpoint N/A (Internal API calls) ### Parameters N/A ### Request Example ```python def DoProfilePacket(self, second): serverApi.StartRecordPacket() def finishProfile(): result = serverApi.StopRecordPacket() for packetName, data in result.iteritems(): head = "packet[{}]".format(packetName) head = head.ljust(20) print "{} sendNum={} sendSize={} recvNum={} recvSize={}".format(head, data["send_num"], data["send_size"], data["recv_num"], data["recv_size"]) comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId()) comp.AddTimer(second, finishProfile) ``` ### Response When the `DoProfilePacket` function is triggered (e.g., via chat or other commands), logs similar to the following will appear in the server process log: #### Success Response (Log Output) - **packet[PacketName]** (string) - The name of the engine message packet. - **sendNum** (integer) - The number of times this packet was sent during the statistics interval. - **sendSize** (integer) - The total size in bytes of data sent using this packet type during the interval (logical size, not network transmitted size). - **recvNum** (integer) - The number of times this packet was received during the statistics interval. - **recvSize** (integer) - The total size in bytes of data received using this packet type during the interval (logical size, not network transmitted size). #### Response Example ``` [2021-05-07 11:25:54 INFO] Python:packet[NeteaseNetGameTransferPacket] sendNum=29 sendSize=1525 recvNum=271 recvSize=14162 [2021-05-07 11:25:54 INFO] Python:packet[MovePlayerPacket] sendNum=0 sendSize=0 recvNum=4 recvSize=120 [2021-05-07 11:25:54 INFO] Python:packet[LevelChunkPacket] sendNum=15 sendSize=360 recvNum=0 recvSize=0 ``` ### Notes - `NeteaseNetGameTransferPacket` often represents the sum of all other packet transfers due to proxy forwarding. - `LevelSoundEventPacket` is an example of an engine message packet name. - `sendNum` and `recvNum` indicate the count of packet transmissions/receptions. - `sendSize` and `recvSize` indicate the logical byte size of the data transferred, not the actual network payload size after encryption/compression. ``` -------------------------------- ### Create Custom Book Component Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/15-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B8%E6%88%8F%E5%86%85%E5%AE%B9/5-%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC/02-%E8%84%9A%E6%9C%AC%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B9%A6%E6%9C%AC.html Demonstrates how to inherit from BaseComp, initialize the component with UI node mapping, store data, and render the component using the Show method. ```python BaseComp = bookManager.GetBaseCompCls() class MyCustomComp(BaseComp): def __init__(self): BaseComp.__init__(self, "CustomMod:MyCustomComp", "CustomComp.main", "testComp") self.text = None self.textSize = None self.textColor = None self.image = None def SetDataBeforeShow(self, image, text, textColor, textSize): self.text = text self.textSize = textSize self.textColor = textColor self.image = image return self def Show(self): BaseComp.Show(self) textNode = self.GetRootUINode().GetChildByPath("/text").asLabel() self.SetNodeText(textNode, self.text).SetNodeTextFontSize(textNode, 10, self.textSize) textNode.SetTextColor(self.textColor) imageNode = self.GetRootUINode().GetChildByPath("/image").asImage() imageNode.SetSprite(self.image) return self ``` -------------------------------- ### Configure Command Variants Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/15-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B8%E6%88%8F%E5%86%85%E5%AE%B9/9-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8C%87%E4%BB%A4.html Demonstrates how to define multiple parameter sets (args1, args2, etc.) for a single command to support different input patterns. ```json { "format_version": "0.0.1", "name": "customtest3", "description": "测试参数变体", "args": [ ... ], "args1": [ ... ], "args2": [ ... ] } ``` -------------------------------- ### Register KetherScript Component (AbolethPlus Get) Source: https://mcwiki.easecation.net/mcguide/28-%E7%94%B5%E8%84%91%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B4%EF%BC%9A%E5%B8%B8%E8%A7%81%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%95%99%E7%A8%8B/31-TabooLib/1-%E5%9F%BA%E7%A1%80%E6%8A%80%E6%9C%AF/10-KetherScript.html This Kotlin code defines and registers a custom KetherScript component for AbolethPlus, specifically for retrieving key-value pairs. It includes parsers for different retrieval scenarios, handling default values and target players, and provides examples of its usage within KetherScript. ```kotlin class AboPlusGetActions { class GetKeyValue(val key: ParsedAction<*>, val default: ParsedAction<*>? = null, val target: ParsedAction<*>? = null) : ScriptAction() { override fun run(frame: ScriptFrame): CompletableFuture { val future = CompletableFuture() val keyString = frame.newFrame(key).run().get() val defString = default?.let { frame.newFrame(it).run().get() } ?: "" val targetOrNull = target?.let { frame.newFrame(it).run().get() } val targetString = if (targetOrNull.isNullOrEmpty()) { frame.player().uniqueId } else { AbolethPlusAPI.getUserUUID(targetOrNull) } val result = AbolethPlusAPI.getValue(targetString, keyString, defString).getValueData(defString) future.complete(result) return future } } class GetKeyDefault(private val key: ParsedAction<*>) : ScriptAction() { override fun run(frame: ScriptFrame): CompletableFuture { val future = CompletableFuture() val keyString = frame.newFrame(key).run().get() val result = AbolethPlusAPI.getDefault(keyString) future.complete(result) return future } } /** * shared = true 公有语句 * abpg {action} [def [{action}]] [@ (server|ID)] -> 获取语句 * * abpg key -> 获取 key 值, 默认值 "" * abpg key def -> 获取 key 的默认值 * abpg key def "default" -> 获取 key 的值, 默认值 "default" * * @author 鹰 * @since 2023/9/6 * */ companion object { @KetherParser(["abpg", "abolethplusget"], shared = true) fun parser() = scriptParser { val keyAction = it.nextParsedAction() it.mark() try { it.expect("def") it.mark() val defaultAction = it.nextParsedAction() if (it.hasNext()) { val target = matchTarget(it) GetKeyValue(keyAction, defaultAction, target) } else { it.reset() GetKeyDefault(keyAction) } } catch (ex: Exception) { it.reset() val target = matchTarget(it) GetKeyValue(keyAction, target = target) } } private fun matchTarget(it: QuestReader) = try { it.mark() it.expect("@") it.nextParsedAction() } catch (ex: Throwable) { it.reset() literalAction("") } } } ``` -------------------------------- ### Implement Server-Side Player Login Source: https://mcwiki.easecation.net/mcguide/27-%E6%89%8B%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B4%EF%BC%9A%E7%AE%80%E6%98%93%E7%BD%91%E7%BB%9C%E6%9C%8D%E6%A8%A1%E6%9D%BF%E7%9F%A5%E8%AF%86%E8%AE%B2%E8%A7%A3/%E7%AC%AC3%E8%8A%82%EF%BC%9A%E8%BF%9B%E5%85%A5%E4%B8%8E%E9%80%80%E5%87%BA%E6%B8%B8%E6%88%8F.html Demonstrates how to listen for the AddServerPlayerEvent in a server system to initialize player information upon login. ```python class AwesomeServer(ServerSystem): def __init__(self, namespace, systemName): ServerSystem.__init__(self, namespace, systemName) self.ListenForEvent( serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), modConfig.AddServerPlayerEvent, self, self.OnAddServerPlayer ) def OnAddServerPlayer(self, args): playerId = args.get('id','-1') uid = netgameApi.GetPlayerUid(playerId) self.mPlayerid2uid[playerId] = uid ``` -------------------------------- ### Minecraft Command Syntax and Examples Source: https://mcwiki.easecation.net/mconline/60-%E6%88%91%E7%9A%84%E4%B8%96%E7%95%8C%E5%88%9B%E9%80%A0%E8%90%A5%E6%95%99%E7%A8%8B/%E7%8E%A9%E6%B3%95%E5%9C%B0%E5%9B%BE%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/4-%E5%8F%AF%E4%BB%A5%E6%94%B9%E5%8F%98%E4%B8%96%E7%95%8C%E7%9A%84%E5%91%BD%E4%BB%A4%E5%92%8C%E6%96%B9%E5%9D%97%E4%BB%A5%E5%8F%8A%E6%9D%90%E8%B4%A8%E5%8C%85.html Demonstrates the basic structure of Minecraft commands, which are entered in the chat window. Commands typically start with a forward slash (/) followed by the command name and its arguments. Common commands include changing game modes, setting game rules, generating blocks, and giving items to players. ```minecraft-commands /gamemode creative /gamerule doDaylightCycle false /setblock ~ ~ ~ minecraft:stone /give @p diamond 64 ``` -------------------------------- ### Initialize Portal System Source: https://mcwiki.easecation.net/mconline/15-%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6%E6%95%99%E7%A8%8B/14-%E5%88%9B%E9%80%A0%E6%96%B0%E7%9A%84%E4%B8%96%E7%95%8C/2-%E8%AE%BE%E8%AE%A1%E7%BB%B4%E5%BA%A6%E4%BC%A0%E9%80%81%E9%97%A8.html Sets up the portal system class, defining dimension IDs, portal block names, and structural patterns. It also registers necessary event listeners for server-side interactions. ```python class Main(ServerSystem): def __init__(self, namespace, system): ServerSystem.__init__(self, namespace, system) self.TARGET_DIMENSION_ID = 23333 self.telePortBlockName = 'portalGateDemo:gateProtal' self.backPortBlockName = 'portalGateDemo:gateProtalBack' self.pattern = [ '####', '#**#', '#**#', '####', ] self.defines = {'#': 'minecraft:glowstone', '*': 'minecraft:air'} self.touchPos =[(3,1), (3,2)] self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'ServerItemUseOnEvent', self, self.OnServerItemUseOnEvent) self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'DimensionChangeFinishServerEvent', self, self.OnPortalForcerServerEvent) ``` -------------------------------- ### Get Entities In Square Area (Client) Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E4%B8%96%E7%95%8C/%E5%9C%B0%E5%9B%BE.html Retrieves a list of entity IDs within a defined square area on the client. The area is specified by start and end positions. This method operates within the player's current dimension and uses the Separating Axis Theorem for collision detection. Similar to the server version, block 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)) ``` -------------------------------- ### Client UI Initialization and Screen Management (Python) Source: https://mcwiki.easecation.net/mconline/15-%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6%E6%95%99%E7%A8%8B/13-%E5%88%9B%E5%BB%BAUI/3-%E6%8C%91%E6%88%98%EF%BC%9A%E8%AE%BE%E8%AE%A1%E7%AE%B1%E5%AD%90%E9%94%81.html Demonstrates the client-side initialization of custom UI elements in a Minecraft mod. It covers registering the UI, pushing screens onto the scene stack, and popping them off, along with parameter passing to UI代理类. ```python # -*- coding: utf-8 -*- import mod.client.extraClientApi as clientApi from ChestLockScripts.config.sys import MOD_PASSWORD_SAVE_EVENT, MOD_PASSWORD_CHECK_EVENT ScreenNode = clientApi.GetScreenNodeCls() ViewBinder = clientApi.GetViewBinderCls() ViewRequest = clientApi.GetViewViewRequestCls() ``` -------------------------------- ### Create a Basic Chest GUI Source: https://mcwiki.easecation.net/mcguide/28-%E7%94%B5%E8%84%91%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F/%E8%AF%BE%E7%A8%8B4%EF%BC%9A%E5%B8%B8%E8%A7%81%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%95%99%E7%A8%8B/31-TabooLib/1-%E5%9F%BA%E7%A1%80%E6%8A%80%E6%9C%AF/7-%E7%AE%B1%E5%AD%90%E9%A1%B5%E9%9D%A2%E4%B8%8E%E8%87%AA%E5%AE%9A%E4%B9%89GUI.html Demonstrates how to open a standard chest menu with a custom layout and an interactive item using the TabooLib DSL. ```kotlin fun openMenu(player: Player) { player.openMenu("箱子标题") { map( "#########", "# A #", "#########", ) set('A', buildItem(XMaterial.APPLE) { name = "&a苹果" lore.add("&f这是一个苹果") colored() }) { player.sendMessage("点击了苹果") } } } ``` -------------------------------- ### Get Container Size Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E6%96%B9%E5%9D%97/%E5%AE%B9%E5%99%A8.html Gets the capacity size of a container. ```APIDOC ## GetContainerSize ### Description Gets the capacity size of a container. ### Method Server ### Endpoint mod.server.component.itemCompServer.ItemCompServer ### Parameters #### Path Parameters - **pos** (tuple(int,int,int)) - Required - The position of the container. - **dimensionId** (int) - Required - The dimension ID of the container. ### Response #### Success Response (200) - **int** - The size of the container. Returns -1 for an error. ### Remarks - This interface does not support Ender Chests, as their size is fixed at 27. ### Response Example ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(levelId) comp.GetContainerSize((x, y, z), 0) ``` ``` -------------------------------- ### Get Entities In Square Area (Server) Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E4%B8%96%E7%95%8C/%E5%9C%B0%E5%9B%BE.html Fetches a list of entity IDs within a defined square area (axis-aligned bounding box) on the server. The area is defined by start and end positions and a dimension ID. It uses the Separating Axis Theorem for collision detection, meaning only overlapping AABBs are considered collisions. Note that block coordinates represent vertex positions, not block centers. ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateGame(levelId) comp.GetEntitiesInSquareArea(None, (0,0,0), (100,100,100), 0) ``` -------------------------------- ### Implement Client-Side Attack Logic Source: https://mcwiki.easecation.net/mconline/60-%E6%88%91%E7%9A%84%E4%B8%96%E7%95%8C%E5%88%9B%E9%80%A0%E8%90%A5%E6%95%99%E7%A8%8B/SDK%E5%A4%A7%E5%B8%88%E6%95%99%E7%A8%8B/2-%E6%AD%A6%E5%99%A8%E5%92%8C%E8%A3%85%E5%A4%87%E5%88%B6%E4%BD%9C/1-%E5%88%B6%E4%BD%9C3D%E6%AD%A6%E5%99%A8.html The TutorialClientSystem class handles player input events, checks for custom weapon usage, and triggers state-based attack sequences. It uses timers to manage attack phases and notifies the server to synchronize states with other clients. ```python class TutorialClientSystem(clientApi.GetClientSystemCls()): def __init__(self, namespace, name): super(TutorialClientSystem, self).__init__(namespace, name) self.ListenEvent() self.mQueryVariableComp = CompFactory.CreateQueryVariable(clientApi.GetLocalPlayerId()) self.mItemComp = CompFactory.CreateItem(clientApi.GetLocalPlayerId()) self.mCarriedItem = self.mItemComp.GetCarriedItem() self.mAttackStep = 0 self.mLastAttackTime = 0 def OnLeftClick(self, args=None): if self._IsCarriedCustomWeapon(): args['cancel'] = True if self._LastAttackWillFinished(): self._HandleAttack() def _HandleAttack(self): self.mLastAttackTime = time.time() gameComp.AddTimer(0, self._SetAttackStateAndSyncToOtherClients, 'start') gameComp.AddTimer(0.2, self._SetAttackStateAndSyncToOtherClients, 'will_hit') gameComp.AddTimer(0.5, self._SetAttackStateAndSyncToOtherClients, 'end') ``` -------------------------------- ### Get Chest Box Size Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E6%96%B9%E5%9D%97/%E5%AE%B9%E5%99%A8.html Gets the size (capacity) of a chest block. ```APIDOC ## GetChestBoxSize ### Description Gets the size (capacity) of a chest block. ### Method Server ### Endpoint mod.server.component.chestContainerCompServer.ChestContainerCompServer ### Parameters #### Path Parameters - **playerId** (None) - Deprecated. - **pos** (tuple(int,int,int)) - Required - The position of the chest. - **dimensionId** (int) - Required - The dimension ID of the chest. Can get the capacity of chests in continuously loaded chunks within the corresponding dimension. #### Request Body None ### Response #### Success Response (200) - **int** - The size of the chest, returns -1 for an error. #### Response Example ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateChestBlock(levelId) comp.GetChestBoxSize(None, (x, y, z), 0) ``` ``` -------------------------------- ### Implement Dynamic Configuration Loading Source: https://mcwiki.easecation.net/mcguide/20-%E7%8E%A9%E6%B3%95%E5%BC%80%E5%8F%91/18-%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%BC%98%E5%8C%96.html Shows how to split large configuration files into smaller modules and load them dynamically on demand to save memory. ```python def load_build_config(data): building = data['build'] if build == '1': # Import configuration on demand import build1 place_build(data, build1) elif build == '2': # Import configuration on demand import build2 place_build(data, build) ``` -------------------------------- ### GET /GetEntityRenderDistance Source: https://mcwiki.easecation.net/mcdocs/1-ModAPI/%E6%8E%A5%E5%8F%A3/%E5%AE%9E%E4%BD%93/%E6%B8%B2%E6%9F%93.html Gets the current render distance for entities relative to the local player. ```APIDOC ## GET /GetEntityRenderDistance ### Description Retrieves the maximum distance at which entities are rendered for the local player. ### Method GET ### Response #### Success Response (200) - **distance** (float) - The render distance value. ``` -------------------------------- ### Implementing UI Screen Nodes Source: https://mcwiki.easecation.net/mconline/60-%E6%88%91%E7%9A%84%E4%B8%96%E7%95%8C%E5%88%9B%E9%80%A0%E8%90%A5%E6%95%99%E7%A8%8B/%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6%E8%BF%9B%E9%98%B6%E6%95%99%E7%A8%8B/3-%E4%BD%BF%E7%94%A8Python%E7%BC%96%E5%86%99%E7%8E%A9%E6%B3%95%E7%BB%84%E4%BB%B6/6-%E4%BB%A3%E7%A0%81%E7%BC%96%E5%86%99%E8%BF%9B%E9%98%B6.html Demonstrates the standard structure for a UI screen node, including member variable initialization and event callback registration. ```python class TitleScreen(ScreenNode): def __init__(self, namespace, name, param): ScreenNode.__init__(self, namespace, name, param) self.mMainPanel = "/main_panel" self.mTitleText = self.mMainPanel + "/title_text" self.mConfirmButton = self.mMainPanel + "/confirm_button" def Create(self): """ @description UI创建成功时调用 """ buttonControl = self.GetBaseUIControl(self.mConfirmButton).asButton() buttonControl.AddTouchEventParams({"isSwallow": True}) buttonControl.SetButtonTouchUpCallback(self.OnConfirmButtonClick) def OnConfirmButtonClick(self, args): text = self.GetBaseUIControl(self.mTitleText).asTextEditBox().GetEditText() presetApi.GetPresetByName("TitleScreen").GetPartByName("界面服务端监听").NotifyToServer("TitleEvent", {"text": text}) clientApi.PopScreen() ``` -------------------------------- ### Initialize NPC Dialogue System in Python Source: https://mcwiki.easecation.net/mconline/20-%E7%8E%A9%E6%B3%95%E5%9C%B0%E5%9B%BE%E6%95%99%E7%A8%8B/%E7%AC%AC08%E7%AB%A0%EF%BC%9A%E5%9C%A8%E5%BC%80%E5%A4%B4%E6%B7%BB%E5%8A%A0%E5%BC%95%E5%AF%BC%E5%85%B3%E5%8D%A1/%E8%AF%BE%E7%A8%8B01.%E4%BD%BF%E7%94%A8MODSDK%E8%87%AA%E5%AE%9A%E4%B9%89NPC%E7%9A%84%E8%81%8A%E5%A4%A9%E5%AF%B9%E8%AF%9D.html Sets up the server system to listen for player attacks on a specific NPC. It initializes dialogue state and handles the first interaction, storing dialogue progress in extra data. ```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) # 提前获取到的NPCid self.guide_id = "-481036336358" # 创建一个控制对话阶段的变量 self.guide_dialogue = {} # 事件触发的函数 def PlayerAttack(self, args): # 事件获取的玩家id self.playername = args["playerId"] # 创建指令、方块和物品的接口 commandcomp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId()) blockcomp = serverApi.GetEngineCompFactory().CreateBlockInfo(serverApi.GetLevelId()) itemcomp = serverApi.GetEngineCompFactory().CreateItem(self.playername) # 事件获取的生物id entityid = args["victimId"] # 如果事件获取的生物id和提前获取的NPCid一致 if entityid == self.guide_id: # 获取 player_guide 数据 guide_data = leveldatacomp.GetExtraData('player_guide') # 如果没有此数据则设置一个 if not guide_data: leveldatacomp.SetExtraData('player_guide', self.guide_dialogue) else: # 如果有就把guide_data传给self.guide_dialogue self.guide_dialogue = guide_data # 如果self.guide_dialogue={}(说明第一次点击这个NPC) if self.guide_dialogue == {}: # 使用指令的接口,生成对话和音效 commandcomp.SetCommand( "execute @a ~ ~ ~ tellraw @a {\"rawtext\":[{\"text\":\" §6§l【家人】 §r§f塔塔村落是一个坐落在深山里的村庄, '成为一个更独立的人' 是村子悠久的传承。 §6[1/6]\"}]}") commandcomp.SetCommand("execute @a ~ ~ ~ /playsound random.orb @a ~ ~ ~ 3 1 3") # 给变量一个新的参数用于控制进入下一个对话阶段 self.guide_dialogue["dialogue"] = 0 # 存储新的player_guide leveldatacomp.SetExtraData('player_guide', self.guide_dialogue) ```