From aecf4f7f83f8a08c27728bb0eb1e087e6798e95a Mon Sep 17 00:00:00 2001 From: Indyuce Date: Thu, 27 Aug 2020 13:04:09 +0200 Subject: [PATCH] Fixed fishing drop tables --- .../dropitem/fishing/FishingDropItem.java | 3 +-- .../Indyuce/mmocore/api/loot/LootBuilder.java | 13 ++++++++++--- .../listener/profession/FishingListener.java | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java b/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java index a1c52840..d62bcaf2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java @@ -57,8 +57,7 @@ public class FishingDropItem { return dropItem; } - public ItemStack collect() { - LootBuilder builder = new LootBuilder(null, 0); + public ItemStack collect(LootBuilder builder) { dropItem.collect(builder); return builder.getLoot().stream().findAny().get(); } diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java b/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java index 873573f7..5521e341 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java +++ b/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java @@ -13,9 +13,16 @@ public class LootBuilder { private double capacity; - /* - * instance which saves what entity is currently rolling a loot table and - * how much item capacity the table has left + /** + * Used to create loot from a drop table + * + * @param player + * Player looting + * @param capacity + * Capacity is the maximum amount of item weight generated using + * this table. If capacity is set to 10, this table cannot drop + * an item with 5 weight and another with 6 weight at the saeme + * time. */ public LootBuilder(PlayerData player, double capacity) { this.player = player; diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 9f92cd26..b92e7c15 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -25,6 +25,7 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; import net.Indyuce.mmocore.api.experience.EXPSource; +import net.Indyuce.mmocore.api.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable; @@ -53,7 +54,8 @@ public class FishingListener implements Listener { new FishingData(player, hook, table); if (MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(hook.getLocation(), MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message()); + MMOCore.plugin.hologramSupport.displayIndicator(hook.getLocation(), + MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message()); } } @@ -124,7 +126,8 @@ public class FishingListener implements Listener { /* * lose the catch if the current fish is gone! */ - //TODO: Cancelling the event also cancels Rod damage (so it's technically unbreakable) + // TODO: Cancelling the event also cancels Rod damage (so it's + // technically unbreakable) event.setCancelled(true); if (isTimedOut()) { close(); @@ -158,7 +161,7 @@ public class FishingListener implements Listener { if (called.isCancelled()) return; - ItemStack collect = caught.collect(); + ItemStack collect = caught.collect(new LootBuilder(playerData, 0)); if (collect == null) { hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08); return; @@ -167,7 +170,8 @@ public class FishingListener implements Listener { // calculate velocity Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect); if (MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(location, MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message()); + MMOCore.plugin.hologramSupport.displayIndicator(location, + MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message()); Vector vec = player.getLocation().subtract(hook.getLocation()).toVector(); vec.setY(vec.getY() * .031 + vec.length() * .05); vec.setX(vec.getX() * .08); @@ -175,10 +179,12 @@ public class FishingListener implements Listener { item.setVelocity(vec); player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0); for (int j = 0; j < 16; j++) - location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2, 4 * (random.nextDouble() - .5), .05); + location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2, + 4 * (random.nextDouble() - .5), .05); if (MMOCore.plugin.professionManager.has("fishing")) - playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, location, EXPSource.FISHING); + playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, location, + EXPSource.FISHING); } } }