-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbd6bcb
commit a4a07b0
Showing
16 changed files
with
211 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ain/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunBehaviorUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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; | ||
import com.tacz.guns.api.item.IGun; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.ai.behavior.BehaviorUtils; | ||
import net.minecraft.world.entity.ai.memory.MemoryModuleType; | ||
import net.minecraft.world.entity.ai.targeting.TargetingConditions; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
public class GunBehaviorUtils { | ||
// 可见性校验工具,来自于 Sensor | ||
// 依据枪械种类,可以区分为远、中、近三类 | ||
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) { | ||
ItemStack handItem = maid.getMainHandItem(); | ||
IGun iGun = IGun.getIGunOrNull(handItem); | ||
if (iGun != null) { | ||
ResourceLocation gunId = iGun.getGunId(handItem); | ||
return TimelessAPI.getCommonGunIndex(gunId).map(index -> { | ||
String type = index.getType(); | ||
// 狙击枪?用远距离模式 | ||
String sniper = GunTabType.SNIPER.name().toLowerCase(Locale.ENGLISH); | ||
if (sniper.equals(type)) { | ||
return LONG_DISTANCE_TARGET_CONDITIONS.test(maid, target); | ||
} | ||
// 霰弹枪?手枪?近距离模式 | ||
String shotgun = GunTabType.SHOTGUN.name().toLowerCase(Locale.ENGLISH); | ||
String pistol = GunTabType.PISTOL.name().toLowerCase(Locale.ENGLISH); | ||
if (shotgun.equals(type) || pistol.equals(type)) { | ||
return NEAR_DISTANCE_TARGET_CONDITIONS.test(maid, target); | ||
} | ||
// 其他情况,中等距离 | ||
return MEDIUM_DISTANCE_TARGET_CONDITIONS.test(maid, target); | ||
}).orElse(BehaviorUtils.canSee(maid, target)); | ||
} | ||
return BehaviorUtils.canSee(maid, target); | ||
} | ||
|
||
// 寻找第一个可见目标,使用独立的方法,区别于 IAttackTask | ||
public static Optional<? extends LivingEntity> findFirstValidAttackTarget(EntityMaid maid) { | ||
if (maid.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES).isPresent()) { | ||
List<LivingEntity> list = maid.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES).get(); | ||
return list.stream().filter(e -> maid.canAttack(e) && GunBehaviorUtils.canSee(maid, e)).findAny(); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../github/tartaricacid/touhoulittlemaid/compat/tacz/utils/GunNearestLivingEntitySensor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 { | ||
public static boolean isGunTask(EntityMaid maid) { | ||
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(searchRange); | ||
} else { | ||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.