forked from Upstream/mmocore
Changed durability application method
This commit is contained in:
parent
848b402393
commit
1671df5ed9
@ -1,7 +1,6 @@
|
|||||||
package net.Indyuce.mmocore.api.util;
|
package net.Indyuce.mmocore.api.util;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import io.lumine.mythic.utils.holograms.Hologram;
|
import io.lumine.mythic.utils.holograms.Hologram;
|
||||||
import io.lumine.mythic.utils.serialize.Position;
|
import io.lumine.mythic.utils.serialize.Position;
|
||||||
@ -184,8 +183,11 @@ public class MMOCoreUtils {
|
|||||||
/**
|
/**
|
||||||
* Method used when mining a custom block or fishing, as the corresponding
|
* Method used when mining a custom block or fishing, as the corresponding
|
||||||
* interaction event is cancelled durability is not handled. This method is
|
* interaction event is cancelled durability is not handled. This method is
|
||||||
* needed and actually calls a damage event so that MMOItems can listen to
|
* needed and actually calls a damage event so that MMOItems can listen to it.
|
||||||
* it
|
* <p>
|
||||||
|
* This method only supports item types which DO have a durability bar like
|
||||||
|
* fishing rods or pickaxes. This shouldn't cause any issue because you can
|
||||||
|
* only use fishing rods to fish and pickaxes to mine stuff.
|
||||||
*
|
*
|
||||||
* @param player Player holding the item with durability
|
* @param player Player holding the item with durability
|
||||||
* @param slot The slot of the item with durability
|
* @param slot The slot of the item with durability
|
||||||
@ -193,26 +195,21 @@ public class MMOCoreUtils {
|
|||||||
*/
|
*/
|
||||||
public static void decreaseDurability(Player player, EquipmentSlot slot, int damage) {
|
public static void decreaseDurability(Player player, EquipmentSlot slot, int damage) {
|
||||||
ItemStack item = player.getInventory().getItem(slot);
|
ItemStack item = player.getInventory().getItem(slot);
|
||||||
NBTItem nbt = NBTItem.get(item);
|
if (!item.hasItemMeta() || !(item.getItemMeta() instanceof Damageable) || item.getItemMeta().isUnbreakable())
|
||||||
|
|
||||||
if (!nbt.hasTag("MMOITEMS_MAX_DURABILITY")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (!nbt.getBoolean("Unbreakable") && item.getItemMeta() instanceof Damageable) {
|
if (event.getDamage() + ((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
||||||
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + damage);
|
player.getInventory().setItem(slot, null);
|
||||||
|
} else {
|
||||||
|
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + event.getDamage());
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
if (((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
|
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
|
||||||
player.getInventory().setItem(slot, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class FishingListener implements Listener {
|
|||||||
lootFish();
|
lootFish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void criticalFish() {
|
public void setCriticalFish() {
|
||||||
currentPulls = fishStrength + 2;
|
currentPulls = fishStrength + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ public class FishingListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* @return If the fish is weak enough to be looted by the player.
|
* @return If the fish is weak enough to be looted by the player.
|
||||||
*/
|
*/
|
||||||
public boolean pull() {
|
public boolean pullOnce() {
|
||||||
last = System.currentTimeMillis();
|
last = System.currentTimeMillis();
|
||||||
currentPulls++;
|
currentPulls++;
|
||||||
return currentPulls >= fishStrength;
|
return currentPulls >= fishStrength;
|
||||||
@ -116,7 +116,7 @@ public class FishingListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Critical fish's means you catch the fish on the very first try
|
* Critical fish's means you catch the fish on the very first try
|
||||||
*/
|
*/
|
||||||
public boolean isCrit() {
|
public boolean isCriticalFish() {
|
||||||
return currentPulls > fishStrength + 1;
|
return currentPulls > fishStrength + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,13 +148,11 @@ public class FishingListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Pulls: " + currentPulls + " / " + fishStrength);
|
|
||||||
|
|
||||||
if (currentPulls == 0 && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
if (currentPulls == 0 && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
||||||
criticalFish();
|
setCriticalFish();
|
||||||
|
|
||||||
// Check if enough pulls; if not, wait till the next fish event
|
// Check if enough pulls; if not, wait till the next fish event
|
||||||
if (pull())
|
if (pullOnce())
|
||||||
lootFish();
|
lootFish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ public class FishingListener implements Listener {
|
|||||||
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
|
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
|
||||||
|
|
||||||
// Critical fishing failure
|
// Critical fishing failure
|
||||||
if (!isCrit() && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
|
if (!isCriticalFish() && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
|
||||||
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
|
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
|
||||||
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;
|
||||||
@ -189,7 +187,7 @@ public class FishingListener implements Listener {
|
|||||||
// Calculate yeet velocity
|
// Calculate yeet velocity
|
||||||
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
||||||
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
|
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCriticalFish() ? "-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);
|
||||||
|
Loading…
Reference in New Issue
Block a user