From 0804f90efd9f8a211b7fc8851ac4196b3cbf3c10 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 1 Sep 2024 11:45:50 +0800 Subject: [PATCH] Improve player spawn performance by moving advancement loading --- .../nms/v1_13_R2/entity/EntityHumanNPC.java | 16 ++++++------- .../nms/v1_14_R1/entity/EntityHumanNPC.java | 11 ++++++--- .../nms/v1_14_R1/util/NMSImpl.java | 13 ----------- .../nms/v1_15_R1/entity/EntityHumanNPC.java | 11 ++++++--- .../nms/v1_15_R1/util/NMSImpl.java | 13 ----------- .../nms/v1_16_R3/entity/EntityHumanNPC.java | 13 +++++++---- .../nms/v1_16_R3/util/NMSImpl.java | 13 ----------- .../nms/v1_17_R1/entity/EntityHumanNPC.java | 12 ++++++---- .../nms/v1_17_R1/util/NMSImpl.java | 12 ---------- .../nms/v1_18_R2/entity/EntityHumanNPC.java | 12 ++++++---- .../nms/v1_18_R2/util/NMSImpl.java | 16 ------------- .../nms/v1_19_R3/entity/EntityHumanNPC.java | 23 +++++++++++-------- .../nms/v1_19_R3/util/NMSImpl.java | 12 ---------- .../nms/v1_20_R4/entity/EntityHumanNPC.java | 23 +++++++++++-------- .../nms/v1_20_R4/util/NMSImpl.java | 12 ---------- .../nms/v1_21_R1/entity/EntityHumanNPC.java | 12 ++++++---- .../util/EmptyAdvancementDataPlayer.java | 2 +- .../nms/v1_21_R1/util/NMSImpl.java | 11 --------- 18 files changed, 85 insertions(+), 152 deletions(-) diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java index 90d6409fd..15cee872c 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java @@ -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); } diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java index b4e61db56..76a9f4116 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index a5b5b2be2..237ecc582 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -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 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); diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java index 8ac4040cc..9aae90c7b 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 494ba9140..e3ba20ae3 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -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 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", diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java index c7731a720..0185a0056 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index db7cbe20a..b1d11ac00 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -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 BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE, diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java index 88d1b1179..36ffeb53b 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index c6e54ecc8..151b2c3d2 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -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); diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java index b2e43cb2e..823bb96f1 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index e39def2d3..fa8504000 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -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 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); diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/entity/EntityHumanNPC.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/entity/EntityHumanNPC.java index f459dce1d..0cb53c3c5 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/entity/EntityHumanNPC.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java index f2225cce5..a7226f547 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java @@ -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); diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/entity/EntityHumanNPC.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/entity/EntityHumanNPC.java index f94b3efe3..c8c0db951 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/entity/EntityHumanNPC.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java index 98d49ae98..47118a535 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java @@ -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, 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); diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java index 970f2a5a7..b3a13e37f 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java @@ -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 diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EmptyAdvancementDataPlayer.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EmptyAdvancementDataPlayer.java index 9ac2a03a6..3935e5b8d 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EmptyAdvancementDataPlayer.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EmptyAdvancementDataPlayer.java @@ -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 diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java index 1617b8100..7348d008b 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java @@ -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, 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,