mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
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:
parent
ae70dbeece
commit
5c28eaca15
1 changed files with 133 additions and 37 deletions
|
@ -82,7 +82,6 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
|
|||
}
|
||||
|
||||
passenger.updateBedrockMetadata(session);
|
||||
this.updateOffset(passenger, entity.getEntityType(), session, rider, true, (passengers.size() > 1));
|
||||
rider = false;
|
||||
}
|
||||
|
||||
|
@ -90,6 +89,9 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
|
|||
|
||||
for (long passengerId : entity.getPassengers()) {
|
||||
Entity passenger = session.getEntityCache().getEntityByJavaId(passengerId);
|
||||
if (passengerId == session.getPlayerEntity().getEntityId()) {
|
||||
passenger = session.getPlayerEntity();
|
||||
}
|
||||
if (passenger == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -99,66 +101,160 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
|
|||
session.sendUpstreamPacket(linkPacket);
|
||||
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
|
||||
passenger.updateBedrockMetadata(session);
|
||||
}
|
||||
|
||||
if (entity.getEntityType() == EntityType.HORSE) {
|
||||
entity.getMetadata().put(EntityData.RIDER_SEAT_POSITION, Vector3f.from(0.0f, 2.3200102f, -0.2f));
|
||||
entity.getMetadata().put(EntityData.RIDER_MAX_ROTATION, 181.0f);
|
||||
|
||||
entity.updateBedrockMetadata(session);
|
||||
switch (entity.getEntityType()) {
|
||||
case HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case DONKEY:
|
||||
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) {
|
||||
// Without the Y offset, Bedrock players will find themselves in the floor when mounting
|
||||
float yOffset = 0;
|
||||
private float getMountedHeightOffset(Entity mount) {
|
||||
final EntityType mountType = mount.getEntityType();
|
||||
float mountedHeightOffset = mountType.getHeight() * 0.75f;
|
||||
switch (mountType) {
|
||||
case BOAT:
|
||||
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : -0.2f;
|
||||
break;
|
||||
case MINECART:
|
||||
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : 0f;
|
||||
case CHICKEN:
|
||||
case SPIDER:
|
||||
mountedHeightOffset = mountType.getHeight() * 0.5f;
|
||||
break;
|
||||
case DONKEY:
|
||||
yOffset = 2.1f;
|
||||
break;
|
||||
case HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case ZOMBIE_HORSE:
|
||||
case MULE:
|
||||
yOffset = 2.3f;
|
||||
mountedHeightOffset -= 0.25f;
|
||||
break;
|
||||
case LLAMA:
|
||||
case TRADER_LLAMA:
|
||||
yOffset = 2.5f;
|
||||
mountedHeightOffset = mountType.getHeight() * 0.67f;
|
||||
break;
|
||||
case PIG:
|
||||
yOffset = 1.85001f;
|
||||
case MINECART:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_TNT:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_SPAWNER:
|
||||
case MINECART_COMMAND_BLOCK:
|
||||
mountedHeightOffset = 0;
|
||||
break;
|
||||
case ARMOR_STAND:
|
||||
yOffset = 1.3f;
|
||||
case BOAT:
|
||||
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;
|
||||
case STRIDER:
|
||||
yOffset = passenger.getEntityType() == EntityType.PLAYER ? 2.8200102f : 1.6f;
|
||||
mountedHeightOffset = mountType.getHeight() - 0.19f;
|
||||
break;
|
||||
}
|
||||
Vector3f offset = Vector3f.from(0f, yOffset, 0f);
|
||||
if (mountType == EntityType.STRIDER) {
|
||||
offset = offset.add(0f, 0f, -0.2f);
|
||||
}
|
||||
// Without the X offset, more than one entity on a boat is stacked on top of each other
|
||||
if (rider && moreThanOneEntity) {
|
||||
offset = offset.add(Vector3f.from(0.2, 0, 0));
|
||||
} else if (moreThanOneEntity) {
|
||||
offset = offset.add(Vector3f.from(-0.6, 0, 0));
|
||||
return mountedHeightOffset;
|
||||
}
|
||||
|
||||
private float getHeightOffset(Entity passenger) {
|
||||
boolean isBaby;
|
||||
switch (passenger.getEntityType()) {
|
||||
case SKELETON:
|
||||
case STRAY:
|
||||
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);
|
||||
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.updateBedrockMetadata(session);
|
||||
|
|
Loading…
Reference in a new issue