Pass location & type as params, rather than calling inside the function.

This commit is contained in:
gmcferrin 2013-01-08 09:35:41 -05:00
parent 57ff84cd4d
commit 159ec3f04d
4 changed files with 30 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -57,15 +58,17 @@ public class BlastMining {
while (oresIterator.hasNext()) {
Block temp = oresIterator.next();
Location tempLocation = temp.getLocation();
Material tempType = temp.getType();
if (random.nextFloat() < (yield + oreBonus)) {
blocksDropped.add(temp);
Mining.miningDrops(temp);
Mining.miningDrops(temp, tempLocation, tempType);
if (!mcMMO.placeStore.isTrue(temp)) {
for (int i = 1 ; i < extraDrops ; i++) {
blocksDropped.add(temp);
Mining.miningDrops(temp);
Mining.miningDrops(temp, tempLocation, tempType);
}
}
}
@ -76,9 +79,11 @@ public class BlastMining {
while (debrisIterator.hasNext()) {
Block temp = debrisIterator.next();
Location tempLocation = temp.getLocation();
Material tempType = temp.getType();
if (random.nextFloat() < (yield - debrisReduction))
Mining.miningDrops(temp);
Mining.miningDrops(temp, tempLocation, tempType);
}
}

View File

@ -201,10 +201,10 @@ public class Mining {
* 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
*/
protected static void silkTouchDrops(Block block) {
Location location = block.getLocation();
Material type = block.getType();
protected static void silkTouchDrops(Block block, Location location, Material type) {
ItemStack item = new ItemStack(type);
switch (type) {
@ -215,7 +215,7 @@ public class Mining {
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
miningDrops(block);
miningDrops(block, location, type);
break;
case COAL_ORE:
@ -276,10 +276,10 @@ public class Mining {
* 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
*/
protected static void miningDrops(Block block) {
Location location = block.getLocation();
Material type = block.getType();
protected static void miningDrops(Block block, Location location, Material type) {
ItemStack item = new ItemStack(type);
switch (type) {

View File

@ -1,19 +1,27 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import com.gmail.nossr50.util.Misc;
public class MiningDropsBlockHandler {
public class MiningBlockEventHandler {
private MiningManager manager;
private Block block;
private Location blockLocation;
private Material blockType;
protected int skillModifier;
protected MiningDropsBlockHandler(MiningManager manager, Block block) {
protected MiningBlockEventHandler(MiningManager manager, Block block) {
this.manager = manager;
this.block = block;
this.blockLocation = block.getLocation();
this.blockType = block.getType();
calculateSkillModifier();
}
@ -30,10 +38,10 @@ public class MiningDropsBlockHandler {
*/
protected void processDrops() {
if (manager.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Mining.silkTouchDrops(block);
Mining.silkTouchDrops(block, blockLocation, blockType);
}
else {
Mining.miningDrops(block);
Mining.miningDrops(block, blockLocation, blockType);
}
}
}

View File

@ -38,17 +38,17 @@ public class MiningManager {
return;
}
MiningDropsBlockHandler blockHandler = new MiningDropsBlockHandler(this, block);
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
int randomChance = 100;
if (Permissions.luckyMining(player)) {
randomChance = (int) (randomChance * 0.75);
}
float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * blockHandler.skillModifier);
float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier);
if (chance > Mining.getRandom().nextInt(randomChance)) {
blockHandler.processDrops();
eventHandler.processDrops();
}
}