Cast a Block to Furnace (CraftBukkit)

Discussion in 'Plugin Development' started by Löwenpower, Dec 6, 2014.

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

    Löwenpower

    (May not good english)
    Like the title sais, i want to cast a Block to a Furnace.
    But this doesnt is working .
    First the code:
    Code:java
    1.  
    2. //furnacesSmelt is a ArrayList with Locations from Furnaces
    3. //this is standing in a while-Loop
    4. Furnace f = (Furnace)furnacesSmelt.get(i).getBlock.getState();
    5.  

    But it throws a exception:
    org.bukkit.craftbukkit.v1_7_R1.block.CraftBlockState cannot be cast to org.bukkit.blocks.Furnace
    I am working with craftbukkit for editing Entitys and such stuff.
    The Problem is: I get CraftBlockState and not "normale" BlockState, which i think is strange?
    So how can i cast a CraftBlock to Furnace / CraftFurnace. (I tried both)
    Thx for help.
     
  2. Offline

    mrCookieSlime

    Löwenpower
    Could you maybe post all your imports?
     
  3. Offline

    Abs0rbed

    From what I see, you're referencing the actual craftbukkit jar, and not the api, which isn't really necessary unless you're planning on sending packets and things like that. Try reorganizing your imports and choose the ones that you need (No clue what IDE you're using, but usually you can see the package name)
     
  4. Offline

    fireblast709

    Löwenpower Is your block even a furnace? (print the Block's getType().name() to be 100% sure)
     
  5. Offline

    Kilovice

    Perhaps try
    Code:java
    1. //Assuming This is on Interact Event....
    2. Block b = event.getClickedBlock();
    3. if(b instanceof Furnace){
    4. //TODO Do stuff if furnace
    5. System.out.printf("This is a furnace");
    6. }
    7. else{
    8. //TODO DO stuff if not furnace
    9. System.out.printf("The furnace was a lie");
    10. }
     
Thread Status:
Not open for further replies.

Share This Page