3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

New entity mount offsets (#3861)

* Add missing entities to getMountedHeightOffset and getHeightOffset

* Fix mount offset on Camels for more than 1 passenger

* Fix mount offset for Shulkers on Bamboo boats and minecarts with stuff

Also fix mount offsets for minecart and boat passengers

* Combine

* More missing mount offsets

* Fix mount offsets for entities riding players
Dieser Commit ist enthalten in:
Amberichu 2023-06-11 13:32:42 -04:00 committet von GitHub
Ursprung 049d64d34d
Commit f55d84321a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 64 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -493,9 +493,10 @@ public class Entity implements GeyserEntity {
* Update the mount offsets of each passenger on this vehicle * Update the mount offsets of each passenger on this vehicle
*/ */
protected void updatePassengerOffsets() { protected void updatePassengerOffsets() {
for (Entity passenger : passengers) { for (int i = 0; i < passengers.size(); i++) {
Entity passenger = passengers.get(i);
if (passenger != null) { if (passenger != null) {
boolean rider = passengers.get(0) == this; boolean rider = i == 0;
EntityUtils.updateMountOffset(passenger, this, rider, true, passengers.size() > 1); EntityUtils.updateMountOffset(passenger, this, rider, true, passengers.size() > 1);
passenger.updateBedrockMetadata(); passenger.updateBedrockMetadata();
} }

Datei anzeigen

@ -43,7 +43,7 @@ import java.util.UUID;
public class CamelEntity extends AbstractHorseEntity { public class CamelEntity extends AbstractHorseEntity {
private static final float SITTING_HEIGHT_DIFFERENCE = 1.43F; public static final float SITTING_HEIGHT_DIFFERENCE = 1.43F;
public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@ -103,7 +103,7 @@ public class CamelEntity extends AbstractHorseEntity {
@Override @Override
protected void setDimensions(Pose pose) { protected void setDimensions(Pose pose) {
if (pose == Pose.SITTING) { if (pose == Pose.SITTING) {
setBoundingBoxWidth(definition.height() - SITTING_HEIGHT_DIFFERENCE); setBoundingBoxHeight(definition.height() - SITTING_HEIGHT_DIFFERENCE);
setBoundingBoxWidth(definition.width()); setBoundingBoxWidth(definition.width());
} else { } else {
super.setDimensions(pose); super.setDimensions(pose);

Datei anzeigen

@ -36,6 +36,7 @@ import org.geysermc.geyser.entity.type.BoatEntity;
import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.living.ArmorStandEntity; import org.geysermc.geyser.entity.type.living.ArmorStandEntity;
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
import org.geysermc.geyser.entity.type.living.animal.horse.CamelEntity;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
@ -82,19 +83,28 @@ public final class EntityUtils {
float height = mount.getBoundingBoxHeight(); float height = mount.getBoundingBoxHeight();
float mountedHeightOffset = height * 0.75f; float mountedHeightOffset = height * 0.75f;
switch (mount.getDefinition().entityType()) { switch (mount.getDefinition().entityType()) {
case CHICKEN, SPIDER -> mountedHeightOffset = height * 0.5f; case CAMEL -> {
boolean isBaby = mount.getFlag(EntityFlag.BABY);
mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f);
}
case CAVE_SPIDER, CHICKEN, SPIDER -> mountedHeightOffset = height * 0.5f;
case DONKEY, MULE -> mountedHeightOffset -= 0.25f; case DONKEY, MULE -> mountedHeightOffset -= 0.25f;
case TRADER_LLAMA, LLAMA -> mountedHeightOffset = height * 0.6f; case TRADER_LLAMA, LLAMA -> mountedHeightOffset = height * 0.6f;
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0; COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0;
case BOAT, CHEST_BOAT -> mountedHeightOffset = -0.1f; case BOAT, CHEST_BOAT -> {
boolean isBamboo = ((BoatEntity) mount).getVariant() == 8;
mountedHeightOffset = isBamboo ? 0.25f : -0.1f;
}
case HOGLIN, ZOGLIN -> { case HOGLIN, ZOGLIN -> {
boolean isBaby = mount.getFlag(EntityFlag.BABY); boolean isBaby = mount.getFlag(EntityFlag.BABY);
mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f); mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f);
} }
case PIGLIN -> mountedHeightOffset = height * 0.92f; case PIGLIN -> mountedHeightOffset = height * 0.92f;
case PHANTOM -> mountedHeightOffset = height * 0.35f;
case RAVAGER -> mountedHeightOffset = 2.1f; case RAVAGER -> mountedHeightOffset = 2.1f;
case SKELETON_HORSE -> mountedHeightOffset -= 0.1875f; case SKELETON_HORSE -> mountedHeightOffset -= 0.1875f;
case SNIFFER -> mountedHeightOffset = 1.8f;
case STRIDER -> mountedHeightOffset = height - 0.19f; case STRIDER -> mountedHeightOffset = height - 0.19f;
} }
return mountedHeightOffset; return mountedHeightOffset;
@ -103,9 +113,9 @@ public final class EntityUtils {
private static float getHeightOffset(Entity passenger) { private static float getHeightOffset(Entity passenger) {
boolean isBaby; boolean isBaby;
switch (passenger.getDefinition().entityType()) { switch (passenger.getDefinition().entityType()) {
case SKELETON: case ALLAY, VEX:
case STRAY: return 0.4f;
case WITHER_SKELETON: case SKELETON, STRAY, WITHER_SKELETON:
return -0.6f; return -0.6f;
case ARMOR_STAND: case ARMOR_STAND:
if (((ArmorStandEntity) passenger).isMarker()) { if (((ArmorStandEntity) passenger).isMarker()) {
@ -113,26 +123,23 @@ public final class EntityUtils {
} else { } else {
return 0.1f; return 0.1f;
} }
case ENDERMITE: case ENDERMITE, SILVERFISH:
case SILVERFISH:
return 0.1f; return 0.1f;
case PIGLIN: case PIGLIN, PIGLIN_BRUTE, ZOMBIFIED_PIGLIN:
case PIGLIN_BRUTE:
case ZOMBIFIED_PIGLIN:
isBaby = passenger.getFlag(EntityFlag.BABY); isBaby = passenger.getFlag(EntityFlag.BABY);
return isBaby ? -0.05f : -0.45f; return isBaby ? -0.05f : -0.45f;
case ZOMBIE: case DROWNED, HUSK, ZOMBIE_VILLAGER, ZOMBIE:
isBaby = passenger.getFlag(EntityFlag.BABY); isBaby = passenger.getFlag(EntityFlag.BABY);
return isBaby ? 0.0f : -0.45f; return isBaby ? 0.0f : -0.45f;
case EVOKER: case EVOKER, ILLUSIONER, PILLAGER, RAVAGER, VINDICATOR, WITCH:
case ILLUSIONER:
case PILLAGER:
case RAVAGER:
case VINDICATOR:
case WITCH:
return -0.45f; return -0.45f;
case PLAYER: case PLAYER:
return -0.35f; return -0.35f;
case SHULKER:
Entity vehicle = passenger.getVehicle();
if (vehicle instanceof BoatEntity || vehicle.getDefinition() == EntityDefinitions.MINECART) {
return 0.1875f - getMountedHeightOffset(vehicle);
}
} }
if (passenger instanceof AnimalEntity) { if (passenger instanceof AnimalEntity) {
return 0.14f; return 0.14f;
@ -156,39 +163,59 @@ public final class EntityUtils {
switch (mount.getDefinition().entityType()) { switch (mount.getDefinition().entityType()) {
case BOAT -> { case BOAT -> {
// Without the X offset, more than one entity on a boat is stacked on top of each other // Without the X offset, more than one entity on a boat is stacked on top of each other
if (rider && moreThanOneEntity) { if (moreThanOneEntity) {
xOffset = 0.2f; if (rider) {
} else if (moreThanOneEntity) { xOffset = 0.2f;
xOffset = -0.6f; } else {
xOffset = -0.6f;
}
if (passenger instanceof AnimalEntity) {
xOffset += 0.2f;
}
}
}
case CAMEL -> {
zOffset = 0.5f;
if (moreThanOneEntity) {
if (!rider) {
zOffset = -0.7f;
}
if (passenger instanceof AnimalEntity) {
zOffset += 0.2f;
}
}
if (mount.getFlag(EntityFlag.SITTING)) {
if (mount.getFlag(EntityFlag.BABY)) {
yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE * 0.5f;
} else {
yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE;
}
} }
} }
case CHEST_BOAT -> xOffset = 0.15F; case CHEST_BOAT -> xOffset = 0.15F;
case CHICKEN -> zOffset = -0.1f; case CHICKEN -> zOffset = -0.1f;
case TRADER_LLAMA, LLAMA -> zOffset = -0.3f; case TRADER_LLAMA, LLAMA -> zOffset = -0.3f;
} }
if (passenger.getDefinition().entityType() == EntityType.SHULKER) {
switch (mount.getDefinition().entityType()) {
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset = 0.1875f;
}
}
/* /*
* Bedrock Differences * Bedrock Differences
* Zoglin & Hoglin seem to be taller in Bedrock edition * Zoglin & Hoglin seem to be taller in Bedrock edition
* Horses are tinier * Horses are tinier
* Players, Minecarts, and Boats have different origins * Players, Minecarts, and Boats have different origins
*/ */
if (mount.getDefinition().entityType() == EntityType.PLAYER) {
yOffset -= EntityDefinitions.PLAYER.offset();
}
if (passenger.getDefinition().entityType() == EntityType.PLAYER) { if (passenger.getDefinition().entityType() == EntityType.PLAYER) {
if (mount.getDefinition().entityType() != EntityType.PLAYER && mount.getDefinition().entityType() != EntityType.AREA_EFFECT_CLOUD) { yOffset += EntityDefinitions.PLAYER.offset();
yOffset += EntityDefinitions.PLAYER.offset();
}
} }
switch (mount.getDefinition().entityType()) { switch (mount.getDefinition().entityType()) {
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset -= mount.getDefinition().height() * 0.5f; COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset -= mount.getDefinition().height() * 0.5f;
} }
if (passenger.getDefinition().entityType() == EntityType.FALLING_BLOCK) { switch (passenger.getDefinition().entityType()) {
yOffset += 0.5f; case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset += passenger.getDefinition().height() * 0.5f;
case FALLING_BLOCK -> yOffset += 0.5f;
} }
if (mount instanceof ArmorStandEntity armorStand) { if (mount instanceof ArmorStandEntity armorStand) {
yOffset -= armorStand.getYOffset(); yOffset -= armorStand.getYOffset();