Need help getting Furnace instance

Discussion in 'Spigot Plugin Development' started by DKrolls, Jun 3, 2016.

  1. Basically, what I'm trying to do is when a player right clicks on a command block, I want them to open a customized GUI that represents a rain collector (when it's raining, it will slowly fill any buckets or glass bottles placed in the smelting spot. In order to do this, I'd need a Furnace instance in order to use the get/setCookTime() method. Does anyone know the best way to do this?
    Code (Text):
    public void openRainCollectorInventory(PlayerInteractEvent e){
            if(e.getClickedBlock().getType() == Material.COMMAND){=
                Inventory f = Bukkit.getServer().createInventory(null, InventoryType.FURNACE, "Rain Collector");
                BlockState b = e.getClickedBlock().getState();
                if(e.getPlayer().getWorld().hasStorm()){
                }
                e.getPlayer().openInventory(f);
            }
        }
    NOTE: ^This^ gives me the furnace inventory, but none of the desired methods.
    Thanks in advance.
     
  2. Choco

    Moderator

    Cast BlockState b to Furnace
    Code (Java):
    Furnace furnace = (Furnace) e.getClickedBlock().getState();


    EDIT: You want to instead cast the Inventory to FurnaceInventory. You can delete the BlockState all together. It's not necessary. You're right clicking on a CommandBlock so you'd have a BlockState of a CommandBlock rather than a Furnace (ClassCastException)
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/FurnaceInventory.html
     
  3. Choco

    Moderator

    Unfortunately, if you're clicking on a block that is not a Furnace, you're unable to do that. You would have to do FurnaceInventory#getHolder(), but the issue with that is it would return null. You're returning the holder for the inventory you created which does not exist.

    You'd have to have a physical Furnace block somewhere in the world to reference
     
  4. Would this idea work?

    Every time someone places a new rain collector (command block), it will create a unique dummy furnace beyond my world border and use that to access Furnace methods. Since this is for a minigame and the map resets every round, it wouldn't create more than a few dummy furnaces.

    ...Or is there some way to achieve this using NMS? I know there are several "virtual furnace" plugins that may use it.