4 Commits

Author SHA1 Message Date
f1f4526f9d Updates to the Blacksmith Snapshot API
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
2024-09-27 01:43:13 +02:00
c013e3e65d Changes the Blacksmith version
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
2024-08-07 16:24:27 +02:00
6ab99031dc Changes the FAQ somewhat
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
2024-08-07 14:54:29 +02:00
c7365af9c4 Adds dependency information to the README
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
2024-08-07 14:08:03 +02:00
4 changed files with 33 additions and 22 deletions

View File

@ -4,6 +4,14 @@ This plugin adds additional visual and audial details to blacksmiths while they
they are working or not. It is recommended to put a mace or other hammer-like item in the NPC's off-hand for full they are working or not. It is recommended to put a mace or other hammer-like item in the NPC's off-hand for full
effect. effect.
## Dependencies
This plugin requires the following:
- [Blacksmith](https://www.spigotmc.org/resources/blacksmith.105938/)
- [Citizens](https://www.spigotmc.org/resources/citizens.13811/) (also a dependency for Blacksmith)
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/)
## Setting up a new NPC ## Setting up a new NPC
While most things are automatic, you should set the NPC's idle and working locations for the NPC to automatically move While most things are automatic, you should set the NPC's idle and working locations for the NPC to automatically move
@ -21,9 +29,9 @@ Remember to disable lookclose or adjust it as described in the FAQ.
### Citizens lookclose makes NPC rotate weirdly and not face its crafting station ### Citizens lookclose makes NPC rotate weirdly and not face its crafting station
It has been found that with some options, lookclose can still be used. An example of a working lookclose setup is: It has been found that with some options, lookclose can still be used. An example of a working lookclose setup is:
`/npc lookclose --linkedbody false --disablewhennavigating true --perplayer true --range 3 --targetnpcs false --headonly true --linkedbody false -r false` `/npc lookclose --linkedbody false --disablewhennavigating true --perplayer true --range 3 --targetnpcs false --headonly true --linkedbody false`
Some other options might work as well, but a lot of options won't, as it messes with manual NPC rotation. Keep that in The value of realistic looking `/npc lookclose -r` may also affect behavior. Some other options might work as well, but
mind. a lot of options won't, as it messes with manual NPC rotation. Keep that in mind.
### NPCs teleport part of the way while walking to or from a crafting station ### NPCs teleport part of the way while walking to or from a crafting station

View File

@ -6,7 +6,7 @@
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>BlacksmithVisuals</artifactId> <artifactId>BlacksmithVisuals</artifactId>
<version>1.0.0</version> <version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BlacksmithVisuals</name> <name>BlacksmithVisuals</name>
@ -111,7 +111,7 @@
<dependency> <dependency>
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>blacksmith</artifactId> <artifactId>blacksmith</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -11,6 +11,7 @@ import org.bukkit.SoundCategory;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -34,7 +35,8 @@ public class PlayTestSoundCommand implements TabExecutor {
return true; return true;
} }
if (arguments.length < 2) { Entity entity = npc.getEntity();
if (arguments.length < 2 || !npc.isSpawned() || entity == null) {
return false; return false;
} }
@ -62,8 +64,7 @@ public class PlayTestSoundCommand implements TabExecutor {
return false; return false;
} }
SoundData soundData = new SoundData(soundCategory, sound, volume, pitch, 0, true); SoundHelper.playSound(entity, new SoundData(soundCategory, sound, volume, pitch, 0, true));
SoundHelper.playSound(npc.getEntity(), soundData);
return true; return true;
} }

View File

@ -80,22 +80,22 @@ public class BlacksmithListener implements Listener {
@EventHandler @EventHandler
public void onReforgeSuccess(@NotNull BlacksmithReforgeSucceedEvent event) { public void onReforgeSuccess(@NotNull BlacksmithReforgeSucceedEvent event) {
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS)); SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS));
} }
@EventHandler @EventHandler
public void onSalvageSuccess(@NotNull ScrapperSalvageSucceedEvent event) { public void onSalvageSuccess(@NotNull ScrapperSalvageSucceedEvent event) {
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS)); SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS));
} }
@EventHandler @EventHandler
public void onReforgeFail(@NotNull BlacksmithReforgeFailEvent event) { public void onReforgeFail(@NotNull BlacksmithReforgeFailEvent event) {
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE)); SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE));
} }
@EventHandler @EventHandler
public void onSalvageFail(@NotNull ScrapperSalvageFailEvent event) { public void onSalvageFail(@NotNull ScrapperSalvageFailEvent event) {
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE)); SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE));
} }
/** /**
@ -112,7 +112,7 @@ public class BlacksmithListener implements Listener {
NPC npc = event.getNpc(); NPC npc = event.getNpc();
NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation()); NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation());
long delay = moveToWorkingPosition(npc, npcPosition); long delay = moveToWorkingPosition(npc, event.getEntity(), 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());
@ -120,17 +120,18 @@ 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(event.getEntity(),
this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay); this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay);
scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc()), finishTime); scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc(), event.getEntity()), finishTime);
} }
/** /**
* Moves an NPC back to its idle position * Moves an NPC back to its idle position
* *
* @param npc <p>The NPC to move</p> * @param npc <p>The NPC to move</p>
* @param entity <p>The entity of the NPC</p>
*/ */
private void moveBack(@NotNull NPC npc) { private void moveBack(@NotNull NPC npc, @NotNull Entity entity) {
if (!npc.isSpawned()) { if (!npc.isSpawned()) {
return; return;
} }
@ -156,7 +157,7 @@ public class BlacksmithListener implements Listener {
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
npc.getEntity().teleport(targetLocation), getWalkTime(npc.getEntity().getLocation(), targetLocation)); entity.teleport(targetLocation), getWalkTime(entity.getLocation(), targetLocation));
npc.getNavigator().setTarget(targetLocation); npc.getNavigator().setTarget(targetLocation);
} }
@ -164,10 +165,11 @@ public class BlacksmithListener implements Listener {
* Moves a npc to its working position * Moves a npc to its working position
* *
* @param npc <p>The NPC to move</p> * @param npc <p>The NPC to move</p>
* @param entity <p>The entity of the NPC</p>
* @param npcPosition <p>The npc position to move to</p> * @param npcPosition <p>The npc position to move to</p>
* @return <p>The time the move will take</p> * @return <p>The time the move will take</p>
*/ */
private long moveToWorkingPosition(@NotNull NPC npc, @Nullable NPCPosition npcPosition) { private long moveToWorkingPosition(@NotNull NPC npc, @NotNull Entity entity, @Nullable NPCPosition npcPosition) {
if (!npc.isSpawned() || npcPosition == null) { if (!npc.isSpawned() || npcPosition == null) {
return 0; return 0;
} }
@ -193,15 +195,15 @@ public class BlacksmithListener implements Listener {
Location finalTargetLocation = targetLocation; Location finalTargetLocation = targetLocation;
// Move NPC using Citizens path-finding // Move NPC using Citizens path-finding
Location current = npc.getEntity().getLocation().clone(); Location current = entity.getLocation().clone();
npc.teleport(current.setDirection(targetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN); npc.teleport(current.setDirection(targetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN);
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2); Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2);
// Teleport the NPC tp get it in the exact final location // Teleport the NPC tp get it in the exact final location
long walkTime = getWalkTime(npc.getEntity().getLocation(), targetLocation); long walkTime = getWalkTime(entity.getLocation(), targetLocation);
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
npc.getEntity().teleport(finalTargetLocation), walkTime); entity.teleport(finalTargetLocation), walkTime);
return walkTime; return walkTime;
} }