Skip to content

Commit

Permalink
为女仆 AI 添加接口
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Oct 22, 2024
1 parent 302f924 commit f4c25cc
Showing 5 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.overlay.MaidTipsOverlay;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.entity.EntityMaidRenderer;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.entity.GeckoEntityMaidRenderer;
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.ExtraMaidBrainManager;
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
import com.github.tartaricacid.touhoulittlemaid.entity.data.TaskDataRegister;
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskManager;
@@ -72,6 +73,14 @@ default void addMaidMeal(MaidMealManager manager) {
default void registerTaskData(TaskDataRegister register) {
}

/**
* 给女仆添加额外的 AI 数据,比如 MemoryModuleType 或者 SensorType
*
* @param manager 注册器
*/
default void addExtraMaidBrain(ExtraMaidBrainManager manager) {
}

/**
* 添加女仆相关提示
* <p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.tartaricacid.touhoulittlemaid.api.entity.ai;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.sensing.Sensor;
import net.minecraft.world.entity.ai.sensing.SensorType;

import java.util.Collections;
import java.util.List;

public interface IExtraMaidBrain {
/**
* 为女仆 AI 添加新的 MemoryModuleType
*/
default List<MemoryModuleType<?>> getExtraMemoryTypes() {
return Collections.emptyList();
}

/**
* 为女仆 AI 添加新的 SensorType
*/
default List<SensorType<? extends Sensor<? super EntityMaid>>> getExtraSensorTypes() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.tartaricacid.touhoulittlemaid.entity.ai.brain;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.ILittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.entity.ai.IExtraMaidBrain;
import com.google.common.collect.Lists;

import java.util.List;

public final class ExtraMaidBrainManager {
static List<IExtraMaidBrain> EXTRA_MAID_BRAINS = Lists.newArrayList();

public static void init() {
ExtraMaidBrainManager manager = new ExtraMaidBrainManager();
for (ILittleMaid littleMaid : TouhouLittleMaid.EXTENSIONS) {
littleMaid.addExtraMaidBrain(manager);
}
}

public void addExtraMaidBrain(IExtraMaidBrain extraMaidBrain) {
EXTRA_MAID_BRAINS.add(extraMaidBrain);
}
}
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

public final class MaidBrain {
public static ImmutableList<MemoryModuleType<?>> getMemoryTypes() {
return ImmutableList.of(
List<MemoryModuleType<?>> defaultTypes = Lists.newArrayList(
MemoryModuleType.PATH,
MemoryModuleType.DOORS_TO_CLOSE,
MemoryModuleType.LOOK_TARGET,
@@ -34,15 +34,19 @@ public static ImmutableList<MemoryModuleType<?>> getMemoryTypes() {
MemoryModuleType.ATTACK_COOLING_DOWN,
InitEntities.TARGET_POS.get()
);
ExtraMaidBrainManager.EXTRA_MAID_BRAINS.forEach(extra -> defaultTypes.addAll(extra.getExtraMemoryTypes()));
return ImmutableList.copyOf(defaultTypes);
}

public static ImmutableList<SensorType<? extends Sensor<? super EntityMaid>>> getSensorTypes() {
return ImmutableList.of(
List<SensorType<? extends Sensor<? super EntityMaid>>> defaultTypes = Lists.newArrayList(
InitEntities.MAID_NEAREST_LIVING_ENTITY_SENSOR.get(),
SensorType.HURT_BY,
InitEntities.MAID_HOSTILES_SENSOR.get(),
InitEntities.MAID_PICKUP_ENTITIES_SENSOR.get()
);
ExtraMaidBrainManager.EXTRA_MAID_BRAINS.forEach(extra -> defaultTypes.addAll(extra.getExtraSensorTypes()));
return ImmutableList.copyOf(defaultTypes);
}

public static void registerBrainGoals(Brain<EntityMaid> brain, EntityMaid maid) {
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.block.multiblock.MultiBlockManager;
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.ExtraMaidBrainManager;
import com.github.tartaricacid.touhoulittlemaid.entity.ai.fishing.FishingTypeManager;
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
import com.github.tartaricacid.touhoulittlemaid.entity.data.TaskDataRegister;
@@ -27,6 +28,7 @@ public static void onSetupEvent(FMLCommonSetupEvent event) {

private static void modApiInit() {
TouhouLittleMaid.EXTENSIONS = AnnotatedInstanceUtil.getModExtensions();
ExtraMaidBrainManager.init();
TaskManager.init();
BackpackManager.init();
BaubleManager.init();

0 comments on commit f4c25cc

Please sign in to comment.