diff --git a/pom.xml b/pom.xml index 8611844..38eac62 100644 --- a/pom.xml +++ b/pom.xml @@ -30,13 +30,40 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.3.0 package shade + + false + + + net.knarcraft.knarlib + net.knarcraft.blacksmithvisuals.lib.knarlib + + + org.jetbrains.annotations + net.knarcraft.blacksmithvisuals.lib.annotations + + + + + net.knarcraft:knarlib + + net/knarcraft/knarlib/** + + + + org.jetbrains:annotations + + org/jetbrains/annotations/** + + + + @@ -100,5 +127,17 @@ + + org.jetbrains + annotations + 24.0.1 + compile + + + net.knarcraft + knarlib + 1.2.7 + compile + diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java b/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java index f301ca8..dd4b89c 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java @@ -22,8 +22,12 @@ import net.knarcraft.blacksmithvisuals.manager.ConfigurationManager; import net.knarcraft.blacksmithvisuals.property.NPCPosition; import net.knarcraft.blacksmithvisuals.property.SoundIdentifier; import net.knarcraft.blacksmithvisuals.util.SoundHelper; +import net.knarcraft.knarlib.particle.ParticleConfig; +import net.knarcraft.knarlib.particle.ParticleMode; +import net.knarcraft.knarlib.util.ParticleHelper; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -107,7 +111,8 @@ public class BlacksmithListener implements Listener { BukkitScheduler scheduler = Bukkit.getScheduler(); NPC npc = event.getNpc(); - long delay = moveToWorkingPosition(npc, NPCPosition.getFromMaterial(event.getCraftingStation())); + NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation()); + long delay = moveToWorkingPosition(npc, npcPosition); if (npc.hasTrait(LookClose.class)) { LookClose trait = npc.getTraitNullable(LookClose.class); this.oldLookRanges.put(npc.getUniqueId(), trait.getRange()); @@ -116,7 +121,7 @@ public class BlacksmithListener implements Listener { long finishTime = event.getActionDurationTicks() - (2 * delay); scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(npc.getEntity(), - this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20), delay); + this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay); scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc()), finishTime); } @@ -207,14 +212,16 @@ public class BlacksmithListener implements Listener { * @param soundData

The sound data for the sound to play

* @param animationData

The animation data for the animation to play

* @param durationTicks

The duration of the work animation

+ * @param npcPosition

The npc position to animate

*/ private void startWorkAnimation(@NotNull Entity entity, @NotNull SoundData soundData, - @NotNull AnimationData animationData, long durationTicks) { + @NotNull AnimationData animationData, long durationTicks, + @Nullable NPCPosition npcPosition) { BlacksmithVisuals instance = BlacksmithVisuals.getInstance(); BukkitScheduler scheduler = Bukkit.getScheduler(); int playWorkSound = scheduler.scheduleSyncRepeatingTask(instance, - () -> animateNPC(entity, soundData, animationData), 20, animationData.animationDelay()); + () -> animateNPC(entity, soundData, animationData, npcPosition), 20, animationData.animationDelay()); scheduler.scheduleSyncDelayedTask(instance, () -> scheduler.cancelTask(playWorkSound), durationTicks); } @@ -237,8 +244,10 @@ public class BlacksmithListener implements Listener { * @param entity

The entity to animate and play the sound at

* @param soundData

The sound to be played

* @param animationData

The animation to be played

+ * @param npcPosition

The npc position to animate

*/ - private void animateNPC(@NotNull Entity entity, @NotNull SoundData soundData, @NotNull AnimationData animationData) { + private void animateNPC(@NotNull Entity entity, @NotNull SoundData soundData, @NotNull AnimationData animationData, + @Nullable NPCPosition npcPosition) { if (random.nextInt(100) >= animationData.animationChance()) { return; } @@ -256,6 +265,34 @@ public class BlacksmithListener implements Listener { } else { animateOffhand(entity); } + + if (npcPosition == null) { + npcPosition = NPCPosition.WORKING_REPAIRABLE; + } + for (int i = 0; i < random.nextInt(5) + 1; i++) { + spawnSparkParticle(entity, npcPosition); + } + } + + /** + * Spawns a spark particle at the given NPC's work station + * + * @param entity

The entity whose working station should produce a spark

+ * @param npcPosition

The npc potion to spawn a particle for

+ */ + private void spawnSparkParticle(@NotNull Entity entity, @NotNull NPCPosition npcPosition) { + double randomX = this.random.nextDouble(-1, 1); + double randomY = this.random.nextDouble(0.1, 1); + double randomZ = this.random.nextDouble(-1, 1); + Particle particle; + if (npcPosition == NPCPosition.WORKING_CRAFTING) { + particle = Particle.ELECTRIC_SPARK; + } else { + particle = Particle.FLAME; + } + Location spawnLocation = entity.getLocation().clone().getBlock().getRelative(entity.getFacing()).getLocation().add(0.5, 0, 0.5); + ParticleConfig particleConfig = new ParticleConfig(ParticleMode.SINGLE, particle, 0, 0, 1.1, randomX, randomY, randomZ, 0.1); + ParticleHelper.spawnParticle(entity.getWorld(), spawnLocation, particleConfig, 1); } /**