Java Code Examples for org.bukkit.Material#DISPENSER

The following examples show how to use org.bukkit.Material#DISPENSER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DispenserListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockDispensing(BlockDispenseEvent e) {
    Block b = e.getBlock();

    if (b.getType() == Material.DISPENSER && b.getRelative(BlockFace.DOWN).getType() != Material.HOPPER) {
        SlimefunItem machine = BlockStorage.check(b);

        if (machine != null) {
            machine.callItemHandler(BlockDispenseHandler.class, handler -> {
                Dispenser dispenser = (Dispenser) b.getState();
                BlockFace face = ((Directional) b.getBlockData()).getFacing();
                Block block = b.getRelative(face);
                handler.onBlockDispense(e, dispenser, block, machine);
            });
        }
    }
}
 
Example 2
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected void depositItems(BlockMenu menu, Block facedBlock) {
    if (facedBlock.getType() == Material.DISPENSER && BlockStorage.check(facedBlock, "ANDROID_INTERFACE_ITEMS")) {
        Dispenser d = (Dispenser) facedBlock.getState();

        for (int slot : getOutputSlots()) {
            ItemStack stack = menu.getItemInSlot(slot);

            if (stack != null) {
                Optional<ItemStack> optional = d.getInventory().addItem(stack).values().stream().findFirst();

                if (optional.isPresent()) {
                    menu.replaceExistingItem(slot, optional.get());
                }
                else {
                    menu.replaceExistingItem(slot, null);
                }
            }
        }
    }
}
 
Example 3
Source File: MagicSugar.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        // Check if it is being placed into an ancient altar.
        if (e.getClickedBlock().isPresent()) {
            Material block = e.getClickedBlock().get().getType();

            if (block == Material.DISPENSER || block == Material.ENCHANTING_TABLE) {
                return;
            }
        }

        Player p = e.getPlayer();
        if (p.getGameMode() != GameMode.CREATIVE) {
            ItemUtils.consumeItem(e.getItem(), false);
        }

        p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
        p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, 3));
    };
}
 
Example 4
Source File: Juicer.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public Juicer(Category category, SlimefunItemStack item) {
       super(category, item, 
			new ItemStack[] {null, new ItemStack(Material.GLASS), null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
			new ItemStack[0],
			BlockFace.SELF
	);
}
 
Example 5
Source File: CraftDispenser.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockProjectileSource getBlockProjectileSource() {
    Block block = getBlock();

    if (block.getType() != Material.DISPENSER) {
        return null;
    }

    return new CraftBlockProjectileSource((TileEntityDispenser) this.getTileEntityFromWorld());
}
 
Example 6
Source File: TntTracker.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityDispense(BlockDispenseEntityEvent event){
    if (event.getBlock().getType() == Material.DISPENSER){
        if (event.getEntity().getType() == EntityType.PRIMED_TNT) {
            Location location = event.getBlock().getLocation();
            if (dispenserPlaced.containsKey(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ())) {
                UUID player = dispenserPlaced.get(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ());
                event.getEntity().setMetadata("source", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), player));
            }
        }
    }
}
 
Example 7
Source File: ArmorForge.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public ArmorForge(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { 
          null, null, null, 
          null, new ItemStack(Material.ANVIL), null, 
          null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null 
    }, new ItemStack[0], BlockFace.SELF);
}
 
Example 8
Source File: MagicWorkbench.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private Block locateDispenser(Block b) {
    Block block = null;

    if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) block = b.getRelative(1, 0, 0);
    else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) block = b.getRelative(0, 0, 1);
    else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) block = b.getRelative(-1, 0, 0);
    else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) block = b.getRelative(0, 0, -1);

    return block;
}
 
Example 9
Source File: CraftDispenser.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public BlockProjectileSource getBlockProjectileSource() {
    Block block = getBlock();

    if (block.getType() != Material.DISPENSER) {
        return null;
    }

    return new CraftBlockProjectileSource(dispenser);
}
 
Example 10
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void blockDispense(BlockDispenseEvent event) {
	if (event.getBlock().getType() != Material.DISPENSER) {
		return;
	}
	CustomItem customItem = CustomItemManager.getCustomItem(event.getItem());
	if (customItem != null) {
		if (verifyCustomItem(customItem, event.getBlock().getWorld())) {
			customItem.onDispense(event, new DispenserDetails(event, customItem._owner));
		} else {
			event.setCancelled(true);
		}
	}
}
 
Example 11
Source File: BlockDispenseHandler.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
default Optional<IncompatibleItemHandlerException> validate(SlimefunItem item) {
    if (item instanceof NotPlaceable || item.getItem().getType() != Material.DISPENSER) {
        return Optional.of(new IncompatibleItemHandlerException("Only dispensers that are not marked as 'NotPlaceable' can have a BlockDispenseHandler.", item, this));
    }

    return Optional.empty();
}
 
