Teleportation Yaw and Pitch problem

Discussion in 'Plugin Development' started by SeamusMcFreak, Feb 1, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    SeamusMcFreak

    Hello, I currency have a problem with my plugin on the NPC (from citizens) yaw and pitch.
    Code:
            double x0 = -557;
            double y0 = 4;
            double z0 = 577;
            World w0 = Bukkit.getWorlds().get(0);
            org.bukkit.Location loc0 = new org.bukkit.Location(w0, x0, y0, z0);
            loc0.setYaw(90F);
            loc0.setPitch(0F);
    Problem: Only his head faces 90° his body faces about 45°. How would I make the body face 90°?
    This would be the same if it was teleporting a player.
    Images:
    2016-02-01_14.54.53.png
     
    Last edited: Feb 1, 2016
  2. Offline

    teej107

    @SeamusMcFreak I don't think it's possible with Bukkit. You can try sending packets but I'm not sure if it'll work.
     
  3. Offline

    SeamusMcFreak

    @teej107 I'm sure its possible. And how do I send a packet again?
     
  4. Offline

    teej107

    @SeamusMcFreak Cast Player to CraftPlayer then call getHandle() and call sendPacket() from the Object returned by getHandle(). You need to supply a Packet in the parameters when calling sendPacket(). I don't know which packet it is though.
     
  5. Offline

    SeamusMcFreak

    @teej107 I found the packet but I can't find getHandle().

    Anyone else know how?


    [merged by moderator: please use the edit button in future]
     
    Last edited by a moderator: Feb 1, 2016
  6. Offline

    Xerox262

    Try Entity#setLocation();
     
  7. Offline

    SeamusMcFreak

    @Xerox262, Im using CitizensAPI and there is no teleport.

    Forgot to mention the teleport:
    Code:
    npc.teleport(loc, null);

    [merged by moderator: please use the Edit button]
     
    Last edited by a moderator: Feb 2, 2016
  8. Offline

    Xerox262

    According to the API there's NPC#faceLocation();

    Also there's NPC#getEntity(); which can be cast to nms Entity, which then has Entity#setLocation(x, y, z, yaw, pitch);
     
  9. Offline

    SeamusMcFreak

    Yes there is. But I have no idea what it does. If its a face location its probably not gonna move the body with it.
     
  10. Offline

    Xerox262

    Unless you try you wont know, if it doesn't work try the nms method I said above.
     
  11. Offline

    SeamusMcFreak

    Doesn't work. And setLocation() isn't in CitizensAPI.getNPCRegistry().getNPC().
     
  12. Offline

    Xerox262

    @SeamusMcFreak I said, you need to cast it to NMS entity, then do setLocation();
     
  13. Offline

    SeamusMcFreak

    What is NMS?
     
  14. Offline

    Xerox262

    net.minecraft.server
     
  15. Offline

    SeamusMcFreak

  16. Offline

    Xerox262

    How exactly would you cast to it? It's different for all versions, for mine it would be
    Code:
    Entity entity = (Entity) NPC#getEntity();
    // with the import
    import net.minecraft.server.v1_8_R3.Entity;
    If you've already got Bukkit entity imported then you'd need to do something along the lines of
    Code:
    net.minecraft.server.v1_8_R3.Entity entity = (net.minecraft.server.v1_8_R3.Entity) NPC#getEntity();
    v1_8_R3 differs depending on bukkit version.

    After that you can do entity.setLocation();
     
  17. Offline

    SeamusMcFreak

    Error:
    Screen Shot 2016-02-01 at 7.18.42 PM.png
     
  18. Offline

    Xerox262

    No, not NPC#getEntity(); that means call the method on the NPC object, don't copy and paste what I wrote.
     
  19. Offline

    SeamusMcFreak

    So what do I do?
     
  20. Offline

    Xerox262

    @SeamusMcFreak get the entity from the NPC class the way you did before. Then cast it and setLocation(); casting is a basic Java problem, you should really not be having an issue with this if you learnt Java before messing with the bukkit api.
     
  21. Offline

    SeamusMcFreak

    So this?
    Code:
    test = (npc) setLocation();
     
  22. Offline

    Xerox262

    @SeamusMcFreak No, First you get your NPC class, something like this (Don't copy and paste any of this, it wont work you just have to read it then look at your code for similar things)
    Code:
    NPC npc = whatEverItIsToGetYourNPC.youNeverPosted();
    I don't know how you actually get the NPC, I assume you have it in your code already.

    Then you get the entity from it like so
    Code:
    Entity entity = (Entity) npc.getEntity();
    Assuming you haven't imported the bukkit entity then just import nms entity, otherwise edit that line to cast it to nms entity, something like

    Code:
    net.minecraft.server.v_1_8_3R3.Entity entity = (net.minecraft.server.v_1_8_3R3.Entity) npc.getEntity();
    Then do
    Code:
    entity.setLocation(whatever);
    If you still cannot understand this then you should learn more Java and come back to this.

    Edit: Scratch that last line, no matter if you understand what I mean or not you should really learn more Java then come back to the plugin.
     
  23. Offline

    SeamusMcFreak

    Doesn't work because setLocation() has multiple args. And I wouldn't be able to set the yaw. And the loc0 is from a static.
     
  24. Offline

    Xerox262

    @SeamusMcFreak How does it not work, why can't you set the yaw and pitch, what do you think the arguments are?
    Hint, they're
    X
    Y
    Z
    Yaw
    Pitch

    And your static location stores what? Hmm, Oh, world, x, y, z, yaw and pitch.
     
  25. Offline

    Konato_K

    Isn't that how players work? If you turn your head your body won't move unless your head rotates too much (but it still won't be straight to your head), if you punch the air your body will face the same as your face, not sure if this works for NPCs though
     
  26. Offline

    Xerox262

    Setting their location should zero or center it though, aka both body and head facing forward.
     
  27. Offline

    SeamusMcFreak

    My static stores the locations. It works with a random.
    Code:
    static {     
            double x0 = -557.5;
            double y0 = 4;
            double z0 = 577.5;
            World w0 = Bukkit.getWorlds().get(0);
            org.bukkit.Location loc0 = new org.bukkit.Location(w0, x0, y0, z0);
         
            int x1 = -561;
            int y1 = 4;
            int z1 = 581;
            World w1 = Bukkit.getWorlds().get(0);
            org.bukkit.Location loc1 = new org.bukkit.Location(w1, x1, y1, z1);
            loc1.setYaw(90F);
            loc1.setPitch(0F);
         
            Shop1locations.add(loc0);
            Shop1locations.add(loc1);
        }
     
  28. Offline

    Xerox262

    They still store the data, what is the reason that you can't use them with setLocation()?
     
  29. Offline

    SeamusMcFreak

    Because they are in separate places.
    Code:
    public static void randomShop1NPCLoc() {
            NPCRegistry registry = CitizensAPI.getNPCRegistry();
            NPC npc = registry.getById(1);
            int count = Shop1locations.size();
            int randomNumber = (int) (Math.random()*count);
            org.bukkit.Location loc = Shop1locations.get(randomNumber);
            Entity entity = (Entity) npc.getEntity();
            entity.setLocation(loc); //Error here
    //        npc.teleport(loc, null);
        }
     
  30. Offline

    Xerox262

    Separate places? Also you need to get the data from location, remember 5 arguments,
    entity.setLocation(loc.getX(), loc.getY(), etc...);
     
Thread Status:
Not open for further replies.

Share This Page