Pitch of Player BODY

Discussion in 'Plugin Development' started by ShowbizLocket61, Apr 13, 2016.

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

    ShowbizLocket61

    Is there any way to change the pitch of a player BODY, not the head, like in armor stands?

    If not, how does one do a faux bed pose, without ProtocolLib?
     
  2. Offline

    Lightspeed

    I don't think you can set it to what you want like armour stands but, you can set the player to be sleeping pose WITHOUT protocal lib I belive using the http://wiki.vg/Protocol#Use_Bed.

    Of course they can get out of the bed I think(Maybe not).

    Just send that packet to everyone around the bed.
     
  3. Offline

    ShowbizLocket61

    @Lightspeed
    How do I send one of those packets? What is the class name?
     
  4. Code:java
    1.  
    2. @SuppressWarnings("deprecation")
    3. public void sleep(boolean sleep){
    4. if(sleep){
    5. Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
    6. PacketPlayOutBed packet = new PacketPlayOutBed();
    7. setValue(packet, "a", entityID);
    8. setValue(packet, "b", new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
    9. for(Player p : Bukkit.getOnlinePlayers()){
    10. p.sendBlockChange(location, Material.BED_BLOCK, (byte)0);
    11. }
    12. sendPacket(packet);
    13. teleport(location.clone().add(0,0.3,0));
    14. }else{
    15. animation(2);
    16. teleport(location.clone().subtract(0,0.3,0));
    17. }
    18. }
    19.  


    Code:java
    1.  
    2. public void teleport(Location location){
    3. PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
    4. setValue(packet, "a", entityID);
    5.  
    6. setValue(packet, "b", (int) MathHelper.floor(location.getX() * 32.0D));
    7. setValue(packet, "c", (int) MathHelper.floor(location.getY() * 32.0D));
    8. setValue(packet, "d", (int) MathHelper.floor(location.getZ() * 32.0D));
    9.  
    10. setValue(packet, "e", (byte) ((int) location.getYaw() * 256.0F / 360.0F));
    11. setValue(packet, "f", (byte) ((int) location.getPitch() * 256.0F / 360.0F));
    12.  
    13. sendPacket(packet);
    14.  
    15. this.location = location;
    16. }
    17.  


    Code:java
    1.  
    2. public void setValue(Object object, String name, Object value){
    3. try{
    4. Field field = object.getClass().getDeclaredField(name);
    5. field.setAccessible(true);
    6. field.set(object, value);
    7. }catch(Exception e){
    8. e.printStackTrace();
    9. }
    10. }
    11.  
    12. public Object getValue(Object object, String name){
    13. try{
    14. Field field = object.getClass().getDeclaredField(name);
    15. field.setAccessible(true);
    16. return field.get(object);
    17. }catch(Exception e){
    18. e.printStackTrace();
    19. }
    20. return null;
    21. }
    22.  
    23. public void sendPacket(Packet<?> packet, Player player){
    24. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    25. }
    26.  
    27. public void sendPacket(Packet<?> packet){
    28. for(Player p : Bukkit.getOnlinePlayers()){
    29. sendPacket(packet, p);
    30. }
    31. }
    32.  
     
    Last edited: Apr 13, 2016
  5. Offline

    ShowbizLocket61

    @whereisthemonkey
    Is that tested? Is that also making a bed under the player? What is the setValue method? What's the animation method? What's the save method?
     
  6. Updated code is up there. Yes it will create the bed, but this won't work with real players only with a via minecraft protocol created "fake-player". You cannot lay down real player else in packets
     
  7. Offline

    Lightspeed

    Why are you using reflection!?!?!?!?!
    Theres a constructor for a reason.
     
  8. @Lightspeed because it works very well for me and I have experience with that code
     
  9. Offline

    Lightspeed

    Code:
    PacketPlayOutBed(EntityPlayer ep, BlockPosition pos)
    Done
     
  10. @Lightspeed well good for you, I am happy for you that you know how to use packets! Instead of complaining how "bad", "horrible" and "long" my code is, you could have taken action and send your own code proposal what you obviously did not do, you send a link to something, about what the author clearly had no clue before telling him. Even worse, you start complaining about something but you are not trying to do it well from the beginning. People like you are the fault that societies all over the world are failing and crumbling in pieces, because instead of taking action and doing the work they are or are not supposed to do, you complain (and that usually on social media) and say "oh, he/she is doing that and that bad...", but actually didn't try to do it well from the beginning. There is a difference between criticism with a solution and stupid complaining to make others believe that you are better than them.

    Sure I could have used the method you used, but I like my method and I don't think that you send something other than the link.

    So I will give you now an advice for every forum you are on and your daily life: In french, we have a proverb stating to "turn your tongue 7 times in your mouth before speaking" and you should apply that to you and before speaking up think about those questions:
    - Do I have a right to say that?
    - Is it appropriate?
    - Is it complaining about something irrelevant or actually solving a problem?
    - Do I give a solution?

    If everybody would do that, this world would be a much nicer place.
    I hope you will understand some day,

    Regards,
    whereisthemonkey
     
  11. Offline

    Lightspeed

    I was just trying to show the arguments for the smaller bit of code that he could use instead of reflection.

    I was going to come back and give maybe a way to set someone as laying down on the ground without needing a bed.

    So far you can set the player to lay down as long as there ontop of a bed(Yes they can hang off XD).
     
  12. Offline

    mcdorli

    Please don't spoonfeed, either post is as a util or don't post it.
     
  13. Offline

    ShowbizLocket61

    That would be appreciated
     
Thread Status:
Not open for further replies.

Share This Page