Ejemplo n.º 1
0
 @EventHandler
 public void onSmelt(FurnaceSmeltEvent event) {
   // this ensures that an STB item smelted in a furnace leaves the
   // correct result in the furnace's output slot
   BaseSTBItem item = SensibleToolbox.getItemRegistry().fromItemStack(event.getSource());
   if (item != null) {
     event.setResult(item.getSmeltingResult());
   }
 }
Ejemplo n.º 2
0
 private boolean validateSmeltingIngredient(ItemStack stack) {
   BaseSTBItem item = SensibleToolbox.getItemRegistry().fromItemStack(stack);
   if (item != null) {
     return item.getSmeltingResult() != null;
   } else {
     // vanilla item - need to ensure it's actually smeltable (i.e. wasn't added
     // as a furnace recipe because it's the material for some custom STB item)
     return RecipeCalculator.getSmeltedOutput(stack.getType()) != null;
   }
 }
Ejemplo n.º 3
0
 @EventHandler(ignoreCancelled = true)
 public void onFurnaceInsert(final InventoryClickEvent event) {
   if (event.getInventory().getType() != InventoryType.FURNACE) {
     return;
   }
   if (event.getRawSlot() == 0 && event.getCursor().getType() != Material.AIR) {
     if (!validateSmeltingIngredient(event.getCursor())) {
       event.setCancelled(true);
     }
   } else if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) {
     if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
       if (!validateSmeltingIngredient(event.getCurrentItem())
           && !STBUtil.isFuel(event.getCurrentItem().getType())) {
         event.setCancelled(true);
         int newSlot = findNewSlot(event);
         if (newSlot >= 0) {
           event.getWhoClicked().getInventory().setItem(newSlot, event.getCurrentItem());
           event.setCurrentItem(null);
         }
       }
     }
   } else if (event.getRawSlot() == 2
       && SensibleToolbox.getItemRegistry().isSTBItem(event.getCurrentItem())) {
     // work around CB bug where shift-clicking custom items out of furnace seems
     // to cause a de-sync, leaving phantom items in the furnace
     Bukkit.getScheduler()
         .runTask(
             plugin,
             new Runnable() {
               @Override
               public void run() {
                 STBUtil.forceInventoryRefresh(event.getInventory());
               }
             });
   }
 }