Rotating blocks doesn't work

Discussion in 'Spigot Plugin Development' started by MartinPL, Jul 19, 2018.

Thread Status:
Not open for further replies.
  1. Hello! I'm making computer in minecraft. When you right click it's ready to use. Computer-off is pumpkin Computer working is Jack'o lantern. When i'm just changing block it rotate to default BlockFace. With custom model this looks terrible. I had this code (working without rotating)
    Code (Text):

    p.getWorld().getBlockAt(xp, yp, zp).setType(Material.JACK_O_LANTERN);
     
    But this code isn't working:
    Code (Text):

    Pumpkin pu = (Pumpkin) p.getWorld().getBlockAt(xp, yp, zp);
                           BlockFace f = pu.getFacing();                              
                           p.getWorld().getBlockAt(xp, yp, zp).setType(Material.JACK_O_LANTERN);
                           pu.setFacingDirection(f);
     
    I was trying with 2 Pumpkin objects with same result.

    Thanks in advance :)
     
  2. When casting a block to Pumpkin, you should be casting the blockstate, not the block itself.

    So
    Code (Text):

    Pumpkin pu = (Pumpkin) p.getWorld().getBlockAt(xp, yp, zp).getState();
     
     
  3. Code (Text):

    Pumpkin pu = (Pumpkin) p.getWorld().getBlockAt(xp, yp, zp).getState();
                           BlockFace f = pu.getFacing();                              
                           p.getWorld().getBlockAt(xp, yp, zp).setType(Material.JACK_O_LANTERN);
                           pu.setFacingDirection(f);  
     
    Doesn't working. Still, block isn't changing. I'm playing on 1.11.2 btw.
     
  4. Not sure what you're doing here
    Code (Text):

    BlockFace f = pu.getFacing();  
    ...
    pu.setFacingDirection(f);  
     
    You're getting the direction the pumpkin is facing, then setting the direction it is facing to the direction it was already facing.
     
  5. I'm getting FaceDirection. Then i want to change direction of new placed block, because it's reseting to default
     
  6. When changing block, direction change to default
     
  7. Ohhh I get you now, sorry.

    Maybe instead of getting the block face, try
    Code (Text):

    Byte data = pu.getData().getData();
     
    then

    Code (Text):

    pu.setData(data);
     
     
  8. Code (Text):

    Pumpkin pu = (Pumpkin) p.getWorld().getBlockAt(xp, yp, zp).getState();
     
    This is creating error. But this block Is Pumpkin so idk :p
     
  9. Hmm but i don't think that it will work :)
     
  10. The error is?
     
  11. Yup this is error, but your answer helped me :D the one with byte. I'm just saving byte, not block. Thanks :D
     
Thread Status:
Not open for further replies.