Fixed fishing drop tables

This commit is contained in:
Indyuce 2020-08-27 13:04:09 +02:00
parent dbc0733bbb
commit aecf4f7f83
3 changed files with 23 additions and 11 deletions

View File

@ -57,8 +57,7 @@ public class FishingDropItem {
return dropItem; return dropItem;
} }
public ItemStack collect() { public ItemStack collect(LootBuilder builder) {
LootBuilder builder = new LootBuilder(null, 0);
dropItem.collect(builder); dropItem.collect(builder);
return builder.getLoot().stream().findAny().get(); return builder.getLoot().stream().findAny().get();
} }

View File

@ -13,9 +13,16 @@ public class LootBuilder {
private double capacity; private double capacity;
/* /**
* instance which saves what entity is currently rolling a loot table and * Used to create loot from a drop table
* how much item capacity the table has left *
* @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) { public LootBuilder(PlayerData player, double capacity) {
this.player = player; this.player = player;

View File

@ -25,6 +25,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent;
import net.Indyuce.mmocore.api.experience.EXPSource; 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.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable; import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
@ -53,7 +54,8 @@ public class FishingListener implements Listener {
new FishingData(player, hook, table); new FishingData(player, hook, table);
if (MMOCore.plugin.hasHolograms()) 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! * 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); event.setCancelled(true);
if (isTimedOut()) { if (isTimedOut()) {
close(); close();
@ -158,7 +161,7 @@ public class FishingListener implements Listener {
if (called.isCancelled()) if (called.isCancelled())
return; return;
ItemStack collect = caught.collect(); ItemStack collect = caught.collect(new LootBuilder(playerData, 0));
if (collect == null) { if (collect == null) {
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08); hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
return; return;
@ -167,7 +170,8 @@ public class FishingListener implements Listener {
// calculate velocity // calculate velocity
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect); Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
if (MMOCore.plugin.hasHolograms()) 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(); Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
vec.setY(vec.getY() * .031 + vec.length() * .05); vec.setY(vec.getY() * .031 + vec.length() * .05);
vec.setX(vec.getX() * .08); vec.setX(vec.getX() * .08);
@ -175,10 +179,12 @@ public class FishingListener implements Listener {
item.setVelocity(vec); item.setVelocity(vec);
player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0); player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
for (int j = 0; j < 16; j++) 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")) 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);
} }
} }
} }