From fdc47c5368267a8584195dd97eb51793f3da129e Mon Sep 17 00:00:00 2001 From: Tofaa <82680183+Tofaa2@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:20:12 +0300 Subject: [PATCH] implement dyecolor for cat meta --- .../entitylib/MetaConverterRegistry.java | 2 + .../java/me/tofaa/entitylib/extras/Color.java | 55 ++++++++++++ .../me/tofaa/entitylib/extras/DyeColor.java | 85 +++++++++++++++++++ .../tofaa/entitylib/meta/mobs/GoatMeta.java | 25 ++++++ .../tofaa/entitylib/meta/mobs/HoglinMeta.java | 26 ++++++ .../entitylib/meta/mobs/MooshroomMeta.java | 33 +++++++ .../entitylib/meta/mobs/tameable/CatMeta.java | 38 +++++++++ .../entitylib/meta/types/TameableMeta.java | 46 ++++++++++ 8 files changed, 310 insertions(+) create mode 100644 src/main/java/me/tofaa/entitylib/extras/Color.java create mode 100644 src/main/java/me/tofaa/entitylib/extras/DyeColor.java create mode 100644 src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java create mode 100644 src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java create mode 100644 src/main/java/me/tofaa/entitylib/meta/mobs/MooshroomMeta.java create mode 100644 src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java create mode 100644 src/main/java/me/tofaa/entitylib/meta/types/TameableMeta.java diff --git a/src/main/java/me/tofaa/entitylib/MetaConverterRegistry.java b/src/main/java/me/tofaa/entitylib/MetaConverterRegistry.java index 84ef510..f648e2a 100644 --- a/src/main/java/me/tofaa/entitylib/MetaConverterRegistry.java +++ b/src/main/java/me/tofaa/entitylib/MetaConverterRegistry.java @@ -42,6 +42,8 @@ final class MetaConverterRegistry { put(STRIDER, StriderMeta::new); put(FOX, FoxMeta::new); put(FROG, FrogMeta::new); + put(GOAT, GoatMeta::new); + put(HOGLIN, HoglinMeta::new); } private void put(EntityType entityType, BiFunction function) { diff --git a/src/main/java/me/tofaa/entitylib/extras/Color.java b/src/main/java/me/tofaa/entitylib/extras/Color.java new file mode 100644 index 0000000..8feba87 --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/extras/Color.java @@ -0,0 +1,55 @@ +package me.tofaa.entitylib.extras; + +import net.kyori.adventure.util.RGBLike; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Range; + +public final class Color implements RGBLike { + + private static final int BIT_MASK = 0xFF; + + private final int red, green, blue; + + public Color(@Range(from = 0L, to = 255L) int red, @Range(from = 0L, to = 255L) int green, @Range(from = 0L, to = 255L) int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + public Color(int rgb) { + this((rgb >> 16) & BIT_MASK, (rgb >> 8) & BIT_MASK, rgb & BIT_MASK); + } + + public @NotNull Color withRed(@Range(from = 0L, to = 255L) int red) { + return new Color(red, green, blue); + } + + public @NotNull Color withGreen(@Range(from = 0L, to = 255L) int green) { + return new Color(red, green, blue); + } + + public @NotNull Color withBlue(@Range(from = 0L, to = 255L) int blue) { + return new Color(red, green, blue); + } + + public int asRGB() { + int rgb = red; + rgb = (rgb << 8) + green; + return (rgb << 8) + blue; + } + + @Override + public @Range(from = 0L, to = 255L) int red() { + return red; + } + + @Override + public @Range(from = 0L, to = 255L) int green() { + return green; + } + + @Override + public @Range(from = 0L, to = 255L) int blue() { + return blue; + } +} diff --git a/src/main/java/me/tofaa/entitylib/extras/DyeColor.java b/src/main/java/me/tofaa/entitylib/extras/DyeColor.java new file mode 100644 index 0000000..798036f --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/extras/DyeColor.java @@ -0,0 +1,85 @@ +package me.tofaa.entitylib.extras; + +import net.kyori.adventure.util.RGBLike; +import org.jetbrains.annotations.NotNull; + +public enum DyeColor implements RGBLike { + WHITE(new Color(0xf9fffe), new Color(0xffffff), new Color(0xf0f0f0), 8), + + ORANGE(new Color(0xf9801d), new Color(0xff681f), new Color(0xeb8844), 15), + + MAGENTA(new Color(0xc74ebd), new Color(0xff00ff), new Color(0xc354cd), 16), + + LIGHT_BLUE(new Color(0x3ab3da), new Color(0x9ac0cd), new Color(0x6689d3), 17), + + YELLOW(new Color(0xfed83d), new Color(0xffff00), new Color(0xdecf2a), 18), + + LIME(new Color(0x80c71f), new Color(0xbfff00), new Color(0x41cd34), 19), + + PINK(new Color(0xf38baa), new Color(0xff69b4), new Color(0xd88198), 20), + + GRAY(new Color(0x474f52), new Color(0x808080), new Color(0x434343), 21), + + LIGHT_GRAY(new Color(0x9d9d97), new Color(0xd3d3d3), new Color(0xababab), 22), + + CYAN(new Color(0x169c9c), new Color(0xffff), new Color(0x287697), 23), + + PURPLE(new Color(0x8932b8), new Color(0xa020f0), new Color(0x7b2fbe), 24), + + BLUE(new Color(0x3c44aa), new Color(0xff), new Color(0x253192), 25), + + BROWN(new Color(0x835432), new Color(0x8b4513), new Color(0x51301a), 26), + + GREEN(new Color(0x5e7c16), new Color(0xff00), new Color(0x3b511a), 27), + + RED(new Color(0xb02e26), new Color(0xff0000), new Color(0xb3312c), 28), + + BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29); + + private final Color textureDiffuseColor; + + private final Color textColor; + + private final Color fireworkColor; + + private final int mapColorId; + + DyeColor(@NotNull Color textureDiffuseColor, @NotNull Color textColor, + @NotNull Color fireworkColor, int mapColorId) { + this.textureDiffuseColor = textureDiffuseColor; + this.textColor = textColor; + this.fireworkColor = fireworkColor; + this.mapColorId = mapColorId; + } + + public @NotNull Color color() { + return this.textureDiffuseColor; + } + + public @NotNull Color textColor() { + return this.textColor; + } + + public @NotNull Color fireworkColor() { + return this.fireworkColor; + } + + @Override + public int red() { + return this.textureDiffuseColor.red(); + } + + @Override + public int green() { + return this.textureDiffuseColor.green(); + } + + @Override + public int blue() { + return this.textureDiffuseColor.blue(); + } + + public int mapColorId() { + return this.mapColorId; + } +} diff --git a/src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java b/src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java new file mode 100644 index 0000000..0fb05b9 --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java @@ -0,0 +1,25 @@ +package me.tofaa.entitylib.meta.mobs; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import me.tofaa.entitylib.meta.Metadata; +import me.tofaa.entitylib.meta.types.AgeableMeta; + +public class GoatMeta extends AgeableMeta { + + public static final byte OFFSET = AgeableMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 1; + + + public GoatMeta(int entityId, Metadata metadata) { + super(entityId, metadata); + } + + public boolean isScreaming() { + return metadata.getIndex(OFFSET, false); + } + + public void setScreaming(boolean screaming) { + metadata.setIndex(OFFSET, EntityDataTypes.BOOLEAN, screaming); + } + +} diff --git a/src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java b/src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java new file mode 100644 index 0000000..5c3c4bc --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java @@ -0,0 +1,26 @@ +package me.tofaa.entitylib.meta.mobs; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import me.tofaa.entitylib.meta.Metadata; +import me.tofaa.entitylib.meta.types.AgeableMeta; + +public class HoglinMeta extends AgeableMeta { + + public static final byte OFFSET = AgeableMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 1; + + public HoglinMeta(int entityId, Metadata metadata) { + super(entityId, metadata); + } + + + public boolean isImmuneToZombification() { + return super.metadata.getIndex(OFFSET, false); + } + + public void setImmuneToZombification(boolean value) { + super.metadata.setIndex(OFFSET, EntityDataTypes.BOOLEAN, value); + } + + +} diff --git a/src/main/java/me/tofaa/entitylib/meta/mobs/MooshroomMeta.java b/src/main/java/me/tofaa/entitylib/meta/mobs/MooshroomMeta.java new file mode 100644 index 0000000..b989d08 --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/meta/mobs/MooshroomMeta.java @@ -0,0 +1,33 @@ +package me.tofaa.entitylib.meta.mobs; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import me.tofaa.entitylib.meta.Metadata; +import org.jetbrains.annotations.NotNull; + +import java.util.Locale; + +public class MooshroomMeta extends CowMeta{ + + public static final byte OFFSET = CowMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 1; + + public MooshroomMeta(int entityId, Metadata metadata) { + super(entityId, metadata); + } + + @NotNull + public Variant getVariant() { + return Variant.valueOf(super.metadata.getIndex(OFFSET, "red").toUpperCase(Locale.ROOT)); + } + + public void setVariant(@NotNull Variant value) { + super.metadata.setIndex(OFFSET, EntityDataTypes.STRING, value.name().toLowerCase(Locale.ROOT)); + } + + public enum Variant { + RED, + BROWN + } + + +} diff --git a/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java b/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java new file mode 100644 index 0000000..80e1181 --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java @@ -0,0 +1,38 @@ +package me.tofaa.entitylib.meta.mobs.tameable; + +import me.tofaa.entitylib.meta.Metadata; +import me.tofaa.entitylib.meta.types.TameableMeta; +import net.kyori.adventure.text.format.NamedTextColor; + +public class CatMeta extends TameableMeta { + + public static final byte OFFSET = TameableMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 4; + + private static final NamedTextColor[] COLORS = new NamedTextColor[] { + NamedTextColor.BLACK, NamedTextColor.RED, NamedTextColor.WHITE, NamedTextColor.YELLOW, NamedTextColor.GRAY, + NamedTextColor.WHITE, + }; + + public CatMeta(int entityId, Metadata metadata) { + super(entityId, metadata); + } + + + public enum Variant { + TABBY, + BLACK, + RED, + SIAMESE, + BRITISH_SHORTHAIR, + CALICO, + PERSIAN, + RAGDOLL, + WHITE, + JELLIE, + ALL_BLACK; + + private static final Variant[] VALUES = values(); + } + +} diff --git a/src/main/java/me/tofaa/entitylib/meta/types/TameableMeta.java b/src/main/java/me/tofaa/entitylib/meta/types/TameableMeta.java new file mode 100644 index 0000000..0db1569 --- /dev/null +++ b/src/main/java/me/tofaa/entitylib/meta/types/TameableMeta.java @@ -0,0 +1,46 @@ +package me.tofaa.entitylib.meta.types; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import me.tofaa.entitylib.meta.Metadata; + +import java.util.Optional; +import java.util.UUID; + +public class TameableMeta extends AgeableMeta{ + + public static final byte OFFSET = AgeableMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 2; + + private final static byte SITTING_BIT = 0x01; + private final static byte TAMED_BIT = 0x04; + + public TameableMeta(int entityId, Metadata metadata) { + super(entityId, metadata); + } + + + public boolean isSitting() { + return getMaskBit(OFFSET, SITTING_BIT); + } + + public void setSitting(boolean value) { + setMaskBit(OFFSET, SITTING_BIT, value); + } + + public boolean isTamed() { + return getMaskBit(OFFSET, TAMED_BIT); + } + + public void setTamed(boolean value) { + setMaskBit(OFFSET, TAMED_BIT, value); + } + + public Optional getOwner() { + return super.metadata.getIndex(offset(OFFSET, 1), Optional.empty()); + } + + public void setOwner(UUID value) { + super.metadata.setIndex(offset(OFFSET, 1), EntityDataTypes.OPTIONAL_UUID, Optional.ofNullable(value)); + } + +}