mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Use onPreSpawn event to avoid 'FOUC' in armorstands. Fix invulnerable ticks being reduced too quickly.
This commit is contained in:
parent
620cda6542
commit
3d3de6576d
@ -255,6 +255,16 @@ public class CitizensNPC extends AbstractNPC {
|
||||
entityController.spawn(at.clone(), this);
|
||||
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
|
||||
|
||||
Collection<Trait> onPreSpawn = traits.values();
|
||||
for (Trait trait : onPreSpawn.toArray(new Trait[onPreSpawn.size()])) {
|
||||
try {
|
||||
trait.onPreSpawn();
|
||||
} catch (Throwable ex) {
|
||||
Messaging.severeTr(Messages.TRAIT_ONSPAWN_FAILED, trait.getName(), getId());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
boolean loaded = Util.isLoaded(at);
|
||||
boolean couldSpawn = !loaded ? false : NMS.addEntityToWorld(getEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
@ -294,10 +304,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
navigator.onSpawn();
|
||||
|
||||
// Modify NPC using traits after the entity has been created
|
||||
Collection<Trait> onSpawn = traits.values();
|
||||
|
||||
// work around traits modifying the map during this iteration.
|
||||
for (Trait trait : onSpawn.toArray(new Trait[onSpawn.size()])) {
|
||||
try {
|
||||
trait.onSpawn();
|
||||
|
@ -65,54 +65,59 @@ public class ArmorStandTrait extends Trait {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreSpawn() {
|
||||
onSpawn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (npc.getEntity() instanceof ArmorStand) {
|
||||
ArmorStand entity = (ArmorStand) npc.getEntity();
|
||||
if (leftArm != null) {
|
||||
entity.setLeftArmPose(leftArm);
|
||||
}
|
||||
if (leftLeg != null) {
|
||||
entity.setLeftLegPose(leftLeg);
|
||||
}
|
||||
if (rightArm != null) {
|
||||
entity.setRightArmPose(rightArm);
|
||||
}
|
||||
if (rightLeg != null) {
|
||||
entity.setRightLegPose(rightLeg);
|
||||
}
|
||||
if (body != null) {
|
||||
entity.setBodyPose(body);
|
||||
}
|
||||
if (head != null) {
|
||||
entity.setHeadPose(head);
|
||||
}
|
||||
entity.setVisible(visible);
|
||||
entity.setGravity(gravity);
|
||||
entity.setArms(hasarms);
|
||||
entity.setBasePlate(hasbaseplate);
|
||||
entity.setSmall(small);
|
||||
entity.setMarker(marker);
|
||||
if (!(npc.getEntity() instanceof ArmorStand))
|
||||
return;
|
||||
ArmorStand entity = (ArmorStand) npc.getEntity();
|
||||
if (leftArm != null) {
|
||||
entity.setLeftArmPose(leftArm);
|
||||
}
|
||||
if (leftLeg != null) {
|
||||
entity.setLeftLegPose(leftLeg);
|
||||
}
|
||||
if (rightArm != null) {
|
||||
entity.setRightArmPose(rightArm);
|
||||
}
|
||||
if (rightLeg != null) {
|
||||
entity.setRightLegPose(rightLeg);
|
||||
}
|
||||
if (body != null) {
|
||||
entity.setBodyPose(body);
|
||||
}
|
||||
if (head != null) {
|
||||
entity.setHeadPose(head);
|
||||
}
|
||||
entity.setVisible(visible);
|
||||
entity.setGravity(gravity);
|
||||
entity.setArms(hasarms);
|
||||
entity.setBasePlate(hasbaseplate);
|
||||
entity.setSmall(small);
|
||||
entity.setMarker(marker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.getEntity() instanceof ArmorStand) {
|
||||
ArmorStand entity = (ArmorStand) npc.getEntity();
|
||||
body = entity.getBodyPose();
|
||||
leftArm = entity.getLeftArmPose();
|
||||
leftLeg = entity.getLeftLegPose();
|
||||
rightArm = entity.getRightArmPose();
|
||||
rightLeg = entity.getRightLegPose();
|
||||
head = entity.getHeadPose();
|
||||
entity.setVisible(visible);
|
||||
entity.setGravity(gravity);
|
||||
entity.setArms(hasarms);
|
||||
entity.setBasePlate(hasbaseplate);
|
||||
entity.setSmall(small);
|
||||
entity.setMarker(marker);
|
||||
}
|
||||
if (!(npc.getEntity() instanceof ArmorStand))
|
||||
return;
|
||||
ArmorStand entity = (ArmorStand) npc.getEntity();
|
||||
body = entity.getBodyPose();
|
||||
leftArm = entity.getLeftArmPose();
|
||||
leftLeg = entity.getLeftLegPose();
|
||||
rightArm = entity.getRightArmPose();
|
||||
rightLeg = entity.getRightLegPose();
|
||||
head = entity.getHeadPose();
|
||||
entity.setVisible(visible);
|
||||
entity.setGravity(gravity);
|
||||
entity.setArms(hasarms);
|
||||
entity.setBasePlate(hasbaseplate);
|
||||
entity.setSmall(small);
|
||||
entity.setMarker(marker);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,10 +127,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
@ -140,10 +140,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
@ -421,10 +421,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
@ -424,11 +424,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
((WorldServer) world).removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -425,10 +425,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
/*
|
||||
double diff = this.yaw - this.aK;
|
||||
|
@ -183,7 +183,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
((WorldServer) world).removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -455,10 +455,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
boolean navigating = npc.getNavigator().isNavigating();
|
||||
updatePackets(navigating);
|
||||
|
||||
if (noDamageTicks > 0) {
|
||||
--noDamageTicks;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
/*
|
||||
double diff = this.yaw - this.aK;
|
||||
|
@ -197,11 +197,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
|
||||
if (this.hurtTime > 0)
|
||||
this.hurtTime--;
|
||||
if (this.invulnerableTime > 0)
|
||||
this.invulnerableTime--;
|
||||
|
||||
if (isDeadOrDying()) {
|
||||
tickDeath();
|
||||
}
|
||||
|
||||
if (this.lastHurtByPlayerTime > 0) {
|
||||
this.lastHurtByPlayerTime--;
|
||||
} else {
|
||||
@ -482,10 +482,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updatePackets(npc.getNavigator().isNavigating());
|
||||
|
||||
if (invulnerableTime > 0) {
|
||||
--invulnerableTime;
|
||||
}
|
||||
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user