Skull Problem. Help?!

Discussion in 'Plugin Development' started by Jetsinsu, May 16, 2014.

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

    Jetsinsu

    Ok, so, I been working on this for about 2 days trying to get this right and I think this is a good time to post this because i'm going to eat. I have an issue with just one thing! When I add the code "if (!(skulltype.equals(SkullType.ZOMBIE)))return;" After I add this, the whole thing beneath that code doesn't work and I get no errors. If you know this, please help me! Thanks!

    Code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onBlockPlace(BlockPlaceEvent e){
    4. Block block = e.getBlock();
    5. if (!(block.getState() instanceof Skull)){
    6. return;
    7. }
    8.  
    9. Skull skull = (Skull) block.getState();
    10. SkullType skulltype = skull.getSkullType();
    11.  
    12. if (e.getBlock().getType() == Material.SKULL_ITEM){
    13. if (!(skulltype.equals(SkullType.ZOMBIE)))return;
    14. int x = e.getBlock().getLocation().getBlockX();
    15. int y = e.getBlock().getLocation().getBlockY();
    16. int z = e.getBlock().getLocation().getBlockZ();
    17. Location loc = new Location(e.getBlockPlaced().getWorld(), x, y-1, z);
    18. Location loc2 = new Location(e.getBlockPlaced().getWorld(), x, y-2, z);
    19. int b = loc.getBlock().getTypeId();
    20. int b2 = loc2.getBlock().getTypeId();
    21.  
    22. if (b == 88){
    23. if (b2 == 88){
    24. LivingEntity p = e.getBlockPlaced().getWorld().spawnCreature(e.getBlockPlaced().getLocation(), EntityType.PIG_ZOMBIE);
    25. p.setMaxHealth(100.0);
    26. p.setHealth(100.0);
    27. return;
    28. }
    29. }
    30. }
    31. }
     
  2. Offline

    Barnyard_Owl

    I believe the problem instead lies within the line above --
    Code:java
    1. if (e.getBlock().getType() == Material.SKULL_ITEM){

    It should be comparing against Material.SKULL, as SKULL_ITEM is referring to the item rather than the block. Also, it's not really necessary to have it there as you already checked before.
    Code:java
    1. if (!(block.getState() instanceof Skull)){
    2. return;
    3. }
     
  3. Offline

    Jetsinsu

    Barnyard_Owl
    Alrighty. This is what I got and It still doesn't work. Sorry if I coded it wrong. I changed it up a bit.

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onBlockPlace(BlockPlaceEvent e){
    4. Block block = e.getBlock();
    5. if (!(block.getState() instanceof Skull)){
    6. return;
    7. }
    8.  
    9. Skull skull = (Skull) block.getState();
    10. SkullType skulltype = skull.getSkullType();
    11.  
    12. if (skulltype.equals(SkullType.ZOMBIE)){
    13. int x = e.getBlock().getLocation().getBlockX();
    14. int y = e.getBlock().getLocation().getBlockY();
    15. int z = e.getBlock().getLocation().getBlockZ();
    16. Location loc = new Location(e.getBlockPlaced().getWorld(), x, y-1, z);
    17. Location loc2 = new Location(e.getBlockPlaced().getWorld(), x, y-2, z);
    18. int b = loc.getBlock().getTypeId();
    19. int b2 = loc2.getBlock().getTypeId();
    20.  
    21. if (b == 88){
    22. if (b2 == 88){
    23. LivingEntity p = e.getBlockPlaced().getWorld().spawnCreature(e.getBlockPlaced().getLocation(), EntityType.PIG_ZOMBIE);
    24. p.setMaxHealth(100.0);
    25. p.setHealth(100.0);
    26. return;
    27. }
    28. }
    29. }
    30. }


    Bump.

    Bumped. Anyone, really? Just one thing :)

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

    CodePlaysMC

    You should try and change it to:
    Code:java
    1. if(e.getBlock().getType == Material.SKULL_ITEM, 1, (short) 2);

    Not sure if it works, but I guess you could give it a try.
    The (short) 2 in the code makes it a Zombie head instead of a regular skull head.
     
  5. Offline

    Jetsinsu

    It says "The method SKULL_ITEM(int, short) is undefined for the type Material"
    Anyone else?

    Bump. again.

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

    Jetsinsu

    Bumped. Sigh....
     
  7. Jetsinsu The suggestion by CodePlaysMC makes no sense and won't work - can I see whatever the most recent copy was before you implemented the suggested changes?
     
  8. Offline

    Jetsinsu

    AdamQpzm
    Code:
    Code:java
    1. @SuppressWarnings({ "deprecation", "unused" })
    2. @EventHandler
    3. public void onBlockPlace(BlockPlaceEvent e){
    4. if (!(e.getBlock().getState() instanceof Skull)){
    5. return;
    6. }
    7.  
    8. Block block = e.getBlock();
    9. Skull skull = (Skull) block.getState();
    10. SkullType skulltype = skull.getSkullType();
    11.  
    12. if (skull.equals(SkullType.ZOMBIE)){
    13. int x = e.getBlock().getLocation().getBlockX();
    14. int y = e.getBlock().getLocation().getBlockY();
    15. int z = e.getBlock().getLocation().getBlockZ();
    16. Location loc = new Location(e.getBlockPlaced().getWorld(), x, y-1, z);
    17. Location loc2 = new Location(e.getBlockPlaced().getWorld(), x, y-2, z);
    18. int b = loc.getBlock().getTypeId();
    19. int b2 = loc2.getBlock().getTypeId();
    20.  
    21. if (b == 88){
    22. if (b2 == 88){
    23. LivingEntity p = e.getBlockPlaced().getWorld().spawnCreature(e.getBlockPlaced().getLocation(), EntityType.ZOMBIE);
    24. p.setMaxHealth(100.0);
    25. p.setHealth(100.0);
    26. return;
    27. }
    28. }
    29. }
    30. }
     
  9. Offline

    DxDy

    if(skulltype.equals(SkullType.ZOMBIE)) would make more sense ;)
     
    AdamQpzm likes this.
  10. Offline

    Jetsinsu

    DxDy
    It doesn't work. I tried it. If you wold like to add me on skype, my name is Belinkster.
     
  11. Jetsinsu Print out what the value of skulltype is and then come back to us :)
     
  12. Offline

    Jetsinsu

    AdamQpzm
    Idk if I should have found that rude or confusing. Lol
     
  13. Jetsinsu It wasn't intended as either of them - if you're saying that the value of skulltype isn't SkullType.ZOMBIE it would be good to find out what the actual value is, no?
     
  14. Offline

    DxDy

    Basic problem solving skills. You do have an error. You don't know what it is. The thing you know is: My Statement inside the if does not return true (ie equals does not return true).

    Hence you'll print out skull-type to see what actually is inside that variable at the time of the comparison.

    You should have appreciated that statement by AdamQpzm as helpful and well-intentioned ;)
     
  15. Offline

    Jetsinsu

    DxDy
    Hmmm.

    AdamQpzm
    So the value of the skull for zombies? Like "Material.SKULL, 1, (short)2);" ?
     
  16. Jetsinsu Nope, just put this in right after SkullType skulltype = etc
    Code:
    System.out.println(skulltype);
     
  17. Offline

    DxDy

    System.out.println(skulltype.toString());

    edit: ninja'd by AdamQpzm^^
     
    AdamQpzm likes this.
  18. Offline

    Jetsinsu

    DxDy
    O. I'm pretty new to that. What does it exactly do.
     
  19. Jetsinsu It prints the value of skulltype to your console
     
  20. Offline

    DxDy

    System.out.println prints a message to the standard output (in your case: your console window (simplified)), skulltype.toString() will get you the name of the enum constant the skulltype currently has.
     
  21. Offline

    Jetsinsu

    AdamQpzm
    It keeps saying Skeleton when I place down Zombie head.
     
  22. Jetsinsu Well that definitely sounds wrong, doesn't it? What does it print out when you place a skeleton skull? How about other types of skull? Failing that, try printing out the byte data value for different skulls when placing them

    DxDy Fun fact: Did you know that PrintStream's println(Object) method calls String.valueOf(Object) which ends up calling the object's toString() method if the object isn't null? The only real difference is that System.out.println(Object) is null-safe, but System.out.println(Object.toString()) isn't. :p
     
    DxDy likes this.
  23. Offline

    Jetsinsu

    AdamQpzm
    I like this game, it's fun.
     
    AdamQpzm likes this.
  24. Offline

    DxDy

    I did know that it called the method, but to be honest I completely forgot about null-safety in the spur of the moment :)
     
    AdamQpzm likes this.
  25. Offline

    Jetsinsu

    AdamQpzm

    All I got is this..... System.out.println(skull.getData().toString());
     
  26. Jetsinsu Fair enough. And what prints when you try to place a zombie skull and what prints when you try to print a skeleton skull?
     
  27. Offline

    Jetsinsu

    AdamQpzm
    Both says, SKULL(1) facing SELF

    AdamQpzm
    Do you know what is wrong?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  28. Jetsinsu Nope. I'd have to run my own tests, which I'm not able to do right now.
     
Thread Status:
Not open for further replies.

Share This Page