mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
Multiple tweaks to how salvaged items travel towards a player
This commit is contained in:
@ -140,18 +140,28 @@ public class SalvageManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Location anvilLoc = location.clone();
|
||||
Location playerLoc = player.getLocation().clone();
|
||||
double distance = anvilLoc.distance(playerLoc);
|
||||
|
||||
double speedLimit = .6;
|
||||
double minSpeed = .3;
|
||||
|
||||
//Clamp the speed and vary it by distance
|
||||
double vectorSpeed = Math.min(speedLimit, Math.max(minSpeed, distance * .2));
|
||||
|
||||
//Add a very small amount of height
|
||||
anvilLoc.add(0, .1, 0);
|
||||
|
||||
if (enchantBook != null) {
|
||||
Misc.dropItem(location, enchantBook);
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), enchantBook, vectorSpeed);
|
||||
}
|
||||
|
||||
Misc.spawnItemTowardsLocation(location, player.getLocation().add(0, 0.25, 0), salvageResults);
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), salvageResults, vectorSpeed);
|
||||
|
||||
// BWONG BWONG BWONG - CLUNK!
|
||||
if (Config.getInstance().getSalvageAnvilUseSoundsEnabled()) {
|
||||
// SoundManager.sendSound(player, player.getLocation(), SoundType.ANVIL);
|
||||
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_BREAK);
|
||||
|
||||
//player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Salvage.Skills.Success");
|
||||
|
@ -121,40 +121,58 @@ public final class Misc {
|
||||
/**
|
||||
* Drop items at a given location.
|
||||
*
|
||||
* @param location The location to drop the items at
|
||||
* @param fromLocation The location to drop the items at
|
||||
* @param is The items to drop
|
||||
* @param speed the speed that the item should travel
|
||||
* @param quantity The amount of items to drop
|
||||
*/
|
||||
public static void spawnItemsTowardsLocation(Location location, Location targetLocation, ItemStack is, int quantity) {
|
||||
public static void spawnItemsTowardsLocation(Location fromLocation, Location toLocation, ItemStack is, int quantity, double speed) {
|
||||
for (int i = 0; i < quantity; i++) {
|
||||
spawnItemTowardsLocation(location, targetLocation, is);
|
||||
spawnItemTowardsLocation(fromLocation, toLocation, is, speed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop an item at a given location.
|
||||
* This method is fairly expensive as it creates clones of everything passed to itself since they are mutable objects
|
||||
*
|
||||
* @param spawnLocation The location to drop the item at
|
||||
* @param itemStack The item to drop
|
||||
* @param fromLocation The location to drop the item at
|
||||
* @param toLocation The location the item will travel towards
|
||||
* @param itemToSpawn The item to spawn
|
||||
* @param speed the speed that the item should travel
|
||||
* @return Dropped Item entity or null if invalid or cancelled
|
||||
*/
|
||||
public static Item spawnItemTowardsLocation(Location spawnLocation, Location targetLocation, ItemStack itemStack) {
|
||||
if (itemStack.getType() == Material.AIR) {
|
||||
public static Item spawnItemTowardsLocation(Location fromLocation, Location toLocation, ItemStack itemToSpawn, double speed) {
|
||||
if (itemToSpawn.getType() == Material.AIR) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Work with fresh copies of everything
|
||||
ItemStack clonedItem = itemToSpawn.clone();
|
||||
Location spawnLocation = fromLocation.clone();
|
||||
Location targetLocation = toLocation.clone();
|
||||
|
||||
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
|
||||
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, itemStack);
|
||||
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, clonedItem);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
//Something cancelled the event so back out
|
||||
if (event.isCancelled() || event.getItemStack() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Item item = spawnLocation.getWorld().dropItem(spawnLocation, itemStack);
|
||||
Vector vector = targetLocation.toVector().subtract(spawnLocation.toVector()).normalize();
|
||||
item.setVelocity(vector);
|
||||
return item;
|
||||
//Use the item from the event
|
||||
Item spawnedItem = spawnLocation.getWorld().dropItem(spawnLocation, clonedItem);
|
||||
Vector vecFrom = spawnLocation.clone().toVector().clone();
|
||||
Vector vecTo = targetLocation.clone().toVector().clone();
|
||||
|
||||
//Vector which is pointing towards out target location
|
||||
Vector direction = vecTo.subtract(vecFrom).normalize();
|
||||
|
||||
//Modify the speed of the vector
|
||||
direction = direction.multiply(speed);
|
||||
spawnedItem.setVelocity(direction);
|
||||
return spawnedItem;
|
||||
}
|
||||
|
||||
public static void profileCleanup(String playerName) {
|
||||
|
@ -368,8 +368,8 @@ Experience_Values:
|
||||
Mossy_Cobblestone: 30
|
||||
Netherrack: 30
|
||||
Obsidian: 150
|
||||
Packed_Ice: 50
|
||||
Blue_Ice: 100
|
||||
Packed_Ice: 20
|
||||
Blue_Ice: 20
|
||||
Nether_Quartz_Ore: 100
|
||||
Redstone_Ore: 150
|
||||
Sandstone: 30
|
||||
|
Reference in New Issue
Block a user