Make custom entity registry forcibly unfrozen as suggested in #2947

This commit is contained in:
fullwall 2022-12-16 20:44:26 +08:00
parent 8f29e6ff73
commit d44cebdcfd
2 changed files with 9 additions and 10 deletions

View File

@ -152,7 +152,7 @@ public class CustomEntityRegistry extends DefaultedMappedRegistry {
public CustomEntityRegistry(DefaultedRegistry<EntityType<?>> original) throws Throwable {
super(original.getDefaultKey().getNamespace(),
(ResourceKey<Registry<EntityType<?>>>) IREGISTRY_RESOURCE_KEY.invoke(original),
(Lifecycle) IREGISTRY_LIFECYCLE.invoke(original), IREGISTRY_HOLDER_PROVDER.invoke(original) != null);
(Lifecycle) IREGISTRY_LIFECYCLE.invoke(original), true);
this.wrapped = (MappedRegistry<EntityType<?>>) original;
}
@ -303,7 +303,6 @@ public class CustomEntityRegistry extends DefaultedMappedRegistry {
return wrapped.size();
}
private static final MethodHandle IREGISTRY_HOLDER_PROVDER = NMS.getGetter(MappedRegistry.class, "m");
private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(MappedRegistry.class, Lifecycle.class);
// replace regex .*?> ([A-Z_]+).*?of\((.*?)::new.*?$ minecraftClassMap.put(EntityType.\1, \2.class);
private static final MethodHandle IREGISTRY_RESOURCE_KEY = NMS.getFirstGetter(MappedRegistry.class,

View File

@ -1209,19 +1209,19 @@ public class NMSImpl implements NMSBridge {
Preconditions.checkNotNull(recipient);
Preconditions.checkNotNull(listPlayer);
ServerPlayer entity = ((CraftPlayer) listPlayer).getHandle();
ServerPlayer from = ((CraftPlayer) listPlayer).getHandle();
ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket
.createPlayerInitializing(Arrays.asList(entity));
.createPlayerInitializing(Arrays.asList(from));
boolean list = entity instanceof NPCHolder
? !((NPCHolder) entity).getNPC().data().get("removefromtablist", Setting.DISABLE_TABLIST.asBoolean())
boolean list = from instanceof NPCHolder
? !((NPCHolder) from).getNPC().data().get("removefromtablist", Setting.DISABLE_TABLIST.asBoolean())
: false;
ClientboundPlayerInfoUpdatePacket.Entry entry = new ClientboundPlayerInfoUpdatePacket.Entry(entity.getUUID(),
entity.getGameProfile(), list, entity.latency, entity.gameMode.getGameModeForPlayer(),
!list ? Component.empty() : entity.getTabListDisplayName(),
entity.getChatSession() == null ? null : entity.getChatSession().asData());
ClientboundPlayerInfoUpdatePacket.Entry entry = new ClientboundPlayerInfoUpdatePacket.Entry(from.getUUID(),
from.getGameProfile(), list, from.latency, from.gameMode.getGameModeForPlayer(),
list ? from.getTabListDisplayName() : Component.empty(),
from.getChatSession() == null ? null : from.getChatSession().asData());
try {
PLAYERINFO_ENTRIES.invoke(packet, Lists.newArrayList(entry));