Fix Strider cold state when riding and removing of the RIDING flag when a parent is killed

This commit is contained in:
rtm516 2020-07-03 22:55:54 +01:00
parent ab71bf0727
commit da96a5b19c
3 changed files with 41 additions and 2 deletions

View file

@ -146,6 +146,12 @@ public class Entity {
public boolean despawnEntity(GeyserSession session) { public boolean despawnEntity(GeyserSession session) {
if (!valid) return true; if (!valid) return true;
for (long passenger : passengers) {
Entity entity = session.getEntityCache().getEntityByJavaId(passenger);
entity.getMetadata().getFlags().setFlag(EntityFlag.RIDING, false);
entity.updateBedrockMetadata(session);
}
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket(); RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(geyserId); removeEntityPacket.setUniqueEntityId(geyserId);
session.sendUpstreamPacket(removeEntityPacket); session.sendUpstreamPacket(removeEntityPacket);

View file

@ -29,11 +29,14 @@ package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
public class StriderEntity extends AnimalEntity { public class StriderEntity extends AnimalEntity {
private boolean shaking = false;
public StriderEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { public StriderEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation); super(entityId, geyserId, entityType, position, motion, rotation);
@ -44,8 +47,7 @@ public class StriderEntity extends AnimalEntity {
@Override @Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 17) { if (entityMetadata.getId() == 17) {
metadata.getFlags().setFlag(EntityFlag.BREATHING, !(boolean) entityMetadata.getValue()); shaking = (boolean) entityMetadata.getValue();
metadata.getFlags().setFlag(EntityFlag.SHAKING, (boolean) entityMetadata.getValue());
} }
if (entityMetadata.getId() == 18) { if (entityMetadata.getId() == 18) {
metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue()); metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue());
@ -53,4 +55,32 @@ public class StriderEntity extends AnimalEntity {
super.updateBedrockMetadata(entityMetadata, session); super.updateBedrockMetadata(entityMetadata, session);
} }
@Override
public void updateBedrockMetadata(GeyserSession session) {
// Make sure they are not shaking when riding another entity
// Needs to copy the parent state
if (metadata.getFlags().getFlag(EntityFlag.RIDING)) {
boolean parentShaking = false;
for (Entity ent : session.getEntityCache().getEntities().values()) {
if (ent.getPassengers().contains(entityId) && ent instanceof StriderEntity) {
parentShaking = ent.getMetadata().getFlags().getFlag(EntityFlag.SHAKING);
break;
}
}
metadata.getFlags().setFlag(EntityFlag.BREATHING, !parentShaking);
metadata.getFlags().setFlag(EntityFlag.SHAKING, parentShaking);
} else {
metadata.getFlags().setFlag(EntityFlag.BREATHING, !shaking);
metadata.getFlags().setFlag(EntityFlag.SHAKING, shaking);
}
// Update the passengers if we have any
for (long passenger : passengers) {
session.getEntityCache().getEntityByJavaId(passenger).updateBedrockMetadata(session);
}
super.updateBedrockMetadata(session);
}
} }

View file

@ -101,6 +101,9 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
this.updateOffset(passenger, entity.getEntityType(), session, false, false, (passengers.size() > 1)); this.updateOffset(passenger, entity.getEntityType(), session, false, false, (passengers.size() > 1));
} }
// Force an update to the passenger metadata
passenger.updateBedrockMetadata(session);
} }
if (entity.getEntityType() == EntityType.HORSE) { if (entity.getEntityType() == EntityType.HORSE) {