Fix mob mount positions (#1392)

* Fix mob mount positions

Uses offsets from Java Edition.

* Fix Boat mount pos for multiple passengers and Fix Ravager

Remove unnecessary horse metadata

* Fix Minecart & Boat Mount Pos, Fix Player Height Offset

* Use offset of EntityType.PLAYER

* Add back metadata
This commit is contained in:
David Choo 2020-10-17 23:50:41 -04:00 committed by GitHub
parent ae70dbeece
commit 5c28eaca15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,7 +82,6 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
} }
passenger.updateBedrockMetadata(session); passenger.updateBedrockMetadata(session);
this.updateOffset(passenger, entity.getEntityType(), session, rider, true, (passengers.size() > 1));
rider = false; rider = false;
} }
@ -90,6 +89,9 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
for (long passengerId : entity.getPassengers()) { for (long passengerId : entity.getPassengers()) {
Entity passenger = session.getEntityCache().getEntityByJavaId(passengerId); Entity passenger = session.getEntityCache().getEntityByJavaId(passengerId);
if (passengerId == session.getPlayerEntity().getEntityId()) {
passenger = session.getPlayerEntity();
}
if (passenger == null) { if (passenger == null) {
continue; continue;
} }
@ -99,66 +101,160 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
session.sendUpstreamPacket(linkPacket); session.sendUpstreamPacket(linkPacket);
passengers.remove(passenger.getEntityId()); passengers.remove(passenger.getEntityId());
this.updateOffset(passenger, entity.getEntityType(), session, false, false, (passengers.size() > 1)); this.updateOffset(passenger, entity, session, false, false, (packet.getPassengerIds().length > 1));
} else {
this.updateOffset(passenger, entity, session, (packet.getPassengerIds()[0] == passengerId), true, (packet.getPassengerIds().length > 1));
} }
// Force an update to the passenger metadata // Force an update to the passenger metadata
passenger.updateBedrockMetadata(session); passenger.updateBedrockMetadata(session);
} }
if (entity.getEntityType() == EntityType.HORSE) { switch (entity.getEntityType()) {
entity.getMetadata().put(EntityData.RIDER_SEAT_POSITION, Vector3f.from(0.0f, 2.3200102f, -0.2f)); case HORSE:
entity.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 181.0f); case SKELETON_HORSE:
case DONKEY:
entity.updateBedrockMetadata(session); case MULE:
case RAVAGER:
entity.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 181.0f);
entity.updateBedrockMetadata(session);
break;
} }
} }
private void updateOffset(Entity passenger, EntityType mountType, GeyserSession session, boolean rider, boolean riding, boolean moreThanOneEntity) { private float getMountedHeightOffset(Entity mount) {
// Without the Y offset, Bedrock players will find themselves in the floor when mounting final EntityType mountType = mount.getEntityType();
float yOffset = 0; float mountedHeightOffset = mountType.getHeight() * 0.75f;
switch (mountType) { switch (mountType) {
case BOAT: case CHICKEN:
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : -0.2f; case SPIDER:
break; mountedHeightOffset = mountType.getHeight() * 0.5f;
case MINECART:
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : 0f;
break; break;
case DONKEY: case DONKEY:
yOffset = 2.1f;
break;
case HORSE:
case SKELETON_HORSE:
case ZOMBIE_HORSE:
case MULE: case MULE:
yOffset = 2.3f; mountedHeightOffset -= 0.25f;
break; break;
case LLAMA: case LLAMA:
case TRADER_LLAMA: mountedHeightOffset = mountType.getHeight() * 0.67f;
yOffset = 2.5f;
break; break;
case PIG: case MINECART:
yOffset = 1.85001f; case MINECART_HOPPER:
case MINECART_TNT:
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_SPAWNER:
case MINECART_COMMAND_BLOCK:
mountedHeightOffset = 0;
break; break;
case ARMOR_STAND: case BOAT:
yOffset = 1.3f; mountedHeightOffset = -0.1f;
break;
case HOGLIN:
case ZOGLIN:
boolean isBaby = mount.getMetadata().getFlags().getFlag(EntityFlag.BABY);
mountedHeightOffset = mountType.getHeight() - (isBaby ? 0.2f : 0.15f);
break;
case PIGLIN:
mountedHeightOffset = mountType.getHeight() * 0.92f;
break;
case RAVAGER:
mountedHeightOffset = 2.1f;
break;
case SKELETON_HORSE:
mountedHeightOffset -= 0.1875f;
break; break;
case STRIDER: case STRIDER:
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 2.8200102f : 1.6f; mountedHeightOffset = mountType.getHeight() - 0.19f;
break; break;
} }
Vector3f offset = Vector3f.from(0f, yOffset, 0f); return mountedHeightOffset;
if (mountType == EntityType.STRIDER) { }
offset = offset.add(0f, 0f, -0.2f);
} private float getHeightOffset(Entity passenger) {
// Without the X offset, more than one entity on a boat is stacked on top of each other boolean isBaby;
if (rider && moreThanOneEntity) { switch (passenger.getEntityType()) {
offset = offset.add(Vector3f.from(0.2, 0, 0)); case SKELETON:
} else if (moreThanOneEntity) { case STRAY:
offset = offset.add(Vector3f.from(-0.6, 0, 0)); case WITHER_SKELETON:
return -0.6f;
case ARMOR_STAND:
// Armor stand isn't a marker
if (passenger.getMetadata().getFloat(EntityData.BOUNDING_BOX_HEIGHT) != 0.0f) {
return 0.1f;
} else {
return 0.0f;
}
case ENDERMITE:
case SILVERFISH:
return 0.1f;
case PIGLIN:
case PIGLIN_BRUTE:
case ZOMBIFIED_PIGLIN:
isBaby = passenger.getMetadata().getFlags().getFlag(EntityFlag.BABY);
return isBaby ? -0.05f : -0.45f;
case ZOMBIE:
isBaby = passenger.getMetadata().getFlags().getFlag(EntityFlag.BABY);
return isBaby ? 0.0f : -0.45f;
case EVOKER:
case ILLUSIONER:
case PILLAGER:
case RAVAGER:
case VINDICATOR:
case WITCH:
return -0.45f;
case PLAYER:
return -0.35f;
} }
return 0f;
}
private void updateOffset(Entity passenger, Entity mount, GeyserSession session, boolean rider, boolean riding, boolean moreThanOneEntity) {
passenger.getMetadata().getFlags().setFlag(EntityFlag.RIDING, riding); passenger.getMetadata().getFlags().setFlag(EntityFlag.RIDING, riding);
if (riding) { if (riding) {
// Without the Y offset, Bedrock players will find themselves in the floor when mounting
float mountedHeightOffset = getMountedHeightOffset(mount);
float heightOffset = getHeightOffset(passenger);
float xOffset = 0;
float yOffset = mountedHeightOffset + heightOffset;
float zOffset = 0;
switch (mount.getEntityType()) {
case BOAT:
// Without the X offset, more than one entity on a boat is stacked on top of each other
if (rider && moreThanOneEntity) {
xOffset = 0.2f;
} else if (moreThanOneEntity) {
xOffset = -0.6f;
}
break;
case CHICKEN:
zOffset = -0.1f;
break;
case LLAMA:
zOffset = -0.3f;
break;
}
/*
* Bedrock Differences
* Zoglin & Hoglin seem to be taller in Bedrock edition
* Horses are tinier
* Players, Minecarts, and Boats have different origins
*/
if (passenger.getEntityType() == EntityType.PLAYER) {
yOffset += EntityType.PLAYER.getOffset();
}
switch (mount.getEntityType()) {
case MINECART:
case MINECART_HOPPER:
case MINECART_TNT:
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_SPAWNER:
case MINECART_COMMAND_BLOCK:
case BOAT:
yOffset -= mount.getEntityType().getHeight() * 0.5f;
}
Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset);
passenger.getMetadata().put(EntityData.RIDER_SEAT_POSITION, offset); passenger.getMetadata().put(EntityData.RIDER_SEAT_POSITION, offset);
} }
passenger.updateBedrockMetadata(session); passenger.updateBedrockMetadata(session);