Set block skulltype in player interact event

Discussion in 'Plugin Development' started by Hex_27, Aug 12, 2015.

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

    Hex_27

    Code:
    p.setItemInHand(null);
                                        final Block turret = event.getClickedBlock().getRelative(0, 1, 0);
                                        turret.setType(Material.SKULL);
                                        turret.setData((byte) 1);
                                       
                                       
                                       
                                                  Block skull = turret.getLocation().getBlock();
                                                  ((Skull) skull.getState()).setSkullType(SkullType.WITHER);
                                                    ((Skull) skull.getState()).update();

    This just places a skeleton skull, instead of a wither skull.
     
  2. Offline

    Hex_27

  3. Offline

    CoolDude53

    Code:
    Block turret = player.getLocation().getBlock();
    turret.setType(Material.SKULL);
    turret.setData((byte) 1);
    
    Skull skull = (Skull) turret.getState();
    
    skull.setSkullType(SkullType.WITHER);
    skull.update();
    Sometimes, it's better to just create an object, much easier to keep track.
     
  4. Offline

    Hex_27

    Last edited: Aug 14, 2015
  5. Offline

    CoolDude53

    Except this works and yours does not.
     
  6. Offline

    Hex_27

    @CoolDude53 what? It is exactly the same code. Why would this work? Unless you point out a difference, stop being irrational

    1. =====My code=====
    2. turret.setType(Material.SKULL);
    3. turret.setData((byte) 1);
    4. Block skull = turret.getLocation().getBlock();
    5. ((Skull) skull.getState()).setSkullType(SkullType.WITHER);
    6. ((Skull) skull.getState()).update();
    7. =====your code=====
    8. turret.setType(Material.SKULL);
    9. turret.setData((byte) 1);
    10. Skull skull = (Skull) turret.getState();
    11. skull.setSkullType(SkullType.WITHER);
    12. skull.update();

    Spot the difference

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Aug 15, 2015
  7. Offline

    CoolDude53

    I tested both ways, mine worked and yours did not, simple as that. If you aren't going to accept the help people give you then don't post on this forum asking for help in the first place.
     
  8. Offline

    Hex_27

    @CoolDude53 Got down to trying it, and it didn't work.
     
  9. Offline

    CoolDude53

    You need to remove the final modifier from your turret block object.
     
  10. Offline

    teej107

    That won't make a difference.

    @Hex_27 Why are you creating two different variables from the same Block Object?
     
  11. Offline

    CoolDude53

    I tested the code I originally posted, and it worked without a problem...soooo yeah, that's the only difference I see from his repost and my original.
     
  12. Offline

    teej107

    The difference I see is your server version.
    Final won't fix the Skull problem. Final just keeps your variable from being reassigned a value.
     
  13. Offline

    CoolDude53

    I built off of 1.7.10, so that could very well be the case.
     
  14. @Hex_27
    The reason your code doesn't work is because you create a new "BlockState" instance twice by calling Block#getState() each time, meaning the update method and setSkullType method are called on a different instance, so it's not working. You need to setup a variable where you modify the skulltype ánd update.
     
Thread Status:
Not open for further replies.

Share This Page