From cd5df82d72bc417abfc8be765b77ee05ba403f39 Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Fri, 28 Dec 2012 20:47:39 -0800 Subject: [PATCH 1/2] Fixing more NPEs with custom blocks. --- src/main/java/com/gmail/nossr50/skills/gathering/Mining.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java index db51cfd9b..0f37a542f 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java @@ -219,7 +219,7 @@ public class Mining { break; default: - if (ModChecks.isCustomMiningBlock(block)) { + if (ModChecks.isCustomMiningBlock(block) && ModChecks.getCustomBlock(block) != null) { CustomBlock customBlock = ModChecks.getCustomBlock(block); int minimumDropAmount = customBlock.getMinimumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount(); @@ -365,7 +365,7 @@ public class Mining { int durabilityLoss = Config.getInstance().getAbilityToolDamage(); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); - if (ModChecks.isCustomMiningBlock(block)) { + if (ModChecks.isCustomMiningBlock(block) && ModChecks.getCustomBlock(block) != null) { if (ModChecks.getCustomBlock(block).getTier() < tier) { return; } From cafed2d98c46edb64d25114747a94c359f72c381 Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Fri, 28 Dec 2012 21:11:22 -0800 Subject: [PATCH 2/2] Fixing remaining NPEs with custom blocks using vanilla IDs. --- .../nossr50/skills/gathering/Mining.java | 6 +-- .../com/gmail/nossr50/util/ModChecks.java | 44 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java index 0f37a542f..2fe813fdb 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java @@ -219,7 +219,7 @@ public class Mining { break; default: - if (ModChecks.isCustomMiningBlock(block) && ModChecks.getCustomBlock(block) != null) { + if (ModChecks.isCustomMiningBlock(block)) { CustomBlock customBlock = ModChecks.getCustomBlock(block); int minimumDropAmount = customBlock.getMinimumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount(); @@ -308,7 +308,7 @@ public class Mining { break; default: - if (ModChecks.isCustomMiningBlock(block) && ModChecks.getCustomBlock(block) != null) { + if (ModChecks.isCustomMiningBlock(block)) { xp += ModChecks.getCustomBlock(block).getXpGain(); } break; @@ -365,7 +365,7 @@ public class Mining { int durabilityLoss = Config.getInstance().getAbilityToolDamage(); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); - if (ModChecks.isCustomMiningBlock(block) && ModChecks.getCustomBlock(block) != null) { + if (ModChecks.isCustomMiningBlock(block)) { if (ModChecks.getCustomBlock(block).getTier() < tier) { return; } diff --git a/src/main/java/com/gmail/nossr50/util/ModChecks.java b/src/main/java/com/gmail/nossr50/util/ModChecks.java index f69a77d65..4c27facd4 100644 --- a/src/main/java/com/gmail/nossr50/util/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ModChecks.java @@ -76,11 +76,14 @@ public class ModChecks { item.setData(new MaterialData(block.getTypeId(), block.getData())); if (customBlocksEnabled && blocksInstance.customMiningBlocks.contains(item)) { - return true; - } - else { - return false; + for (CustomBlock b : blocksInstance.customBlocks) { + if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { + return true; + } + } } + + return false; } /** @@ -94,11 +97,14 @@ public class ModChecks { item.setData(new MaterialData(block.getTypeId(), block.getData())); if (blocksInstance.customLeaves.contains(item)) { - return true; - } - else { - return false; + for (CustomBlock b : blocksInstance.customBlocks) { + if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { + return true; + } + } } + + return false; } /** @@ -112,11 +118,14 @@ public class ModChecks { item.setData(new MaterialData(block.getTypeId(), block.getData())); if (blocksInstance.customLogs.contains(item)) { - return true; - } - else { - return false; + for (CustomBlock b : blocksInstance.customBlocks) { + if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { + return true; + } + } } + + return false; } /** @@ -130,11 +139,14 @@ public class ModChecks { item.setData(new MaterialData(block.getTypeId(), block.getData())); if (blocksInstance.customOres.contains(item)) { - return true; - } - else { - return false; + for (CustomBlock b : blocksInstance.customBlocks) { + if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { + return true; + } + } } + + return false; } /**