Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AnimalBreeding;
- import net.risingworld.api.Plugin;
- import net.risingworld.api.Timer;
- import net.risingworld.api.objects.Npc;
- import net.risingworld.api.objects.Player;
- import net.risingworld.api.utils.Layer;
- import net.risingworld.api.utils.Quaternion;
- import net.risingworld.api.utils.RaycastResult;
- import net.risingworld.api.utils.Vector3f;
- import net.risingworld.api.worldelements.Prefab;
- public class MoveNpc {
- private Plugin plugin;
- public MoveNpc(Plugin plugin){
- this.plugin = plugin;
- }
- public void move(Player player){
- Prefab move_arrow = (Prefab)Main.prefabs.moveArrow(player);
- player.setAttribute("move_arrow", move_arrow);
- player.addGameObject(move_arrow);
- moveArrowTimer(player);
- }
- public void moveArrowTimer(Player player){
- Timer move_arrow_timer = new Timer(0.05f, 0f, -1, () -> {
- updateArrowPosition(player);
- });
- player.setAttribute("move_arrow_timer", move_arrow_timer);
- move_arrow_timer.start();
- }
- public void updateArrowPosition(Player player){
- int layerMask = Layer.getBitmask(Layer.TERRAIN, Layer.CONSTRUCTION, Layer.TRANSPARENT_CONSTRUCTION, Layer.OBJECT, Layer.DEFAULT, Layer.WATER);
- player.raycast(layerMask, (RaycastResult result) -> {
- if(result != null && player.hasAttribute("move_arrow")){
- Prefab arrow = (Prefab)player.getAttribute("move_arrow");
- arrow.moveToLocalPosition(result.getCollisionPoint(), -1);
- }
- });
- }
- public void setNpcPosition(Player player){
- Timer move_arrow_timer = (Timer)player.getAttribute("move_arrow_timer");
- move_arrow_timer.kill();
- Npc npc = (Npc)player.getAttribute("npc");
- Prefab move_arrow = (Prefab)player.getAttribute("move_arrow");
- npc.setPosition(move_arrow.getLocalPosition());
- Vector3f playerposition = player.getPosition();
- Vector3f npcposition = npc.getPosition();
- Vector3f direction = playerposition.subtract(npcposition);
- direction.normalizeLocal();
- Quaternion rotation = new Quaternion().lookAt(direction);
- npc.setRotation(rotation);
- npc.setLocked(true);
- player.removeGameObject(move_arrow);
- player.deleteAttribute("npc");
- player.deleteAttribute("move_arrow");
- player.deleteAttribute("move_arrow_timer");
- }
- public void dieWhileMoving(Player player){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement