From 123a139e43fc9203aa4f7c9d16527091cee5bb00 Mon Sep 17 00:00:00 2001 From: Sid Shakal Date: Wed, 16 Mar 2016 11:47:40 -0500 Subject: [PATCH 1/5] Moving the center of block drops to block center. Fixes #2544. --- .../com/gmail/nossr50/listeners/PlayerListener.java | 2 +- .../nossr50/skills/excavation/ExcavationManager.java | 2 +- .../nossr50/skills/herbalism/HerbalismManager.java | 4 ++-- .../java/com/gmail/nossr50/skills/mining/Mining.java | 12 ++++++------ .../gmail/nossr50/skills/mining/MiningManager.java | 4 ++-- .../nossr50/skills/smelting/SmeltingManager.java | 2 +- .../nossr50/skills/woodcutting/Woodcutting.java | 4 ++-- .../skills/woodcutting/WoodcuttingManager.java | 10 +++++----- src/main/java/com/gmail/nossr50/util/Misc.java | 7 ++++++- 9 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 57dfdcaa9..aa206102e 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -460,7 +460,7 @@ public class PlayerListener implements Listener { // Make sure the player knows what he's doing when trying to salvage an enchanted item if (!(heldItem.getEnchantments().size() > 0) || salvageManager.checkConfirmation(true)) { SkillUtils.handleAbilitySpeedDecrease(player); - salvageManager.handleSalvage(block.getLocation(), heldItem); + salvageManager.handleSalvage(Misc.getBlockCenter(block.getState()), heldItem); player.updateInventory(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java index 1f0ed74ce..302415188 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java @@ -34,7 +34,7 @@ public class ExcavationManager extends SkillManager { if (!treasures.isEmpty()) { int skillLevel = getSkillLevel(); - Location location = blockState.getLocation(); + Location location = Misc.getBlockCenter(blockState); for (ExcavationTreasure treasure : treasures) { if (skillLevel >= treasure.getDropLevel() && SkillUtils.treasureDropSuccessful(getPlayer(), treasure.getDropChance(), activationChance)) { diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 4ab0bff76..c363c7043 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -181,7 +181,7 @@ public class HerbalismManager extends SkillManager { for (int i = greenTerra ? 2 : 1; i != 0; i--) { if (SkillUtils.activationSuccessful(SecondaryAbility.HERBALISM_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance)) { for (ItemStack item : drops) { - Misc.dropItems(blockState.getLocation(), item, amount); + Misc.dropItems(Misc.getBlockCenter(blockState), item, amount); } } } @@ -246,7 +246,7 @@ public class HerbalismManager extends SkillManager { return false; } int skillLevel = getSkillLevel(); - Location location = blockState.getLocation(); + Location location = Misc.getBlockCenter(blockState); for (HylianTreasure treasure : treasures) { if (skillLevel >= treasure.getDropLevel() && SkillUtils.treasureDropSuccessful(getPlayer(), treasure.getDropChance(), activationChance)) { diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index 21f8dd0b4..a36cfa997 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -51,7 +51,7 @@ public class Mining { case GLOWING_REDSTONE_ORE: if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) { - Misc.dropItem(blockState.getLocation(), new ItemStack(Material.REDSTONE_ORE)); + Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(Material.REDSTONE_ORE)); } return; @@ -65,12 +65,12 @@ public class Mining { case REDSTONE_ORE: case STONE: case PRISMARINE: - Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack(1)); + Misc.dropItem(Misc.getBlockCenter(blockState), blockState.getData().toItemStack(1)); return; default: if (mcMMO.getModManager().isCustomMiningBlock(blockState)) { - Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack(1)); + Misc.dropItem(Misc.getBlockCenter(blockState), blockState.getData().toItemStack(1)); } return; } @@ -101,18 +101,18 @@ public class Mining { case STAINED_CLAY: case STONE: case QUARTZ_ORE: - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); return; case GLOWING_REDSTONE_ORE: if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) { - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); } return; default: if (mcMMO.getModManager().isCustomMiningBlock(blockState)) { - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); } return; } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 491795007..62701aca0 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -148,7 +148,7 @@ public class MiningManager extends SkillManager { xp += Mining.getBlockXp(blockState); } - Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack(1)); // Initial block that would have been dropped + Misc.dropItem(Misc.getBlockCenter(blockState), blockState.getData().toItemStack(1)); // Initial block that would have been dropped if (!mcMMO.getPlaceStore().isTrue(blockState)) { for (int i = 1; i < dropMultiplier; i++) { @@ -161,7 +161,7 @@ public class MiningManager extends SkillManager { if (debrisYield > 0) { for (BlockState blockState : debris) { if (Misc.getRandom().nextFloat() < debrisYield) { - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index a9b09f004..3bf41ef96 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -85,7 +85,7 @@ public class SmeltingManager extends SkillManager { SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage()); - Misc.dropItems(blockState.getLocation(), item, isSecondSmeltSuccessful() ? 2 : 1); + Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1); blockState.setType(Material.AIR); diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index bb142d29b..ebd2388e1 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -72,7 +72,7 @@ public final class Woodcutting { */ protected static void checkForDoubleDrop(BlockState blockState) { if (mcMMO.getModManager().isCustomLog(blockState) && mcMMO.getModManager().getBlock(blockState).isDoubleDropEnabled()) { - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); } else { //TODO Remove this workaround when casting to Tree works again @@ -91,7 +91,7 @@ public final class Woodcutting { } if (Config.getInstance().getWoodcuttingDoubleDropsEnabled(species)) { - Misc.dropItems(blockState.getLocation(), blockState.getBlock().getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops()); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java index cd9e84db3..6e01a9337 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java @@ -125,7 +125,7 @@ public class WoodcuttingManager extends SkillManager { if (material == Material.HUGE_MUSHROOM_1 || material == Material.HUGE_MUSHROOM_2) { xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER); - Misc.dropItems(blockState.getLocation(), block.getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops()); } else if (mcMMO.getModManager().isCustomLog(blockState)) { if (canGetDoubleDrops()) { @@ -135,10 +135,10 @@ public class WoodcuttingManager extends SkillManager { CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState); xp = customBlock.getXpGain(); - Misc.dropItems(blockState.getLocation(), block.getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops()); } else if (mcMMO.getModManager().isCustomLeaf(blockState)) { - Misc.dropItems(blockState.getLocation(), block.getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops()); } else { //TODO Remove this workaround when casting to Tree works again @@ -154,12 +154,12 @@ public class WoodcuttingManager extends SkillManager { Woodcutting.checkForDoubleDrop(blockState); } xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER); - Misc.dropItems(blockState.getLocation(), block.getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops()); break; case LEAVES: case LEAVES_2: - Misc.dropItems(blockState.getLocation(), block.getDrops()); + Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops()); break; default: diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 9d0f503d4..eb33a52ab 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -6,6 +6,7 @@ import java.util.Set; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.NPC; @@ -17,7 +18,6 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask; import com.gmail.nossr50.util.player.UserManager; - import com.google.common.collect.ImmutableSet; public final class Misc { @@ -72,6 +72,11 @@ public final class Misc { return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0); } + public static Location getBlockCenter(BlockState blockstate) + { + return blockstate.getLocation().add(0.5, 0.5, 0.5); + } + public static void dropItems(Location location, Collection drops) { for (ItemStack drop : drops) { dropItem(location, drop); From a6e445b7ef4eb4b1b3d0755f03e48d9c1c2fcd6b Mon Sep 17 00:00:00 2001 From: Sid Shakal Date: Wed, 16 Mar 2016 12:01:52 -0500 Subject: [PATCH 2/5] Minor formatting adjustments to keep my commit to code style. Whoops. Eclipse removed a line in imports, and I placed a brace on the wrong line. Fixed. --- src/main/java/com/gmail/nossr50/util/Misc.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index eb33a52ab..02b203a5a 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -18,6 +18,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask; import com.gmail.nossr50.util.player.UserManager; + import com.google.common.collect.ImmutableSet; public final class Misc { @@ -72,8 +73,7 @@ public final class Misc { return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0); } - public static Location getBlockCenter(BlockState blockstate) - { + public static Location getBlockCenter(BlockState blockstate) { return blockstate.getLocation().add(0.5, 0.5, 0.5); } From 4cb4a6224b2ec67ade1eb2a17c3cf09589ef4e63 Mon Sep 17 00:00:00 2001 From: Sid Date: Wed, 16 Mar 2016 15:47:24 -0500 Subject: [PATCH 3/5] Added javadoc for Misc.getBlockCenter(BlockState) And camel-cased the parameter name to conform to style. --- src/main/java/com/gmail/nossr50/util/Misc.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 02b203a5a..93337f2e4 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -73,7 +73,13 @@ public final class Misc { return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0); } - public static Location getBlockCenter(BlockState blockstate) { + /** + * Get the center of the given block. + * + * @param blockState The {@link BlockState} of the block + * @return A {@link Location} lying at the center of the block + */ + public static Location getBlockCenter(BlockState blockState) { return blockstate.getLocation().add(0.5, 0.5, 0.5); } From 2d4cf76825aa35733abcd9d6f2e20550f9065c1c Mon Sep 17 00:00:00 2001 From: Sid Shakal Date: Wed, 16 Mar 2016 20:38:24 -0500 Subject: [PATCH 4/5] ... (completing the previous style fix) Not sure how I missed this one. (Well, sure I do. I used the GitHub editor for the re-casing of the variable name. Noob mistake.) --- src/main/java/com/gmail/nossr50/util/Misc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 93337f2e4..60fa0e2d7 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -80,7 +80,7 @@ public final class Misc { * @return A {@link Location} lying at the center of the block */ public static Location getBlockCenter(BlockState blockState) { - return blockstate.getLocation().add(0.5, 0.5, 0.5); + return blockState.getLocation().add(0.5, 0.5, 0.5); } public static void dropItems(Location location, Collection drops) { From 60bfabb0973134dff02fd242f524c99dc1472a46 Mon Sep 17 00:00:00 2001 From: Sid Shakal Date: Thu, 17 Mar 2016 02:06:19 -0500 Subject: [PATCH 5/5] Moved salvaged material spawn center to center of top face of anvil. My fix for the central spawn points of various block-based item drops moved them from the low corner of the block to the center of the block. In the case of the salvaged materials, this moved the central spawn point from the low corner of the top face of the anvil block to the center of the block above the anvil block. This felt unnatural, so the point has been moved to the center of the top face of the anvil block. --- src/main/java/com/gmail/nossr50/listeners/PlayerListener.java | 2 +- .../java/com/gmail/nossr50/skills/salvage/SalvageManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index aa206102e..57dfdcaa9 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -460,7 +460,7 @@ public class PlayerListener implements Listener { // Make sure the player knows what he's doing when trying to salvage an enchanted item if (!(heldItem.getEnchantments().size() > 0) || salvageManager.checkConfirmation(true)) { SkillUtils.handleAbilitySpeedDecrease(player); - salvageManager.handleSalvage(Misc.getBlockCenter(block.getState()), heldItem); + salvageManager.handleSalvage(block.getLocation(), heldItem); player.updateInventory(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 86df9ee2e..18698dd17 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -95,7 +95,7 @@ public class SalvageManager extends SkillManager { salvageableAmount = Math.max((int) (salvageableAmount * getMaxSalvagePercentage()), 1); // Always get at least something back, if you're capable of salvaging it. player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); - location.add(0, 1, 0); + location.add(0.5, 1, 0.5); Map enchants = item.getEnchantments();