From 74a2485cffc987c75ba41b24eeee28e8317445d5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 25 Jun 2019 18:02:16 -0700 Subject: [PATCH] Multiple tweaks to how salvaged items travel towards a player --- Changelog.txt | 11 +++++ pom.xml | 2 +- .../skills/salvage/SalvageManager.java | 20 ++++++--- .../java/com/gmail/nossr50/util/Misc.java | 44 +++++++++++++------ src/main/resources/experience.yml | 4 +- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7c7c2569a..67ca1df1a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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. diff --git a/pom.xml b/pom.xml index ca4960d21..aebe9be8e 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.89 + 2.1.90-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index bc7a80983..de0e0f74b 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -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"); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 99dbf057d..ff892d659 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -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) { diff --git a/src/main/resources/experience.yml b/src/main/resources/experience.yml index 585066949..2da86f197 100644 --- a/src/main/resources/experience.yml +++ b/src/main/resources/experience.yml @@ -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