implement dyecolor for cat meta
This commit is contained in:
parent
c38cc5871a
commit
fdc47c5368
8 changed files with 310 additions and 0 deletions
|
@ -42,6 +42,8 @@ final class MetaConverterRegistry {
|
||||||
put(STRIDER, StriderMeta::new);
|
put(STRIDER, StriderMeta::new);
|
||||||
put(FOX, FoxMeta::new);
|
put(FOX, FoxMeta::new);
|
||||||
put(FROG, FrogMeta::new);
|
put(FROG, FrogMeta::new);
|
||||||
|
put(GOAT, GoatMeta::new);
|
||||||
|
put(HOGLIN, HoglinMeta::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void put(EntityType entityType, BiFunction<Integer, Metadata, EntityMeta> function) {
|
private void put(EntityType entityType, BiFunction<Integer, Metadata, EntityMeta> function) {
|
||||||
|
|
55
src/main/java/me/tofaa/entitylib/extras/Color.java
Normal file
55
src/main/java/me/tofaa/entitylib/extras/Color.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
85
src/main/java/me/tofaa/entitylib/extras/DyeColor.java
Normal file
85
src/main/java/me/tofaa/entitylib/extras/DyeColor.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
25
src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java
Normal file
25
src/main/java/me/tofaa/entitylib/meta/mobs/GoatMeta.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
26
src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java
Normal file
26
src/main/java/me/tofaa/entitylib/meta/mobs/HoglinMeta.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<UUID> 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue