InventoryClickEvent - Get the furnace

Discussion in 'Plugin Development' started by Randy Schouten, Mar 8, 2014.

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

    Randy Schouten

    I was trying to get the player who put something into a furnace for some time but I can't find a variable that doesn't change for the life of me. Is there any way I can get the block or location from the object you put something in?

    I have tried using the ItemStack as well, but that doesn't really work well.
  2. Offline


    Randy Schouten
    1. InventoryType topType = event.getView().getTopInventory().getType();
    3. if(event.getWhoClicked() instanceof Player){
    4. if(topType == InventoryType.BREWING || topType == InventoryType.CHEST || topType == InventoryType.DISPENSER || topType == InventoryType.WORKBENCH
    5. || topType == InventoryType.HOPPER || topType == InventoryType.ENDER_CHEST || topType == InventoryType.FURNACE){
    7. event.setCancelled(true);
    9. }
    10. }

    this is what i used
  3. Offline


    Here's something I just came up with:
    public void onInventoryClick(InventoryClickEvent event) {
        if (event.getInventory().getType() == InventoryType.FURNACE) {
            FurnaceInventory fi = (FurnaceInventory)event.getInventory();
            Location loc = fi.getHolder().getLocation();
            Block block = loc.getBlock();
            //do something with the location or the block
    Randy Schouten likes this.
  4. Offline

    Randy Schouten

    If you read my question, that's not what I asked. But thanks anyway :).

    Yeah that's sorta what I do up to now.
    What I have now is I have 2 events. The smelt event and the item drag event. Then I have one hashmap where I want to keep who put what in a furnace. The problem is that I can't find a "shared" variable that doesn't change in both events.

    Ideally I'd want to get the specific furnace, but the Click event doesn't allow me to get the furnace as a block (as far as I know), that means also the location.

    I've seen something you did a few edits ago with the hashmap, that's sort of what I have, but that only keeps track of a single furnace, that's where the problem comes in. I want to keep track of all the furnaces that somebody put something in.

    Sorry if it's a bit confusing to understand, but I hope you understand it haha :p

    Here's the code:

    1. public void onInventoryMoveItem(InventoryClickEvent event){
    2. if(event.getInventory().getType().equals(InventoryType.FURNACE) && event.getRawSlot() == 0){
    4. Player player = (Player)event.getWhoClicked();
    5. EpicSystem.furnaceList.put(event.getCurrentItem(), EpicSystem.getEpicPlayer(player));
    6. }
    7. }

    1. public void OnFurnaceSmelt(FurnaceSmeltEvent event){
    3. ItemStack oldStack = event.getSource();
    5. System.out.print(EpicSystem.furnaceList.toString());
    6. System.out.print(oldStack);
    8. EpicPlayer player = EpicSystem.furnaceList.get(oldStack);
    9. }

    I have "furnaceList" as a hashmap. I tried to use the ItemStack now, but it doesn't really work out.

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


  6. Offline


    Read my modified post. :)
  7. Offline

    Randy Schouten

    Welp. How did I miss that variable?!
Thread Status:
Not open for further replies.

Share This Page