Skip to content

Commit

Permalink
移除妖怪名单
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Oct 28, 2024
1 parent ecdc483 commit b494edd
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.github.tartaricacid.touhoulittlemaid.entity.misc.DefaultMonsterType;
import com.github.tartaricacid.touhoulittlemaid.entity.misc.MonsterType;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitItems;
import com.github.tartaricacid.touhoulittlemaid.item.ItemMonsterList;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
Expand All @@ -15,9 +13,7 @@
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

import java.util.Map;
import java.util.Optional;

public interface IAttackTask extends IMaidTask {
Expand Down Expand Up @@ -57,18 +53,11 @@ default boolean canAttack(EntityMaid maid, LivingEntity target) {
return false;
}

// 获取女仆副手是否有妖怪名单
ItemStack offhandItem = maid.getOffhandItem();
if (offhandItem.is(InitItems.MONSTER_LIST.get())) {
Map<ResourceLocation, MonsterType> monsterList = ItemMonsterList.getMonsterList(offhandItem);
if (monsterList.containsKey(id)) {
MonsterType monsterType = monsterList.get(id);
return DefaultMonsterType.canAttack(maid, target, monsterType);
}
}
// TODO 获取女仆 Task Data


// 那如果没有呢?走默认配置
MonsterType monsterType = DefaultMonsterType.getMonsterType(target.getType());
MonsterType monsterType = DefaultMonsterType.getMonsterType(target);
return DefaultMonsterType.canAttack(maid, target, monsterType);
}

