From 8d7f1cb5953f56df85a537bde4bb7c5f5300fd3b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 19 Mar 2020 19:00:50 -0700 Subject: [PATCH] Fixed not being able to place blocks on top of certain repair/salvage anvils --- Changelog.txt | 5 ++++ .../nossr50/listeners/PlayerListener.java | 27 +++++++++++-------- .../com/gmail/nossr50/util/BlockUtils.java | 4 ++- .../gmail/nossr50/util/MaterialMapStore.java | 5 ---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 06be45728..3216b6b51 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,8 @@ +Version 2.1.125 + *Fixed a bug where you could not place blocks on top of certain repair/salvage anvils + + Notes: You won't be able to place blocks on top of stuff that has an interactable component if its setup as an anvil for either Repair or Salvage, for example if you set the vanilla minecraft anvil to Repair, you won't be able to place blocks on top of that. If the repair anvil is still set to iron block then you can now place blocks on it again. + Version 2.1.124 Repair/Salvage can now be set to use vanilla blocks that already do something and that vanilla functionality will be disabled by mcMMO (you could use vanilla-anvils instead of iron_blocks for repair now) Added Gold_Nugget to Mining's Bonus_Drops in config.yml (edit your config) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index a026bf790..ff0047f4f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -597,17 +597,23 @@ public class PlayerListener implements Listener { return; } - //Cancel the event to prevent vanilla functionality - if(event.getClickedBlock() != null) { - if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { - if(event.getClickedBlock().getType() == Repair.anvilMaterial || event.getClickedBlock().getType() == Salvage.anvilMaterial) { - if(event.useInteractedBlock() == Event.Result.ALLOW) { + Block clickedBlock = event.getClickedBlock(); + if(clickedBlock != null) { + Material clickedBlockType = clickedBlock.getType(); + //The blacklist contains interactable blocks so its a convenient filter + if(clickedBlockType == Repair.anvilMaterial || clickedBlockType == Salvage.anvilMaterial) { + Bukkit.broadcastMessage("Debug"); + event.setUseItemInHand(Event.Result.ALLOW); + + if(mcMMO.getMaterialMapStore().isToolActivationBlackListed(clickedBlockType)) { + Bukkit.broadcastMessage("Derp 2"); event.setUseInteractedBlock(Event.Result.DENY); - } } } - } + //Cancel the event to prevent vanilla functionality + //Only cancel if item in hand has durability + } if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) { return; @@ -621,12 +627,11 @@ public class PlayerListener implements Listener { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); MiningManager miningManager = mcMMOPlayer.getMiningManager(); - Block block = event.getClickedBlock(); ItemStack heldItem = player.getInventory().getItemInMainHand(); switch (event.getAction()) { case RIGHT_CLICK_BLOCK: - Material type = block.getType(); + Material type = clickedBlock.getType(); if (!Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { /* REPAIR CHECKS */ @@ -655,7 +660,7 @@ public class PlayerListener implements Listener { // Make sure the player knows what he's doing when trying to salvage an enchanted item if (salvageManager.checkConfirmation(true)) { SkillUtils.handleAbilitySpeedDecrease(player); - salvageManager.handleSalvage(block.getLocation(), heldItem); + salvageManager.handleSalvage(clickedBlock.getLocation(), heldItem); player.updateInventory(); } } @@ -674,7 +679,7 @@ public class PlayerListener implements Listener { break; case LEFT_CLICK_BLOCK: - type = block.getType(); + type = clickedBlock.getType(); if (!Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() || player.isSneaking()) { /* REPAIR CHECKS */ diff --git a/src/main/java/com/gmail/nossr50/util/BlockUtils.java b/src/main/java/com/gmail/nossr50/util/BlockUtils.java index 2d6b47343..ef6b3df76 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockUtils.java +++ b/src/main/java/com/gmail/nossr50/util/BlockUtils.java @@ -89,7 +89,9 @@ public final class BlockUtils { * otherwise */ public static boolean canActivateTools(BlockState blockState) { - return !mcMMO.getMaterialMapStore().isToolActivationBlackListed(blockState.getType()); + return !mcMMO.getMaterialMapStore().isToolActivationBlackListed(blockState.getType()) + && blockState.getType() != Repair.anvilMaterial + && blockState.getType() != Salvage.anvilMaterial; } /** diff --git a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java index 659dd716e..ef5e6891d 100644 --- a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java +++ b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java @@ -939,14 +939,11 @@ public class MaterialMapStore { abilityBlackList.add("smoker"); abilityBlackList.add("stonecutter"); abilityBlackList.add("sweet_berry_bush"); - abilityBlackList.add("iron_block"); - abilityBlackList.add("gold_block"); abilityBlackList.add("bell"); abilityBlackList.add("barrel"); abilityBlackList.add("blast_furnace"); abilityBlackList.add("campfire"); abilityBlackList.add("composter"); - } private void fillToolBlackList() @@ -1072,8 +1069,6 @@ public class MaterialMapStore { toolBlackList.add("oak_log"); toolBlackList.add("oak_wood"); toolBlackList.add("spruce_log"); - toolBlackList.add("iron_block"); - toolBlackList.add("gold_block"); toolBlackList.add("bell"); toolBlackList.add("barrel"); toolBlackList.add("blast_furnace");