mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Code cleaning and optimization
This commit is contained in:
parent
92f40aedf9
commit
5fcfd5a9f0
3 changed files with 28 additions and 12 deletions
|
|
@ -316,7 +316,6 @@ public final class EntityDefinitions {
|
||||||
.addTranslator(null) // Height
|
.addTranslator(null) // Height
|
||||||
.addTranslator(null) // Glow color override
|
.addTranslator(null) // Glow color override
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
TEXT_DISPLAY = EntityDefinition.inherited(TextDisplayEntity::new, displayBase)
|
TEXT_DISPLAY = EntityDefinition.inherited(TextDisplayEntity::new, displayBase)
|
||||||
.type(EntityType.TEXT_DISPLAY)
|
.type(EntityType.TEXT_DISPLAY)
|
||||||
.identifier("minecraft:armor_stand")
|
.identifier("minecraft:armor_stand")
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class DisplayBaseEntity extends Entity {
|
public class DisplayBaseEntity extends Entity {
|
||||||
|
|
||||||
public Vector3f baseTranslation;
|
private Vector3f baseTranslation;
|
||||||
|
private boolean noBaseTranslation;
|
||||||
|
|
||||||
public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
|
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);
|
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||||
|
|
@ -64,12 +64,24 @@ public class DisplayBaseEntity extends Entity {
|
||||||
|
|
||||||
public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta){
|
public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta){
|
||||||
this.baseTranslation = translationMeta.getValue();
|
this.baseTranslation = translationMeta.getValue();
|
||||||
if(this.vehicle == null){
|
if (this.baseTranslation == null){
|
||||||
|
this.noBaseTranslation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.vehicle == null){
|
||||||
this.setRiderSeatPosition(this.baseTranslation);
|
this.setRiderSeatPosition(this.baseTranslation);
|
||||||
this.moveRelative(0, this.baseTranslation.getY(), 0, yaw, pitch, headYaw, false);
|
this.moveRelative(0, this.baseTranslation.getY(), 0, yaw, pitch, headYaw, false);
|
||||||
} else {
|
} else {
|
||||||
EntityUtils.updateMountOffset(this, this.vehicle, true, true, false);
|
EntityUtils.updateMountOffset(this, this.vehicle, true, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3f getTranslation() {
|
||||||
|
return baseTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTranslation(){
|
||||||
|
return !this.noBaseTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,8 +154,8 @@ 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 textDisplay
|
if (passenger instanceof TextDisplayEntity textDisplay
|
||||||
&& textDisplay.baseTranslation == null) return;
|
&& !textDisplay.hasTranslation()) return;
|
||||||
|
|
||||||
passenger.setFlag(EntityFlag.RIDING, riding);
|
passenger.setFlag(EntityFlag.RIDING, riding);
|
||||||
if (riding) {
|
if (riding) {
|
||||||
|
|
@ -197,6 +197,15 @@ 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 -> {
|
||||||
|
TextDisplayEntity textDisplay;
|
||||||
|
if (passenger instanceof TextDisplayEntity) {
|
||||||
|
textDisplay = (TextDisplayEntity) passenger;
|
||||||
|
xOffset = textDisplay.getTranslation().getX();
|
||||||
|
yOffset = textDisplay.getTranslation().getY() + 0.2f;
|
||||||
|
zOffset = textDisplay.getTranslation().getZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Bedrock Differences
|
* Bedrock Differences
|
||||||
|
|
@ -222,11 +231,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( passenger instanceof TextDisplayEntity textDisplay ?
|
|
||||||
textDisplay.baseTranslation.add(offset).add(0f, 0.2f, 0f) : offset
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue