Fix Lure above 3 breaking fishing

This commit is contained in:
nossr50 2020-11-16 14:36:59 -08:00
parent f346d3b758
commit cfcdcd1676
6 changed files with 54 additions and 10 deletions

View File

@ -1,3 +1,9 @@
Version 2.1.158
Fixed a bug where Lure level 4 and above would break fishing with the new Master Angler
NOTES:
Master Angler will emulate the effects of Lure if the level is higher than 3 instead of attempting to stack with it to avoid a vanilla Minecraft bug where fish are never caught
Version 2.1.157
Fixed a NPE that prevented mctop (Leaderboards) from working

View File

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

View File

@ -92,7 +92,7 @@ public class FishingCommand extends SkillCommand {
// MASTER ANGLER
if (canMasterAngler) {
maMinWaitTime = StringUtils.ticksToSeconds(fishingManager.getMasterAnglerTickMinWaitReduction(RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false));
maMaxWaitTime = StringUtils.ticksToSeconds(fishingManager.getMasterAnglerTickMaxWaitReduction(RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false));
maMaxWaitTime = StringUtils.ticksToSeconds(fishingManager.getMasterAnglerTickMaxWaitReduction(RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false, 0));
}
}

View File

@ -35,6 +35,7 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.PoweredMinecart;
import org.bukkit.event.Event;
@ -387,7 +388,21 @@ public class PlayerListener implements Listener {
switch (event.getState()) {
case FISHING:
if (fishingManager.canMasterAngler()) {
fishingManager.masterAngler(event.getHook());
int lureLevel = 0;
ItemStack inHand = player.getInventory().getItemInMainHand();
//Grab lure level
if(inHand != null && inHand.getType().getKey().getKey().equalsIgnoreCase("fishing_rod")) {
if(inHand.getItemMeta().hasEnchants()) {
for(Enchantment enchantment : inHand.getItemMeta().getEnchants().keySet()) {
if(enchantment.toString().toLowerCase().contains("lure")) {
lureLevel = inHand.getEnchantmentLevel(enchantment);
}
}
}
}
fishingManager.masterAngler(event.getHook(), lureLevel);
fishingManager.setFishingTarget();
}
return;

View File

@ -8,14 +8,16 @@ import org.jetbrains.annotations.NotNull;
public class MasterAnglerTask extends BukkitRunnable {
private final @NotNull FishHook fishHook;
private final @NotNull FishingManager fishingManager;
private final int lureLevel;
public MasterAnglerTask(@NotNull FishHook fishHook, @NotNull FishingManager fishingManager) {
public MasterAnglerTask(@NotNull FishHook fishHook, @NotNull FishingManager fishingManager, int lureLevel) {
this.fishHook = fishHook;
this.fishingManager = fishingManager;
this.lureLevel = lureLevel;
}
@Override
public void run() {
fishingManager.processMasterAngler(fishHook);
fishingManager.processMasterAngler(fishHook, lureLevel);
}
}

View File

@ -247,8 +247,8 @@ public class FishingManager extends SkillManager {
EventUtils.callFakeFishEvent(getPlayer(), hook);
}
public void masterAngler(@NotNull FishHook hook) {
new MasterAnglerTask(hook, this).runTaskLater(mcMMO.p, 0); //We run later to get the lure bonus applied
public void masterAngler(@NotNull FishHook hook, int lureLevel) {
new MasterAnglerTask(hook, this, lureLevel).runTaskLater(mcMMO.p, 0); //We run later to get the lure bonus applied
}
/**
@ -256,7 +256,7 @@ public class FishingManager extends SkillManager {
* Reduced tick time on fish hook, etc
* @param fishHook target fish hook
*/
public void processMasterAngler(@NotNull FishHook fishHook) {
public void processMasterAngler(@NotNull FishHook fishHook, int lureLevel) {
MasterAnglerCompatibilityLayer masterAnglerCompatibilityLayer = (MasterAnglerCompatibilityLayer) mcMMO.getCompatibilityManager().getMasterAnglerCompatibilityLayer();
if(masterAnglerCompatibilityLayer != null) {
@ -264,10 +264,17 @@ public class FishingManager extends SkillManager {
int minWaitTicks = masterAnglerCompatibilityLayer.getMinWaitTime(fishHook);
int masterAnglerRank = RankUtils.getRank(mmoPlayer, SubSkillType.FISHING_MASTER_ANGLER);
int convertedLureBonus = 0;
//This avoids a Minecraft bug where lure levels above 3 break fishing
if(lureLevel > 3) {
masterAnglerCompatibilityLayer.setApplyLure(fishHook, false);
convertedLureBonus = lureLevel * 100;
}
boolean boatBonus = isInBoat();
int minWaitReduction = getMasterAnglerTickMinWaitReduction(masterAnglerRank, boatBonus);
int maxWaitReduction = getMasterAnglerTickMaxWaitReduction(masterAnglerRank, boatBonus);
int maxWaitReduction = getMasterAnglerTickMaxWaitReduction(masterAnglerRank, boatBonus, convertedLureBonus);
//Ticks for minWait and maxWait never go below this value
int bonusCapMin = AdvancedConfig.getInstance().getFishingReductionMinWaitCap();
@ -276,9 +283,21 @@ public class FishingManager extends SkillManager {
int reducedMinWaitTime = getReducedTicks(minWaitTicks, minWaitReduction, bonusCapMin);
int reducedMaxWaitTime = getReducedTicks(maxWaitTicks, maxWaitReduction, bonusCapMax);
boolean badValuesFix = false;
//If we find bad values correct it
if(reducedMaxWaitTime < reducedMinWaitTime) {
reducedMaxWaitTime = reducedMinWaitTime + 100;
badValuesFix = true;
}
if(mmoPlayer.isDebugMode()) {
mmoPlayer.getPlayer().sendMessage(ChatColor.GOLD + "Master Angler Debug");
if(badValuesFix) {
mmoPlayer.getPlayer().sendMessage(ChatColor.RED + "Bad values were applied and corrected, check your configs, max wait should never be lower than min wait.");
}
mmoPlayer.getPlayer().sendMessage("ALLOW STACK WITH LURE: " + masterAnglerCompatibilityLayer.getApplyLure(fishHook));
mmoPlayer.getPlayer().sendMessage("MIN TICK REDUCTION: " + minWaitReduction);
mmoPlayer.getPlayer().sendMessage("MAX TICK REDUCTION: " + maxWaitReduction);
@ -321,13 +340,15 @@ public class FishingManager extends SkillManager {
return mmoPlayer.getPlayer().isInsideVehicle() && mmoPlayer.getPlayer().getVehicle() instanceof Boat;
}
public int getMasterAnglerTickMaxWaitReduction(int masterAnglerRank, boolean boatBonus) {
public int getMasterAnglerTickMaxWaitReduction(int masterAnglerRank, boolean boatBonus, int emulatedLureBonus) {
int totalBonus = AdvancedConfig.getInstance().getFishingReductionMaxWaitTicks() * masterAnglerRank;
if(boatBonus) {
totalBonus += getFishingBoatMaxWaitReduction();
}
totalBonus += emulatedLureBonus;
return totalBonus;
}