From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Wed, 24 Mar 2021 04:40:11 -0500
Subject: [PATCH] Option to make doors require redstone


diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorInteractDoor.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorInteractDoor.java
index 4b8df9f05e10b7f42f2b45f31082886d597b3bc9..bde24d90fd1c1dc19fb26bce4e625fab4983e8c2 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorInteractDoor.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorInteractDoor.java
@@ -62,7 +62,7 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
         BlockPosition blockposition = pathpoint.a();
         IBlockData iblockdata = worldserver.getType(blockposition);
 
-        if (iblockdata.a((Tag) TagsBlock.WOODEN_DOORS)) {
+        if (iblockdata.a((Tag) TagsBlock.WOODEN_DOORS) && !BlockDoor.requiresRedstone(entityliving.world, iblockdata, blockposition)) { // Purpur
             BlockDoor blockdoor = (BlockDoor) iblockdata.getBlock();
 
             if (!blockdoor.h(iblockdata)) {
@@ -82,7 +82,7 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
         BlockPosition blockposition1 = pathpoint1.a();
         IBlockData iblockdata1 = worldserver.getType(blockposition1);
 
-        if (iblockdata1.a((Tag) TagsBlock.WOODEN_DOORS)) {
+        if (iblockdata1.a((Tag) TagsBlock.WOODEN_DOORS) && !BlockDoor.requiresRedstone(entityliving.world, iblockdata, blockposition1)) { // Purpur
             BlockDoor blockdoor1 = (BlockDoor) iblockdata1.getBlock();
 
             if (!blockdoor1.h(iblockdata1)) {
@@ -117,7 +117,7 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
                     } else {
                         IBlockData iblockdata = worldserver.getType(blockposition);
 
-                        if (!iblockdata.a((Tag) TagsBlock.WOODEN_DOORS)) {
+                        if (!iblockdata.a((Tag) TagsBlock.WOODEN_DOORS) || BlockDoor.requiresRedstone(entityliving.world, iblockdata, blockposition)) { // Purpur
                             iterator.remove();
                         } else {
                             BlockDoor blockdoor = (BlockDoor) iblockdata.getBlock();
diff --git a/src/main/java/net/minecraft/world/level/block/BlockDoor.java b/src/main/java/net/minecraft/world/level/block/BlockDoor.java
index 453b46851f021d4285be123bedc8982fc8844da2..2a7695c899b12c87ab89d00116b6f0dd0c9fd9dc 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockDoor.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockDoor.java
@@ -167,6 +167,10 @@ public class BlockDoor extends Block {
     public EnumInteractionResult interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
         if (this.material == Material.ORE) {
             return EnumInteractionResult.PASS;
+            // Purpur start
+        } else if (requiresRedstone(world, iblockdata, blockposition)) {
+            return EnumInteractionResult.CONSUME;
+            // Purpur end
         } else {
             iblockdata = (IBlockData) iblockdata.a((IBlockState) BlockDoor.OPEN);
             world.setTypeAndData(blockposition, iblockdata, 10);
@@ -254,4 +258,18 @@ public class BlockDoor extends Block {
     public static boolean l(IBlockData iblockdata) {
         return iblockdata.getBlock() instanceof BlockDoor && (iblockdata.getMaterial() == Material.WOOD || iblockdata.getMaterial() == Material.NETHER_WOOD);
     }
+
+    // Purpur start
+    public static boolean requiresRedstone(World world, IBlockData iblockdata, BlockPosition blockposition) {
+        if (world.purpurConfig.doorRequiresRedstone.contains(iblockdata.getBlock())) {
+            // force update client
+            BlockPosition otherBlockPosition = blockposition.shift(iblockdata.get(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN);
+            IBlockData otherIBlockData = world.getType(otherBlockPosition);
+            world.notify(blockposition, iblockdata, iblockdata, 3);
+            world.notify(otherBlockPosition, otherIBlockData, otherIBlockData, 3);
+            return true;
+        }
+        return false;
+    }
+    // Purpur end
 }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 40771bafbcf3b65e3a9d6397d492296eee01c85b..be6637a7de0dc9514af5f0d30e1095c95652e26b 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -450,6 +450,16 @@ public class PurpurWorldConfig {
         }
     }
 
+    public List<Block> doorRequiresRedstone = new ArrayList<>();
+    private void doorSettings() {
+        getList("blocks.door.requires-redstone", new ArrayList<String>()).forEach(key -> {
+            Block block = IRegistry.BLOCK.get(new MinecraftKey(key.toString()));
+            if (!block.getBlockData().isAir()) {
+                doorRequiresRedstone.add(block);
+            }
+        });
+    }
+
     public boolean snowOnBlueIce = true;
     public boolean mobsSpawnOnPackedIce = true;
     public boolean mobsSpawnOnBlueIce = true;
