Skip to content

Commit

Permalink
添加配置文件管控枪械识别距离
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Sep 20, 2024
1 parent dc32f2f commit fb41d00
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ private static void maidConfig(ConfigBuilder root, ConfigEntryBuilder entryBuild
}
MaidConfig.MAID_EATEN_RETURN_CONTAINER_LIST.set(maidMealContainerList);
}).build());

maid.addEntry(entryBuilder.startIntField(Component.translatable("config.touhou_little_maid.maid.maid_gun_long_distance"), MaidConfig.MAID_GUN_LONG_DISTANCE.get())
.setDefaultValue(64).setMin(0).setMax(512).requireRestart()
.setTooltip(Component.translatable("config.touhou_little_maid.maid.maid_gun_long_distance.tooltip"))
.setSaveConsumer(i -> MaidConfig.MAID_GUN_LONG_DISTANCE.set(i)).build());

maid.addEntry(entryBuilder.startIntField(Component.translatable("config.touhou_little_maid.maid.maid_gun_medium_distance"), MaidConfig.MAID_GUN_MEDIUM_DISTANCE.get())
.setDefaultValue(48).setMin(0).setMax(512).requireRestart()
.setTooltip(Component.translatable("config.touhou_little_maid.maid.maid_gun_medium_distance.tooltip"))
.setSaveConsumer(i -> MaidConfig.MAID_GUN_MEDIUM_DISTANCE.set(i)).build());

maid.addEntry(entryBuilder.startIntField(Component.translatable("config.touhou_little_maid.maid.maid_gun_near_distance"), MaidConfig.MAID_GUN_NEAR_DISTANCE.get())
.setDefaultValue(32).setMin(0).setMax(512).requireRestart()
.setTooltip(Component.translatable("config.touhou_little_maid.maid.maid_gun_near_distance.tooltip"))
.setSaveConsumer(i -> MaidConfig.MAID_GUN_NEAR_DISTANCE.set(i)).build());
}

