mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Add custom holder support to CustomEntityRegistry
This commit is contained in:
parent
0a91768369
commit
ae36f4bd9f
@ -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)) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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.*?$
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user