From 2190eeca8cff1902a5410ac2687036c77958e7bc Mon Sep 17 00:00:00 2001 From: GoodestEnglish Date: Thu, 3 Oct 2024 05:18:29 -0400 Subject: [PATCH 1/3] fix: text display entity data index incorrect and teleport packet wrong pitch and yaw --- .../entity/impl/TextDisplayHologramEntity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java index aab70592..17a182e1 100644 --- a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java +++ b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java @@ -72,8 +72,8 @@ public void update(MCPlayer player) { WrapperPlayServerEntityTeleport packet = new WrapperPlayServerEntityTeleport( this.entityId, this.packetPosition(), - this.hologram.getPosition().getPitch(), this.hologram.getPosition().getYaw(), + this.hologram.getPosition().getPitch(), false ); WrapperPlayServerEntityMetadata metadataPacket = new WrapperPlayServerEntityMetadata( @@ -101,10 +101,10 @@ public void hide(MCPlayer player) { private List createEntityData(MCPlayer mcPlayer) { List entityDataList = new ArrayList<>(); - entityDataList.add(new EntityData(22, EntityDataTypes.COMPONENT, MCAdventure.asItemString(line.render(mcPlayer), mcPlayer.getLocale()))); // text - entityDataList.add(new EntityData(23, EntityDataTypes.CAT_VARIANT, 200)); // line width - entityDataList.add(new EntityData(24, EntityDataTypes.CAT_VARIANT, 0x40000000)); // background color - entityDataList.add(new EntityData(25, EntityDataTypes.CAT_VARIANT, -1)); // text opacity + entityDataList.add(new EntityData(23, EntityDataTypes.COMPONENT, MCAdventure.asItemString(line.render(mcPlayer), mcPlayer.getLocale()))); // text + entityDataList.add(new EntityData(24, EntityDataTypes.INT, 200)); // line width + entityDataList.add(new EntityData(25, EntityDataTypes.INT, 0x40000000)); // background color + entityDataList.add(new EntityData(26, EntityDataTypes.BYTE, (byte) -1)); // text opacity /** * bit mask * 0x01 = has shadow @@ -116,7 +116,7 @@ private List createEntityData(MCPlayer mcPlayer) { boolean isSeeThrough = false; boolean useDefaultBackgroundColor = true; int alignment = 0; - entityDataList.add(new EntityData(26, EntityDataTypes.CAT_VARIANT, (hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment)); + entityDataList.add(new EntityData(27, EntityDataTypes.BYTE, (byte)((hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment))); return entityDataList; } From 533126d751e6ba42f7022dedc086cc28b78360fc Mon Sep 17 00:00:00 2001 From: GoodestEnglish Date: Thu, 3 Oct 2024 05:59:37 -0400 Subject: [PATCH 2/3] feat: add support for older API version in text display hologram --- .../entity/impl/TextDisplayHologramEntity.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java index 17a182e1..1f2eec39 100644 --- a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java +++ b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java @@ -24,6 +24,8 @@ package io.fairyproject.mc.hologram.entity.impl; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; @@ -99,12 +101,13 @@ public void hide(MCPlayer player) { } private List createEntityData(MCPlayer mcPlayer) { + boolean modern = PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_20_2); List entityDataList = new ArrayList<>(); - entityDataList.add(new EntityData(23, EntityDataTypes.COMPONENT, MCAdventure.asItemString(line.render(mcPlayer), mcPlayer.getLocale()))); // text - entityDataList.add(new EntityData(24, EntityDataTypes.INT, 200)); // line width - entityDataList.add(new EntityData(25, EntityDataTypes.INT, 0x40000000)); // background color - entityDataList.add(new EntityData(26, EntityDataTypes.BYTE, (byte) -1)); // text opacity + entityDataList.add(new EntityData(modern ? 23 : 22, EntityDataTypes.COMPONENT, MCAdventure.asItemString(line.render(mcPlayer), mcPlayer.getLocale()))); // text + entityDataList.add(new EntityData(modern ? 24 : 23, EntityDataTypes.CAT_VARIANT, 200)); // line width + entityDataList.add(new EntityData(modern ? 25 : 24, EntityDataTypes.CAT_VARIANT, 0x40000000)); // background color + entityDataList.add(new EntityData(modern ? 26 : 25, EntityDataTypes.CAT_VARIANT, (byte) -1)); // text opacity /** * bit mask * 0x01 = has shadow @@ -116,7 +119,7 @@ private List createEntityData(MCPlayer mcPlayer) { boolean isSeeThrough = false; boolean useDefaultBackgroundColor = true; int alignment = 0; - entityDataList.add(new EntityData(27, EntityDataTypes.BYTE, (byte)((hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment))); + entityDataList.add(new EntityData(modern ? 27 : 26, EntityDataTypes.CAT_VARIANT, (byte)((hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment))); return entityDataList; } From 4d3bfceac3559af44a8b53aa976d6fa2881bed3d Mon Sep 17 00:00:00 2001 From: GoodestEnglish Date: Thu, 3 Oct 2024 06:03:12 -0400 Subject: [PATCH 3/3] fix: use the correct entity data types in text display hologram --- .../hologram/entity/impl/TextDisplayHologramEntity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java index 1f2eec39..fbec0d75 100644 --- a/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java +++ b/framework/modules/mc/mc-hologram/src/main/java/io/fairyproject/mc/hologram/entity/impl/TextDisplayHologramEntity.java @@ -105,9 +105,9 @@ private List createEntityData(MCPlayer mcPlayer) { List entityDataList = new ArrayList<>(); entityDataList.add(new EntityData(modern ? 23 : 22, EntityDataTypes.COMPONENT, MCAdventure.asItemString(line.render(mcPlayer), mcPlayer.getLocale()))); // text - entityDataList.add(new EntityData(modern ? 24 : 23, EntityDataTypes.CAT_VARIANT, 200)); // line width - entityDataList.add(new EntityData(modern ? 25 : 24, EntityDataTypes.CAT_VARIANT, 0x40000000)); // background color - entityDataList.add(new EntityData(modern ? 26 : 25, EntityDataTypes.CAT_VARIANT, (byte) -1)); // text opacity + entityDataList.add(new EntityData(modern ? 24 : 23, EntityDataTypes.INT, 200)); // line width + entityDataList.add(new EntityData(modern ? 25 : 24, EntityDataTypes.INT, 0x40000000)); // background color + entityDataList.add(new EntityData(modern ? 26 : 25, EntityDataTypes.BYTE, (byte) -1)); // text opacity /** * bit mask * 0x01 = has shadow @@ -119,7 +119,7 @@ private List createEntityData(MCPlayer mcPlayer) { boolean isSeeThrough = false; boolean useDefaultBackgroundColor = true; int alignment = 0; - entityDataList.add(new EntityData(modern ? 27 : 26, EntityDataTypes.CAT_VARIANT, (byte)((hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment))); + entityDataList.add(new EntityData(modern ? 27 : 26, EntityDataTypes.BYTE, (byte)((hasShadow ? 0x01 : 0) | (isSeeThrough ? 0x02 : 0) | (useDefaultBackgroundColor ? 0x04 : 0) | alignment))); return entityDataList; }