ArmorStand head rotate

Discussion in 'Plugin Development' started by MinecraftDorado, Jun 17, 2016.

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

    MinecraftDorado

    Hi, I need help. This part of the code does not work, and that is not bad.
    Code:
            float eye = player.getEyeLocation().getYaw();
       
            if(as.getCustomName() == "armorstand"){
                as.getEyeLocation().setYaw(eye);
            }
     
  2. .getCustomName().equals(...) instead of == ...
    should work
     
  3. Offline

    Zombie_Striker

    This is a basic "==" vs ".equals" problem. Strings do not share the same memoryspace in Java. You need top use .equals() to compare the values of the string.
     
  4. Offline

    MinecraftDorado

    It does not work this way.
    Code:
        public void Player(Player b, ArmorStand as) {
            Player player = b.getPlayer();
           
            float eye = player.getEyeLocation().getYaw();
           
            if(as.getCustomName().equals("armorstand")){
                as.getEyeLocation().setYaw(eye);
            }
        }
     
  5. Offline

    Zombie_Striker

    @MinecraftDorado
    Locations and yaw/pitch values are not updated using those values. You would need to create a new location, set the location,pitch and yaw of that location, and then teleport the armourstand to that location.

    BTW: Rename your method. It should start with a lowercase letter and be descriptive as to what it does.
     
  6. Offline

    MinecraftDorado

    Thank you. But if you could tell me the code to work, I would be very useful.
     
  7. Offline

    Zombie_Striker

    @MinecraftDorado
    If you want me to tell you what to do, I already did in the previous post. If you want me to write the code for you, then I must tell you that we do not do that. We are here to help you with your problems, not write your code for you. If you want code written for you, you should post in the plugin requests forum.

    Again, to solve your problem, create a location variable, set the yaw,pitch,and location, and then teleport the entity to that location.
     
  8. Offline

    MinecraftDorado

    @Zombie_Striker
    Okay, so I can update the location of the armor stand, simply teleporting to where already?
     
  9. Offline

    Zombie_Striker

  10. Offline

    MinecraftDorado

    @Zombie_Striker
    Thank you. The last question, that difference would have to use the Yaw and Pitch?
     
  11. Offline

    Zombie_Striker

    @MinecraftDorado
    Can rephrase your question? I do not understand the question.
     
  12. Offline

    MinecraftDorado

  13. Offline

    Zombie_Striker

    @MinecraftDorado
    If you mean what is the difference between yaw and pitch, pitch is the angle up and down, while yaw is left and right.
     
  14. Offline

    MinecraftDorado

    @Zombie_Striker
    Good.
    I've modified the code but still does not work, any idea that you can be wrong?
    Code:
        public void eye (Player b, ArmorStand as) {
            Player player = b.getPlayer();
           
            float eye = player.getEyeLocation().getYaw();
            float eye2 = player.getEyeLocation().getPitch();
           
            if(as.getCustomName().equals("armorstand")){
               
                double x = as.getLocation().getX();
                double y = as.getLocation().getY();
                double z = as.getLocation().getZ();
               
                as.getEyeLocation().setYaw(eye);
                as.getEyeLocation().setPitch(eye2);
               
                as.getLocation().setX(x);
                as.getLocation().setY(y);
                as.getLocation().setZ(z);
               
            }
        }
     
  15. Offline

    I Al Istannen

    @MinecraftDorado
    You, uhm, never teleport it. Make a variable and assign as.getLocation() to it. Then change this variable and at the end teleport the armostand to the saved variable.
     
  16. Offline

    Zombie_Striker

    @MinecraftDorado
    To teleport an entity (in case you do not know), use Entity#teleport(the location);. Replace Entity with the entity's instance, # with a period ( . ), and the location with the location instance.
     
  17. Offline

    MinecraftDorado

    @Zombie_Striker @I Al Istannen
    Still does not work.

    Code:
            if(as.getCustomName().equals("armorstand")){
               
                Location loc = as.getLocation();
               
                as.getEyeLocation().setYaw(eye);
                as.getEyeLocation().setPitch(eye2);
               
                as.teleport(loc);
               
            }
     
  18. Offline

    Zombie_Striker

    @MinecraftDorado
    First, you need to clone "loc".
    Second, you need to edit "locs" values, not the armourstand's values.
    Finally, The Eyelocation is not the same thing as the cloned location.

    Add ".clone" to the end of "getLocation", and replace "as.getEyeLocation" with "loc"
     
    I Al Istannen likes this.
  19. Offline

    I Al Istannen

    @Zombie_Striker
    as.getLocation() returns a clone. See here. I am quite confident it was the same for the versions before.
    Apart from that, I fully agree.
     
  20. Offline

    MinecraftDorado

    @Zombie_Striker @I Al Istannen
    It so?
    Code:
            if(as.getCustomName().equals("armorstand")){
               
                Location loc = as.getLocation().clone();
               
                loc.setYaw(eye);
                loc.setPitch(eye2);
               
                as.teleport(loc);
               
            }
     
  21. Offline

    Zombie_Striker

  22. Offline

    MinecraftDorado

    @Zombie_Striker
    Does not work, it might not work for the as.teleport (loc); ?
     
  23. Offline

    Zombie_Striker

    @MinecraftDorado
    What do you mean by "does not work"? Is the yaw not correct?

    [EDIT] It seems armourstand has it's own rotation values.:
    https://hub.spigotmc.org/javadocs/b....html#setHeadPose(org.bukkit.util.EulerAngle)

    Since it's a little bit too complicated to just explain, I will write a method with some comments explaining what each line does
    Code:
    public void setHeadPos(ArmorStand as, double yaw, double pitch){
    double xint = Math.cos(yaw/Math.PI);
    double zint = Math.sin(yaw/Math.PI);
    //This will convert the yaw to a xint and zint between -1 and 1. Here are some examples of how the yaw changes:
    /*
    yaw = 0 : xint = 1. zint = 0;  East
    yaw = 90 : xint = 0. zint = 1; South
    yaw = 180: xint = -1. zint = 0; North
    yaw = 270 : xint = 0. zint = -1; West
    */
    double yint = Math.sin(pitch/Math.PI);
    //This converts the pitch to a yint
    EulerAngle ea = as.getHeadPos();
    ea.setX(xint);
    ea.setY(yint);
    ea.setZ(zint);
    as.setHeadPos(ea);
    //This gets the EulerAngle of the armorStand, sets the values, and then updates the armorstand.
    }
    I have not tested it, so it may not work.
     
  24. Offline

    MinecraftDorado

    @Zombie_Striker
    I've modified the code with what you have given me, and unfortunately does not work, or maybe it is because something wrong. But thanks for the help.

    Code:
        public void eye (Player b, ArmorStand as) {
            Player player = b.getPlayer();
          
            float yaw = player.getEyeLocation().getYaw();
            float pitch = player.getEyeLocation().getPitch();
          
            if(as.getCustomName().equals("armorstand")){
                double xint = Math.cos(yaw/Math.PI);
                double zint = Math.sin(yaw/Math.PI);
                double yint = Math.sin(pitch/Math.PI);
              
                EulerAngle ea = as.getHeadPose();
          
                ea.setX(xint);
                ea.setY(yint);
                ea.setZ(zint);
                as.setHeadPose(ea);
            }
        }
     
  25. Offline

    Zombie_Striker

    @MinecraftDorado
    How is it not working? Is the armorstand facing the wrong direction?

    Have you tried debugging? If you face to the east, is xint equal to 1? If you face south, does zint equal 1, If you face west, does xint equal -1?
     
  26. Offline

    MinecraftDorado

    @Zombie_Striker the armor stand does not move

    [EDIT] Perhaps it is the error committed, I do not know
     
  27. Offline

    Zombie_Striker

    @MinecraftDorado
    Do you mean it's head does not move? If so, debug
     
  28. Offline

    MinecraftDorado

    @Zombie_Striker As to debug?

    [EDIT] He was referring to this?

    Code:
    [19:39:10 ERROR]: Could not load 'plugins\head v1.0.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalStateException: JavaPlugin requires org.bukkit.plugin.java.PluginClassLoader
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot.jar:git-Spigot-3104eb1-68b7277]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-3104eb1-68b7277]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-3104eb1-68b7277]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugins(CraftServer.java:296) [spigot.jar:git-Spigot-3104eb1-68b7277]
        at net.minecraft.server.v1_9_R1.DedicatedServer.init(DedicatedServer.java:201) [spigot.jar:git-Spigot-3104eb1-68b7277]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:527) [spigot.jar:git-Spigot-3104eb1-68b7277]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.IllegalStateException: JavaPlugin requires org.bukkit.plugin.java.PluginClassLoader
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:64) ~[spigot.jar:git-Spigot-3104eb1-68b7277]
        at mine.head.main.<init>(main.java:9) ~[bin/:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_60]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_60]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_60]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_60]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_60]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-3104eb1-68b7277]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-3104eb1-68b7277]
        ... 6 more
     
    Last edited: Jun 17, 2016
  29. Offline

    Zombie_Striker

    @MinecraftDorado
    Don't use Eclipses debug button. By debug, I mean sending variables like "xint" and "yint" to the player as a message. Basically, you're trying to figure out what xint, yint, and zint are equal to.
     
  30. Offline

    MinecraftDorado

    @Zombie_Striker Well, I'll try it.
    Even this does not work:
    Code:
        public void eye (Player b, ArmorStand as) {
            Player player = b.getPlayer();
            player.sendMessage("hi");
    }
     
    Last edited: Jun 17, 2016
Thread Status:
Not open for further replies.

Share This Page