Item Frame Always Spawn Facing East?

Discussion in 'Plugin Development' started by Vandrake, Nov 20, 2012.

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

    Vandrake

    But thats the point of refreshing The Chunk xD Resending The Packets
     
  2. Offline

    DarkBladee12

    Vandrake I thought that only blocks were affected by this^^
     
  3. Offline

    fireblast709

    Chunks contain (tile)entities as well (at least, the "chunk format" page on minecraftwiki groups the chunk, tile entities and entities)
     
  4. Offline

    Vandrake

    fireblast709
    DarkBladee12
    netherfoam

    updated the code. Modified the cardinal direction so the code should be smaller now...way smaller xD credits go to sk89 for making the cardinaldirection code. I only changed it a bit. :3 Have fun
     
  5. Offline

    DarkBladee12

    Vandrake does your ne code also update the item frames, so that they are looking instant at the right direction?
     
  6. Offline

    Vandrake

    nope but that's easy to achieve x.x however if you use it on a signchangeevent you will lose the contents of the sign.
     
  7. Offline

    DarkBladee12

    Vandrake if that is easy, you could tell me how you do this ^^
     
  8. Offline

    Vandrake

    Original Code Posting:

    public void refreshChunkAtPlayer(Player p)//Refresh the chunk by teleporting the player elsewhere and re-teleporting him back
    {
    Location loc = p.getLocation();
    Location to = loc;
    if(getPlayerDirection(p) == BlockFace.WEST)
    {
    to = new Location(loc.getWorld(),loc.getX(),loc.getY()+2000,loc.getZ());
    }
    else
    {
    to = new Location(loc.getWorld(),loc.getX(),loc.getY(),loc.getZ()+2000);
    }
    p.teleport(to);
    p.getWorld().unloadChunk(loc.getChunk());
    p.teleport(loc);
    }
     
  9. Offline

    DarkBladee12

    Vandrake that doesn't work for me, the chunk keeps being unloaded ^^
     
  10. Offline

    Vandrake

    the chunk unloads forcing the system to reload the chunk. but if theres another player in it I dunno if the chunk will unload properly. So try to use the world.refreshchunk(); but It doesnt work for me. Thats why I came up with this.
     
  11. Offline

    DarkBladee12

    Vandrake unfortunately bot doesn't work :(
     
  12. Offline

    Vandrake

    I
    I dont know if its the Refreshchunk Or the unload Chunk But 1 Or Both Of Them Has a boolean Method On It. Play around With It A Bit
     
  13. Offline

    fireblast709

    dat case
     
  14. Offline

    fireblast709

    OK....wtf has just happened... I checked the Craftbukkit CraftWorld source and almost got a heart attack
    Code:java
    1. } else if (Hanging.class.isAssignableFrom(clazz)) {
    2. Block block = getBlockAt(location);
    3. BlockFace face = BlockFace.SELF;
    4. if (block.getRelative(BlockFace.EAST).getTypeId() == 0) {
    5. face = BlockFace.EAST;
    6. } else if (block.getRelative(BlockFace.NORTH).getTypeId() == 0) {
    7. face = BlockFace.NORTH;
    8. } else if (block.getRelative(BlockFace.WEST).getTypeId() == 0) {
    9. face = BlockFace.WEST;
    10. } else if (block.getRelative(BlockFace.SOUTH).getTypeId() == 0) {
    11. face = BlockFace.SOUTH;
    12. }
    13. int dir;
    14. switch (face) {
    15. case SOUTH:
    16. default:
    17. dir = 0;
    18. break;
    19. case WEST:
    20. dir = 1;
    21. break;
    22. case NORTH:
    23. dir = 2;
    24. break;
    25. case EAST:
    26. dir = 3;
    27. break;
    28. }
    29.  
    30. if (Painting.class.isAssignableFrom(clazz)) {
    31. entity = new EntityPainting(world, (int) x, (int) y, (int) z, dir);
    32. } else if (ItemFrame.class.isAssignableFrom(clazz)) {
    33. entity = new EntityItemFrame(world, (int) x, (int) y, (int) z, dir);
    34. }
    35.  
    36. if (entity != null && !((EntityHanging) entity).survives()) {
    37. entity = null;
    38. }
    39. }
    You see that if-else block after BlockFace dir = BlockFace.SELF... if the block to the east is AIR, it willALWAYS spawn on east. Why does such a big bug exist?

    Vandrake got the bug after looking in CraftServer.java for 2 seconds

    [edit] ignore the post
     
  15. Offline

    darkhelmet

    It's defaulting to the first side it finds with air, and it has to default to something. The bug here is that setFacingDirection never changes it.
     
  16. Offline

    fireblast709

    mmh true overlooked that ^_^"... Onwards to the source again
     
  17. Offline

    Vandrake

    Actually it changes it if You Add A Boolean After The Direction. But It Doesnt resend the packet To the Player So Yeah XD

    Setfacingdirection(Blockface.north, true); Something Like This
     
  18. Offline

    fireblast709

    Yes that is called the forcing boolean in the javadocs
     
  19. Offline

    Nitnelave

    There should be a way to spawn a hanging without a block to the east... Shouldn't it be != 0 in the block of code fireblast mentioned earlier? or, rather, if the block to the west is != 0 then face east?
    Or even better, face to the east, if you don't survive face north, etc, and then throw illegal argument.

    Because for now, trying to spawn a painting facing west without a block to the west of the painting throws a illegalargumentexception.
     
  20. Offline

    darkhelmet

    What I do know is:

    - The block you spawn the hanging item on must be same coords as the block it must attach to.
    - The item spawns properly, but defaults to a specific direction.
    - setFacingDirection never works, even with the "forcing boolean"

    Basic code we use that should work, but doesn't:

    http://pastie.org/5731749
     
  21. Offline

    Vandrake

    it works. It just won't refresh. force it then relog. you'll see the changes
     
Thread Status:
Not open for further replies.

Share This Page