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);