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

Fix sitting with armor stand and animal mount offsets (#1492)

* Fix sitting with armor stand and animal offsets

* Fix riding players

* Moved @Getter
Dieser Commit ist enthalten in:
David Choo 2020-11-04 20:30:55 -05:00 committet von GitHub
Ursprung ea521078e1
Commit ce64dd2788
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 24 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadat
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType; import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import lombok.Getter;
import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.entity.LivingEntity;
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;
@ -36,6 +37,7 @@ import org.geysermc.connector.network.session.GeyserSession;
public class ArmorStandEntity extends LivingEntity { public class ArmorStandEntity extends LivingEntity {
// These are used to store the state of the armour stand for use when handling invisibility // These are used to store the state of the armour stand for use when handling invisibility
@Getter
private boolean isMarker = false; private boolean isMarker = false;
private boolean isInvisible = false; private boolean isInvisible = false;
private boolean isSmall = false; private boolean isSmall = false;
@ -47,7 +49,7 @@ public class ArmorStandEntity extends LivingEntity {
@Override @Override
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) { public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
// Fake the height to be above where it is so the nametag appears in the right location for invisible non-marker armour stands // Fake the height to be above where it is so the nametag appears in the right location for invisible non-marker armour stands
if (!isMarker && isInvisible) { if (!isMarker && isInvisible && passengers.isEmpty()) {
position = position.add(0d, entityType.getHeight() * (isSmall ? 0.55d : 1d), 0d); position = position.add(0d, entityType.getHeight() * (isSmall ? 0.55d : 1d), 0d);
} }

Datei anzeigen

@ -33,6 +33,8 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.living.ArmorStandEntity;
import org.geysermc.connector.entity.living.animal.AnimalEntity;
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;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -46,6 +48,10 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
@Override @Override
public void translate(ServerEntitySetPassengersPacket packet, GeyserSession session) { public void translate(ServerEntitySetPassengersPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null) return; if (entity == null) return;
LongOpenHashSet passengers = entity.getPassengers().clone(); LongOpenHashSet passengers = entity.getPassengers().clone();
@ -123,19 +129,19 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
} }
private float getMountedHeightOffset(Entity mount) { private float getMountedHeightOffset(Entity mount) {
final EntityType mountType = mount.getEntityType(); float height = mount.getMetadata().getFloat(EntityData.BOUNDING_BOX_HEIGHT);
float mountedHeightOffset = mountType.getHeight() * 0.75f; float mountedHeightOffset = height * 0.75f;
switch (mountType) { switch (mount.getEntityType()) {
case CHICKEN: case CHICKEN:
case SPIDER: case SPIDER:
mountedHeightOffset = mountType.getHeight() * 0.5f; mountedHeightOffset = height * 0.5f;
break; break;
case DONKEY: case DONKEY:
case MULE: case MULE:
mountedHeightOffset -= 0.25f; mountedHeightOffset -= 0.25f;
break; break;
case LLAMA: case LLAMA:
mountedHeightOffset = mountType.getHeight() * 0.67f; mountedHeightOffset = height * 0.67f;
break; break;
case MINECART: case MINECART:
case MINECART_HOPPER: case MINECART_HOPPER:
@ -152,10 +158,10 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
case HOGLIN: case HOGLIN:
case ZOGLIN: case ZOGLIN:
boolean isBaby = mount.getMetadata().getFlags().getFlag(EntityFlag.BABY); boolean isBaby = mount.getMetadata().getFlags().getFlag(EntityFlag.BABY);
mountedHeightOffset = mountType.getHeight() - (isBaby ? 0.2f : 0.15f); mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f);
break; break;
case PIGLIN: case PIGLIN:
mountedHeightOffset = mountType.getHeight() * 0.92f; mountedHeightOffset = height * 0.92f;
break; break;
case RAVAGER: case RAVAGER:
mountedHeightOffset = 2.1f; mountedHeightOffset = 2.1f;
@ -164,7 +170,7 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
mountedHeightOffset -= 0.1875f; mountedHeightOffset -= 0.1875f;
break; break;
case STRIDER: case STRIDER:
mountedHeightOffset = mountType.getHeight() - 0.19f; mountedHeightOffset = height - 0.19f;
break; break;
} }
return mountedHeightOffset; return mountedHeightOffset;
@ -178,11 +184,10 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
case WITHER_SKELETON: case WITHER_SKELETON:
return -0.6f; return -0.6f;
case ARMOR_STAND: case ARMOR_STAND:
// Armor stand isn't a marker if (((ArmorStandEntity) passenger).isMarker()) {
if (passenger.getMetadata().getFloat(EntityData.BOUNDING_BOX_HEIGHT) != 0.0f) {
return 0.1f;
} else {
return 0.0f; return 0.0f;
} else {
return 0.1f;
} }
case ENDERMITE: case ENDERMITE:
case SILVERFISH: case SILVERFISH:
@ -205,6 +210,9 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
case PLAYER: case PLAYER:
return -0.35f; return -0.35f;
} }
if (passenger instanceof AnimalEntity) {
return 0.14f;
}
return 0f; return 0f;
} }
@ -240,7 +248,7 @@ public class JavaEntitySetPassengersTranslator extends PacketTranslator<ServerEn
* Horses are tinier * Horses are tinier
* Players, Minecarts, and Boats have different origins * Players, Minecarts, and Boats have different origins
*/ */
if (passenger.getEntityType() == EntityType.PLAYER) { if (passenger.getEntityType() == EntityType.PLAYER && mount.getEntityType() != EntityType.PLAYER) {
yOffset += EntityType.PLAYER.getOffset(); yOffset += EntityType.PLAYER.getOffset();
} }
switch (mount.getEntityType()) { switch (mount.getEntityType()) {