mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix: Text display passenger offsets (#4676)
This commit is contained in:
parent
a807fa6bb5
commit
e0af0a54b7
4 changed files with 97 additions and 26 deletions
|
@ -307,11 +307,11 @@ public final class EntityDefinitions {
|
||||||
.addTranslator(MetadataType.INT, TNTEntity::setFuseLength)
|
.addTranslator(MetadataType.INT, TNTEntity::setFuseLength)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
EntityDefinition<Entity> displayBase = EntityDefinition.inherited(entityBase.factory(), entityBase)
|
EntityDefinition<DisplayBaseEntity> displayBase = EntityDefinition.inherited(DisplayBaseEntity::new, entityBase)
|
||||||
.addTranslator(null) // Interpolation delay
|
.addTranslator(null) // Interpolation delay
|
||||||
.addTranslator(null) // Transformation interpolation duration
|
.addTranslator(null) // Transformation interpolation duration
|
||||||
.addTranslator(null) // Position/Rotation interpolation duration
|
.addTranslator(null) // Position/Rotation interpolation duration
|
||||||
.addTranslator(null) // Translation
|
.addTranslator(MetadataType.VECTOR3, DisplayBaseEntity::setTranslation) // Translation
|
||||||
.addTranslator(null) // Scale
|
.addTranslator(null) // Scale
|
||||||
.addTranslator(null) // Left rotation
|
.addTranslator(null) // Left rotation
|
||||||
.addTranslator(null) // Right rotation
|
.addTranslator(null) // Right rotation
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.geyser.entity.type;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
|
import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
import org.geysermc.geyser.util.EntityUtils;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DisplayBaseEntity extends Entity {
|
||||||
|
|
||||||
|
private @Nullable Vector3f baseTranslation;
|
||||||
|
|
||||||
|
public DisplayBaseEntity(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
|
||||||
|
// Don't allow the display name to be hidden - messes with our armor stand.
|
||||||
|
// On JE: Hiding the display name still shows the display entity text.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
|
||||||
|
// This would usually set EntityDataTypes.NAME, but we are instead using NAME for the text display.
|
||||||
|
// On JE: custom name does not override text display.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta){
|
||||||
|
this.baseTranslation = translationMeta.getValue();
|
||||||
|
if (this.baseTranslation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.vehicle == null) {
|
||||||
|
this.setRiderSeatPosition(this.baseTranslation);
|
||||||
|
this.moveRelative(this.baseTranslation.getX(), this.baseTranslation.getY(), this.baseTranslation.getZ(), yaw, pitch, headYaw, false);
|
||||||
|
} else {
|
||||||
|
EntityUtils.updateMountOffset(this, this.vehicle, true, true, false);
|
||||||
|
this.updateBedrockMetadata();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f getTranslation() {
|
||||||
|
return baseTranslation;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
* Copyright (c) 2024 GeyserMC. http://geysermc.org
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -32,13 +32,11 @@ import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
// Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition
|
// Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition
|
||||||
public class TextDisplayEntity extends Entity {
|
public class TextDisplayEntity extends DisplayBaseEntity {
|
||||||
public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
|
public TextDisplayEntity(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);
|
||||||
}
|
}
|
||||||
|
@ -51,18 +49,6 @@ public class TextDisplayEntity extends Entity {
|
||||||
this.dirtyMetadata.put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, (byte) 1);
|
this.dirtyMetadata.put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
|
|
||||||
// Don't allow the display name to be hidden - messes with our armor stand.
|
|
||||||
// On JE: Hiding the display name still shows the display entity text.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
|
|
||||||
// This would usually set EntityDataTypes.NAME, but we are instead using NAME for the text display.
|
|
||||||
// On JE: custom name does not override text display.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setText(EntityMetadata<Component, ?> entityMetadata) {
|
public void setText(EntityMetadata<Component, ?> entityMetadata) {
|
||||||
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
|
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
* Copyright (c) 2024 GeyserMC. http://geysermc.org
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import org.geysermc.geyser.entity.EntityDefinitions;
|
import org.geysermc.geyser.entity.EntityDefinitions;
|
||||||
import org.geysermc.geyser.entity.type.BoatEntity;
|
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.TextDisplayEntity;
|
||||||
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.entity.type.living.animal.horse.CamelEntity;
|
||||||
|
@ -172,11 +173,7 @@ public final class EntityUtils {
|
||||||
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 (moreThanOneEntity) {
|
if (moreThanOneEntity) {
|
||||||
if (rider) {
|
xOffset = rider ? 0.2f : -0.6f;
|
||||||
xOffset = 0.2f;
|
|
||||||
} else {
|
|
||||||
xOffset = -0.6f;
|
|
||||||
}
|
|
||||||
if (passenger instanceof AnimalEntity) {
|
if (passenger instanceof AnimalEntity) {
|
||||||
xOffset += 0.2f;
|
xOffset += 0.2f;
|
||||||
}
|
}
|
||||||
|
@ -203,6 +200,18 @@ public final class EntityUtils {
|
||||||
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;
|
||||||
|
case TEXT_DISPLAY -> {
|
||||||
|
if (passenger instanceof TextDisplayEntity textDisplay) {
|
||||||
|
Vector3f displayTranslation = textDisplay.getTranslation();
|
||||||
|
if (displayTranslation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xOffset = displayTranslation.getX();
|
||||||
|
yOffset = displayTranslation.getY() + 0.2f;
|
||||||
|
zOffset = displayTranslation.getZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Bedrock Differences
|
* Bedrock Differences
|
||||||
|
@ -228,8 +237,7 @@ public final class EntityUtils {
|
||||||
if (mount instanceof ArmorStandEntity armorStand) {
|
if (mount instanceof ArmorStandEntity armorStand) {
|
||||||
yOffset -= armorStand.getYOffset();
|
yOffset -= armorStand.getYOffset();
|
||||||
}
|
}
|
||||||
Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset);
|
passenger.setRiderSeatPosition(Vector3f.from(xOffset, yOffset, zOffset));
|
||||||
passenger.setRiderSeatPosition(offset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue