diff --git a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java index 1c9ac145b..c3fa51f3d 100644 --- a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java +++ b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java @@ -107,7 +107,7 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { entry("minecraft:falling_block", FallingBlockMeta::new), entry("minecraft:firework_rocket", FireworkRocketMeta::new), entry("minecraft:fox", FoxMeta::new), - entry("minecraft:frog", EntityMeta::new), // TODO dedicated metadata + entry("minecraft:frog", FrogMeta::new), entry("minecraft:ghast", GhastMeta::new), entry("minecraft:giant", GiantMeta::new), entry("minecraft:glow_item_frame", GlowItemFrameMeta::new), diff --git a/src/main/java/net/minestom/server/entity/Metadata.java b/src/main/java/net/minestom/server/entity/Metadata.java index 6cfffe1af..0ba13868d 100644 --- a/src/main/java/net/minestom/server/entity/Metadata.java +++ b/src/main/java/net/minestom/server/entity/Metadata.java @@ -2,6 +2,8 @@ package net.minestom.server.entity; import net.kyori.adventure.text.Component; import net.minestom.server.coordinate.Point; +import net.minestom.server.entity.metadata.animal.FrogMeta; +import net.minestom.server.entity.metadata.animal.tameable.CatMeta; import net.minestom.server.item.ItemStack; import net.minestom.server.network.NetworkBuffer; import net.minestom.server.network.packet.server.play.EntityMetaDataPacket; @@ -99,6 +101,14 @@ public final class Metadata { return new MetadataImpl.EntryImpl<>(TYPE_POSE, value, NetworkBuffer.POSE); } + public static Entry CatVariant(@NotNull CatMeta.Variant value) { + return new MetadataImpl.EntryImpl<>(TYPE_CAT_VARIANT, value, NetworkBuffer.CAT_VARIANT); + } + + public static Entry FrogVariant(@NotNull FrogMeta.Variant value) { + return new MetadataImpl.EntryImpl<>(TYPE_FROG_VARIANT, value, NetworkBuffer.FROG_VARIANT); + } + public static final byte TYPE_BYTE = 0; public static final byte TYPE_VARINT = 1; public static final byte TYPE_LONG = 2; @@ -119,6 +129,8 @@ public final class Metadata { public static final byte TYPE_VILLAGERDATA = 17; public static final byte TYPE_OPTVARINT = 18; public static final byte TYPE_POSE = 19; + public static final byte TYPE_CAT_VARIANT = 20; + public static final byte TYPE_FROG_VARIANT = 21; private static final VarHandle NOTIFIED_CHANGES; diff --git a/src/main/java/net/minestom/server/entity/metadata/animal/FrogMeta.java b/src/main/java/net/minestom/server/entity/metadata/animal/FrogMeta.java new file mode 100644 index 000000000..a98c919b7 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/metadata/animal/FrogMeta.java @@ -0,0 +1,38 @@ +package net.minestom.server.entity.metadata.animal; + +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.Metadata; +import org.jetbrains.annotations.NotNull; + +public class FrogMeta extends AnimalMeta { + public static final byte OFFSET = AnimalMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 2; + + public FrogMeta(@NotNull Entity entity, @NotNull Metadata metadata) { + super(entity, metadata); + } + + public Variant getVariant() { + return super.metadata.getIndex(OFFSET, Variant.TEMPERATE); + } + + public void setVariant(@NotNull Variant value) { + super.metadata.setIndex(OFFSET, Metadata.FrogVariant(value)); + } + + public int getTongueTarget() { + return super.metadata.getIndex(OFFSET + 1, 0); + } + + public void setTongueTarget(int value) { + super.metadata.setIndex(OFFSET + 1, Metadata.OptVarInt(value)); + } + + public enum Variant { + TEMPERATE, + WARM, + COLD; + + private final static FrogMeta.Variant[] VALUES = values(); + } +} diff --git a/src/main/java/net/minestom/server/entity/metadata/animal/tameable/CatMeta.java b/src/main/java/net/minestom/server/entity/metadata/animal/tameable/CatMeta.java index 09b5f4da9..087743b76 100644 --- a/src/main/java/net/minestom/server/entity/metadata/animal/tameable/CatMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/animal/tameable/CatMeta.java @@ -1,5 +1,6 @@ package net.minestom.server.entity.metadata.animal.tameable; +import net.minestom.server.color.DyeColor; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; import org.jetbrains.annotations.NotNull; @@ -8,17 +9,19 @@ public class CatMeta extends TameableAnimalMeta { public static final byte OFFSET = TameableAnimalMeta.MAX_OFFSET; public static final byte MAX_OFFSET = OFFSET + 4; + private static final DyeColor[] DYE_VALUES = DyeColor.values(); + public CatMeta(@NotNull Entity entity, @NotNull Metadata metadata) { super(entity, metadata); } @NotNull - public Color getColor() { - return Color.VALUES[super.metadata.getIndex(OFFSET, 1)]; + public CatMeta.Variant getVariant() { + return super.metadata.getIndex(OFFSET, Variant.BLACK); } - public void setColor(@NotNull Color value) { - super.metadata.setIndex(OFFSET, Metadata.VarInt(value.ordinal())); + public void setVariant(@NotNull CatMeta.Variant value) { + super.metadata.setIndex(OFFSET, Metadata.CatVariant(value)); } public boolean isLying() { @@ -37,15 +40,15 @@ public class CatMeta extends TameableAnimalMeta { super.metadata.setIndex(OFFSET + 2, Metadata.Boolean(value)); } - public int getCollarColor() { - return super.metadata.getIndex(OFFSET + 3, 14); + public @NotNull DyeColor getCollarColor() { + return DYE_VALUES[super.metadata.getIndex(OFFSET + 3, DyeColor.RED.ordinal())]; } - public void setCollarColor(int value) { - super.metadata.setIndex(OFFSET + 3, Metadata.VarInt(value)); + public void setCollarColor(@NotNull DyeColor value) { + super.metadata.setIndex(OFFSET + 3, Metadata.VarInt(value.ordinal())); } - public enum Color { + public enum Variant { TABBY, BLACK, RED, @@ -58,7 +61,7 @@ public class CatMeta extends TameableAnimalMeta { JELLIE, ALL_BLACK; - private final static Color[] VALUES = values(); + private static final Variant[] VALUES = values(); } } diff --git a/src/main/java/net/minestom/server/network/NetworkBuffer.java b/src/main/java/net/minestom/server/network/NetworkBuffer.java index 6ff7431e5..7e61f2ed8 100644 --- a/src/main/java/net/minestom/server/network/NetworkBuffer.java +++ b/src/main/java/net/minestom/server/network/NetworkBuffer.java @@ -3,6 +3,8 @@ package net.minestom.server.network; import net.kyori.adventure.text.Component; import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; +import net.minestom.server.entity.metadata.animal.FrogMeta; +import net.minestom.server.entity.metadata.animal.tameable.CatMeta; import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.play.data.DeathLocation; import net.minestom.server.utils.Direction; @@ -57,6 +59,8 @@ public final class NetworkBuffer { public static final Type OPT_VAR_INT = NetworkBufferTypes.OPT_VAR_INT; public static final Type POSE = NetworkBufferTypes.POSE; public static final Type DEATH_LOCATION = NetworkBufferTypes.DEATH_LOCATION; + public static final Type CAT_VARIANT = NetworkBufferTypes.CAT_VARIANT; + public static final Type FROG_VARIANT = NetworkBufferTypes.FROG_VARIANT; ByteBuffer nioBuffer; final boolean resizable; diff --git a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java index ad68078b5..6ee3308c6 100644 --- a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java +++ b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java @@ -5,6 +5,8 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; +import net.minestom.server.entity.metadata.animal.FrogMeta; +import net.minestom.server.entity.metadata.animal.tameable.CatMeta; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.network.packet.server.play.data.DeathLocation; @@ -523,6 +525,24 @@ final class NetworkBufferTypes { } return null; }); + static final TypeImpl CAT_VARIANT = new TypeImpl<>(CatMeta.Variant.class, + (buffer, value) -> { + buffer.write(VAR_INT, value.ordinal()); + return -1; + }, + buffer -> { + final int ordinal = buffer.read(VAR_INT); + return CatMeta.Variant.values()[ordinal]; + }); + static final TypeImpl FROG_VARIANT = new TypeImpl<>(FrogMeta.Variant.class, + (buffer, value) -> { + buffer.write(VAR_INT, value.ordinal()); + return -1; + }, + buffer -> { + final int ordinal = buffer.read(VAR_INT); + return FrogMeta.Variant.values()[ordinal]; + }); record TypeImpl(@NotNull Class type, @NotNull TypeWriter writer,