mcMMO/src/main/java/com/gmail/nossr50/skills/mining/Mining.java

184 lines
6.1 KiB
Java
Raw Normal View History

2013-01-01 22:01:51 +01:00
package com.gmail.nossr50.skills.mining;
2012-01-09 20:00:13 +01:00
2012-03-13 08:31:07 +01:00
import org.bukkit.CoalType;
2013-01-08 17:31:07 +01:00
import org.bukkit.DyeColor;
2012-01-09 20:00:13 +01:00
import org.bukkit.Location;
import org.bukkit.Material;
2012-01-09 20:00:13 +01:00
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
2012-11-21 21:49:54 +01:00
import com.gmail.nossr50.config.AdvancedConfig;
2012-06-05 16:13:10 +02:00
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
2013-01-30 17:35:33 +01:00
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.SkillType;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.util.Misc;
2012-01-09 20:00:13 +01:00
2012-03-26 17:04:17 +02:00
public class Mining {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
2013-01-07 18:51:39 +01:00
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
2013-01-08 18:52:16 +01:00
public static final int DIAMOND_TOOL_TIER = 4;
public static final int IRON_TOOL_TIER = 3;
public static final int STONE_TOOL_TIER = 2;
2013-01-07 18:51:39 +01:00
/**
* Award XP for Mining blocks.
*
* @param mcMMOPlayer The player to award XP to
2013-01-07 18:51:39 +01:00
* @param block The block to award XP for
*/
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
int xp = Config.getInstance().getXp(SkillType.MINING, type);
2013-01-07 18:51:39 +01:00
if (type == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
}
else if (xp == 0 && ModChecks.isCustomMiningBlock(block)) {
xp = ModChecks.getCustomBlock(block).getXpGain();
2013-01-07 18:51:39 +01:00
}
mcMMOPlayer.beginXpGain(SkillType.MINING, xp);
2013-01-07 18:51:39 +01:00
}
2012-05-18 17:15:30 +02:00
/**
* Handle double drops when using Silk Touch.
*
* @param block The block to process drops for
* @param location The location of the block
* @param type The material type of the block
2012-05-18 17:15:30 +02:00
*/
protected static void silkTouchDrops(Block block, Location location, Material type) {
2012-05-18 17:15:30 +02:00
ItemStack item = new ItemStack(type);
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) {
return;
}
2012-05-18 17:15:30 +02:00
switch (type) {
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
miningDrops(block, location, type);
2012-05-18 17:15:30 +02:00
break;
case GLOWING_REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
2012-05-18 17:15:30 +02:00
}
break;
case COAL_ORE:
2012-05-18 17:15:30 +02:00
case DIAMOND_ORE:
case REDSTONE_ORE:
case GLOWSTONE:
case LAPIS_ORE:
case STONE:
case EMERALD_ORE:
Misc.dropItem(location, item);
break;
2012-05-18 17:15:30 +02:00
default:
if (ModChecks.isCustomMiningBlock(block)) {
ItemStack dropItem = new ItemStack(block.getTypeId(), 1, block.getData());
2012-12-25 07:01:10 +01:00
Misc.dropItem(location, dropItem);
2012-05-18 17:15:30 +02:00
}
break;
}
}
2012-03-13 08:31:07 +01:00
/**
* Drop items from Mining & Blast Mining skills.
*
* @param block The block to process drops for
* @param location The location of the block
* @param type The material type of the block
2012-03-13 08:31:07 +01:00
*/
protected static void miningDrops(Block block, Location location, Material type) {
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) {
return;
}
ItemStack item = new ItemStack(type);
2012-03-13 08:31:07 +01:00
switch (type) {
case COAL_ORE:
item = new ItemStack(Material.COAL, 1, CoalType.COAL.getData());
Misc.dropItem(location, item);
2012-03-13 08:31:07 +01:00
break;
case DIAMOND_ORE:
item = new ItemStack(Material.DIAMOND);
Misc.dropItem(location, item);
break;
case EMERALD_ORE:
item = new ItemStack(Material.EMERALD);
Misc.dropItem(location, item);
2012-03-13 08:31:07 +01:00
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
item = new ItemStack(Material.REDSTONE);
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, 4);
Misc.randomDropItem(location, item, 50);
}
2012-03-13 08:31:07 +01:00
break;
case GLOWSTONE:
item = new ItemStack(Material.GLOWSTONE_DUST);
Misc.dropItems(location, item, 2);
Misc.randomDropItems(location, item, 2);
2012-03-13 08:31:07 +01:00
break;
case LAPIS_ORE:
item = new ItemStack(Material.INK_SACK, 1, DyeColor.BLUE.getDyeData());
Misc.dropItems(location, item, 4);
Misc.randomDropItems(location, item, 4);
break;
case STONE:
item = new ItemStack(Material.COBBLESTONE);
Misc.dropItem(location, item);
break;
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
Misc.dropItem(location, item);
break;
2012-03-13 08:31:07 +01:00
default:
if (ModChecks.isCustomMiningBlock(block)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
item = ModChecks.getCustomBlock(block).getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, minimumDropAmount);
2013-02-17 07:26:47 +01:00
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
else {
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, minimumDropAmount);
}
}
2012-03-13 08:31:07 +01:00
break;
}
2012-01-09 20:00:13 +01:00
}
}