Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import de.bsommerfeld.pathetic.api.pathing.result.PathfinderResult;
- import de.bsommerfeld.pathetic.api.wrapper.PathPosition;
- import de.bsommerfeld.pathetic.bukkit.context.BukkitEnvironmentContext;
- import de.bsommerfeld.pathetic.bukkit.mapper.BukkitMapper;
- import net.citizensnpcs.api.ai.tree.BehaviorGoalAdapter;
- import net.citizensnpcs.api.ai.tree.BehaviorStatus;
- import net.citizensnpcs.api.trait.trait.Equipment;
- import net.citizensnpcs.trait.waypoint.Waypoints;
- import org.bukkit.*;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import net.citizensnpcs.api.npc.NPC;
- import org.bukkit.util.Vector;
- import org.mcmonkey.sentinel.SentinelTrait;
- import java.util.*;
- import java.util.concurrent.CompletionStage;
- public class HandSwitchBehavior extends BehaviorGoalAdapter {
- /**
- * This behavior cycles through weapons
- * @param npcWanderer that switches weapons
- * @param g weapon 1
- * @param g2 weapon 2
- */
- public HandSwitchBehavior(NPC npcWanderer, ItemStack g, ItemStack g2) {
- this.npc = npcWanderer;
- // more fields initialized here
- }
- @Override
- public void reset() {
- target = null;
- }
- @Override
- public BehaviorStatus run() {
- Entity entity = npc.getEntity();
- if (entity == null || !entity.isValid() || entity.isDead()) {
- return BehaviorStatus.RUNNING; // stop pathfinding entirely
- }
- SentinelTrait st = npc.getOrAddTrait(SentinelTrait.class);
- // SEARCH FOR TARGET
- if (target == null) {
- // Loop and find best candidate
- target = bestCandidate;
- }
- // TARGET FOUND
- if (target instanceof Player player) {
- npc.getNavigator().setPaused(true);
- npc.getNavigator().getLocalParameters().speedModifier(1f);
- }
- // TARGET INVALID
- if (target != null && target.isDead()) {
- target = null;
- npc.getNavigator().setPaused(false);
- npc.getNavigator().getLocalParameters().speedModifier(1f);
- }
- // --- PATHFINDING TO TARGET ---
- if (target != null) {
- // Compute path here
- }
- // --- Taking Control here ---
- if (!simplifiedPath.isEmpty() && pathIndex < simplifiedPath.size()) {
- Vector currentTarget = simplifiedPath.get(pathIndex);
- Location targetLoc = currentTarget.toLocation(npc.getEntity().getWorld());
- // Update every tick with setMoveDestination()
- npc.getNavigator().getLocalParameters().speedModifier(1.95f);
- npc.getNavigator().getLocalParameters().range(0.5f);
- npc.setMoveDestination(targetLoc);
- pathIndex++;
- }
- // Back to wander mode (not working)
- if (target == null) {
- if (!wandering) {
- npc.getOrAddTrait(Waypoints.class).setWaypointProvider("wander");
- wandering = true;
- }
- return BehaviorStatus.RUNNING;
- }
- // FACE TARGET ENTITY
- st.faceLocation(target.getLocation());
- if (target instanceof Player player) {
- if (st.attackHelper.tryAttack((LivingEntity) target)) {
- return BehaviorStatus.RUNNING;
- }
- return BehaviorStatus.RUNNING;
- }
- return BehaviorStatus.RUNNING;
- }
- @Override
- public boolean shouldExecute() {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment