Advertisement
james1bow

Untitled

Feb 11th, 2024
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. package AnimalBreeding;
  2.  
  3. import net.risingworld.api.Plugin;
  4. import net.risingworld.api.Timer;
  5. import net.risingworld.api.objects.Npc;
  6. import net.risingworld.api.objects.Player;
  7. import net.risingworld.api.utils.Layer;
  8. import net.risingworld.api.utils.Quaternion;
  9. import net.risingworld.api.utils.RaycastResult;
  10. import net.risingworld.api.utils.Vector3f;
  11. import net.risingworld.api.worldelements.Prefab;
  12.  
  13.  
  14. public class MoveNpc {
  15.    
  16.    
  17.      private Plugin plugin;
  18.    
  19.     public  MoveNpc(Plugin plugin){
  20.    
  21.         this.plugin = plugin;
  22.  
  23.     }
  24.    
  25.     public void move(Player player){
  26.         Prefab move_arrow = (Prefab)Main.prefabs.moveArrow(player);
  27.         player.setAttribute("move_arrow", move_arrow);
  28.         player.addGameObject(move_arrow);
  29.         moveArrowTimer(player);
  30.        
  31.     }
  32.    
  33.     public void moveArrowTimer(Player player){
  34.         Timer move_arrow_timer = new Timer(0.05f, 0f, -1, () -> {
  35.             updateArrowPosition(player);
  36.         });
  37.         player.setAttribute("move_arrow_timer", move_arrow_timer);
  38.         move_arrow_timer.start();
  39.     }
  40.    
  41.     public void updateArrowPosition(Player player){
  42.         int layerMask = Layer.getBitmask(Layer.TERRAIN, Layer.CONSTRUCTION, Layer.TRANSPARENT_CONSTRUCTION, Layer.OBJECT, Layer.DEFAULT, Layer.WATER);
  43.         player.raycast(layerMask, (RaycastResult result) -> {
  44.             if(result != null && player.hasAttribute("move_arrow")){
  45.             Prefab arrow = (Prefab)player.getAttribute("move_arrow");
  46.             arrow.moveToLocalPosition(result.getCollisionPoint(), -1);
  47.             }
  48.         });
  49.     }
  50.    
  51.    
  52.     public void setNpcPosition(Player player){
  53.         Timer move_arrow_timer = (Timer)player.getAttribute("move_arrow_timer");
  54.         move_arrow_timer.kill();
  55.        
  56.         Npc npc = (Npc)player.getAttribute("npc");
  57.         Prefab move_arrow = (Prefab)player.getAttribute("move_arrow");
  58.         npc.setPosition(move_arrow.getLocalPosition());
  59.         Vector3f playerposition = player.getPosition();
  60.         Vector3f npcposition = npc.getPosition();
  61.         Vector3f direction = playerposition.subtract(npcposition);
  62.         direction.normalizeLocal();
  63.         Quaternion rotation = new Quaternion().lookAt(direction);
  64.         npc.setRotation(rotation);
  65.         npc.setLocked(true);
  66.         player.removeGameObject(move_arrow);
  67.         player.deleteAttribute("npc");
  68.         player.deleteAttribute("move_arrow");
  69.         player.deleteAttribute("move_arrow_timer");
  70.        
  71.        
  72.     }
  73.    
  74.    
  75.     public void dieWhileMoving(Player player){
  76.        
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement