mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-31 14:49:35 +01:00
*CLEANUP* - Mining.java
This commit is contained in:
parent
2c417d28c5
commit
a3da6b7df5
@ -41,7 +41,7 @@ public class Herbalism {
|
||||
|
||||
if (m.blockBreakSimulate(block, player, false)) {
|
||||
if (LoadProperties.enableSmoothToMossy && type.equals(Material.SMOOTH_BRICK)) {
|
||||
block.setData((byte) 0x1);
|
||||
block.setData((byte) 0x1); //Set type of the brick to mossy
|
||||
}
|
||||
else if (LoadProperties.enableDirtToGrass && type.equals(Material.DIRT)) {
|
||||
block.setType(Material.GRASS);
|
||||
@ -108,6 +108,8 @@ public class Herbalism {
|
||||
*/
|
||||
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
||||
final PlayerProfile PP = Users.getProfile(player);
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
||||
int id = block.getTypeId();
|
||||
Material type = block.getType();
|
||||
@ -134,7 +136,7 @@ public class Herbalism {
|
||||
if (b.getType().equals(Material.CACTUS)) {
|
||||
mat = Material.CACTUS;
|
||||
if (!plugin.misc.blockWatchList.contains(b)) {
|
||||
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel)) {
|
||||
if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
|
||||
catciDrops++;
|
||||
}
|
||||
xp += LoadProperties.mcactus;
|
||||
@ -187,7 +189,7 @@ public class Herbalism {
|
||||
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
|
||||
mat = Material.SUGAR_CANE;
|
||||
if (!plugin.misc.blockWatchList.contains(b)) {
|
||||
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel)) {
|
||||
if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
|
||||
caneDrops++;
|
||||
}
|
||||
xp += LoadProperties.msugar;
|
||||
@ -220,7 +222,7 @@ public class Herbalism {
|
||||
else {
|
||||
ItemStack is = new ItemStack(mat);
|
||||
|
||||
if (herbLevel > 1000 || (Math.random() * 1000 <= herbLevel)) {
|
||||
if (herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
|
||||
if (type.equals(Material.CACTUS)) {
|
||||
m.mcDropItems(loc, is, catciDrops);
|
||||
}
|
||||
@ -254,13 +256,15 @@ public class Herbalism {
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
||||
final int MAX_BONUS_LEVEL = 1500;
|
||||
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean hasSeeds = inventory.contains(Material.SEEDS);
|
||||
Location loc = block.getLocation();
|
||||
|
||||
if (hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel >= 1500 || (Math.random() * 1500 <= herbLevel))) {
|
||||
if (hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1500 <= herbLevel))) {
|
||||
event.setCancelled(true);
|
||||
|
||||
m.mcDropItem(loc, new ItemStack(Material.WHEAT, 1));
|
||||
@ -281,13 +285,15 @@ public class Herbalism {
|
||||
* @param block The block being used in the ability
|
||||
*/
|
||||
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
|
||||
final int MAX_BONUS_LEVEL = 1500;
|
||||
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
int skillLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
||||
int seeds = is.getAmount();
|
||||
|
||||
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
||||
|
||||
if (skillLevel > 1500 || Math.random() * 1500 <= skillLevel) {
|
||||
if (skillLevel > MAX_BONUS_LEVEL || Math.random() * 1500 <= skillLevel) {
|
||||
greenTerra(player, block);
|
||||
}
|
||||
else {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.gmail.nossr50.skills;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CoalType;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -22,193 +24,246 @@ import com.gmail.nossr50.datatypes.SkillType;
|
||||
public class Mining
|
||||
{
|
||||
|
||||
public static void miningDrops(Block block)
|
||||
{
|
||||
Location loc = block.getLocation();
|
||||
Material type = block.getType();
|
||||
ItemStack item = new ItemStack(type, 1);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case COAL_ORE:
|
||||
item = new ItemStack(Material.COAL, 1, (byte)0, (byte)0x0);
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
case DIAMOND_ORE:
|
||||
item = new ItemStack(Material.DIAMOND, 1);
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
item = new ItemStack(Material.REDSTONE, 1);
|
||||
m.mcDropItems(loc, item, 4);
|
||||
m.mcRandomDropItem(loc, item, 50);
|
||||
break;
|
||||
case GLOWSTONE:
|
||||
item = new ItemStack(Material.GLOWSTONE_DUST, 1);
|
||||
m.mcDropItems(loc, item, 2);
|
||||
m.mcRandomDropItems(loc, item, 50, 2);
|
||||
break;
|
||||
case LAPIS_ORE:
|
||||
item = new ItemStack(Material.INK_SACK, 1, (byte)0, (byte)0x4);
|
||||
m.mcDropItems(loc, item, 4);
|
||||
m.mcRandomDropItems(loc, item, 50, 4);
|
||||
break;
|
||||
case STONE:
|
||||
item = new ItemStack(Material.COBBLESTONE, 1);
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
default:
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void miningXP(Player player, Block block)
|
||||
{
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
Material type = block.getType();
|
||||
int xp = 0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case COAL_ORE:
|
||||
xp += LoadProperties.mcoal;
|
||||
break;
|
||||
case DIAMOND_ORE:
|
||||
xp += LoadProperties.mdiamond;
|
||||
break;
|
||||
case ENDER_STONE:
|
||||
xp += LoadProperties.mendstone;
|
||||
break;
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
xp += LoadProperties.mredstone;
|
||||
break;
|
||||
case GLOWSTONE:
|
||||
xp += LoadProperties.mglowstone;
|
||||
break;
|
||||
case GOLD_ORE:
|
||||
xp += LoadProperties.mgold;
|
||||
break;
|
||||
case IRON_ORE:
|
||||
xp += LoadProperties.miron;
|
||||
break;
|
||||
case LAPIS_ORE:
|
||||
xp += LoadProperties.mlapis;
|
||||
break;
|
||||
case MOSSY_COBBLESTONE:
|
||||
xp += LoadProperties.mmossstone;
|
||||
break;
|
||||
case NETHERRACK:
|
||||
xp += LoadProperties.mnetherrack;
|
||||
break;
|
||||
case OBSIDIAN:
|
||||
xp += LoadProperties.mobsidian;
|
||||
break;
|
||||
case SANDSTONE:
|
||||
xp += LoadProperties.msandstone;
|
||||
break;
|
||||
case STONE:
|
||||
xp += LoadProperties.mstone;
|
||||
break;
|
||||
}
|
||||
|
||||
PP.addXP(SkillType.MINING, xp, player);
|
||||
Skills.XpCheckSkill(SkillType.MINING, player);
|
||||
}
|
||||
|
||||
public static void blockProcSimulate(Block block, Player player)
|
||||
{
|
||||
//Drop natural block with Silk Touch
|
||||
if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH))
|
||||
m.mcDropItem(block.getLocation(), new ItemStack(block.getType(), 1));
|
||||
else
|
||||
miningDrops(block);
|
||||
}
|
||||
|
||||
public static void blockProcCheck(Block block, Player player)
|
||||
{
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
|
||||
if(skillLevel > 1000 || (Math.random() * 1000 <= skillLevel))
|
||||
blockProcSimulate(block, player);
|
||||
}
|
||||
|
||||
public static void miningBlockCheck(Player player, Block block, mcMMO plugin)
|
||||
{
|
||||
if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5)
|
||||
return;
|
||||
miningXP(player, block);
|
||||
if(canBeSuperBroken(block.getType()))
|
||||
blockProcCheck(block, player);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handling SuperBreaker stuff
|
||||
/**
|
||||
* Drop items from Mining & Blast Mining skills.
|
||||
*
|
||||
* @param block The block to process drops for
|
||||
*/
|
||||
public static Boolean canBeSuperBroken(Material type)
|
||||
{
|
||||
switch(type){
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
case ENDER_STONE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case GLOWSTONE:
|
||||
case GOLD_ORE:
|
||||
case IRON_ORE:
|
||||
case LAPIS_ORE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case OBSIDIAN:
|
||||
case REDSTONE_ORE:
|
||||
case SANDSTONE:
|
||||
case STONE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public static void miningDrops(Block block) {
|
||||
Location loc = block.getLocation();
|
||||
Material type = block.getType();
|
||||
ItemStack item = new ItemStack(type, 1);
|
||||
|
||||
switch (type) {
|
||||
case COAL_ORE:
|
||||
item = new ItemStack(Material.COAL, 1, (byte) 0x0, CoalType.COAL.getData());
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
item = new ItemStack(Material.DIAMOND, 1);
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
item = new ItemStack(Material.REDSTONE, 1);
|
||||
m.mcDropItems(loc, item, 4);
|
||||
m.mcRandomDropItem(loc, item, 50);
|
||||
break;
|
||||
|
||||
case GLOWSTONE:
|
||||
item = new ItemStack(Material.GLOWSTONE_DUST, 1);
|
||||
m.mcDropItems(loc, item, 2);
|
||||
m.mcRandomDropItems(loc, item, 50, 2);
|
||||
break;
|
||||
|
||||
case LAPIS_ORE:
|
||||
item = new ItemStack(Material.INK_SACK, 1, (byte) 0x0, DyeColor.BLUE.getData());
|
||||
m.mcDropItems(loc, item, 4);
|
||||
m.mcRandomDropItems(loc, item, 50, 4);
|
||||
break;
|
||||
|
||||
case STONE:
|
||||
item = new ItemStack(Material.COBBLESTONE, 1);
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
|
||||
default:
|
||||
m.mcDropItem(loc, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SuperBreakerBlockCheck(Player player, Block block, mcMMO plugin)
|
||||
{
|
||||
Material type = block.getType();
|
||||
int tier = m.getTier(player.getItemInHand());
|
||||
int durabilityLoss = LoadProperties.abilityDurabilityLoss;
|
||||
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case OBSIDIAN:
|
||||
if(tier < 4)
|
||||
return;
|
||||
durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
|
||||
case DIAMOND_ORE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case GOLD_ORE:
|
||||
case LAPIS_ORE:
|
||||
case REDSTONE_ORE:
|
||||
if(tier < 3)
|
||||
return;
|
||||
case IRON_ORE:
|
||||
if(tier < 2)
|
||||
return;
|
||||
case COAL_ORE:
|
||||
case ENDER_STONE:
|
||||
case GLOWSTONE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case SANDSTONE:
|
||||
case STONE:
|
||||
if((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block))
|
||||
return;
|
||||
Bukkit.getPluginManager().callEvent(armswing);
|
||||
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
|
||||
blockProcCheck(block, player);
|
||||
blockProcCheck(block, player);
|
||||
if(!plugin.misc.blockWatchList.contains(block) && block.getData() != (byte) 5)
|
||||
miningXP(player, block);
|
||||
if(LoadProperties.spoutEnabled)
|
||||
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Award XP for Mining blocks.
|
||||
*
|
||||
* @param player The player to award XP to
|
||||
* @param block The block to award XP for
|
||||
*/
|
||||
public static void miningXP(Player player, Block block) {
|
||||
PlayerProfile PP = Users.getProfile(player);
|
||||
Material type = block.getType();
|
||||
int xp = 0;
|
||||
|
||||
switch (type) {
|
||||
case COAL_ORE:
|
||||
xp += LoadProperties.mcoal;
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
xp += LoadProperties.mdiamond;
|
||||
break;
|
||||
|
||||
case ENDER_STONE:
|
||||
xp += LoadProperties.mendstone;
|
||||
break;
|
||||
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
xp += LoadProperties.mredstone;
|
||||
break;
|
||||
|
||||
case GLOWSTONE:
|
||||
xp += LoadProperties.mglowstone;
|
||||
break;
|
||||
|
||||
case GOLD_ORE:
|
||||
xp += LoadProperties.mgold;
|
||||
break;
|
||||
|
||||
case IRON_ORE:
|
||||
xp += LoadProperties.miron;
|
||||
break;
|
||||
|
||||
case LAPIS_ORE:
|
||||
xp += LoadProperties.mlapis;
|
||||
break;
|
||||
|
||||
case MOSSY_COBBLESTONE:
|
||||
xp += LoadProperties.mmossstone;
|
||||
break;
|
||||
|
||||
case NETHERRACK:
|
||||
xp += LoadProperties.mnetherrack;
|
||||
break;
|
||||
|
||||
case OBSIDIAN:
|
||||
xp += LoadProperties.mobsidian;
|
||||
break;
|
||||
|
||||
case SANDSTONE:
|
||||
xp += LoadProperties.msandstone;
|
||||
break;
|
||||
|
||||
case STONE:
|
||||
xp += LoadProperties.mstone;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PP.addXP(SkillType.MINING, xp, player);
|
||||
Skills.XpCheckSkill(SkillType.MINING, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Mining block drops.
|
||||
*
|
||||
* @param player The player mining the block
|
||||
* @param block The block being broken
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void miningBlockCheck(Player player, Block block, mcMMO plugin) {
|
||||
if (plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
miningXP(player, block);
|
||||
|
||||
if (canBeSuperBroken(block.getType())) {
|
||||
final int MAX_BONUS_LEVEL = 1000;
|
||||
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
|
||||
if (MAX_BONUS_LEVEL > 1000 || (Math.random() * 1000 <= skillLevel)) {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
m.mcDropItem(block.getLocation(), new ItemStack(block.getType(), 1));
|
||||
}
|
||||
else {
|
||||
miningDrops(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a block is broken by Super Breaker.
|
||||
*
|
||||
* @param type The type of Block to check
|
||||
* @return true if the block would be broken by Super Breaker, false otherwise
|
||||
*/
|
||||
public static Boolean canBeSuperBroken(Material type) {
|
||||
switch (type) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
case ENDER_STONE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case GLOWSTONE:
|
||||
case GOLD_ORE:
|
||||
case IRON_ORE:
|
||||
case LAPIS_ORE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case OBSIDIAN:
|
||||
case REDSTONE_ORE:
|
||||
case SANDSTONE:
|
||||
case STONE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Super Breaker ability.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param block The block being affected
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void SuperBreakerBlockCheck(Player player, Block block, mcMMO plugin) {
|
||||
Material type = block.getType();
|
||||
int tier = m.getTier(player.getItemInHand());
|
||||
int durabilityLoss = LoadProperties.abilityDurabilityLoss;
|
||||
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
|
||||
|
||||
switch (type) {
|
||||
case OBSIDIAN:
|
||||
if (tier < 4) {
|
||||
return;
|
||||
}
|
||||
durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
|
||||
/* FALL THROUGH */
|
||||
|
||||
case DIAMOND_ORE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case GOLD_ORE:
|
||||
case LAPIS_ORE:
|
||||
case REDSTONE_ORE:
|
||||
if (tier < 3) {
|
||||
return;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case IRON_ORE:
|
||||
if (tier < 2) {
|
||||
return;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case COAL_ORE:
|
||||
case ENDER_STONE:
|
||||
case GLOWSTONE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case SANDSTONE:
|
||||
case STONE:
|
||||
if ((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(armswing);
|
||||
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
|
||||
|
||||
miningBlockCheck(player, block, plugin);
|
||||
miningBlockCheck(player, block, plugin);
|
||||
|
||||
if (LoadProperties.spoutEnabled) {
|
||||
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user