diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/cloth/MenuIntegration.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/cloth/MenuIntegration.java index 69576de61..125ec20d2 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/cloth/MenuIntegration.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/cloth/MenuIntegration.java @@ -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) { diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/ai/GunAttackStrafingTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/ai/GunAttackStrafingTask.java index c7edd9e3f..af3fd1276 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/ai/GunAttackStrafingTask.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/ai/GunAttackStrafingTask.java @@ -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; @@ -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; diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/task/TaskGunAttack.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/task/TaskGunAttack.java index dc5e1528d..148979c63 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/task/TaskGunAttack.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/task/TaskGunAttack.java @@ -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; @@ -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(); } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunBehaviorUtils.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunBehaviorUtils.java index ed43b748f..de84c5a76 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunBehaviorUtils.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunBehaviorUtils.java @@ -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; @@ -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) { diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunNearestLivingEntitySensor.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunNearestLivingEntitySensor.java index 2e22ea80d..a2051f3bd 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunNearestLivingEntitySensor.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunNearestLivingEntitySensor.java @@ -1,31 +1,32 @@ 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 list = world.getEntitiesOfClass(LivingEntity.class, aabb, (entity) -> entity != maid && entity.isAlive()); list.sort(Comparator.comparingDouble(maid::distanceToSqr)); @@ -33,8 +34,4 @@ public static void doGunTick(ServerLevel world, EntityMaid maid) { 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; - } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MaidConfig.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MaidConfig.java index 539eb8cb1..ba33c5662 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MaidConfig.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MaidConfig.java @@ -36,6 +36,10 @@ public final class MaidConfig { public static ForgeConfigSpec.ConfigValue> MAID_HEAL_MEALS_BLOCK_LIST_REGEX; public static ForgeConfigSpec.ConfigValue>> 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"); @@ -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(); } } diff --git a/src/main/resources/assets/touhou_little_maid/lang/en_us.json b/src/main/resources/assets/touhou_little_maid/lang/en_us.json index 88e6bd6ca..a1f27f5ce 100644 --- a/src/main/resources/assets/touhou_little_maid/lang/en_us.json +++ b/src/main/resources/assets/touhou_little_maid/lang/en_us.json @@ -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", diff --git a/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json b/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json index a46a6441a..c33b16f49 100644 --- a/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json +++ b/src/main/resources/assets/touhou_little_maid/lang/zh_cn.json @@ -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": "坐垫能否自由切换模型",