From e163301d2315de337b98f335c550d2abe3bf217f Mon Sep 17 00:00:00 2001
From: Camotoy <20743703+Camotoy@users.noreply.github.com>
Date: Tue, 1 Mar 2022 15:44:13 -0500
Subject: [PATCH] Fix StackOverflow possibility with undead horses

---
 .../animal/horse/AbstractHorseEntity.java      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java
index de26e380e..f573840a6 100644
--- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java
+++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java
@@ -130,6 +130,11 @@ public class AbstractHorseEntity extends AnimalEntity {
     @Nonnull
     @Override
     protected InteractiveTag testMobInteraction(@Nonnull GeyserItemStack itemInHand) {
+        return testHorseInteraction(itemInHand);
+    }
+
+    @Nonnull
+    protected InteractiveTag testHorseInteraction(@Nonnull GeyserItemStack itemInHand) {
         boolean isBaby = isBaby();
         if (!isBaby) {
             if (getFlag(EntityFlag.TAMED) && session.isSneaking()) {
@@ -175,6 +180,11 @@ public class AbstractHorseEntity extends AnimalEntity {
     @Nonnull
     @Override
     protected InteractionResult mobInteract(@Nonnull GeyserItemStack itemInHand) {
+        return mobHorseInteract(itemInHand);
+    }
+
+    @Nonnull
+    protected final InteractionResult mobHorseInteract(@Nonnull GeyserItemStack itemInHand) {
         boolean isBaby = isBaby();
         if (!isBaby) {
             if (getFlag(EntityFlag.TAMED) && session.isSneaking()) {
@@ -243,11 +253,11 @@ public class AbstractHorseEntity extends AnimalEntity {
         if (!getFlag(EntityFlag.TAMED)) {
             return InteractiveTag.NONE;
         } else if (isBaby()) {
-            return testMobInteraction(itemInHand);
+            return testHorseInteraction(itemInHand);
         } else if (session.isSneaking()) {
             return InteractiveTag.OPEN_CONTAINER;
         } else if (!passengers.isEmpty()) {
-            return testMobInteraction(itemInHand);
+            return testHorseInteraction(itemInHand);
         } else {
             if (session.getItemMappings().getStoredItems().saddle() == itemInHand.getJavaId()) {
                 return InteractiveTag.OPEN_CONTAINER;
@@ -265,12 +275,12 @@ public class AbstractHorseEntity extends AnimalEntity {
         if (!getFlag(EntityFlag.TAMED)) {
             return InteractionResult.PASS;
         } else if (isBaby()) {
-            return mobInteract(itemInHand);
+            return mobHorseInteract(itemInHand);
         } else if (session.isSneaking()) {
             // Opens inventory
             return InteractionResult.SUCCESS;
         } else if (!passengers.isEmpty()) {
-            return mobInteract(itemInHand);
+            return mobHorseInteract(itemInHand);
         } else {
             // The client tests for saddle but it doesn't matter for us at this point.
             return InteractionResult.SUCCESS;