From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 18 Oct 2019 22:50:12 -0500
Subject: [PATCH] Llama API


diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLlamaFollow.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLlamaFollow.java
index 4fd1744f13b87c79ae3f46b28a56daeaba343aa6..34a854131dd939693a6df4d52103714ebe373dc3 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLlamaFollow.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalLlamaFollow.java
@@ -11,7 +11,7 @@ import net.minecraft.world.phys.Vec3D;
 
 public class PathfinderGoalLlamaFollow extends PathfinderGoal {
 
-    public final EntityLlama a;
+    public final EntityLlama a; public EntityLlama getLlama() { return a; } // Purpur
     private double b;
     private int c;
 
@@ -23,6 +23,7 @@ public class PathfinderGoalLlamaFollow extends PathfinderGoal {
 
     @Override
     public boolean a() {
+        if (!getLlama().shouldJoinCaravan) return false; // Purpur
         if (!this.a.isLeashed() && !this.a.fC()) {
             List<Entity> list = this.a.world.getEntities(this.a, this.a.getBoundingBox().grow(9.0D, 4.0D, 9.0D), (entity) -> {
                 EntityTypes<?> entitytypes = entity.getEntityType();
@@ -82,6 +83,7 @@ public class PathfinderGoalLlamaFollow extends PathfinderGoal {
 
     @Override
     public boolean b() {
+        if (!getLlama().shouldJoinCaravan) return false; // Purpur
         if (this.a.fC() && this.a.fD().isAlive() && this.a(this.a, 0)) {
             double d0 = this.a.h((Entity) this.a.fD());
 
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/EntityLlama.java b/src/main/java/net/minecraft/world/entity/animal/horse/EntityLlama.java
index 2005cb484ba6b5929ad81d3d120521f247f3d4cf..1c6435bf2cd870b795f87368057d8dfc1e1c938a 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/EntityLlama.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/EntityLlama.java
@@ -63,7 +63,8 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
     @Nullable
     private EntityLlama bB;
     @Nullable
-    private EntityLlama bC;
+    private EntityLlama bC; public EntityLlama getCaravanTail() { return bC; } // Purpur - OBFHELPER
+    public boolean shouldJoinCaravan = true; // Purpur
 
     public EntityLlama(EntityTypes<? extends EntityLlama> entitytypes, World world) {
         super(entitytypes, world);
@@ -92,6 +93,7 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
             nbttagcompound.set("DecorItem", this.inventoryChest.getItem(1).save(new NBTTagCompound()));
         }
 
+        nbttagcompound.setBoolean("Purpur.ShouldJoinCaravan", shouldJoinCaravan); // Purpur
     }
 
     @Override
@@ -103,6 +105,11 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
             this.inventoryChest.setItem(1, ItemStack.a(nbttagcompound.getCompound("DecorItem")));
         }
 
+        // Purpur start
+        if (nbttagcompound.hasKey("Purpur.ShouldJoinCaravan")) {
+            nbttagcompound.setBoolean("Purpur.ShouldJoinCaravan", shouldJoinCaravan);
+        }
+        // Purpur end
         this.fe();
     }
 
@@ -437,19 +444,24 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
         }
     }
 
+    public void leaveCaravan() { fA(); } // Purpur - OBFHELPER
     public void fA() {
         if (this.bB != null) {
+            new net.pl3x.purpur.event.entity.LlamaLeaveCaravanEvent((org.bukkit.entity.Llama) getBukkitEntity()).callEvent(); // Purpur
             this.bB.bC = null;
         }
 
         this.bB = null;
     }
 
+    public void joinCaravan(EntityLlama entitiyllama) { a(entitiyllama); } // Purpur - OBFHELPER
     public void a(EntityLlama entityllama) {
+        if (!shouldJoinCaravan || !new net.pl3x.purpur.event.entity.LlamaJoinCaravanEvent((org.bukkit.entity.Llama) getBukkitEntity(), (org.bukkit.entity.Llama) entityllama.getBukkitEntity()).callEvent()) return; // Purpur
         this.bB = entityllama;
         this.bB.bC = this;
     }
 
+    public boolean hasCaravanTail() { return fB(); } // Purpur - OBFHELPER
     public boolean fB() {
         return this.bC != null;
     }
@@ -460,7 +472,7 @@ public class EntityLlama extends EntityHorseChestedAbstract implements IRangedEn
     }
 
     @Nullable
-    public EntityLlama fD() {
+    public EntityLlama fD() { return getCaravanHead(); } public EntityLlama getCaravanHead() { // Purpur - OBFHELPER
         return this.bB;
     }
 
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java
index 818034c62893a71808e3af0aa33393605611acdd..71536b6ae6a423e33667efcf584a0020f36fb189 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java
@@ -66,4 +66,48 @@ public class CraftLlama extends CraftChestedHorse implements Llama, CraftRangedE
     public EntityType getType() {
         return EntityType.LLAMA;
     }
+
+    // Purpur start
+    @Override
+    public boolean shouldJoinCaravan() {
+        return getHandle().shouldJoinCaravan;
+    }
+
+    @Override
+    public void setShouldJoinCaravan(boolean shouldJoinCaravan) {
+        getHandle().shouldJoinCaravan = shouldJoinCaravan;
+    }
+
+    @Override
+    public boolean inCaravan() {
+        return getHandle().inCaravan();
+    }
+
+    @Override
+    public void joinCaravan(Llama llama) {
+        if (llama != null) {
+            getHandle().joinCaravan(((CraftLlama) llama).getHandle());
+        }
+    }
+
+    @Override
+    public void leaveCaravan() {
+        getHandle().leaveCaravan();
+    }
+
+    @Override
+    public boolean hasCaravanTail() {
+        return getHandle().hasCaravanTail();
+    }
+
+    @Override
+    public Llama getCaravanHead() {
+        return getHandle().getCaravanHead() == null ? null : (Llama) getHandle().getCaravanHead().getBukkitEntity();
+    }
+
+    @Override
+    public Llama getCaravanTail() {
+        return getHandle().getCaravanTail() == null ? null : (Llama) getHandle().getCaravanTail().getBukkitEntity();
+    }
+    // Purpur end
 }
