Itemframe always facing east?

Discussion in 'Plugin Development' started by darkhelmet, Jan 4, 2013.

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

    darkhelmet

    Trying to spawn an itemframe on a block. I finally got that working properly but no matter what, I can never change the side of the block.

    Code:
    // Spawn only works if the location is an existing solid block.
    World currentWorld = event.getBlock().getWorld();
    Location loc = new Location(currentWorld, -131, 65, 180);
    Hanging h = currentWorld.spawn(loc, ItemFrame.class);
               
    // This never works.
    h.setFacingDirection(BlockFace.NORTH);
    No matter what I try, setFacingDirection does nothing.
     
  2. Offline

    gomeow

    I believe if you wanted it on the north side, you might do this:

    Code:java
    1.  
    2. //adding to your code
    3.  
    4. //Get the new location
    5. Location newLocation = h.getLocation().getBlock().getRelative(h.getAttachedFace()).getRelative(BlockFace.NORTH).getLocation();
    6.  
    7. //Abort if the Roth side is not air.
    8. if(newLocation.getBlock().getType() != Material.AIR) return;
    9. //Remove the old entity
    10. h.remove();
    11.  
    12. //spawn a new one
    13. ItemFrame itemFrame = (ItemFrame) newLocation.getWorld().spawnEntity(newLocation, EntityType.ITEM_FRAME).setFacingDirection(BlockFace.NORTH, true);

    Note that that code is untested and may not work.
     
  3. Offline

    darkhelmet

    It won't work because that block location is air. You have to spawn a hanging item at a location that contains a solid block.

    Fyi, opened a bug for this.

    https://bukkit.atlassian.net/browse/BUKKIT-3371

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  4. Offline

    fireblast709

  5. Offline

    darkhelmet

    How is that a bug? It looks alright to me. 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.
     
Thread Status:
Not open for further replies.

Share This Page