Example 12
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
protected void refuel(BlockMenu menu, Block facedBlock) {
    if (facedBlock.getType() == Material.DISPENSER && BlockStorage.check(facedBlock, "ANDROID_INTERFACE_FUEL")) {
        Dispenser d = (Dispenser) facedBlock.getState();

        for (int slot = 0; slot < 9; slot++) {
            ItemStack item = d.getInventory().getItem(slot);

            if (item != null) {
                insertFuel(menu, d.getInventory(), slot, menu.getItemInSlot(43), item);
            }
        }
    }
}
 
Example 13
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSymmetry() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    MultiBlock multiblock = new MultiBlock(item, new Material[] { null, null, null, Material.DIAMOND_BLOCK, null, Material.DIAMOND_BLOCK, null, Material.DISPENSER, null }, BlockFace.DOWN);
    Assertions.assertTrue(multiblock.isSymmetric());

    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.EMERALD_BLOCK, null, null, Material.EMERALD_BLOCK, null, Material.DIAMOND_BLOCK, Material.EMERALD_BLOCK, Material.DISPENSER, null }, BlockFace.DOWN);
    Assertions.assertFalse(multiblock2.isSymmetric());
}
 
Example 14
Source File: OreCrusher.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public OreCrusher(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.IRON_BARS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.IRON_BARS) }, new ItemStack[] { new ItemStack(Material.COBBLESTONE, 8), new ItemStack(Material.SAND, 1), SlimefunItems.GOLD_4K, SlimefunItems.GOLD_DUST, new ItemStack(Material.GRAVEL), new ItemStack(Material.SAND), new ItemStack(Material.MAGMA_BLOCK, 4), SlimefunItems.SULFATE }, BlockFace.SELF);

    addItemSetting(doubleOres);
}
 
Example 15
Source File: DispenserTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlace(ParticipantBlockTransformEvent event) {
  if (event.getNewState().getMaterial() == Material.DISPENSER) {
    blocks().trackBlockState(event.getNewState(), new DispenserInfo(event.getPlayerState()));
  }
}
 
Example 16
Source File: EnhancedCraftingTable.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public EnhancedCraftingTable(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null }, new ItemStack[0], BlockFace.SELF);
}
 
Example 17
Source File: OreWasher.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public OreWasher(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, new ItemStack(Material.DISPENSER), null, null, new ItemStack(Material.OAK_FENCE), null, null, new ItemStack(Material.CAULDRON), null }, new ItemStack[0], BlockFace.SELF);

    legacyMode = SlimefunPlugin.getCfg().getBoolean("options.legacy-ore-washer");
    dusts = new ItemStack[] { SlimefunItems.IRON_DUST, SlimefunItems.GOLD_DUST, SlimefunItems.COPPER_DUST, SlimefunItems.TIN_DUST, SlimefunItems.ZINC_DUST, SlimefunItems.ALUMINUM_DUST, SlimefunItems.MAGNESIUM_DUST, SlimefunItems.LEAD_DUST, SlimefunItems.SILVER_DUST };
}
 
Example 18
Source File: Smeltery.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public Smeltery(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.NETHER_BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.NETHER_BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, new ItemStack[] { SlimefunItems.IRON_DUST, new ItemStack(Material.IRON_INGOT) }, BlockFace.DOWN);

    addItemSetting(fireBreakingChance);
}
 
Example 19
Source File: Dispenser.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Dispenser() {
    super(Material.DISPENSER);
}
 
Example 20
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	ItemStack norm = null;
	if (event.getHand() == EquipmentSlot.HAND) {
		norm = player.getInventory().getItemInMainHand();
	} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
		norm = player.getInventory().getItemInOffHand();
	}

	if (norm == null) return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR) {
		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
		}
	} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		Block block = event.getClickedBlock();

		if (block == null) {
			return;
		}
		if (!player.isSneaking()) {
			Material type = block.getType();

			if (type == Material.ANVIL || type == Material.CRAFTING_TABLE
					|| type == Material.CHEST || type == Material.ENDER_CHEST
					|| type == Material.DROPPER || type == Material.HOPPER
					|| type == Material.DISPENSER || type == Material.TRAPPED_CHEST
					|| type == Material.FURNACE || type == Material.ENCHANTING_TABLE) {

				return;
			}
		}

		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
			return;
		}

		if (block.getType() == Material.getMaterial(MineTinker.getPlugin().getConfig().getString("BlockToEnchantModifiers", Material.BOOKSHELF.name()))) {
			ItemStack item = player.getInventory().getItemInMainHand();

			for (Modifier m : modManager.getAllMods()) {
				if (m.getModItem().getType().equals(item.getType())) {
					if (!m.isEnchantable()) continue;
					m.enchantItem(player);
					event.setCancelled(true);
					break;
				}
			}
		}
	}
}