mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-04 07:27:59 +01:00
Work around entity equipping
This commit is contained in:
parent
eec27c07e4
commit
43e218be05
@ -193,6 +193,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NMS.setHeadYaw(mcEntity, loc.getYaw());
|
||||||
getBukkitEntity().setMetadata(NPC_METADATA_MARKER,
|
getBukkitEntity().setMetadata(NPC_METADATA_MARKER,
|
||||||
new FixedMetadataValue(CitizensAPI.getPlugin(), true));
|
new FixedMetadataValue(CitizensAPI.getPlugin(), true));
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
@ -20,6 +21,7 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.server.Navigation;
|
import net.minecraft.server.Navigation;
|
||||||
import net.minecraft.server.NetHandler;
|
import net.minecraft.server.NetHandler;
|
||||||
import net.minecraft.server.NetworkManager;
|
import net.minecraft.server.NetworkManager;
|
||||||
|
import net.minecraft.server.Packet5EntityEquipment;
|
||||||
import net.minecraft.server.World;
|
import net.minecraft.server.World;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -32,6 +34,8 @@ import org.bukkit.util.Vector;
|
|||||||
public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
private net.minecraft.server.ItemStack[] previousEquipment = { null, null, null, null, null };
|
||||||
|
|
||||||
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
|
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
|
||||||
ItemInWorldManager itemInWorldManager, NPC npc) {
|
ItemInWorldManager itemInWorldManager, NPC npc) {
|
||||||
super(minecraftServer, world, string, itemInWorldManager);
|
super(minecraftServer, world, string, itemInWorldManager);
|
||||||
@ -125,7 +129,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
super.j_();
|
super.j_();
|
||||||
if (npc == null)
|
if (npc == null)
|
||||||
return;
|
return;
|
||||||
|
updateEquipment();
|
||||||
NMS.updateAI(this);
|
NMS.updateAI(this);
|
||||||
Navigation navigation = getNavigation();
|
Navigation navigation = getNavigation();
|
||||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
|
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
|
||||||
@ -169,6 +173,23 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
NMS.setHeadYaw(this, yaw);
|
NMS.setHeadYaw(this, yaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateEquipment() {
|
||||||
|
int changes = 0;
|
||||||
|
for (int i = 0; i < previousEquipment.length; i++) {
|
||||||
|
net.minecraft.server.ItemStack previous = previousEquipment[i];
|
||||||
|
net.minecraft.server.ItemStack current = getEquipment(i);
|
||||||
|
if (current == null)
|
||||||
|
continue;
|
||||||
|
if (!net.minecraft.server.ItemStack.equals(previous, current)) {
|
||||||
|
Util.sendPacketNearby(getBukkitEntity().getLocation(), new Packet5EntityEquipment(id, i,
|
||||||
|
current));
|
||||||
|
++changes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changes > 0)
|
||||||
|
previousEquipment = Arrays.copyOf(getEquipment(), previousEquipment.length);
|
||||||
|
}
|
||||||
|
|
||||||
public static class PlayerNPC extends CraftPlayer implements NPCHolder {
|
public static class PlayerNPC extends CraftPlayer implements NPCHolder {
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
@ -25,16 +25,16 @@ public class DelayTrigger implements WaypointTrigger {
|
|||||||
return String.format("Delay for %d ticks", delay);
|
return String.format("Delay for %d ticks", delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDelay() {
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWaypointReached(NPC npc, Location waypoint) {
|
public void onWaypointReached(NPC npc, Location waypoint) {
|
||||||
if (delay > 0)
|
if (delay > 0)
|
||||||
scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider());
|
scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDelay() {
|
|
||||||
return delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduleTask(final WaypointProvider provider) {
|
private void scheduleTask(final WaypointProvider provider) {
|
||||||
provider.setPaused(true);
|
provider.setPaused(true);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@ -68,7 +68,7 @@ public class NMS {
|
|||||||
return;
|
return;
|
||||||
if (remove) {
|
if (remove) {
|
||||||
handle.world.players.remove(handle);
|
handle.world.players.remove(handle);
|
||||||
} else {
|
} else if (!handle.world.players.contains(handle)) {
|
||||||
handle.world.players.add(handle);
|
handle.world.players.add(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,10 @@ public class Util {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendPacketNearby(Location location, Packet packet) {
|
||||||
|
sendPacketNearby(location, packet, 64);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendPacketNearby(Location location, Packet packet, double radius) {
|
public static void sendPacketNearby(Location location, Packet packet, double radius) {
|
||||||
radius *= radius;
|
radius *= radius;
|
||||||
final World world = location.getWorld();
|
final World world = location.getWorld();
|
||||||
|
Loading…
Reference in New Issue
Block a user