Multiple tweaks to how salvaged items travel towards a player

This commit is contained in:
nossr50 2019-06-25 18:02:16 -07:00
parent 03efd14ff4
commit 74a2485cff
5 changed files with 60 additions and 21 deletions

View File

@ -1,3 +1,14 @@
Version 2.1.90
Default values for Packed Ice and Blue Ice reduced to 20 XP (update manually or delete experience.yml to regen your config)
Salvaged items now travel much slower towards the player
Books from salvage will now travel towards the player
Salvaged items travelling towards you will now have their speed adjusted based on distance
NOTES:
Sorry about salvaged items traveling too quickly, in testing on my LAN server with ideal conditions they always entered my inventory and never shot past me so the high speed of the items was not an apparent issue.
However, conditions are not always ideal so having the item travel at you quickly can lead to problems, and I've gotten reports about the items shooting past players. This was not intentional and something that did not happen during testing, but was a valid bug.
I've made it so now items spawned from salvage can only travel very slowly towards you, this solves the original issue where salvaged items were being flung in random directions (how its been in mcMMO for like 6 years) without potential for accidents.
Version 2.1.89
Many changes were made to this version that affect default values in the config, read the notes carefully if you wish to apply these changes. They are optional.
mcMMO is compatible with the new 1.14.3, in addition to this it is still compatible with 1.14.2, 1.14.1, 1.14, and 1.13.2. This did not require any changes to be made to mcMMO, but I thought I'd add this to the notes for those wondering.

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.89</version>
<version>2.1.90-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

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

View File

@ -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) {

View File

@ -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