private static void chairConfig(ConfigBuilder root, ConfigEntryBuilder entryBuilder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.compat.tacz.ai;

import com.github.tartaricacid.touhoulittlemaid.compat.tacz.utils.GunNearestLivingEntitySensor;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MaidConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.google.common.collect.ImmutableMap;
import com.tacz.guns.api.item.IGun;
Expand Down Expand Up @@ -46,7 +46,7 @@ protected void tick(ServerLevel worldIn, EntityMaid owner, long gameTime) {
float maxAttackDistance = owner.getRestrictRadius();

// 如果在最大攻击距离(128)之内,而且看见的时长足够长
if (distance < GunNearestLivingEntitySensor.getRadiusSearchRange()) {
if (distance < MaidConfig.MAID_GUN_LONG_DISTANCE.get()) {
++this.strafingTime;
} else {
this.strafingTime = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.tartaricacid.touhoulittlemaid.compat.tacz.ai.GunShootTargetTask;
import com.github.tartaricacid.touhoulittlemaid.compat.tacz.ai.GunWalkToTarget;
import com.github.tartaricacid.touhoulittlemaid.compat.tacz.utils.GunBehaviorUtils;
import com.github.tartaricacid.touhoulittlemaid.compat.tacz.utils.GunNearestLivingEntitySensor;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MaidConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitSounds;
import com.github.tartaricacid.touhoulittlemaid.util.SoundUtil;
Expand Down Expand Up @@ -79,6 +79,6 @@ private boolean mainhandHoldGun(EntityMaid maid) {
}

private boolean farAway(LivingEntity target, EntityMaid maid) {
return maid.distanceTo(target) > GunNearestLivingEntitySensor.getRadiusSearchRange();
return maid.distanceTo(target) > MaidConfig.MAID_GUN_LONG_DISTANCE.get();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.compat.tacz.utils;

import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MaidConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.tacz.guns.api.TimelessAPI;
import com.tacz.guns.api.item.GunTabType;
Expand All @@ -18,9 +19,9 @@
public class GunBehaviorUtils {
// 可见性校验工具,来自于 Sensor
// 依据枪械种类,可以区分为远、中、近三类
private static final TargetingConditions LONG_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(128);
private static final TargetingConditions MEDIUM_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(96);
private static final TargetingConditions NEAR_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(64);
private static final TargetingConditions LONG_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(MaidConfig.MAID_GUN_LONG_DISTANCE.get());
private static final TargetingConditions MEDIUM_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(MaidConfig.MAID_GUN_MEDIUM_DISTANCE.get());
private static final TargetingConditions NEAR_DISTANCE_TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(MaidConfig.MAID_GUN_NEAR_DISTANCE.get());

//可见性方法,来自于Sensor类
public static boolean canSee(EntityMaid maid, LivingEntity target) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
package com.github.tartaricacid.touhoulittlemaid.compat.tacz.utils;

import com.github.tartaricacid.touhoulittlemaid.compat.tacz.task.TaskGunAttack;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MaidConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.tacz.guns.api.item.IGun;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.phys.AABB;

import java.util.Comparator;
import java.util.List;

public class GunNearestLivingEntitySensor {
private static final int VERTICAL_SEARCH_RANGE = 64;
private static final int RADIUS_SEARCH_RANGE = 128;

public static boolean isGunTask(EntityMaid maid) {
return maid.getTask().getUid().equals(TaskGunAttack.UID);
return maid.getTask().getUid().equals(TaskGunAttack.UID) && maid.getScheduleDetail() == Activity.WORK && IGun.mainhandHoldGun(maid);
}

public static void doGunTick(ServerLevel world, EntityMaid maid) {
AABB aabb;
int searchRange = MaidConfig.MAID_GUN_LONG_DISTANCE.get();
if (maid.hasRestriction()) {
aabb = new AABB(maid.getRestrictCenter()).inflate(RADIUS_SEARCH_RANGE, VERTICAL_SEARCH_RANGE, RADIUS_SEARCH_RANGE);
aabb = new AABB(maid.getRestrictCenter()).inflate(searchRange);
} else {
aabb = maid.getBoundingBox().inflate(RADIUS_SEARCH_RANGE, VERTICAL_SEARCH_RANGE, RADIUS_SEARCH_RANGE);
aabb = maid.getBoundingBox().inflate(searchRange);
}
List<LivingEntity> list = world.getEntitiesOfClass(LivingEntity.class, aabb, (entity) -> entity != maid && entity.isAlive());
list.sort(Comparator.comparingDouble(maid::distanceToSqr));
Brain<EntityMaid> brain = maid.getBrain();
brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, list);
brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(maid, list));
}

public static int getRadiusSearchRange() {
return RADIUS_SEARCH_RANGE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public final class MaidConfig {
public static ForgeConfigSpec.ConfigValue<List<String>> MAID_HEAL_MEALS_BLOCK_LIST_REGEX;
public static ForgeConfigSpec.ConfigValue<List<List<String>>> MAID_EATEN_RETURN_CONTAINER_LIST;

public static ForgeConfigSpec.IntValue MAID_GUN_LONG_DISTANCE;
public static ForgeConfigSpec.IntValue MAID_GUN_MEDIUM_DISTANCE;
public static ForgeConfigSpec.IntValue MAID_GUN_NEAR_DISTANCE;

public static void init(ForgeConfigSpec.Builder builder) {
builder.push("maid");

Expand Down Expand Up @@ -125,6 +129,15 @@ public static void init(ForgeConfigSpec.Builder builder) {
builder.comment("These entries configure the container returned after a maid has eaten", "Eg: [\"minecraft:beetroot_soup\", \"minecraft:bowl\"]");
MAID_EATEN_RETURN_CONTAINER_LIST = builder.define("MaidEatenReturnContainerList", Lists.newArrayList());

builder.comment("Recognition distance of a maid under the gun task, Suitable for sniper rifles");
MAID_GUN_LONG_DISTANCE = builder.defineInRange("MaidGunLongDistance", 64, 0, 512);

builder.comment("Recognition distance of a maid under the gun task, Suitable for most types");
MAID_GUN_MEDIUM_DISTANCE = builder.defineInRange("MaidGunMediumDistance", 48, 0, 512);

builder.comment("Recognition distance of a maid under the gun task, Suitable for pistols and shotguns");
MAID_GUN_NEAR_DISTANCE = builder.defineInRange("MaidGunNearDistance", 32, 0, 512);

builder.pop();
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@
"config.touhou_little_maid.maid.maid_heal_meals_block_list_regex.tooltip": "These items cannot be used as a maid's heal meals which match the regex, all words have to match",
"config.touhou_little_maid.maid.maid_eaten_return_container_list": "Maid Eaten Return Container List",
"config.touhou_little_maid.maid.maid_eaten_return_container_list.tooltip": "These entries configure the container returned after a maid has eaten \nEg: §eminecraft:beetroot_soup§c,§eminecraft:bowl",
"config.touhou_little_maid.maid.maid_gun_long_distance": "Maid Gun Long Distance",
"config.touhou_little_maid.maid.maid_gun_long_distance.tooltip": "Recognition distance of a maid under the gun task, Suitable for sniper rifles",
"config.touhou_little_maid.maid.maid_gun_medium_distance": "Maid Gun Medium Distance",
"config.touhou_little_maid.maid.maid_gun_medium_distance.tooltip": "Recognition distance of a maid under the gun task, Suitable for most types",
"config.touhou_little_maid.maid.maid_gun_near_distance": "Maid Gun Near Distance",
"config.touhou_little_maid.maid.maid_gun_near_distance.tooltip": "Recognition distance of a maid under the gun task, Suitable for pistols and shotguns",
"config.touhou_little_maid.chair": "Chair",
"config.touhou_little_maid.chair.chair_change_model": "Chair Change Model",
"config.touhou_little_maid.chair.chair_change_model.tooltip": "Chair can switch models freely",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@
"config.touhou_little_maid.maid.maid_heal_meals_block_list_regex.tooltip": "匹配的物品不能用于女仆的回血餐,请使用正则全词匹配",
"config.touhou_little_maid.maid.maid_eaten_return_container_list": "女仆用餐后返回容器的列表",
"config.touhou_little_maid.maid.maid_eaten_return_container_list.tooltip": "这些条目配置了女仆用餐后要返回的容器\n例如: §eminecraft:beetroot_soup§c,§eminecraft:bowl",
"config.touhou_little_maid.maid.maid_gun_long_distance": "远距枪械距离",
"config.touhou_little_maid.maid.maid_gun_long_distance.tooltip": "枪械模式下女仆的识别距离,适用于狙击枪",
"config.touhou_little_maid.maid.maid_gun_medium_distance": "中等枪械距离",
"config.touhou_little_maid.maid.maid_gun_medium_distance.tooltip": "枪械模式下女仆的识别距离,适用于大多数枪械",
"config.touhou_little_maid.maid.maid_gun_near_distance": "近枪械距离",
"config.touhou_little_maid.maid.maid_gun_near_distance.tooltip": "枪械模式下女仆的识别距离,适用于手枪和霰弹枪",
"config.touhou_little_maid.chair": "坐垫",
"config.touhou_little_maid.chair.chair_change_model": "坐垫能否切换模型",
"config.touhou_little_maid.chair.chair_change_model.tooltip": "坐垫能否自由切换模型",
Expand Down

0 comments on commit fb41d00

Please sign in to comment.