Add custom holder support to CustomEntityRegistry

This commit is contained in:
fullwall 2022-03-04 20:23:59 +08:00
parent 0a91768369
commit ae36f4bd9f
4 changed files with 13 additions and 9 deletions

View File

@ -326,9 +326,6 @@ public class CitizensNPC extends AbstractNPC {
if (getEntity() instanceof Player) {
NMS.replaceTrackerEntry((Player) getEntity());
PlayerUpdateTask.registerPlayer(getEntity());
if (!hasTrait(SneakTrait.class)) {
addTrait(SneakTrait.class);
}
}
}
@ -408,6 +405,9 @@ public class CitizensNPC extends AbstractNPC {
if (isLiving && getEntity() instanceof Player) {
updateUsingItemState((Player) getEntity());
if (data().has(NPC.Metadata.SNEAKING) && !hasTrait(SneakTrait.class)) {
addTrait(SneakTrait.class);
}
}
if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) {

View File

@ -16,7 +16,9 @@ public class SneakTrait extends Trait {
}
private void apply() {
NMS.setSneaking(npc.getEntity(), sneaking);
if (npc.isSpawned()) {
NMS.setSneaking(npc.getEntity(), sneaking);
}
}
@Override
@ -34,8 +36,6 @@ public class SneakTrait extends Trait {
public void setSneaking(boolean sneak) {
this.sneaking = sneak;
if (npc.isSpawned()) {
apply();
}
apply();
}
}

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
@ -143,7 +144,8 @@ public class CustomEntityRegistry extends DefaultedRegistry {
public CustomEntityRegistry(DefaultedRegistry<EntityType<?>> original) throws Throwable {
super(original.getDefaultKey().getNamespace(),
(ResourceKey<Registry<EntityType<?>>>) IREGISTRY_RESOURCE_KEY.invoke(original),
(Lifecycle) IREGISTRY_LIFECYCLE.invoke(original), null);
(Lifecycle) IREGISTRY_LIFECYCLE.invoke(original),
(Function) IREGISTRY_CUSTOM_HOLDER_PROVDER.invoke(original));
this.wrapped = original;
}
@ -224,6 +226,8 @@ public class CustomEntityRegistry extends DefaultedRegistry {
entityIds.put(entityClass, entityId);
}
private static final MethodHandle IREGISTRY_CUSTOM_HOLDER_PROVDER = NMS.getFirstGetter(MappedRegistry.class,
Function.class);
private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class);
// replace regex
// .*?> ([A-Z_]+).*?of\((.*?)::new.*?$

View File

@ -147,7 +147,7 @@ public class PlayerNavigation extends PathNavigation {
}
return true;
}
private boolean canWalkOn(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7,
double var9) {
int var11 = var0 - var3 / 2;