mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-27 11:07:44 +01:00
Moving the center of block drops to block center. Fixes #2544.
This commit is contained in:
parent
1488946fc5
commit
123a139e43
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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<ItemStack> drops) {
|
||||
for (ItemStack drop : drops) {
|
||||
dropItem(location, drop);
|
||||
|
Loading…
Reference in New Issue
Block a user