From 34558e75eecc30254c6e22e44280d6381964418f Mon Sep 17 00:00:00 2001 From: David Mayr Date: Mon, 7 Aug 2023 03:32:39 +0200 Subject: [PATCH] hollow-cube/entity-metadata-patches (#35) * feat: add more boat types * feat: goat horn api * feat: pillager crossbow meta * feat: use boat metadata for chestboat * feat: add warden meta * fix: incorrect dolphin meta * feat: allow to set null values for tounge target * feat: nullable tounge target * fix: update max offset in goat --- .../server/entity/EntityTypeImpl.java | 4 ++-- .../entity/metadata/animal/FrogMeta.java | 9 ++++--- .../entity/metadata/animal/GoatMeta.java | 18 +++++++++++++- .../entity/metadata/monster/WardenMeta.java | 24 +++++++++++++++++++ .../metadata/monster/raider/PillagerMeta.java | 10 +++++++- .../entity/metadata/other/BoatMeta.java | 5 +++- .../entity/metadata/water/DolphinMeta.java | 13 +++++----- 7 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/minestom/server/entity/metadata/monster/WardenMeta.java diff --git a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java index 42de94ddb..c7f82f274 100644 --- a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java +++ b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java @@ -88,7 +88,7 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { entry("minecraft:blaze", BlazeMeta::new), entry("minecraft:block_display", BlockDisplayMeta::new), entry("minecraft:boat", BoatMeta::new), - entry("minecraft:chest_boat", EntityMeta::new), // TODO dedicated metadata + entry("minecraft:chest_boat", BoatMeta::new), entry("minecraft:camel", CamelMeta::new), entry("minecraft:cat", CatMeta::new), entry("minecraft:cave_spider", CaveSpiderMeta::new), @@ -189,7 +189,7 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { entry("minecraft:villager", VillagerMeta::new), entry("minecraft:vindicator", VindicatorMeta::new), entry("minecraft:wandering_trader", WanderingTraderMeta::new), - entry("minecraft:warden", EntityMeta::new), // TODO dedicated metadata + entry("minecraft:warden", WardenMeta::new), entry("minecraft:witch", WitchMeta::new), entry("minecraft:wither", WitherMeta::new), entry("minecraft:wither_skeleton", WitherSkeletonMeta::new), 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 index a98c919b7..cfb2914ce 100644 --- a/src/main/java/net/minestom/server/entity/metadata/animal/FrogMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/animal/FrogMeta.java @@ -3,6 +3,7 @@ package net.minestom.server.entity.metadata.animal; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class FrogMeta extends AnimalMeta { public static final byte OFFSET = AnimalMeta.MAX_OFFSET; @@ -20,14 +21,16 @@ public class FrogMeta extends AnimalMeta { super.metadata.setIndex(OFFSET, Metadata.FrogVariant(value)); } - public int getTongueTarget() { - return super.metadata.getIndex(OFFSET + 1, 0); + public @Nullable Integer getTongueTarget() { + return super.metadata.getIndex(OFFSET + 1, null); } - public void setTongueTarget(int value) { + + public void setTongueTarget(@Nullable Integer value) { super.metadata.setIndex(OFFSET + 1, Metadata.OptVarInt(value)); } + public enum Variant { TEMPERATE, WARM, diff --git a/src/main/java/net/minestom/server/entity/metadata/animal/GoatMeta.java b/src/main/java/net/minestom/server/entity/metadata/animal/GoatMeta.java index f830d79b4..de2a71b81 100644 --- a/src/main/java/net/minestom/server/entity/metadata/animal/GoatMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/animal/GoatMeta.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull; public class GoatMeta extends AnimalMeta { public static final byte OFFSET = AnimalMeta.MAX_OFFSET; - public static final byte MAX_OFFSET = OFFSET + 1; + public static final byte MAX_OFFSET = OFFSET + 3; public GoatMeta(@NotNull Entity entity, @NotNull Metadata metadata) { super(entity, metadata); @@ -19,4 +19,20 @@ public class GoatMeta extends AnimalMeta { public void setScreaming(boolean screaming) { metadata.setIndex(OFFSET, Metadata.Boolean(screaming)); } + + public boolean hasLeftHorn() { + return metadata.getIndex(OFFSET + 1, true); + } + + public void setLeftHorn(boolean leftHorn) { + metadata.setIndex(OFFSET + 1, Metadata.Boolean(leftHorn)); + } + + public boolean hasRightHorn() { + return metadata.getIndex(OFFSET + 2, true); + } + + public void setRightHorn(boolean rightHorn) { + metadata.setIndex(OFFSET + 2, Metadata.Boolean(rightHorn)); + } } diff --git a/src/main/java/net/minestom/server/entity/metadata/monster/WardenMeta.java b/src/main/java/net/minestom/server/entity/metadata/monster/WardenMeta.java new file mode 100644 index 000000000..261f6b584 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/metadata/monster/WardenMeta.java @@ -0,0 +1,24 @@ +package net.minestom.server.entity.metadata.monster; + +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.Metadata; +import org.jetbrains.annotations.NotNull; + +public class WardenMeta extends MonsterMeta { + + public static final byte OFFSET = MonsterMeta.MAX_OFFSET; + public static final byte MAX_OFFSET = OFFSET + 1; + + public WardenMeta(@NotNull Entity entity, @NotNull Metadata metadata) { + super(entity, metadata); + } + + public int getAngerLevel() { + return super.metadata.getIndex(OFFSET, 0); + } + + public void setAngerLevel(int value) { + super.metadata.setIndex(OFFSET, Metadata.VarInt(value)); + } + +} diff --git a/src/main/java/net/minestom/server/entity/metadata/monster/raider/PillagerMeta.java b/src/main/java/net/minestom/server/entity/metadata/monster/raider/PillagerMeta.java index 5755ed4b1..8096e5e2a 100644 --- a/src/main/java/net/minestom/server/entity/metadata/monster/raider/PillagerMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/monster/raider/PillagerMeta.java @@ -6,10 +6,18 @@ import org.jetbrains.annotations.NotNull; public class PillagerMeta extends AbstractIllagerMeta { public static final byte OFFSET = AbstractIllagerMeta.MAX_OFFSET; - public static final byte MAX_OFFSET = OFFSET + 0; + public static final byte MAX_OFFSET = OFFSET + 1; public PillagerMeta(@NotNull Entity entity, @NotNull Metadata metadata) { super(entity, metadata); } + public boolean isChargingCrossbow() { + return super.metadata.getIndex(OFFSET, false); + } + + public void setChargingCrossbow(boolean value) { + super.metadata.setIndex(OFFSET, Metadata.Boolean(value)); + } + } diff --git a/src/main/java/net/minestom/server/entity/metadata/other/BoatMeta.java b/src/main/java/net/minestom/server/entity/metadata/other/BoatMeta.java index 6be448318..57e3e40ec 100644 --- a/src/main/java/net/minestom/server/entity/metadata/other/BoatMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/other/BoatMeta.java @@ -76,7 +76,10 @@ public class BoatMeta extends EntityMeta { BIRCH, JUNGLE, ACACIA, - DARK_OAK; + CHERRY, + DARK_OAK, + MANGROVE, + BAMBOO; private final static Type[] VALUES = values(); } diff --git a/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java b/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java index 549027447..6dca1c672 100644 --- a/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java @@ -23,20 +23,19 @@ public class DolphinMeta extends WaterAnimalMeta { super.metadata.setIndex(OFFSET, Metadata.Position(value)); } - public boolean isCanFindTreasure() { + public boolean isHasFish() { return super.metadata.getIndex(OFFSET + 1, false); } - public void setCanFindTreasure(boolean value) { + public void setHasFish(boolean value) { super.metadata.setIndex(OFFSET + 1, Metadata.Boolean(value)); } - public boolean isHasFish() { - return super.metadata.getIndex(OFFSET + 2, false); + public int getMoistureLevel() { + return super.metadata.getIndex(OFFSET + 2, 2400); } - public void setHasFish(boolean value) { - super.metadata.setIndex(OFFSET + 2, Metadata.Boolean(value)); + public void setMoistureLevel(int value) { + super.metadata.setIndex(OFFSET + 2, Metadata.VarInt(value)); } - }