Java Code Examples for org.bukkit.Material#DIRT

The following examples show how to use org.bukkit.Material#DIRT . 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: GrassSeeds.java    From ExoticGarden with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
	return e -> {
		if (e.getClickedBlock().isPresent()) {
			Block b = e.getClickedBlock().get();
			
			if (b.getType() == Material.DIRT) {
				if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
					ItemUtils.consumeItem(e.getItem(), false);
				}
				
				b.setType(Material.GRASS_BLOCK);
				
				if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
					b.getRelative(BlockFace.UP).setType(Material.GRASS);
				}
				
				b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.GRASS);
			}
		}
	};
}
 
Example 2
Source File: GrindStone.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public GrindStone(Category category, SlimefunItemStack item) {
       super(category, item, 
			new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
			new ItemStack[] {
					new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4), 
					new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4), 
					new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT), 
					new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2), 
					new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL), 
					new ItemStack(Material.ANDESITE), new ItemStack(Material.GRAVEL),
					new ItemStack(Material.DIORITE), new ItemStack(Material.GRAVEL),
					new ItemStack(Material.GRANITE), new ItemStack(Material.GRAVEL),
					new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK, 
					new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4), 
					new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4),
					new ItemStack(Material.PRISMARINE_BRICKS), new ItemStack(Material.PRISMARINE, 2),
					new ItemStack(Material.PRISMARINE), new ItemStack(Material.PRISMARINE_SHARD, 4)
			},
			BlockFace.SELF
	);
}
 
Example 3
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFurnaceOutput() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);

    NamespacedKey key = new NamespacedKey(plugin, "furnace_recipe_test2");
    ItemStack result = new ItemStack(Material.GOLD_BLOCK);
    MaterialChoice materials = new MaterialChoice(Material.DIRT, Material.COBBLESTONE);
    FurnaceRecipe recipe = new FurnaceRecipe(key, result, materials, 1, 2);
    server.addRecipe(recipe);

    // The Snapshot has not been taken, so it should fallback to an empty Optional
    Assertions.assertFalse(service.getFurnaceOutput(new ItemStack(Material.DIRT)).isPresent());

    service.refresh();

    Assertions.assertFalse(service.getFurnaceOutput(null).isPresent());
    Assertions.assertFalse(service.getFurnaceOutput(new ItemStack(Material.BEDROCK)).isPresent());

    Optional<ItemStack> optional = service.getFurnaceOutput(new ItemStack(Material.DIRT));
    Assertions.assertTrue(optional.isPresent());
    Assertions.assertEquals(result, optional.get());

    Optional<ItemStack> optional2 = service.getFurnaceOutput(new ItemStack(Material.COBBLESTONE));
    Assertions.assertTrue(optional2.isPresent());
    Assertions.assertEquals(result, optional2.get());
}
 
Example 4
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Material getTrampledType(Material newType) {
  switch (newType) {
    case SOIL:
      return Material.DIRT;
    default:
      return null;
  }
}
 
Example 5
Source File: Ammo.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onRMB(Player e, ItemStack usedItem) {
	QAMain.DEBUG("The item being click is ammo!");
	Block b = e.getTargetBlock(null,6);
	if (usedItem.getType() == Material.DIAMOND_HOE
			&& (b.getType() == Material.DIRT
					||b.getType() == Material.GRASS
					|| b.getType() == Material.GRASS_PATH
					|| b.getType() == MultiVersionLookup.getMycil()))
		return true;
	return false;
}
 
Example 6
Source File: PlayerInteract.java    From AdditionsAPI with MIT License 5 votes vote down vote up
public static boolean shouldPlaySound(Material material, ItemStack item, byte data, Player player) {
	if ((material == Material.GRASS || (material == Material.DIRT && data != (byte) 2))) {
		if (!AdditionsAPI.isCustomItem(item))
			return true;
		CustomItemStack cStack = new CustomItemStack(item);
		ItemPermissions perm = cStack.getCustomItem().getPermissions();
		if (cStack.getCustomItem().hasHoeAbilities() && perm instanceof HoePermissions
				&& PermissionUtils.allowedAction(player, perm.getType(), ((HoePermissions) perm).getHoe()))
			return true;
	}
	return false;
}
 
Example 7
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle blocks that need special treatment
 * Tilling of coarse dirt into dirt using off-hand (regular hand is in 1.8)
 * Usually prevented because it could lead to an endless supply of dirt with gravel
 * 
 * @param e - event
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractEvent e) {
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) {
        return;
    }
    // Prevents tilling of coarse dirt into dirt
    ItemStack inHand = e.getPlayer().getInventory().getItemInOffHand();
    if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE
            || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) {
        // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand");
        Block block = e.getClickedBlock();
        // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() +
        // ":" + block.getData());
        // Check if coarse dirt
        if (block.getType() == Material.DIRT && block.getData() == (byte) 1) {
            // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!");
            e.setCancelled(true);
        }
    }
}
 
