Cannot set ladder direction?

Discussion in 'Spigot Plugin Development' started by J4D3N, Jul 18, 2015.

  1. I am trying to set a direction of a ladder after I set the block to the ladder material type. However my attempts have come to no avail and I cannot seem to get this code to work without using deprecated code.

    Code (Text):
    Block block = ...

    block.setType(Material.LADDER);

    Ladder ladder = (Ladder) block.getState().getData();
    ladder.setFacingDirection(BlockFace.EAST);

    block.getState().update();
    It would always face north after I set the direction and updated it, I even tried creating a ladder class instance and then setting the block data using block.getState().setData(ladder)...

    If anyone has any idea, or if I made a stupid mistake please reply.
     
  2. @J4D3N If you don't try to set the direction, where does the ladder automatically place?
     
  3. I'm pretty sure you have to use data values to set the direction.
     
    • Agree Agree x 1
  4. It automatically places it north.

    Is there no other way to do this without using deprecated methods?
     
  5. No I don't think so.
     
  6. People may hate on you for using depreciated methods.
     
  7. Why would the byte data methods be deprecated when an alternative usage does not function as intended? For now I will just have to use deprecated code which sucks..
     
  8. Yea, but it's the only way to change the direction so..
     
  9. What is the point of the ladder class then?
     
  10. Tbh, I have no idea. I barely work with ladders but if you look at the docs. Most of it is deprecated and there's also facing direction but that doesn't seem to work for you.
     
  11. I hate to necro a thread, but I think having a question go unanswered is even worse—especially since I had the same problem. (This is one of the first things to come up when looking for "spigot set facing direction")

    For any future dwellers, the java docs specifies in the block class that "use block.getState() to get a snapshot state of a block which will not be modified."

    Hence,
    Code (Text):
    block.getState().getData()
    and
    Code (Text):
    block.getState().update(true)
    are two separate state snapshots. You'd want to save the state to its own BlockState variable, then set the direction and update from that variable.
     
    • Like Like x 1