From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: draycia <lonelyyordle@gmail.com>
Date: Wed, 29 Apr 2020 00:45:58 -0700
Subject: [PATCH] Totems work in inventory


diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
index f4407cd0865b0e4861930645615c057d11079034..8930ab8a39c50eaa84372f0e8caf8b92789bb0c4 100644
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
@@ -1426,6 +1426,19 @@ public abstract class EntityLiving extends Entity {
                 }
             }
 
+            // Purpur start
+            if (world.purpurConfig.totemOfUndyingWorksInInventory && this instanceof EntityPlayer && (itemstack == null || itemstack.getItem() != Items.TOTEM_OF_UNDYING)) {
+                EntityPlayer player = (EntityPlayer) this;
+                for (ItemStack item : player.inventory.items) {
+                    if (item.getItem() == Items.TOTEM_OF_UNDYING) {
+                        itemstack1 = item;
+                        itemstack = item.cloneItemStack();
+                        break;
+                    }
+                }
+            }
+            // Purpur end
+
             EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity());
             event.setCancelled(itemstack == null);
             this.world.getServer().getPluginManager().callEvent(event);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index ad32a4b3a601396c8d485d2264088d6cb4c92ebf..2e3667c2c2530a1222f2ad7a4988ba8076759dc4 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -201,6 +201,11 @@ public class PurpurWorldConfig {
         teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
     }
 
+    public boolean totemOfUndyingWorksInInventory = false;
+    private void totemOfUndyingWorksInInventory() {
+        totemOfUndyingWorksInInventory = getBoolean("gameplay-mechanics.player.totem-of-undying-works-in-inventory", totemOfUndyingWorksInInventory);
+    }
+
     public boolean silkTouchEnabled = false;
     public String silkTouchSpawnerName = "Spawner";
     public List<String> silkTouchSpawnerLore = new ArrayList<>();
