add variant data

This commit is contained in:
zimzaza4
2024-07-22 01:38:11 +08:00
parent 8e2b5cd1fc
commit 2973fad195
3 changed files with 12 additions and 2 deletions

View File

@@ -5,8 +5,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.awt.*;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@@ -17,5 +15,6 @@ public class CustomEntityDataPacket extends CustomPayloadPacket {
private Float width;
private Float scale;
private Integer color;
private Integer variant;
}

View File

@@ -470,6 +470,8 @@ public class GeyserUtils implements Extension {
if (customEntityDataPacket.getScale() != null) entity.getDirtyMetadata().put(EntityDataTypes.SCALE, customEntityDataPacket.getScale());
if (customEntityDataPacket.getColor() != null)
entity.getDirtyMetadata().put(EntityDataTypes.COLOR, Byte.parseByte(String.valueOf(getColor(customEntityDataPacket.getColor()))));
if (customEntityDataPacket.getVariant() != null)
entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, customEntityDataPacket.getVariant());
entity.updateBedrockMetadata();
}
} else if (customPacket instanceof EntityPropertyPacket entityPropertyPacket) {

View File

@@ -36,6 +36,15 @@ public class EntityUtils {
}
public static void sendVariant(Player player, int id, int variant) {
CustomEntityDataPacket packet = new CustomEntityDataPacket();
packet.setEntityId(id);
packet.setVariant(variant);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
}
public static void setCustomEntity(Player player, int entityId, String def) {
CustomEntityPacket packet = new CustomEntityPacket(entityId, def);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));