Implement metadata

This commit is contained in:
fullwall 2022-12-19 00:36:53 +08:00
parent e90096eebe
commit 8d202aa988
22 changed files with 181 additions and 23 deletions

View File

@ -154,6 +154,23 @@ public class NPCCommands {
history = new CommandHistory(selector);
}
@Command(
aliases = { "npc" },
usage = "activationrange [range]",
desc = "Sets the activation range",
modifiers = { "activationrange" },
min = 1,
max = 2,
permission = "citizens.npc.activationrange")
public void activationrange(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Integer range) {
if (range == null) {
npc.data().remove(NPC.Metadata.ACTIVATION_RANGE);
} else {
npc.data().setPersistent(NPC.Metadata.ACTIVATION_RANGE, range);
}
Messaging.sendTr(sender, Messages.ACTIVATION_RANGE_SET, range);
}
@Command(
aliases = { "npc" },
usage = "age [age] (-l(ock))",
@ -2851,6 +2868,23 @@ public class NPCCommands {
Messaging.sendTr(sender, Messages.TPTO_SUCCESS);
}
@Command(
aliases = { "npc" },
usage = "trackingrange [range]",
desc = "Sets the tracking range",
modifiers = { "trackingrange" },
min = 1,
max = 2,
permission = "citizens.npc.trackingrange")
public void trackingrange(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Integer range) {
if (range == null) {
npc.data().remove(NPC.Metadata.TRACKING_RANGE);
} else {
npc.data().setPersistent(NPC.Metadata.TRACKING_RANGE, range);
}
Messaging.sendTr(sender, Messages.TRACKING_RANGE_SET, range);
}
@Command(
aliases = { "npc" },
usage = "type [type]",

View File

@ -430,11 +430,20 @@ public class CitizensNPC extends AbstractNPC {
resetCachedCoord();
return;
}
if (data().has(NPC.Metadata.ACTIVATION_RANGE)) {
int range = data().get(NPC.Metadata.ACTIVATION_RANGE);
if (range == -1 || CitizensAPI.getLocationLookup().getNearbyPlayers(getStoredLocation(), range)
.iterator().hasNext()) {
NMS.activate(getEntity());
}
}
if (navigator.isNavigating()) {
if (data().get(NPC.Metadata.SWIMMING, true)) {
Location currentDest = navigator.getPathStrategy().getCurrentDestination();
if (currentDest == null || currentDest.getY() > getStoredLocation().getY()) {
NMS.trySwim(getEntity(), SwimmingExaminer.isWaterMob(getEntity()) ? 0.02F : 0.04F);
NMS.trySwim(getEntity());
}
}
} else if (data().<Boolean> get(NPC.Metadata.SWIMMING, !SwimmingExaminer.isWaterMob(getEntity()))) {
@ -443,6 +452,7 @@ public class CitizensNPC extends AbstractNPC {
NMS.trySwim(getEntity());
}
}
navigator.run();
if (SUPPORT_GLOWING) {
try {

View File

@ -1,6 +1,7 @@
package net.citizensnpcs.util;
public class Messages {
public static final String ACTIVATION_RANGE_SET = "citizens.commands.npc.activationrange.set";
public static final String ADDED_SCOREBOARD_TAGS = "citizens.commands.npc.scoreboard.added-tags";
public static final String ADDED_TO_PLAYERLIST = "citizens.commands.npc.playerlist.added";
public static final String AGE_LOCKED = "citizens.commands.npc.age.locked";
@ -368,6 +369,7 @@ public class Messages {
public static final String TOGGLED_USING_HELD_ITEM = "citizens.commands.npc.useitem.held-item-toggled";
public static final String TOGGLED_USING_OFFHAND_ITEM = "citizens.commands.npc.useitem.offhand-item-toggled";
public static final String TPTO_SUCCESS = "citizens.commands.npc.tpto.success";
public static final String TRACKING_RANGE_SET = "citizens.commands.npc.trackingdistance.set";
public static final String TRAIT_LOAD_FAILED = "citizens.notifications.trait-load-failed";
public static final String TRAIT_NOT_CONFIGURABLE = "citizens.commands.traitc.not-configurable";
public static final String TRAIT_NOT_FOUND = "citizens.commands.traitc.missing";

View File

@ -31,6 +31,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.jnbt.CompoundTag;
@ -50,6 +51,10 @@ public class NMS {
// util class
}
public static void activate(Entity entity) {
BRIDGE.activate(entity);
}
public static boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {
return BRIDGE.addEntityToWorld(entity, custom);
}
@ -649,7 +654,7 @@ public class NMS {
}
public static void trySwim(org.bukkit.entity.Entity entity) {
BRIDGE.trySwim(entity);
trySwim(entity, SwimmingExaminer.isWaterMob(entity) ? 0.02F : 0.04F);
}
public static void trySwim(org.bukkit.entity.Entity entity, float power) {

View File

@ -40,6 +40,9 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
public interface NMSBridge {
default void activate(Entity entity) {
};
public boolean addEntityToWorld(Entity entity, SpawnReason custom);
public void addOrRemoveFromPlayerList(Entity entity, boolean remove);
@ -146,11 +149,11 @@ public interface NMSBridge {
public void sendTabListRemove(Player recipient, Player listPlayer);
public void sendTeamPacket(Player recipient, Team team, int mode);
public void sendTeamPacket(Player recipient, Team team, int mode);;
public default void setAllayDancing(Entity entity, boolean dancing) {
throw new UnsupportedOperationException();
};
}
public void setBodyYaw(Entity entity, float yaw);
@ -166,15 +169,15 @@ public interface NMSBridge {
public void setHeadYaw(Entity entity, float yaw);
public void setKnockbackResistance(LivingEntity entity, double d);
public void setKnockbackResistance(LivingEntity entity, double d);;
public default void setLyingDown(Entity cat, boolean lying) {
throw new UnsupportedOperationException();
};
}
public void setNavigationTarget(Entity handle, Entity target, float speed);
public void setNoGravity(Entity entity, boolean nogravity);
public void setNoGravity(Entity entity, boolean nogravity);;
public default void setPandaSitting(Entity entity, boolean sitting) {
throw new UnsupportedOperationException();
@ -186,13 +189,13 @@ public interface NMSBridge {
public default void setPiglinDancing(Entity entity, boolean dancing) {
throw new UnsupportedOperationException();
};
}
public void setPitch(Entity entity, float pitch);
public void setPitch(Entity entity, float pitch);;
public default void setPolarBearRearing(Entity entity, boolean rearing) {
throw new UnsupportedOperationException();
};
}
public void setProfile(SkullMeta meta, GameProfile profile);
@ -228,5 +231,5 @@ public interface NMSBridge {
public void updateNavigationWorld(Entity entity, World world);
public void updatePathfindingRange(NPC npc, float pathfindingRange);;
public void updatePathfindingRange(NPC npc, float pathfindingRange);
}

View File

@ -9,6 +9,7 @@ citizens.commands.id-not-found=Couldn''t find any NPC with ID [[{0}]].
citizens.commands.invalid.class=Invalid external commands class.
citizens.commands.invalid-mobtype=[[{0}]] is not a valid mobtype.
citizens.commands.invalid-number=That is not a valid number.
citizens.commands.npc.activationrange.set=Activation range set to [[{0}]].
citizens.commands.npc.ai.started=Now using Minecraft AI.
citizens.commands.npc.ai.stopped=No longer using Minecraft AI.
citizens.commands.npc.allay.dancing-set=[[{0}]] is now dancing.
@ -270,6 +271,7 @@ citizens.commands.npc.tpto.to-not-found=Destination entity not found.
citizens.commands.npc.tpto.from-not-found=Source entity not found.
citizens.commands.npc.tphere.missing-cursor-block=Please look at a block to teleport to.
citizens.commands.npc.tphere.teleported=[[{0}]] was teleported to {1}.
citizens.commands.npc.trackingdistance.set=Tracking range set to [[{0}]].
citizens.commands.npc.type.set=[[{0}]]''s type set to [[{1}]].
citizens.commands.npc.type.invalid=[[{0}]] is not a valid type.
citizens.commands.npc.useitem.held-item-toggled=Using held item set to [[{0}]].

View File

@ -4,7 +4,9 @@ import java.lang.reflect.Field;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_10_R1.Entity;
@ -47,6 +49,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
private static int getE(EntityTrackerEntry entry) {
try {
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) E.get(entry));
}
return (Integer) E.get(entry);
} catch (IllegalArgumentException e) {
e.printStackTrace();

View File

@ -4,7 +4,9 @@ import java.lang.reflect.Field;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_11_R1.Entity;
@ -46,6 +48,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
private static int getE(EntityTrackerEntry entry) {
try {
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) E.get(entry));
}
return (Integer) E.get(entry);
} catch (IllegalArgumentException e) {
e.printStackTrace();

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityPlayer;
@ -57,6 +59,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
private static int getE(EntityTrackerEntry entry) {
try {
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) E.get(entry));
}
return (Integer) E.get(entry);
} catch (IllegalArgumentException e) {
e.printStackTrace();

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_13_R2.Entity;
import net.minecraft.server.v1_13_R2.EntityPlayer;
@ -57,6 +59,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
private static int getE(EntityTrackerEntry entry) {
try {
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) E.get(entry));
}
return (Integer) E.get(entry);
} catch (IllegalArgumentException e) {
e.printStackTrace();

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityPlayer;
@ -81,7 +83,12 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static int getTrackingDistance(EntityTracker entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -92,5 +99,5 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static final MethodHandle E = NMS.getGetter(EntityTrackerEntry.class, "e");
private static final MethodHandle TRACKER = NMS.getGetter(EntityTracker.class, "tracker");
private static final MethodHandle TRACKER_ENTRY = NMS.getGetter(EntityTracker.class, "trackerEntry");
private static final MethodHandle TRACKING_DISTANCE = NMS.getGetter(EntityTracker.class, "trackingDistance");
private static final MethodHandle TRACKING_RANGE = NMS.getGetter(EntityTracker.class, "trackingDistance");
}

View File

@ -281,6 +281,7 @@ import net.minecraft.server.v1_15_R1.IInventory;
import net.minecraft.server.v1_15_R1.IRegistry;
import net.minecraft.server.v1_15_R1.MathHelper;
import net.minecraft.server.v1_15_R1.MinecraftKey;
import net.minecraft.server.v1_15_R1.MinecraftServer;
import net.minecraft.server.v1_15_R1.MobEffects;
import net.minecraft.server.v1_15_R1.NavigationAbstract;
import net.minecraft.server.v1_15_R1.NetworkManager;
@ -311,6 +312,11 @@ public class NMSImpl implements NMSBridge {
loadEntityTypes();
}
@Override
public void activate(org.bukkit.entity.Entity entity) {
getHandle(entity).activatedTick = MinecraftServer.currentTick;
}
@SuppressWarnings("resource")
@Override
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityPlayer;
@ -81,7 +83,12 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static int getTrackingDistance(EntityTracker entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -92,5 +99,5 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static final MethodHandle E = NMS.getGetter(EntityTrackerEntry.class, "e");
private static final MethodHandle TRACKER = NMS.getGetter(EntityTracker.class, "tracker");
private static final MethodHandle TRACKER_ENTRY = NMS.getGetter(EntityTracker.class, "trackerEntry");
private static final MethodHandle TRACKING_DISTANCE = NMS.getGetter(EntityTracker.class, "trackingDistance");
private static final MethodHandle TRACKING_RANGE = NMS.getGetter(EntityTracker.class, "trackingDistance");
}

View File

@ -290,6 +290,7 @@ import net.minecraft.server.v1_16_R3.IInventory;
import net.minecraft.server.v1_16_R3.IRegistry;
import net.minecraft.server.v1_16_R3.MathHelper;
import net.minecraft.server.v1_16_R3.MinecraftKey;
import net.minecraft.server.v1_16_R3.MinecraftServer;
import net.minecraft.server.v1_16_R3.MobEffects;
import net.minecraft.server.v1_16_R3.NavigationAbstract;
import net.minecraft.server.v1_16_R3.NetworkManager;
@ -321,6 +322,11 @@ public class NMSImpl implements NMSBridge {
loadEntityTypes();
}
@Override
public void activate(org.bukkit.entity.Entity entity) {
getHandle(entity).activatedTick = MinecraftServer.currentTick;
}
@SuppressWarnings("resource")
@Override
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_16_R3.Entity;
import net.minecraft.server.v1_16_R3.EntityPlayer;
@ -85,7 +87,12 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static int getTrackingDistance(EntityTracker entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -96,5 +103,5 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
private static final MethodHandle E = NMS.getGetter(EntityTrackerEntry.class, "e");
private static final MethodHandle TRACKER = NMS.getGetter(EntityTracker.class, "tracker");
private static final MethodHandle TRACKER_ENTRY = NMS.getGetter(EntityTracker.class, "trackerEntry");
private static final MethodHandle TRACKING_DISTANCE = NMS.getGetter(EntityTracker.class, "trackingDistance");
private static final MethodHandle TRACKING_RANGE = NMS.getGetter(EntityTracker.class, "trackingDistance");
}

View File

@ -250,6 +250,7 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ChunkMap.TrackedEntity;
@ -321,6 +322,11 @@ public class NMSImpl implements NMSBridge {
loadEntityTypes();
}
@Override
public void activate(org.bukkit.entity.Entity entity) {
getHandle(entity).activatedTick = MinecraftServer.currentTick;
}
@SuppressWarnings("resource")
@Override
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ChunkMap;
@ -85,7 +87,12 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static int getTrackingDistance(TrackedEntity entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -96,5 +103,5 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static final MethodHandle F = NMS.getGetter(ServerEntity.class, "f");
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
private static final MethodHandle TRACKING_DISTANCE = NMS.getFirstGetter(TrackedEntity.class, int.class);
private static final MethodHandle TRACKING_RANGE = NMS.getFirstGetter(TrackedEntity.class, int.class);
}

View File

@ -252,6 +252,7 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ChunkMap.TrackedEntity;
@ -326,6 +327,11 @@ public class NMSImpl implements NMSBridge {
loadEntityTypes();
}
@Override
public void activate(org.bukkit.entity.Entity entity) {
getHandle(entity).activatedTick = MinecraftServer.currentTick;
}
@SuppressWarnings("resource")
@Override
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ChunkMap;
@ -85,7 +87,12 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static int getTrackingDistance(TrackedEntity entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -96,5 +103,5 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static final MethodHandle F = NMS.getGetter(ServerEntity.class, "f");
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
private static final MethodHandle TRACKING_DISTANCE = NMS.getFirstGetter(TrackedEntity.class, int.class);
private static final MethodHandle TRACKING_RANGE = NMS.getFirstGetter(TrackedEntity.class, int.class);
}

View File

@ -268,6 +268,7 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ChunkMap.TrackedEntity;
@ -344,6 +345,11 @@ public class NMSImpl implements NMSBridge {
loadEntityTypes();
}
@Override
public void activate(org.bukkit.entity.Entity entity) {
getHandle(entity).activatedTick = MinecraftServer.currentTick;
}
@SuppressWarnings("resource")
@Override
public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_19_R2.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ChunkMap;
@ -91,7 +93,12 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static int getTrackingDistance(TrackedEntity entry) {
try {
return (Integer) TRACKING_DISTANCE.invoke(entry);
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE,
(Integer) TRACKING_RANGE.invoke(entry));
}
return (Integer) TRACKING_RANGE.invoke(entry);
} catch (Throwable e) {
e.printStackTrace();
}
@ -102,5 +109,5 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
private static final MethodHandle F = NMS.getGetter(ServerEntity.class, "f");
private static final MethodHandle TRACKER = NMS.getFirstGetter(TrackedEntity.class, Entity.class);
private static final MethodHandle TRACKER_ENTRY = NMS.getFirstGetter(TrackedEntity.class, ServerEntity.class);
private static final MethodHandle TRACKING_DISTANCE = NMS.getFirstGetter(TrackedEntity.class, int.class);
private static final MethodHandle TRACKING_RANGE = NMS.getFirstGetter(TrackedEntity.class, int.class);
}

View File

@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityPlayer;
@ -59,6 +61,10 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
private static int getB(EntityTrackerEntry entry) {
try {
Entity entity = getTracker(entry);
if (entity instanceof NPCHolder) {
return ((NPCHolder) entity).getNPC().data().get(NPC.Metadata.TRACKING_RANGE, (Integer) B.get(entry));
}
return (Integer) B.get(entry);
} catch (IllegalArgumentException e) {
e.printStackTrace();