Furnace isn't instanceof a furnace O.o

Discussion in 'Plugin Development' started by Darkman2412, Sep 27, 2011.

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

    Darkman2412

    Hi!

    I making a remake of my plugin AutoFurnace. Now... I ran into a problem... Doesn't instanceof work for blocks?
    I send a message in the beginning of PlayerInteractEvent:
    Code:
    e.getPlayer().sendMessage(e.getClickedBlock().getType().toString() + "." + Boolean.toString(e.getClickedBlock() instanceof Furnace));
    This will print "FURNACE.false"...
    Do I need to do e.getClickedBlock().getType().equals(Material.FURNACE) and BURNING_FURNACE?

    Thanks!
     
  2. Offline

    Feed_Dante

    It might be:
    e.getClickedBlock().getState() instanceof Furnace
     
  3. Offline

    Taco

    As mentioned before, I'm pretty sure furnaces are a BlockState.
     
  4. Offline

    Darkman2412

    Ok, thanks! @Feed_Dante @Taco

    Argh... Now I get a ClassCastException error :/
    CraftBlock cannot be cast to Chest
    Code:java
    1. if(!furnace.getRelative(dir).getType().equals(Material.CHEST))
    2. return null;
    3. if(!furnace.getRelative(dir).getRelative(dir).getType().equals(Material.CHEST)&&furnace.getRelative(dir).getType().equals(Material.CHEST))
    4. return furnace.getRelative(dir);
    5. Chest adj = (Chest) furnace.getRelative(dir);
    The error is on the 5th line...

    Looks like I moved the problem to another line, but it's now CraftChest cannot be cast to Block :/
    Code:
    Code:java
    1. public Block getChest(Block furnace, int face) {
    2. if(!furnace.getType().equals(Material.FURNACE))
    3. return null;
    4. Furnace state = (Furnace) furnace.getState();
    5. BlockFace facing = ((FurnaceAndDispenser) state.getData()).getFacing();
    6. BlockFace dir = directions.get((directions.indexOf(facing) + face) % directions.size());
    7. getServer().broadcastMessage(dir.toString());
    8. if(!furnace.getRelative(dir).getType().equals(Material.CHEST))
    9. return null;
    10. if(!furnace.getRelative(dir, 2).getType().equals(Material.CHEST)&&furnace.getRelative(dir).getType().equals(Material.CHEST))
    11. return furnace.getRelative(dir);
    12. Chest adj = (Chest) furnace.getRelative(dir).getState();
    13. Chest dbl = (Chest) furnace.getRelative(dir, 2).getState();
    14. Inventory dblinv = dbl.getInventory();
    15. for(int i=0; i<dblinv.getSize(); i++) {
    16. if(dblinv.getItem(i).equals(new ItemStack(0)))
    17. continue;
    18. else if(!dblinv.getItem(i).equals(new ItemStack(0)))
    19. return (Block) dbl;
    20. }
    21. return (Block) adj;
    22. }

    The problem is at the last return (return (Block) adj; ).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  5. Offline

    Shamebot

    As with furnaces, chests are BlockStates, too.
     
  6. Offline

    Darkman2412

    Actually, I tried to change it to
    Code:
    (Block) ((Block) adj).getState();
    but it still gives me that error
     
  7. Offline

    phaed

    Code:
    return adj.getBlock();
     
  8. Offline

    Taco

    BlockState != Block, you can cast a BlockState to a chest/furnace, but not to a block. You can, however, get a BlockState from a Block using the getState() method.
     
Thread Status:
Not open for further replies.

Share This Page