Expand All @@ -79,4 +68,9 @@ default boolean hasExtraAttack(EntityMaid maid, Entity target) {
default boolean doExtraAttack(EntityMaid maid, Entity target) {
return false;
}

@Override
default boolean enablePanic(EntityMaid maid) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,24 @@ default boolean isEnable(EntityMaid maid) {
* 但是有些需要专心致志的工作模式,这样做反而会带来问题。将其设置为 false 就能禁止这种情况
*
* @param maid 女仆对象
* @return 禁用四处张望和随机走动 AI
* @return 是否禁用四处张望和随机走动 AI
*/
default boolean enableLookAndRandomWalk(EntityMaid maid) {
return true;
}

/**
* 是否启用慌乱 AI,默认情况下女仆受伤后会乱跑
* <p>
* 但是处于攻击模式或者灭火模式时不应当启用
*
* @param maid 女仆对象
* @return 是否禁用慌乱 AI
*/
default boolean enablePanic(EntityMaid maid) {
return true;
}

/**
* 处于该工作模式时,女仆是否允许坐在娱乐方块上?
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MaidClearHurtTask() {
@Override
protected void start(ServerLevel worldIn, EntityMaid maid, long gameTimeIn) {
boolean hurtOrHostile = MaidPanicTask.isHurt(maid) || MaidPanicTask.hasHostile(maid);
if (MaidPanicTask.isAttack(maid) || !hurtOrHostile) {
if (!MaidPanicTask.canPanic(maid) || !hurtOrHostile) {
maid.getBrain().eraseMemory(MemoryModuleType.HURT_BY);
maid.getBrain().eraseMemory(MemoryModuleType.HURT_BY_ENTITY);
MaidUpdateActivityFromSchedule.updateActivityFromSchedule(maid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task;

import com.github.tartaricacid.touhoulittlemaid.api.task.IAttackTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.google.common.collect.ImmutableMap;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -24,14 +23,14 @@ public static boolean isHurt(EntityMaid maid) {
return maid.getBrain().hasMemoryValue(MemoryModuleType.HURT_BY);
}

public static boolean isAttack(EntityMaid maid) {
return maid.getTask() instanceof IAttackTask;
public static boolean canPanic(EntityMaid maid) {
return maid.getTask().enablePanic(maid);
}

@Override
protected void start(ServerLevel worldIn, EntityMaid maid, long gameTimeIn) {
boolean hurtOrHostile = isHurt(maid) || hasHostile(maid);
if (!isAttack(maid) && hurtOrHostile) {
if (canPanic(maid) && hurtOrHostile) {
Brain<?> brain = maid.getBrain();
if (!brain.isActive(Activity.PANIC)) {
brain.eraseMemory(MemoryModuleType.PATH);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,93 +1,26 @@
package com.github.tartaricacid.touhoulittlemaid.entity.misc;

import com.github.tartaricacid.touhoulittlemaid.entity.item.AbstractEntityFromItem;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitItems;
import com.github.tartaricacid.touhoulittlemaid.item.ItemMonsterList;
import com.google.common.collect.Maps;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.entity.npc.Npc;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import javax.annotation.Nullable;
import java.util.Map;

public final class DefaultMonsterType {
private final static Map<EntityType<?>, MonsterType> DEFAULT = Maps.newHashMap();

public static void initDefault(Level level) {
// 只允许初始化一次
if (!DEFAULT.isEmpty()) {
return;
public static MonsterType getMonsterType(LivingEntity target) {
// 如果继承了 Enemy 接口,那就是敌对生物
if (target instanceof Enemy) {
return MonsterType.HOSTILE;
}

BuiltInRegistries.ENTITY_TYPE.forEach(type -> {
Entity entity = null;

// 因为某些模组方法 create 实体会失败
try {
entity = type.create(level);
} catch (Exception e) {
e.fillInStackTrace();
}

if (!(entity instanceof LivingEntity livingEntity)) {
return;
}

// 排除一些盔甲架,还有本模组的实体,以及玩家
if (livingEntity instanceof ArmorStand || livingEntity instanceof AbstractEntityFromItem || livingEntity instanceof Player) {
return;
}

// 如果继承了 Enemy 接口,那就是敌对生物
if (livingEntity instanceof Enemy) {
DEFAULT.putIfAbsent(type, MonsterType.HOSTILE);
return;
}

// 如果是玩家、宠物、NPC、归为友好
if (livingEntity instanceof TamableAnimal || livingEntity instanceof Npc) {
DEFAULT.putIfAbsent(type, MonsterType.FRIENDLY);
return;
}

// 否则归为中立
DEFAULT.putIfAbsent(type, MonsterType.NEUTRAL);
});
}

public static Map<EntityType<?>, MonsterType> getMonsterList(ItemStack stack, @Nullable Level level) {
Map<EntityType<?>, MonsterType> output = Maps.newHashMap();

if (level == null || stack.getItem() != InitItems.MONSTER_LIST.get()) {
return output;
// 如果是玩家、宠物、NPC、归为友好
if (target instanceof TamableAnimal || target instanceof Npc) {
return MonsterType.FRIENDLY;
}

// 先从物品里读取数据
Map<ResourceLocation, MonsterType> monsterList = ItemMonsterList.getMonsterList(stack);
monsterList.forEach((key, monsterType) -> {
EntityType<?> entityType = BuiltInRegistries.ENTITY_TYPE.get(key);
output.put(entityType, monsterType);
});

// 最后补齐默认数据
DEFAULT.forEach(output::putIfAbsent);

return output;
}

public static MonsterType getMonsterType(EntityType<?> entityType) {
return DEFAULT.getOrDefault(entityType, MonsterType.NEUTRAL);
// 否则归为中立
return MonsterType.NEUTRAL;
}

public static boolean canAttack(EntityMaid maid, LivingEntity target, MonsterType monsterType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.entity.task;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.task.IAttackTask;
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidExtinguishingTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitItems;
Expand All @@ -19,7 +19,7 @@
import java.util.List;
import java.util.function.Predicate;

public class TaskExtinguishing implements IAttackTask {
public class TaskExtinguishing implements IMaidTask {
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(TouhouLittleMaid.MOD_ID, "extinguishing");

@Override
Expand Down Expand Up @@ -48,6 +48,11 @@ public List<Pair<String, Predicate<EntityMaid>>> getConditionDescription(EntityM
return Collections.singletonList(Pair.of("has_extinguisher", this::hasExtinguisher));
}

@Override
public boolean enablePanic(EntityMaid maid) {
return false;
}

private boolean hasExtinguisher(EntityMaid maid) {
return maid.getMainHandItem().getItem() == InitItems.EXTINGUISHER.get();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class InitCreativeTabs {
output.accept(RED_FOX_SCROLL.get());
output.accept(WHITE_FOX_SCROLL.get());
output.accept(SERVANT_BELL.get());
output.accept(MONSTER_LIST.get());
output.accept(KAPPA_COMPASS.get());
output.accept(EXTINGUISHER.get());
output.accept(GOMOKU.get());
Expand Down
Loading

0 comments on commit b494edd

Please sign in to comment.