Added support for unbreaking with lava damage
Buffed fire protection
This commit is contained in:
parent
6debaf32bf
commit
84fe7237be
|
|
@ -49,9 +49,9 @@ public class CatchFish implements Listener {
|
|||
@EventHandler
|
||||
public void onItemSwitch(PlayerItemHeldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getInventory().getItem(event.getNewSlot()) != null) {
|
||||
ItemStack oldItem = player.getInventory().getItem(event.getPreviousSlot());
|
||||
if (oldItem == null || !oldItem.getType().equals(Material.FISHING_ROD))
|
||||
return;
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
stopLavaFishStart(uuid);
|
||||
LavaFishing lavaFishing = activeLavaFishers.get(uuid);
|
||||
|
|
@ -91,7 +91,8 @@ public class CatchFish implements Listener {
|
|||
ItemStack itemStack = optionalFishingRod.get();
|
||||
int lure = itemStack.getEnchantmentLevel(Enchantment.LURE);
|
||||
int fireProtection = itemStack.getEnchantmentLevel(Enchantment.PROTECTION_FIRE);
|
||||
LavaFishing lavaFishing = new LavaFishing(lure, fireProtection, player, logger, event.getHook().getLocation());
|
||||
int unbreaking = itemStack.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
LavaFishing lavaFishing = new LavaFishing(lure, fireProtection, unbreaking, player, logger, event.getHook().getLocation());
|
||||
activeLavaFishers.put(uuid, lavaFishing);
|
||||
lavaFishing.runTaskTimerAsynchronously(fishingEvent, 1, 1);
|
||||
logger.debug("in lava above");
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public class LavaFishing extends BukkitRunnable {
|
|||
private int timeUntilLured;
|
||||
private final int lure;
|
||||
private final int fireProtection;
|
||||
private final int unbreaking;
|
||||
private final int minWaitTime = 60;
|
||||
private final int maxWaitTime = 500;
|
||||
private boolean isBiting;
|
||||
|
|
@ -32,12 +33,13 @@ public class LavaFishing extends BukkitRunnable {
|
|||
private final Logger logger;
|
||||
private final Location hookLocation;
|
||||
|
||||
public LavaFishing(int lure, int fireProtection, Player player, Logger logger, Location hookLocation) {
|
||||
public LavaFishing(int lure, int fireProtection, int unbreaking, Player player, Logger logger, Location hookLocation) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (activeFishers.containsKey(uuid)) {
|
||||
activeFishers.get(uuid).cancel();
|
||||
}
|
||||
activeFishers.put(uuid, this);
|
||||
this.unbreaking = unbreaking;
|
||||
this.lure = lure;
|
||||
this.fireProtection = Math.min(5, fireProtection);
|
||||
this.player = player;
|
||||
|
|
@ -56,15 +58,16 @@ public class LavaFishing extends BukkitRunnable {
|
|||
|
||||
private void damageHook() {
|
||||
if (!shouldDamageHook) {
|
||||
logger.debug("Rod should not be damaged for this player");
|
||||
return;
|
||||
}
|
||||
if (timeUntilHookDamage > 0) {
|
||||
timeUntilHookDamage--;
|
||||
return;
|
||||
}
|
||||
logger.debug("Damaging hook...");
|
||||
resetTimeUntilHookDamage();
|
||||
if (unbreaking > 0 && random.nextInt(unbreaking + 1) > 0) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int fishingRodSlot = findFishingRodSlot(inventory);
|
||||
if (fishingRodSlot < 0) {
|
||||
|
|
@ -100,19 +103,17 @@ public class LavaFishing extends BukkitRunnable {
|
|||
}
|
||||
|
||||
private void resetTimeUntilHookDamage() {
|
||||
timeUntilHookDamage = random.nextInt(fireProtection * 5, 20 + fireProtection * 5);
|
||||
timeUntilHookDamage = random.nextInt(fireProtection * 10, 20 + fireProtection * 10);
|
||||
}
|
||||
|
||||
private void spawnLavaParticles() {
|
||||
// Customize the particle effect
|
||||
Particle particle = Particle.LAVA;
|
||||
int count = 10; // Number of particles to spawn
|
||||
double offsetX = 0.2; // X-axis offset
|
||||
double offsetY = 1.0; // Y-axis offset (positive value for upward direction)
|
||||
double offsetZ = 0.2; // Z-axis offset
|
||||
double extra = 0.1; // Extra random offset
|
||||
int count = 10;
|
||||
double offsetX = 0.2;
|
||||
double offsetY = 1.0;
|
||||
double offsetZ = 0.2;
|
||||
double extra = 0.1;
|
||||
|
||||
// Spawn the lava particles
|
||||
hookLocation.getWorld().spawnParticle(particle, hookLocation, count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
|
||||
|
|
@ -121,21 +122,16 @@ public class LavaFishing extends BukkitRunnable {
|
|||
damageHook();
|
||||
if (!isBiting && timeUntilLured > 0) {
|
||||
timeUntilLured--;
|
||||
if (timeUntilLured % 5 == 0)
|
||||
logger.debug("Time until lured: %", String.valueOf(timeUntilLured));
|
||||
return;
|
||||
}
|
||||
if (!isBiting) {
|
||||
isBiting = true;
|
||||
this.timeUntilHooked = random.nextInt(20, 60);
|
||||
spawnLavaParticles();
|
||||
logger.debug("Fish on hook in lava");
|
||||
return;
|
||||
}
|
||||
if (this.timeUntilHooked > 0) {
|
||||
this.timeUntilHooked--;
|
||||
if (timeUntilHooked % 5 == 0)
|
||||
logger.debug("Time until hooked: %", String.valueOf(timeUntilHooked));
|
||||
if (this.timeUntilHooked % 5 == 0)
|
||||
spawnLavaParticles();
|
||||
return;
|
||||
|
|
@ -146,4 +142,11 @@ public class LavaFishing extends BukkitRunnable {
|
|||
public boolean canCatchFish() {
|
||||
return isBiting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void cancel() throws IllegalStateException {
|
||||
super.cancel();
|
||||
logger.debug("Cancelled");
|
||||
activeFishers.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user