mirror of https://github.com/GeyserMC/Geyser.git
Compare commits
8 Commits
342e7aae4e
...
4ef3c9e577
Author | SHA1 | Date |
---|---|---|
|
4ef3c9e577 | |
|
96bfda2ed3 | |
|
b68916feec | |
|
51f7db9ceb | |
|
cb746464bb | |
|
ae1a4c88e7 | |
|
f4a76192df | |
![]() |
bdaa595a7d |
|
@ -301,12 +301,12 @@ 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(MetadataType.VECTOR3, DisplayBaseEntity::setScale) // Scale
|
||||||
.addTranslator(null) // Left rotation
|
.addTranslator(null) // Left rotation
|
||||||
.addTranslator(null) // Right rotation
|
.addTranslator(null) // Right rotation
|
||||||
.addTranslator(null) // Billboard render constraints
|
.addTranslator(null) // Billboard render constraints
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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 it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
||||||
|
import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||||
|
import org.jetbrains.annotations.Async;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.geysermc.geyser.util.EntityUtils.getMountOffset;
|
||||||
|
|
||||||
|
public class DisplayBaseEntity extends Entity {
|
||||||
|
|
||||||
|
public 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
|
||||||
|
protected void initializeMetadata() {
|
||||||
|
super.initializeMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.vehicle == null) {
|
||||||
|
this.setRiderSeatPosition(this.baseTranslation);
|
||||||
|
this.moveRelative(0, this.baseTranslation.getY(), 0, yaw, pitch, headYaw, false);
|
||||||
|
} else {
|
||||||
|
this.setRiderSeatPosition(this.baseTranslation.add(getMountOffset(this, this.vehicle)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setScale(EntityMetadata<Vector3f, ?> translationMeta){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ package org.geysermc.geyser.session.cache;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
|
||||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.LodestoneTracker;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.LodestoneTracker;
|
||||||
|
@ -53,11 +52,13 @@ public final class LodestoneCache {
|
||||||
private int id = 1;
|
private int id = 1;
|
||||||
|
|
||||||
public void cacheInventoryItem(GeyserItemStack itemStack, LodestoneTracker tracker) {
|
public void cacheInventoryItem(GeyserItemStack itemStack, LodestoneTracker tracker) {
|
||||||
GlobalPos position = tracker.getPos();
|
if (!tracker.isTracked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalPos position = tracker.getPos();
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
GeyserImpl.getInstance().getLogger().error("Position is null. Find out why.");
|
// As of 1.20.6, position can still be null even if tracking is enabled.
|
||||||
Thread.dumpStack();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int x = position.getX();
|
int x = position.getX();
|
||||||
|
@ -84,13 +85,16 @@ public final class LodestoneCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int store(LodestoneTracker tracker) {
|
public int store(LodestoneTracker tracker) {
|
||||||
GlobalPos position = tracker.getPos();
|
if (!tracker.isTracked()) {
|
||||||
|
// No coordinates; nothing to convert
|
||||||
if (position == null) {
|
return 0;
|
||||||
GeyserImpl.getInstance().getLogger().error("Position is null. Find out why.");
|
|
||||||
Thread.dumpStack();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalPos position = tracker.getPos();
|
||||||
|
if (position == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int x = position.getX();
|
int x = position.getX();
|
||||||
int y = position.getY();
|
int y = position.getY();
|
||||||
int z = position.getZ();
|
int z = position.getZ();
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -153,6 +154,11 @@ public final class EntityUtils {
|
||||||
* Adjust an entity's height if they have mounted/dismounted an entity.
|
* Adjust an entity's height if they have mounted/dismounted an entity.
|
||||||
*/
|
*/
|
||||||
public static void updateMountOffset(Entity passenger, Entity mount, boolean rider, boolean riding, boolean moreThanOneEntity) {
|
public static void updateMountOffset(Entity passenger, Entity mount, boolean rider, boolean riding, boolean moreThanOneEntity) {
|
||||||
|
if (passenger instanceof TextDisplayEntity displayEntity) {
|
||||||
|
if (displayEntity.baseTranslation == null) return; // still no meta
|
||||||
|
displayEntity.setRiderSeatPosition(displayEntity.baseTranslation.add(getMountOffset(passenger, mount)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
passenger.setFlag(EntityFlag.RIDING, riding);
|
passenger.setFlag(EntityFlag.RIDING, riding);
|
||||||
if (riding) {
|
if (riding) {
|
||||||
// Without the Y offset, Bedrock players will find themselves in the floor when mounting
|
// Without the Y offset, Bedrock players will find themselves in the floor when mounting
|
||||||
|
@ -227,6 +233,57 @@ public final class EntityUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector3f getMountOffset(Entity passenger, Entity mount) {
|
||||||
|
// 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.getDefinition().entityType()) {
|
||||||
|
case CAMEL -> {
|
||||||
|
zOffset = 0.5f;
|
||||||
|
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 CHICKEN -> zOffset = -0.1f;
|
||||||
|
case TRADER_LLAMA, LLAMA -> zOffset = -0.3f;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Bedrock Differences
|
||||||
|
* Zoglin & Hoglin seem to be taller in Bedrock edition
|
||||||
|
* Horses are tinier
|
||||||
|
* Players, Minecarts, and Boats have different origins
|
||||||
|
*/
|
||||||
|
if (mount.getDefinition().entityType() == EntityType.PLAYER) {
|
||||||
|
yOffset -= EntityDefinitions.PLAYER.offset();
|
||||||
|
}
|
||||||
|
if (passenger.getDefinition().entityType() == EntityType.PLAYER) {
|
||||||
|
yOffset += EntityDefinitions.PLAYER.offset();
|
||||||
|
}
|
||||||
|
switch (mount.getDefinition().entityType()) {
|
||||||
|
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
|
||||||
|
COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset -= mount.getDefinition().height() * 0.5f;
|
||||||
|
}
|
||||||
|
switch (passenger.getDefinition().entityType()) {
|
||||||
|
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) {
|
||||||
|
yOffset -= armorStand.getYOffset();
|
||||||
|
}
|
||||||
|
return Vector3f.from(xOffset, yOffset, zOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void updateRiderRotationLock(Entity passenger, Entity mount, boolean isRiding) {
|
public static void updateRiderRotationLock(Entity passenger, Entity mount, boolean isRiding) {
|
||||||
if (isRiding && mount instanceof BoatEntity) {
|
if (isRiding && mount instanceof BoatEntity) {
|
||||||
// Head rotation is locked while riding in a boat
|
// Head rotation is locked while riding in a boat
|
||||||
|
|
Loading…
Reference in New Issue