Adds particle effects to NPCs' crafting stations
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
This commit is contained in:
parent
df4512864f
commit
050491d7ba
41
pom.xml
41
pom.xml
@ -30,13 +30,40 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.knarcraft.knarlib</pattern>
|
||||||
|
<shadedPattern>net.knarcraft.blacksmithvisuals.lib.knarlib</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.jetbrains.annotations</pattern>
|
||||||
|
<shadedPattern>net.knarcraft.blacksmithvisuals.lib.annotations</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>net.knarcraft:knarlib</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>net/knarcraft/knarlib/**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>org.jetbrains:annotations</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>org/jetbrains/annotations/**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
@ -100,5 +127,17 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.knarcraft</groupId>
|
||||||
|
<artifactId>knarlib</artifactId>
|
||||||
|
<version>1.2.7</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -22,8 +22,12 @@ import net.knarcraft.blacksmithvisuals.manager.ConfigurationManager;
|
|||||||
import net.knarcraft.blacksmithvisuals.property.NPCPosition;
|
import net.knarcraft.blacksmithvisuals.property.NPCPosition;
|
||||||
import net.knarcraft.blacksmithvisuals.property.SoundIdentifier;
|
import net.knarcraft.blacksmithvisuals.property.SoundIdentifier;
|
||||||
import net.knarcraft.blacksmithvisuals.util.SoundHelper;
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -107,7 +111,8 @@ public class BlacksmithListener implements Listener {
|
|||||||
BukkitScheduler scheduler = Bukkit.getScheduler();
|
BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||||
NPC npc = event.getNpc();
|
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)) {
|
if (npc.hasTrait(LookClose.class)) {
|
||||||
LookClose trait = npc.getTraitNullable(LookClose.class);
|
LookClose trait = npc.getTraitNullable(LookClose.class);
|
||||||
this.oldLookRanges.put(npc.getUniqueId(), trait.getRange());
|
this.oldLookRanges.put(npc.getUniqueId(), trait.getRange());
|
||||||
@ -116,7 +121,7 @@ public class BlacksmithListener implements Listener {
|
|||||||
long finishTime = event.getActionDurationTicks() - (2 * delay);
|
long finishTime = event.getActionDurationTicks() - (2 * delay);
|
||||||
|
|
||||||
scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(npc.getEntity(),
|
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);
|
scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc()), finishTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,14 +212,16 @@ public class BlacksmithListener implements Listener {
|
|||||||
* @param soundData <p>The sound data for the sound to play</p>
|
* @param soundData <p>The sound data for the sound to play</p>
|
||||||
* @param animationData <p>The animation data for the animation to play</p>
|
* @param animationData <p>The animation data for the animation to play</p>
|
||||||
* @param durationTicks <p>The duration of the work animation</p>
|
* @param durationTicks <p>The duration of the work animation</p>
|
||||||
|
* @param npcPosition <p>The npc position to animate</p>
|
||||||
*/
|
*/
|
||||||
private void startWorkAnimation(@NotNull Entity entity, @NotNull SoundData soundData,
|
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();
|
BlacksmithVisuals instance = BlacksmithVisuals.getInstance();
|
||||||
BukkitScheduler scheduler = Bukkit.getScheduler();
|
BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||||
|
|
||||||
int playWorkSound = scheduler.scheduleSyncRepeatingTask(instance,
|
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);
|
scheduler.scheduleSyncDelayedTask(instance, () -> scheduler.cancelTask(playWorkSound), durationTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,8 +244,10 @@ public class BlacksmithListener implements Listener {
|
|||||||
* @param entity <p>The entity to animate and play the sound at</p>
|
* @param entity <p>The entity to animate and play the sound at</p>
|
||||||
* @param soundData <p>The sound to be played</p>
|
* @param soundData <p>The sound to be played</p>
|
||||||
* @param animationData <p>The animation to be played</p>
|
* @param animationData <p>The animation to be played</p>
|
||||||
|
* @param npcPosition <p>The npc position to animate</p>
|
||||||
*/
|
*/
|
||||||
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()) {
|
if (random.nextInt(100) >= animationData.animationChance()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -256,6 +265,34 @@ public class BlacksmithListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
animateOffhand(entity);
|
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 <p>The entity whose working station should produce a spark</p>
|
||||||
|
* @param npcPosition <p>The npc potion to spawn a particle for</p>
|
||||||
|
*/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user