From a397f55e8b29cf3121545373768d8a8f0768f943 Mon Sep 17 00:00:00 2001
From: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date: Mon, 6 Jun 2022 21:06:02 -0400
Subject: [PATCH] Add goat horn count

---
 .../geyser/entity/EntityDefinitions.java        |  2 ++
 .../entity/type/living/animal/GoatEntity.java   | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java
index 73814628f..52d9250ac 100644
--- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java
+++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java
@@ -772,6 +772,8 @@ public final class EntityDefinitions {
                     .type(EntityType.GOAT)
                     .height(1.3f).width(0.9f)
                     .addTranslator(MetadataType.BOOLEAN, GoatEntity::setScreamer)
+                    .addTranslator(MetadataType.BOOLEAN, GoatEntity::setHasLeftHorn)
+                    .addTranslator(MetadataType.BOOLEAN, GoatEntity::setHasRightHorn)
                     .build();
             MOOSHROOM = EntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase)
                     .type(EntityType.MOOSHROOM)
diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java
index a6f2e268e..d50eb74c5 100644
--- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java
+++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java
@@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanE
 import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
 import com.nukkitx.math.vector.Vector3f;
 import com.nukkitx.protocol.bedrock.data.SoundEvent;
+import com.nukkitx.protocol.bedrock.data.entity.EntityData;
 import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
 import org.geysermc.geyser.entity.EntityDefinition;
 import org.geysermc.geyser.inventory.GeyserItemStack;
@@ -44,6 +45,8 @@ public class GoatEntity extends AnimalEntity {
     private static final float LONG_JUMPING_WIDTH = 0.9f * 0.7f;
 
     private boolean isScreamer;
+    private boolean hasLeftHorn;
+    private boolean hasRightHorn;
 
     public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
         super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@@ -74,4 +77,18 @@ public class GoatEntity extends AnimalEntity {
             return super.mobInteract(hand, itemInHand);
         }
     }
+
+    public void setHasLeftHorn(BooleanEntityMetadata entityMetadata) {
+        hasLeftHorn = entityMetadata.getPrimitiveValue();
+        setHornCount();
+    }
+
+    public void setHasRightHorn(BooleanEntityMetadata entityMetadata) {
+        hasRightHorn = entityMetadata.getPrimitiveValue();
+        setHornCount();
+    }
+
+    private void setHornCount() {
+        dirtyMetadata.put(EntityData.GOAT_HORN_COUNT, (hasLeftHorn ? 1 : 0) + (hasRightHorn ? 1 : 0));
+    }
 }