From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Tue, 4 Aug 2020 21:11:03 -0500
Subject: [PATCH] Dispensers place anvils option


diff --git a/src/main/java/net/minecraft/core/EnumDirection.java b/src/main/java/net/minecraft/core/EnumDirection.java
index 7918d830a4aef09c9f517284e83a9376299116ad..29d747f7fc5824a222755ebf96dfe053896d43d0 100644
--- a/src/main/java/net/minecraft/core/EnumDirection.java
+++ b/src/main/java/net/minecraft/core/EnumDirection.java
@@ -116,6 +116,7 @@ public enum EnumDirection implements INamable {
         return fromType1(this.h);
     }
 
+    public EnumDirection rotateCW() { return g(); } // Purpur - OBFHELPER
     public EnumDirection g() {
         switch (this) {
             case NORTH:
@@ -131,6 +132,7 @@ public enum EnumDirection implements INamable {
         }
     }
 
+    public EnumDirection rotateCCW() { return h(); } // Purpur - OBFHELPER
     public EnumDirection h() {
         switch (this) {
             case NORTH:
@@ -162,6 +164,7 @@ public enum EnumDirection implements INamable {
         return this.j;
     }
 
+    public EnumDirection.EnumAxis getAxis() { return n(); } // Purpur - OBFHELPER
     public EnumDirection.EnumAxis n() {
         return this.k;
     }
diff --git a/src/main/java/net/minecraft/core/dispenser/IDispenseBehavior.java b/src/main/java/net/minecraft/core/dispenser/IDispenseBehavior.java
index 93093c05da53e5ddc59fac179081af2e0893706d..a6f74fc09843de9ad5af5c45e303e754ceea2c6d 100644
--- a/src/main/java/net/minecraft/core/dispenser/IDispenseBehavior.java
+++ b/src/main/java/net/minecraft/core/dispenser/IDispenseBehavior.java
@@ -52,6 +52,7 @@ import net.minecraft.world.level.IMaterial;
 import net.minecraft.world.level.IWorldReader;
 import net.minecraft.world.level.World;
 import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.BlockAnvil;
 import net.minecraft.world.level.block.BlockBeehive;
 import net.minecraft.world.level.block.BlockCampfire;
 import net.minecraft.world.level.block.BlockDispenser;
@@ -989,6 +990,23 @@ public interface IDispenseBehavior {
             }
         }));
         BlockDispenser.a((IMaterial) Items.SHEARS.getItem(), (IDispenseBehavior) (new DispenseBehaviorShears()));
+        // Purpur start
+        BlockDispenser.a(Blocks.ANVIL, new DispenseBehaviorMaybe() {
+            @Override
+            protected ItemStack a(ISourceBlock dispenser, ItemStack itemstack) {
+                World world = dispenser.getWorld();
+                if (!world.purpurConfig.dispenserPlaceAnvils) return super.a(dispenser, itemstack);
+                EnumDirection facing = dispenser.getBlockData().get(BlockDispenser.FACING);
+                BlockPosition blockposition = dispenser.getBlockPosition().shift(facing);
+                IBlockData iblockdata = world.getType(blockposition);
+                if (iblockdata.isAir()) {
+                    world.setTypeUpdate(blockposition, Blocks.ANVIL.getBlockData().set(BlockAnvil.FACING, facing.getAxis() == EnumDirection.EnumAxis.Y ? EnumDirection.NORTH : facing.rotateCW()));
+                    itemstack.subtract(1);
+                }
+                return itemstack;
+            }
+        });
+        // Purpur end
     }
 
     static void a(ISourceBlock isourceblock, Entity entity, EnumDirection enumdirection) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 4901e9b0f418132fbe48a424df57d0e7a8103821..de573b8e09a3ad334991cc313208e0c91990e8a9 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -251,8 +251,10 @@ public class PurpurWorldConfig {
     }
 
     public boolean dispenserApplyCursedArmor = true;
+    public boolean dispenserPlaceAnvils = false;
     private void dispenserSettings() {
         dispenserApplyCursedArmor = getBoolean("blocks.dispenser.apply-cursed-to-armor-slots", dispenserApplyCursedArmor);
+        dispenserPlaceAnvils = getBoolean("blocks.dispenser.place-anvils", dispenserPlaceAnvils);
     }
 
     public boolean farmlandGetsMoistFromBelow = false;
