Refresh entity

Discussion in 'Plugin Development' started by Nogtail, Dec 17, 2013.

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

    Nogtail

    I have recently managed to get item frame rotation working but you need to relog or exit the chunk to see the changes. I am wondering if there is any method to refresh an entity so a client can see changes to it.
     
  2. Offline

    RawCode

    Code:
        public void setRotation(int i) {
            this.getDataWatcher().watch(3, Byte.valueOf((byte) (i % 4)));
        }
    ends inside Packet40EntityMetadata, soo if you want to "update" something without actually changing world, form update data and send packet directly.
     
    Nogtail likes this.
  3. Offline

    Nogtail

    So there is no way other than packets?
     
  4. Offline

    RawCode

    How client going to know about change without packets?
     
  5. Offline

    Nogtail

    Well, obviously you need packets for everything but most of the time they are managed by Bukkit more directly.
     
  6. Offline

    RawCode

    current version of bukkit have "little" bug, you can wait for fix or sent packets directly from your plugin, final result will be same.
     
  7. Offline

    Nogtail

    On further research this seems to be a very old bug (over a year old) which has not had a fix yet, do you think there is any chance it will get a fix any time soon?
     
  8. Offline

    xTrollxDudex

    Nogtail
    Try unloading the chunk the player is in and loading it.
    PHP:
    player.getLocation().getChunk().unload(truefalse);
    player.getLocation().getChunk().load();
     
    Nogtail likes this.
  9. Offline

    Nogtail

    That seems to work thanks :) Originally I was refreshing every time I placed an item frame and it was quite glitchy but later tried using a set of chunks to reload after the placement had occurred and that seems to work quite well :)

    Sadly in some circumstances is still very buggy and won't update or seems to randomly update the positions so will still be switching to a better method when available.

    Edit: The buggyness seems to occur more on the borders of chunks/multiple chunks so may be an issue of getting the right chunk to update.
     
  10. Offline

    RawCode

    refreshing entire chunk will sent entire chunk in packet, it's hurge overhead compared to entity metadata packet...
     
  11. Offline

    DarkBladee12

    RawCode I'm going to try out the setRotation today, but do you know what kind of number I have to use? For example if I want to rotate the item frame north is the value 0 or what?
     
  12. Offline

    RawCode

    you can test all values a lot faster then anyone can answer on forum, set to 0, 1, 2 or 3 and check results.
    also there is no definite north or west for frames, they can be attached to any side of block, same rotation will result in different direction due base direction of block.
     
  13. Offline

    DarkBladee12

    RawCode Sorry, but my testserver is currently under maintenance so I couldn't test it and wanted to ask first for the values...
     
  14. Offline

    RawCode

    you always can run server on your local machine, it consume less then 200 megs of memory for single player, ever low end PC may handle both game and server for testing purposes.
     
  15. Offline

    DarkBladee12

    RawCode The method doesn't work, tried it with values from 0 to 3...

    RawCode I came up with a new idea: spawning item frames with the desired direction through nms. So the item frame is spawnable with different directions, but it pops off every time no matter what direction :/ That's my code I'm using to test this:

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player p = event.getPlayer();
    4. if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.ITEM_FRAME) {
    5. event.setCancelled(true);
    6. Block b = event.getClickedBlock();
    7. int x = b.getX();
    8. int y = b.getY();
    9. int z = b.getZ();
    10. World w = ((CraftWorld) b.getWorld()).getHandle();
    11. EntityItemFrame e = new EntityItemFrame(w, x, y, z, 0);
    12. e.setPosition(x, y, z);
    13. p.sendMessage(Boolean.toString(e.survives()));
    14. w.addEntity(e, SpawnReason.CUSTOM);
    15. }
    16. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  16. Offline

    xTrollxDudex

    Nogtail
    Hmm, unload multiple chunks? Try moving the player far enough away and teleport him back so the client unloads and loads the chunk instead of the server
     
  17. Offline

    Nogtail

    That would most likely work but I don't want to do much to the users experience, a slight chunk flicker as it reloads is fine but teleporting them away or refreshing multiple chunks is not what I want to do.
     
  18. Offline

    xTrollxDudex

    Ah alright.
     
  19. Offline

    RawCode

    DarkBladee12

    for obvious reasons you cant create frame INSIDE block, you must offset X and Z by +1-1 in order to create frame in proper location.
    Code shoud looks like this:

    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.ITEM_FRAME) {
    event.setCancelled(true);
    Block b = event.getClickedBlock();
    BlockFace bf = event.getBlockFace();
    int x = b.getX();
    int y = b.getY();
    int z = b.getZ();
    
    if (bf == BlockFace.NORTH)
    x++;
    if (bf == BlockFace.EAST)
    x--;
    if (bf == BlockFace.SOUTH)
    z++;
    if (bf == BlockFace.WEST)
    z--;
    
    World w = ((CraftWorld) b.getWorld()).getHandle();
    EntityItemFrame e = new EntityItemFrame(w, x, y, z, 0);
    e.setPosition(x, y, z);
    p.sendMessage(Boolean.toString(e.survives()));
    w.addEntity(e, SpawnReason.CUSTOM);
    }
    }
    
     
  20. Offline

    DarkBladee12

    RawCode Well I also tried that, but it doesn't work.. If you spawn it facing north or east it will pop off and if you change the values of north or east that will be increased/decreased it works, but you can't put an item frame on every side on the block, because some will pop off again. However I found a solution, just remove the e.setPosition(...) line and it works perfectly ;)
     
  21. Offline

    Nogtail

Thread Status:
Not open for further replies.

Share This Page