### Custom Task Language File Example Provides an example of a JSON language file for a custom maid task. The keys are derived from the task's UID, allowing for localization of the task's name and description. ```json { "task.example.custom_task": "Custom Task", "task.example.custom_task.desc": "Custom Task Desc" } ``` -------------------------------- ### Gradle 配置: 添加 CurseForge Maven 仓库 配置 Gradle 以使用 CurseForge Maven 仓库,用于下载女仆模组及其源码。这允许开发者方便地进行代码调试和集成。 ```gradle repositories { // 添加 CurseForge Maven 仓库 maven { url "https://cursemaven.com" content { includeGroup "curse.maven" } } } dependencies { // CurseForge Maven 支持同时下载模组与源码,方便开发调试 implementation fg.deobf('curse.maven:touhou-little-maid-355044:7192649-sources-7192650') } ``` ```gradle repositories { // 添加 CurseForge Maven 仓库 maven { url "https://cursemaven.com" content { includeGroup "curse.maven" } } } dependencies { // CurseForge Maven 支持同时下载模组与源码,方便开发调试 implementation 'curse.maven:touhou-little-maid-355044:7192654-sources-7192655' } ``` -------------------------------- ### Gradle 依赖: 更新女仆模组版本 演示如何通过修改 Gradle 依赖配置中的版本号来适配不同版本的女仆模组。主要涉及更新模组文件 ID 和源码文件 ID。 ```gradle 'curse.maven:touhou-little-maid-355044:7192654-sources-7192655' ``` -------------------------------- ### 使用 BehaviorUtils 管理女仆 AI 目标 (Java) 展示了如何利用 Minecraft 的 BehaviorUtils 类来简化女仆 AI 的目标设置。这些工具能够同时设置行走和观察目标,或仅设置观察目标,极大地提高了 AI 行为管理的效率。 ```java import net.minecraft.world.entity.ai.behavior.BehaviorUtils; // ... 假设 maid 对象已初始化,并且 walktarget 和 entity 已定义 // 同时设置 WALK_TARGET 和 LOOK_TARGET BehaviorUtils.setWalkAndLookTargetMemories(maid, walktarget, entity, 1.0F); // 仅设置 LOOK_TARGET BehaviorUtils.lookAtEntity(maid, entity); // 让两个生物相互设置 LOOK_TARGET BehaviorUtils.lookAtEachOther(maid, maid) ``` -------------------------------- ### Java: 注册女仆模组入口类 使用 `@LittleMaidExtension` 注解标记一个类,使其实现 `ILittleMaid` 接口,作为女仆模组的扩展入口。该类将在女仆模组安装时被自动加载和实例化。 ```java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { } ``` -------------------------------- ### Implement IMaidTask for a Custom Maid Task Demonstrates how to create a custom maid task by implementing the `IMaidTask` interface. This involves defining a unique ID, an icon, and optionally ambient sounds. The `createBrainTasks` method is used to define the AI behavior for the task, returning an empty list for simple tasks. ```java public class CustomTask implements IMaidTask { // 任务 ID,用于区分不同的任务 private static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(Example.MOD_ID, "custom_task"); // 任务图标,这里使用苹果作为示例 private static final ItemStack ICON = Items.APPLE.getDefaultInstance(); // 获取任务的 ID @Override public ResourceLocation getUid() { return UID; } // 获取任务的图标 @Override public ItemStack getIcon() { return ICON; } // 获取女仆在该任务时的音效,可以为 null @Override @Nullable public SoundEvent getAmbientSound(EntityMaid maid) { return null; } // 创建女仆 AI,通过 Minecraft 原版的 BehaviorControl 实现 @Override public List>> createBrainTasks(EntityMaid maid) { // 返回一个空的任务列表,表示没有自定义 AI 行为 return List.of(); } } ``` -------------------------------- ### 生成物品合成表 (NeoForge 1.21.1) 此代码段展示了如何在NeoForge 1.21.1环境下,通过JSON文件修改女仆模组祭坛的合成表来生成物品。与Forge版本不同,NeoForge的合成表配置使用`altar_recipe_serializers`类型,并且输出物品的定义方式有所区别,但核心的power和ingredients字段保持一致。 ```json { "type": "touhou_little_maid:altar_recipe_serializers", "result": { "count": 1, "id": "touhou_little_maid:bookshelf" }, "power": 0.1, "lang": "jei.touhou_little_maid.altar_craft.item_craft.result", "ingredients": [ { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "item": "minecraft:book" }, { "tag": "c:gems/diamond" } ] } ``` -------------------------------- ### Java: 扩展女仆功能 - 饰品与任务 通过实现 `ILittleMaid` 接口的 `bindMaidBauble` 和 `addMaidTask` 方法,可以为女仆模组添加自定义饰品绑定和工作任务。 ```java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { /** * 绑定女仆饰品 * 将自定义饰品与物品进行关联 */ @Override public void bindMaidBauble(BaubleManager manager) { // 将木棍绑定为自定义饰品 manager.bind(Items.STICK, new CustomBauble()); } /** * 注册女仆工作任务 */ @Override public void addMaidTask(TaskManager manager) { // 添加自定义任务 manager.add(new CustomTask()); } } ``` -------------------------------- ### 生成实体合成表 (NeoForge 1.21.1) 此代码段展示了如何在NeoForge 1.21.1环境下,通过JSON配置女仆模组祭坛的合成表来生成实体。与Forge版本不同,NeoForge使用`altar_recipe_serializers`类型,并指定实体ID。由于实体无法直接在JEI中显示,它使用一个占位物品`touhou_little_maid:entity_placeholder`来代表,并通过`components`字段关联配方ID。 ```json { "type": "touhou_little_maid:altar_recipe_serializers", "entity": "minecraft:lightning_bolt", "result": { "id": "touhou_little_maid:entity_placeholder", "count": 1, "components": { "touhou_little_maid:recipe_id": "spawn_lightning_bolt" } }, "power": 0.1, "lang": "jei.touhou_little_maid.altar_craft.spawn_lightning_bolt.result", "ingredients": [ { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "item": "minecraft:book" }, { "tag": "c:gems/diamond" } ] } ``` -------------------------------- ### NeoForge.mods.toml: NeoForge 依赖配置 在 `neoforge.mods.toml` 文件中配置 NeoForge 模组的依赖关系,指定女仆模组的最低版本要求。此配置允许可选依赖,并在安装女仆模组时进行版本检查。 ```toml [[dependencies.netmusic]] modId = "touhou_little_maid" # type 为 optional 表示该依赖为可选,仅在安装了女仆模组时才检查版本 type = "optional" # 限制女仆模组最低版本为 1.3.0 versionRange = "[1.3.0,)" # 确保在女仆模组之后加载 ordering = "AFTER" side = "BOTH" ``` -------------------------------- ### 绑定女仆饰品 - Java 在 LittleMaidCompat 类中重写 bindMaubleBauble 方法,使用 BaubleManager 将游戏内物品与自定义饰品进行绑定。这样,当玩家持有该物品时,就可以将其装备为女仆饰品。 ```Java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { // 绑定女仆饰品,将自定义饰品与物品关联 @Override public void bindMaubleBauble(BaubleManager manager) { // 将木棍与自定义饰品绑定 manager.bind(Items.STICK, new CustomBauble()); } } ``` -------------------------------- ### Java: Add Custom Tooltip for Maid Interactions This Java code snippet demonstrates how to add custom in-game tooltips for item interactions with maids. It overrides the addMaidTips method in the LittleMaidCompat class, ensuring the method is only called on the client side using @OnlyIn(Dist.CLIENT). The tooltip is associated with a specific item (apple) and a language key. ```Java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { public LittleMaidCompat() { MinecraftForge.EVENT_BUS.register(new AppleInteractMaidEvent()); } @Override @OnlyIn(Dist.CLIENT) public void addMaidTips(MaidTipsOverlay maidTipsOverlay) { // 第一个参数是语言文件的 key,第二个参数是物品 maidTipsOverlay.addTips("overlay.example.apple.tips", Items.APPLE); } } ``` -------------------------------- ### Java: Handle Apple Interaction with Maid via Event This Java code snippet demonstrates how to handle player interactions with a maid using a specific item (apple) by subscribing to the InteractMaidEvent. It plays a sound, applies a status effect to the maid, consumes the item, and cancels further default actions. It is crucial not to use @Mod.SubscribeEvent on the event handler class itself to prevent crashes when the maid mod is not present. ```Java // 注意:这个类不要使用 @Mod.SubscribeEvent 注解,否则在女仆模组未安装时也会加载该类,导致崩溃 public class AppleInteractMaidEvent { // 处理女仆与苹果交互的事件 @SubscribeEvent public void onAppleInteract(InteractMaidEvent event) { Player player = event.getPlayer(); Level world = event.getWorld(); EntityMaid maid = event.getMaid(); // 获取主手物品 ItemStack stack = event.getStack(); // 不需要判断女仆归属,模组已自动处理 if (stack.is(Items.APPLE)) { // 播放吃东西的音效 world.playSound(null, maid.getX(), maid.getY(), maid.getZ(), maid.getEatingSound(stack), SoundSource.NEUTRAL, 1, 1 + (world.random.nextFloat() - world.random.nextFloat()) * 0.4F); // 添加抗性提升效果,持续60秒,等级1 maid.addEffect(new MobEffectInstance(MobEffectInstance.fromType(MobEffects.DAMAGE_RESISTANCE), 20 * 60, 1)); // 消耗苹果 stack.shrink(1); // 取消后续操作,避免打开女仆GUI event.setCanceled(true); } } } ``` -------------------------------- ### Register a Custom Maid Task with LittleMaidExtension Shows how to register a custom maid task using the `@LittleMaidExtension` annotation and the `ILittleMaid` interface. The `addMaidTask` method is overridden to add an instance of the custom task to the `TaskManager`. ```java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { // 注册女仆工作任务的方法 @Override public void addMaidTask(TaskManager manager) { // 添加自定义任务 manager.add(new CustomTask()); } } ``` -------------------------------- ### Java: Register Maid-Specific Events Safely This Java code snippet shows the recommended way to register maid-specific events within the LittleMaidCompat class. By instantiating the event handler in the constructor of LittleMaidCompat, the event is only registered and triggered if the maid mod is loaded, preventing potential crashes. ```Java @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { // 默认构造函数,女仆模组会在适当时机调用。可在此注册女仆专属事件 public LittleMaidCompat() { MinecraftForge.EVENT_BUS.register(new AppleInteractMaidEvent()); } } ``` -------------------------------- ### JSON: Localization for Maid Interaction Tooltip This JSON snippet provides the localization string for a custom tooltip displayed in the game. It maps the language key 'overlay.example.apple.tips' to the corresponding English text, informing the player about the effect of using an apple with a maid. ```JSON { "overlay.example.apple.tips": "You can right-click with an apple to add a 60-second damage resistance effect" } ``` -------------------------------- ### 生成实体合成表 (Forge 1.20.1) 此代码段演示了如何在Forge 1.20.1环境下,使用JSON配置女仆模组祭坛的合成表来生成实体,例如闪电。该配置指定了输出类型为实体,并允许通过NBT数据进一步定制实体属性。合成所需的能量和材料与生成物品的配置类似。 ```json { "type": "touhou_little_maid:altar_crafting", "output": { "type": "minecraft:lightning_bolt", "nbt": { } }, "power": 0.1, "ingredients": [ { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "item": "minecraft:book" }, { "tag": "forge:gems/diamond" } ] } ``` -------------------------------- ### 实现 IMaidBauble 接口 - Java 创建一个继承自 IMaidBauble 的自定义饰品类,用于定义饰品的行为。onTick 方法会在女仆佩戴饰品后每 tick 调用,可用于 주기적으로 效果。onInjured 方法在女仆受 伤害时调用,可用于处理特定伤害类型。 ```Java public class CustomBauble implements IMaidBauble { /** * 每 tick 调用的方法,为女仆定期添加发光效果。 * * @param maid 女仆实体 * @param baubleItem 饰品物品实例 */ @Override public void onTick(EntityMaid maid, ItemStack baubleItem) { // 每 150 tick 检查一次,减少性能消耗 if (maid.tickCount % 150 == 0) { maid.addEffect(new MobEffectInstance(MobEffects.GLOWING, 200)); } } @Override // onInjured 方法在女仆受到伤害时调用 public boolean onInjured(EntityMaid maid, ItemStack baubleItem, DamageSource source, MutableFloat damage) { // 仅检测火焰伤害类型 if (source.is(DamageTypeTags.IS_FIRE)) { // 损坏饰品(木棍本身无耐久,hurtAndBreak 不起作用) baubleItem.hurtAndBreak(1, maid, m -> maid.sendItemBreakMessage(baubleItem)); // 赋予发光效果 maid.addEffect(new MobEffectInstance(MobEffects.GLOWING, 200)); // 返回 true,表示取消此次伤害 return true; } return false; } } ``` -------------------------------- ### 自定义女仆 Brain 扩展 (Java) 演示了如何通过继承 IExtraMaidBrain 接口来为女仆 AI 添加自定义 Brain 数据。这允许开发者扩展女仆的传感器、记忆模块和 AI 行为,实现更复杂的功能。 ```java import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; import cn.mcmod_mmf.core.entity.maid.EntityMaid; import cn.mcmod_mmf.core.entity.maid.brain.IExtraMaidBrain; import cn.mcmod_mmf.core.entity.maid.brain.behavior.BehaviorControl; import cn.mcmod_mmf.core.entity.maid.brain.memory.MemoryModuleType; import cn.mcmod_mmf.core.entity.maid.brain.manager.ExtraMaidBrainManager; import cn.mcmod_mmf.core.module.LittleMaidExtension; import cn.mcmod_mmf.core.module.ILittleMaid; public class CustomExtraMaidBrain implements IExtraMaidBrain { @Override public List> getExtraMemoryTypes() { // 仅作演示,返回空列表 return Collections.emptyList(); } @Override public List>> getCoreBehaviors() { // 仅作演示,返回空列表 return Collections.emptyList(); } } @LittleMaidExtension public class LittleMaidCompat implements ILittleMaid { @Override public void addExtraMaidBrain(ExtraMaidBrainManager manager) { // 为 Brain 添加自定义内容 manager.addExtraMaidBrain(new CustomExtraMaidBrain()); } } ``` -------------------------------- ### Mods.toml: Forge 依赖配置 在 `mods.toml` 文件中配置 Forge 模组的依赖关系,指定女仆模组的最低版本要求。这有助于确保模组间的兼容性。 ```toml [[dependencies.netmusic]] modId = "touhou_little_maid" # mandatory 为 false 表示该依赖为可选,仅在安装了女仆模组时才检查版本 mandatory = false # 限制女仆模组最低版本为 1.3.0 versionRange = "[1.3.0,)" # 确保在女仆模组之后加载 ordering = "AFTER" side = "BOTH" ``` -------------------------------- ### 残局道具 JSON 结构 - 车万女仆 展示了用于定义残局道具的 JSON 结构。该结构包含标签、显示信息(名称和作者)、棋局数据(FEN 格式)以及权重。'tags' 字段用于区分道具获取方式,'display' 字段包含用于本地化的描述键和作者名,'data' 字段存储棋局状态,'weight' 字段影响道具的随机出现概率。 ```json [ { "tags": [ "library" ], "display": { "description": "board_state.touhou_little_maid.chess.default", "author": "Stockfish" }, "data": "8/8/2k5/8/8/5NB1/4K3/8 w - - 0 1", "weight": 1 } ] ``` -------------------------------- ### 管理女仆 Brain 记忆模块 (Java) 演示了如何使用 Java 管理女仆 AI 的记忆模块。包括设置、设置带有时限以及清除记忆。这些操作对于女仆 AI 的行为决策至关重要,用于数据共享和状态管理。 ```java import net.minecraft.world.entity.ai.memory.MemoryModuleType; // ... 假设 maid 对象已初始化,并且 MemoryModuleType.WALK_TARGET 已定义 // 设置记忆,无超时时间 maid.getBrain().setMemory(MemoryModuleType.WALK_TARGET, walktarget); // 设置记忆,超时时间为 100 tick maid.getBrain().setMemoryWithExpiry(MemoryModuleType.WALK_TARGET, walktarget, 100); // 清除记忆 maid.getBrain().eraseMemory(MemoryModuleType.WALK_TARGET); // 获取记忆数据 maid.getBrain().getMemory(MemoryModuleType.WALK_TARGET) ``` -------------------------------- ### 生成物品合成表 (Forge 1.20.1) 此代码段展示了如何在Forge 1.20.1环境下,通过JSON文件修改女仆模组祭坛的合成表来生成物品。合成表定义了输出物品的NBT信息、所需的能量值(power)以及合成所需的材料(ingredients)。 ```json { "type": "touhou_little_maid:altar_crafting", "output": { "type": "minecraft:item", "nbt": { "Item": { "id": "touhou_little_maid:trumpet", "Count": 1 } } }, "power": 0.1, "ingredients": [ { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "tag": "minecraft:planks" }, { "item": "minecraft:book" }, { "tag": "forge:gems/diamond" } ] } ``` -------------------------------- ### Configure Maid Backup Mechanism (TOML) Configuration settings for the maid backup mechanism in the `touhou_little_maid-server.toml` file. This section allows enabling the backup feature, setting the interval between backups, and defining the maximum number of backups per player. ```toml # 是否启用女仆备份机制,该机制将定期备份服务器上所有玩家的女仆数据 MaidBackupEnable = false # 女仆备份机制备份女仆数据的间隔时间(以秒为单位) # 范围:> 5 MaidBackupIntervalSeconds = 180 # 启用女仆备份机制时每个玩家的最大备份数量 # 范围:1 ~ 64 MaidBackupMaxCount = 3 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.