Example 8
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle V1.8 blocks that need special treatment
 * Tilling of coarse dirt into dirt
 * Usually prevented because it could lead to an endless supply of dirt with gravel
 *
 * @param e - event
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + e.getEventName());
    }
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) {
        return;
    }
    // Prevents tilling of coarse dirt into dirt
    ItemStack inHand = e.getPlayer().getItemInHand();
    if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE
            || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) {
        // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand");
        Block block = e.getClickedBlock();
        // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() +
        // ":" + block.getData());
        // Check if coarse dirt
        if (block.getType() == Material.DIRT && block.getData() == (byte) 1) {
            // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!");
            e.setCancelled(true);
        }
    }
}
 
Example 9
Source File: TreePopulator.java    From GiantTrees with GNU General Public License v3.0 5 votes vote down vote up
int getHighestSoil(Block highestBlock) {
  while ((highestBlock.getY() > 0)
         && (highestBlock.getType() != Material.DIRT)
         && // Includes podzol
         (highestBlock.getType() != Material.GRASS)
         && (highestBlock.getType() != Material.MYCELIUM)
         && (highestBlock.getType() != Material.SAND)) {
    highestBlock = highestBlock.getRelative(BlockFace.DOWN);
  }
  return highestBlock.getY();
}
 
Example 10
Source File: CreateTreeCommand.java    From GiantTrees with GNU General Public License v3.0 5 votes vote down vote up
Block getHighestSoil(Block highestBlock) {
  while ((highestBlock.getY() > 0)
         && (highestBlock.getType() != Material.DIRT)
         && // Includes podzol
         (highestBlock.getType() != Material.GRASS)
         && (highestBlock.getType() != Material.MYCELIUM)
         && (highestBlock.getType() != Material.SAND)) {
    highestBlock = highestBlock.getRelative(BlockFace.DOWN);
  }
  return highestBlock;
}
 
Example 11
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHoeUse(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)) {
		return;
	}

	ItemStack tool = player.getInventory().getItemInMainHand();

	if (!ToolType.HOE.contains(tool.getType())) {
		return;
	}

	if (!modManager.isToolViable(tool)) {
		return;
	}

	Block block = event.getClickedBlock();

	boolean apply = false;

	if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block != null) {
		if (block.getType() == Material.GRASS_BLOCK || block.getType() == Material.DIRT)
			apply = true;

		Block b = player.getWorld().getBlockAt(block.getLocation().add(0, 1, 0));
		if (b.getType() != Material.AIR && b.getType() != Material.CAVE_AIR) //Case Block is on top of clicked Block -> No Soil Tilt -> no Exp
			apply = false;
	}

	if (!apply) {
		return;
	}

	if (!modManager.durabilityCheck(event, player, tool)) {
		return;
	}

	modManager.addExp(player, tool, MineTinker.getPlugin().getConfig().getInt("ExpPerBlockBreak"));

	MTPlayerInteractEvent interactEvent = new MTPlayerInteractEvent(tool, event);
	Bukkit.getPluginManager().callEvent(interactEvent);
}
 
Example 12
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private static Material getTrampledType(Material newType) {
    switch(newType) {
    case SOIL: return Material.DIRT;
    default: return null;
    }
}
 
Example 13
Source File: QMenuCategory.java    From Quests with MIT License 4 votes vote down vote up
public Inventory toInventory(int page) {
    int pageMin = pageSize * (page - 1);
    int pageMax = pageSize * page;
    String title = Options.color(Options.GUITITLE_QUESTS_CATEGORY.getStringValue());

    ItemStack pageIs = new ItemStack(Material.DIRT);

    Inventory inventory = Bukkit.createInventory(null, 54, title);

    for (int pointer = pageMin; pointer < pageMax; pointer++) {
        if (slotsToMenuQuest.containsKey(pointer)) {
            Category category = Quests.get().getQuestManager().getCategoryById(slotsToMenuQuest.get(pointer).getCategoryName());
            if (category != null) {
                inventory.setItem(pointer, category.getDisplayItem());
            }
        }
    }

    inventory.setItem(49, pageIs);

    if (Options.TRIM_GUI_SIZE.getBooleanValue() && page == 1) {
        int slotsUsed = 0;
        for (int pointer = 0; pointer < pageMax; pointer++) {
            if (inventory.getItem(pointer) != null) {
                slotsUsed++;
            }
        }

        int inventorySize = (slotsUsed >= 54) ? 54 : slotsUsed + (9 - slotsUsed % 9) * Math.min(1, slotsUsed % 9);
        inventorySize = inventorySize <= 0 ? 9 : inventorySize;
        if (inventorySize == 54) {
            return inventory;
        }

        Inventory trimmedInventory = Bukkit.createInventory(null, inventorySize, title);

        for (int slot = 0; slot < pageMax; slot++) {
            if (slot >= trimmedInventory.getSize()){
                break;
            }
            trimmedInventory.setItem(slot, inventory.getItem(slot));
        }
        return trimmedInventory;
    } else {
        return inventory;
    }

}