mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 02:55:45 +01:00
Backport alternative entity tracking setup to 1.13
This commit is contained in:
parent
0feb1462ef
commit
9dbe312b44
@ -34,6 +34,7 @@ import net.citizensnpcs.nms.v1_13_R2.util.PlayerControllerJump;
|
||||
import net.citizensnpcs.nms.v1_13_R2.util.PlayerControllerLook;
|
||||
import net.citizensnpcs.nms.v1_13_R2.util.PlayerControllerMove;
|
||||
import net.citizensnpcs.nms.v1_13_R2.util.PlayerNavigation;
|
||||
import net.citizensnpcs.nms.v1_13_R2.util.PlayerlistTrackerEntry;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
||||
@ -46,6 +47,7 @@ import net.minecraft.server.v1_13_R2.AttributeInstance;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.ChatComponentText;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.DataWatcher;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
@ -69,12 +71,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private PlayerControllerJump controllerJump;
|
||||
private PlayerControllerLook controllerLook;
|
||||
private PlayerControllerMove controllerMove;
|
||||
private boolean isTracked = false;
|
||||
private int jumpTicks = 0;
|
||||
private PlayerNavigation navigation;
|
||||
private final CitizensNPC npc;
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private PlayerlistTrackerEntry trackerEntry;
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -100,7 +102,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
@Override
|
||||
public boolean a(EntityPlayer entityplayer) {
|
||||
if (npc != null && !isTracked) {
|
||||
if (npc != null && trackerEntry == null) {
|
||||
return false;
|
||||
}
|
||||
return super.a(entityplayer);
|
||||
@ -232,6 +234,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
return controllerMove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataWatcher getDataWatcher() {
|
||||
if (trackerEntry != null && trackerEntry.isUpdating()) {
|
||||
trackerEntry.updateLastPlayer();
|
||||
}
|
||||
return super.getDataWatcher();
|
||||
}
|
||||
|
||||
public NavigationAbstract getNavigation() {
|
||||
return navigation;
|
||||
}
|
||||
@ -382,8 +392,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||
}
|
||||
|
||||
public void setTracked() {
|
||||
isTracked = true;
|
||||
public void setTracked(PlayerlistTrackerEntry trackerEntry) {
|
||||
this.trackerEntry = trackerEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -950,7 +950,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
||||
((EntityHumanNPC) getHandle(player)).setTracked(replace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,16 +2,20 @@ package net.citizensnpcs.nms.v1_13_R2.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R2.EntityTrackerEntry;
|
||||
|
||||
public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
private EntityPlayer lastUpdatedPlayer;
|
||||
|
||||
public PlayerlistTrackerEntry(Entity entity, int i, int j, int k, boolean flag) {
|
||||
super(entity, i, j, k, flag);
|
||||
}
|
||||
@ -20,53 +24,35 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
this(getTracker(entry), getE(entry), getF(entry), getG(entry), getU(entry));
|
||||
}
|
||||
|
||||
public boolean isUpdating() {
|
||||
return lastUpdatedPlayer != null;
|
||||
}
|
||||
|
||||
public void updateLastPlayer() {
|
||||
if (lastUpdatedPlayer == null)
|
||||
return;
|
||||
Entity tracker = getTracker(this);
|
||||
final EntityPlayer entityplayer = lastUpdatedPlayer;
|
||||
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
lastUpdatedPlayer = null;
|
||||
if (!Setting.DISABLE_TABLIST.asBoolean())
|
||||
return;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePlayer(final EntityPlayer entityplayer) {
|
||||
// prevent updates to NPC "viewers"
|
||||
if (entityplayer instanceof EntityHumanNPC)
|
||||
return;
|
||||
Entity tracker = getTracker(this);
|
||||
if (entityplayer != tracker && c(entityplayer)) {
|
||||
if (!this.trackedPlayers.contains(entityplayer) && ((entityplayer.getWorldServer().getPlayerChunkMap()
|
||||
.a(entityplayer, getChunkX(tracker), getChunkZ(tracker))) || (tracker.attachedToPlayer))) {
|
||||
if ((tracker instanceof SkinnableEntity)) {
|
||||
SkinnableEntity skinnable = (SkinnableEntity) tracker;
|
||||
|
||||
Player player = skinnable.getBukkitEntity();
|
||||
if (!entityplayer.getBukkitEntity().canSee(player))
|
||||
return;
|
||||
|
||||
skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
lastUpdatedPlayer = entityplayer;
|
||||
super.updatePlayer(entityplayer);
|
||||
}
|
||||
|
||||
private static int getChunkX(Entity tracker) {
|
||||
try {
|
||||
return tracker.chunkX;
|
||||
} catch (NoSuchFieldError ex) {
|
||||
try {
|
||||
return CHUNK_X.getInt(tracker);
|
||||
} catch (Exception ex2) {
|
||||
ex2.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getChunkZ(Entity tracker) {
|
||||
try {
|
||||
return tracker.chunkZ;
|
||||
} catch (NoSuchFieldError ex) {
|
||||
try {
|
||||
return CHUNK_Z.getInt(tracker);
|
||||
} catch (Exception ex2) {
|
||||
ex2.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
lastUpdatedPlayer = null;
|
||||
}
|
||||
|
||||
private static int getE(EntityTrackerEntry entry) {
|
||||
@ -124,8 +110,6 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Field CHUNK_X = NMS.getField(Entity.class, "ae", false);
|
||||
private static Field CHUNK_Z = NMS.getField(Entity.class, "ag", false);
|
||||
private static Field E = NMS.getField(EntityTrackerEntry.class, "e");
|
||||
private static Field F = NMS.getField(EntityTrackerEntry.class, "f");
|
||||
private static Field G = NMS.getField(EntityTrackerEntry.class, "g");
|
||||
|
Loading…
Reference in New Issue
Block a user