Improve player spawn performance by moving advancement loading

This commit is contained in:
fullwall 2024-09-01 11:45:50 +08:00
parent 5e6dabe825
commit 0804f90efd
18 changed files with 85 additions and 152 deletions

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.nms.v1_13_R2.entity;
import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.util.List;
import java.util.Map;
@ -40,6 +39,7 @@ import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.SkinTrait;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R2.AdvancementDataPlayer;
import net.minecraft.server.v1_13_R2.AttributeInstance;
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
import net.minecraft.server.v1_13_R2.BlockPosition;
@ -187,6 +187,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
@Override
public AdvancementDataPlayer getAdvancementData() {
return npc == null ? super.getAdvancementData()
: new EmptyAdvancementDataPlayer(server, CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public CraftPlayer getBukkitEntity() {
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
@ -259,13 +265,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
invulnerableTicks = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
try {
ADVANCEMENT_DATA_PLAYER.invoke(this,
new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
} catch (Throwable e) {
e.printStackTrace();
}
}
@Override
@ -528,7 +527,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
private static MethodHandle ADVANCEMENT_DATA_PLAYER = NMS.getFinalSetter(EntityPlayer.class, "cf");
private static final float EPSILON = 0.005F;
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
}

View File

@ -40,6 +40,7 @@ import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.SkinTrait;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_14_R1.AdvancementDataPlayer;
import net.minecraft.server.v1_14_R1.AttributeInstance;
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
import net.minecraft.server.v1_14_R1.BlockPosition;
@ -178,6 +179,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
@Override
public AdvancementDataPlayer getAdvancementData() {
return npc == null ? super.getAdvancementData()
: new EmptyAdvancementDataPlayer(getMinecraftServer(), CitizensAPI.getDataFolder().getParentFile(),
this);
}
@Override
public CraftPlayer getBukkitEntity() {
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
@ -260,9 +268,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
invulnerableTicks = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -215,7 +215,6 @@ import net.citizensnpcs.util.NMS.MinecraftNavigationType;
import net.citizensnpcs.util.NMSBridge;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_14_R1.AdvancementDataPlayer;
import net.minecraft.server.v1_14_R1.AttributeInstance;
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
import net.minecraft.server.v1_14_R1.BehaviorController;
@ -2108,14 +2107,6 @@ public class NMSImpl implements NMSBridge {
NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}
public static void setAdvancement(Player entity, AdvancementDataPlayer instance) {
try {
ADVANCEMENT_PLAYER_FIELD.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setBukkitEntity(Entity entity, CraftEntity bukkitEntity) {
try {
BUKKITENTITY_FIELD_SETTER.invoke(entity, bukkitEntity);
@ -2189,14 +2180,10 @@ public class NMSImpl implements NMSBridge {
navigation.c();
}
private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class,
"advancementDataPlayer");
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST, EntityType.SHULKER,
EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "c");
private static final MethodHandle BLOCK_POSITION_B_D = NMS.getMethodHandle(BlockPosition.PooledBlockPosition.class,
"c", false, double.class, double.class, double.class);

View File

@ -39,6 +39,7 @@ import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.SkinTrait;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_15_R1.AdvancementDataPlayer;
import net.minecraft.server.v1_15_R1.AttributeInstance;
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
import net.minecraft.server.v1_15_R1.BlockPosition;
@ -170,6 +171,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
@Override
public AdvancementDataPlayer getAdvancementData() {
return npc == null ? super.getAdvancementData()
: new EmptyAdvancementDataPlayer(getMinecraftServer(), CitizensAPI.getDataFolder().getParentFile(),
this);
}
@Override
public CraftPlayer getBukkitEntity() {
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
@ -261,9 +269,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
invulnerableTicks = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -217,7 +217,6 @@ import net.citizensnpcs.util.NMS.MinecraftNavigationType;
import net.citizensnpcs.util.NMSBridge;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_15_R1.AdvancementDataPlayer;
import net.minecraft.server.v1_15_R1.AttributeInstance;
import net.minecraft.server.v1_15_R1.AxisAlignedBB;
import net.minecraft.server.v1_15_R1.BehaviorController;
@ -2172,14 +2171,6 @@ public class NMSImpl implements NMSBridge {
NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}
public static void setAdvancement(Player entity, AdvancementDataPlayer instance) {
try {
ADVANCEMENT_PLAYER_FIELD.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setBukkitEntity(Entity entity, CraftEntity bukkitEntity) {
try {
BUKKITENTITY_FIELD_SETTER.invoke(entity, bukkitEntity);
@ -2273,14 +2264,10 @@ public class NMSImpl implements NMSBridge {
navigation.c();
}
private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class,
"advancementDataPlayer");
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE,
EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT,
EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "c");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",

View File

@ -39,6 +39,7 @@ import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.SkinTrait;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.AdvancementDataPlayer;
import net.minecraft.server.v1_16_R3.AxisAlignedBB;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.ChatComponentText;
@ -156,6 +157,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
@Override
public AdvancementDataPlayer getAdvancementData() {
return npc == null ? super.getAdvancementData()
: new EmptyAdvancementDataPlayer(getMinecraftServer().getDataFixer(),
getMinecraftServer().getPlayerList(), getMinecraftServer().getAdvancementData(),
CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -231,10 +240,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
invulnerableTicks = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getDataFixer(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancementData(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -224,7 +224,6 @@ import net.citizensnpcs.util.NMS.MinecraftNavigationType;
import net.citizensnpcs.util.NMSBridge;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.AdvancementDataPlayer;
import net.minecraft.server.v1_16_R3.AttributeBase;
import net.minecraft.server.v1_16_R3.AttributeMapBase;
import net.minecraft.server.v1_16_R3.AttributeModifiable;
@ -2166,14 +2165,6 @@ public class NMSImpl implements NMSBridge {
NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}
public static void setAdvancement(Player entity, AdvancementDataPlayer instance) {
try {
ADVANCEMENT_PLAYER_FIELD.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(EntityLiving entity, AttributeBase attribute, double value) {
AttributeModifiable range = entity.getAttributeInstance(attribute);
if (range == null) {
@ -2296,11 +2287,7 @@ public class NMSImpl implements NMSBridge {
navigation.c();
}
private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class,
"advancementDataPlayer");
private static final MethodHandle ATTRIBUTE_MAP = NMS.getGetter(AttributeMapBase.class, "d");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getGetter(AttributeProvider.class, "a");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFinalSetter(AttributeProvider.class, "a");
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE,

View File

@ -42,6 +42,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
@ -165,6 +166,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public PlayerAdvancements getAdvancements() {
return npc == null ? super.getAdvancements()
: new EmptyAdvancementDataPlayer(getServer().getFixerUpper(), getServer().getPlayerList(),
getServer().getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -250,10 +258,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.invulnerableTime = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -241,7 +241,6 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
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;
import net.minecraft.server.level.ServerBossEvent;
@ -2150,14 +2149,6 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
try {
ADVANCEMENTS_PLAYER_FIELD.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(LivingEntity entity, Attribute attribute, double value) {
AttributeInstance attr = entity.getAttribute(attribute);
if (attr == null) {
@ -2281,10 +2272,7 @@ public class NMSImpl implements NMSBridge {
}
}
private static final MethodHandle ADVANCEMENTS_PLAYER_FIELD = NMS.getFinalSetter(ServerPlayer.class, "cr");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFinalSetter(AttributeSupplier.class, "a");
private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class,
AttributeSupplier.class);

View File

@ -43,6 +43,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
@ -166,6 +167,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public PlayerAdvancements getAdvancements() {
return npc == null ? super.getAdvancements()
: new EmptyAdvancementDataPlayer(getServer().getFixerUpper(), getServer().getPlayerList(),
getServer().getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -250,10 +258,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.invulnerableTime = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -242,7 +242,6 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
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;
import net.minecraft.server.level.ServerBossEvent;
@ -2159,14 +2158,6 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
try {
ADVANCEMENTS_PLAYER_FIELD.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(LivingEntity entity, Attribute attribute, double value) {
AttributeInstance attr = entity.getAttribute(attribute);
if (attr == null) {
@ -2325,22 +2316,15 @@ public class NMSImpl implements NMSBridge {
}
}
private static final MethodHandle ADVANCEMENTS_PLAYER_FIELD = NMS.getFinalSetter(ServerPlayer.class, "cr");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFinalSetter(AttributeSupplier.class, "a");
private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class,
AttributeSupplier.class);
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE,
EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT,
EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST,
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_TREE_MAP = NMS.getGetter(Brain.class, "f");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(ChunkMap.class, "a", true,
ServerPlayer.class, boolean.class);

View File

@ -43,6 +43,7 @@ import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
@ -58,12 +59,8 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
public class EntityHumanNPC extends ServerPlayer implements NPCHolder, SkinnableEntity, ForwardingMobAI {
@Override
public boolean broadcastToPlayer(ServerPlayer player) {
return NMS.shouldBroadcastToPlayer(npc, () -> super.broadcastToPlayer(player));
}
private MobAI ai;
private int jumpTicks = 0;
private final CitizensNPC npc;
private boolean setBukkitEntity;
@ -87,6 +84,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public boolean broadcastToPlayer(ServerPlayer player) {
return NMS.shouldBroadcastToPlayer(npc, () -> super.broadcastToPlayer(player));
}
@Override
public boolean causeFallDamage(float f, float f1, DamageSource damagesource) {
if (npc == null || !npc.isFlyable())
@ -169,6 +171,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public PlayerAdvancements getAdvancements() {
return npc == null ? super.getAdvancements()
: new EmptyAdvancementDataPlayer(getServer().getFixerUpper(), getServer().getPlayerList(),
getServer().getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -254,10 +263,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.invulnerableTime = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -277,7 +277,6 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
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;
import net.minecraft.server.level.ServerBossEvent;
@ -2390,14 +2389,6 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
try {
ADVANCEMENTS_PLAYER_SETTER.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(LivingEntity entity, Attribute attribute, double value) {
AttributeInstance attr = entity.getAttribute(attribute);
if (attr == null) {
@ -2556,9 +2547,6 @@ public class NMSImpl implements NMSBridge {
}
}
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
PlayerAdvancements.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
Map.class);

View File

@ -41,6 +41,7 @@ import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents.LiteralContents;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -58,12 +59,8 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
public class EntityHumanNPC extends ServerPlayer implements NPCHolder, SkinnableEntity, ForwardingMobAI {
@Override
public boolean broadcastToPlayer(ServerPlayer player) {
return NMS.shouldBroadcastToPlayer(npc, () -> super.broadcastToPlayer(player));
}
private MobAI ai;
private int jumpTicks = 0;
private final CitizensNPC npc;
private boolean setBukkitEntity;
@ -88,6 +85,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public boolean broadcastToPlayer(ServerPlayer player) {
return NMS.shouldBroadcastToPlayer(npc, () -> super.broadcastToPlayer(player));
}
@Override
public boolean causeFallDamage(float f, float f1, DamageSource damagesource) {
if (npc == null || !npc.isFlyable())
@ -170,6 +172,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public PlayerAdvancements getAdvancements() {
return npc == null ? super.getAdvancements()
: new EmptyAdvancementDataPlayer(getServer().getFixerUpper(), getServer().getPlayerList(),
getServer().getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -255,10 +264,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.invulnerableTime = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -280,7 +280,6 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
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;
import net.minecraft.server.level.ServerBossEvent;
@ -2398,14 +2397,6 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
try {
ADVANCEMENTS_PLAYER_SETTER.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(LivingEntity entity, Holder<Attribute> attribute, double value) {
AttributeInstance attr = entity.getAttribute(attribute);
if (attr == null) {
@ -2573,9 +2564,6 @@ public class NMSImpl implements NMSBridge {
}
}
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
PlayerAdvancements.class);
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cj");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);

View File

@ -41,6 +41,7 @@ import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents.LiteralContents;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -171,6 +172,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
}
}
@Override
public PlayerAdvancements getAdvancements() {
return npc == null ? super.getAdvancements()
: new EmptyAdvancementDataPlayer(getServer().getFixerUpper(), getServer().getPlayerList(),
getServer().getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this);
}
@Override
public MobAI getAI() {
return ai;
@ -256,10 +264,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.invulnerableTime = 0;
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
setSkinFlags((byte) 0xFF);
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
NMSImpl.setAdvancement(this.getBukkitEntity(),
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
@Override

View File

@ -21,7 +21,7 @@ public class EmptyAdvancementDataPlayer extends PlayerAdvancements {
public EmptyAdvancementDataPlayer(DataFixer datafixer, PlayerList playerlist,
ServerAdvancementManager advancementdataworld, File file, ServerPlayer entityplayer) {
super(datafixer, playerlist, advancementdataworld, CitizensAPI.getDataFolder().toPath(), entityplayer);
this.save();
save();
}
@Override

View File

@ -280,7 +280,6 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
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;
import net.minecraft.server.level.ServerBossEvent;
@ -2392,14 +2391,6 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setAdvancement(Player entity, PlayerAdvancements instance) {
try {
ADVANCEMENTS_PLAYER_SETTER.invoke(getHandle(entity), instance);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void setAttribute(LivingEntity entity, Holder<Attribute> attribute, double value) {
AttributeInstance attr = entity.getAttribute(attribute);
if (attr == null) {
@ -2555,8 +2546,6 @@ public class NMSImpl implements NMSBridge {
}
}
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
PlayerAdvancements.class);
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cn");
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,