mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Merge pull request #2828 from SidShakal/master
Moved center of block drops to block center. Fixes #2544.
This commit is contained in:
commit
fd3d60d112
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Enchantment, Integer> enchants = item.getEnchantments();
|
||||
|
||||
|
@ -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;
|
||||
@ -72,6 +73,16 @@ public final class Misc {
|
||||
return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public static void dropItems(Location location, Collection<ItemStack> drops) {
|
||||
for (ItemStack drop : drops) {
|
||||
dropItem(location, drop);
|
||||
|
Loading…
Reference in New Issue
Block a user