From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <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/InteractWithDoor.java b/src/main/java/net/minecraft/world/entity/ai/behavior/InteractWithDoor.java
index 7ef1572b38f17a6a9947e52effaf3689df9b6c01..d195f5756446cae6bd0c3a97c483eeba3b4a1ce4 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/InteractWithDoor.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/InteractWithDoor.java
@@ -65,7 +65,7 @@ public class InteractWithDoor extends Behavior<LivingEntity> {
         BlockPos blockposition = pathpoint.asBlockPos();
         BlockState iblockdata = world.getBlockState(blockposition);
 
-        if (iblockdata.is((Tag) BlockTags.WOODEN_DOORS)) {
+        if (iblockdata.is(BlockTags.WOODEN_DOORS) && !DoorBlock.requiresRedstone(entity.level, iblockdata, blockposition)) { // Purpur
             DoorBlock blockdoor = (DoorBlock) iblockdata.getBlock();
 
             if (!blockdoor.isOpen(iblockdata)) {
@@ -85,7 +85,7 @@ public class InteractWithDoor extends Behavior<LivingEntity> {
         BlockPos blockposition1 = pathpoint1.asBlockPos();
         BlockState iblockdata1 = world.getBlockState(blockposition1);
 
-        if (iblockdata1.is((Tag) BlockTags.WOODEN_DOORS)) {
+        if (iblockdata1.is(BlockTags.WOODEN_DOORS) && !DoorBlock.requiresRedstone(entity.level, iblockdata, blockposition1)) { // Purpur
             DoorBlock blockdoor1 = (DoorBlock) iblockdata1.getBlock();
 
             if (!blockdoor1.isOpen(iblockdata1)) {
@@ -120,7 +120,7 @@ public class InteractWithDoor extends Behavior<LivingEntity> {
                     } else {
                         BlockState iblockdata = world.getBlockState(blockposition);
 
-                        if (!iblockdata.is((Tag) BlockTags.WOODEN_DOORS)) {
+                        if (!iblockdata.is(BlockTags.WOODEN_DOORS) || DoorBlock.requiresRedstone(entity.level, iblockdata, blockposition)) { // Purpur
                             iterator.remove();
                         } else {
                             DoorBlock blockdoor = (DoorBlock) iblockdata.getBlock();
diff --git a/src/main/java/net/minecraft/world/level/block/DoorBlock.java b/src/main/java/net/minecraft/world/level/block/DoorBlock.java
index c903a1a8d2234bb0fa354d1c44ff3ab2275b04c7..d01e4064a772710c1383927e0848b9b3b7299baa 100644
--- a/src/main/java/net/minecraft/world/level/block/DoorBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/DoorBlock.java
@@ -170,6 +170,7 @@ public class DoorBlock extends Block {
     public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
         if (this.material == Material.METAL) {
             return InteractionResult.PASS;
+        } else if (requiresRedstone(world, state, pos)) { return InteractionResult.CONSUME; // Purpur
         } else {
             state = (BlockState) state.cycle((Property) DoorBlock.OPEN);
             world.setBlock(pos, state, 10);
@@ -265,4 +266,18 @@ public class DoorBlock extends Block {
     public static boolean isWoodenDoor(BlockState state) {
         return state.getBlock() instanceof DoorBlock && (state.getMaterial() == Material.WOOD || state.getMaterial() == Material.NETHER_WOOD);
     }
+
+    // Purpur start
+    public static boolean requiresRedstone(Level level, BlockState state, BlockPos pos) {
+        if (level.purpurConfig.doorRequiresRedstone.contains(state.getBlock())) {
+            // force update client
+            BlockPos otherPos = pos.relative(state.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN);
+            BlockState otherState = level.getBlockState(otherPos);
+            level.sendBlockUpdated(pos, state, state, 3);
+            level.sendBlockUpdated(otherPos, otherState, otherState, 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 95277d97f1e35e9a05fd289f6a639b50fa820c61..cd37fef11cb6469718019d989a10e2e81a9d8b93 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -510,6 +510,16 @@ public class PurpurWorldConfig {
         dispenserPlaceAnvils = getBoolean("blocks.dispenser.place-anvils", dispenserPlaceAnvils);
     }
 
+    public List<Block> doorRequiresRedstone = new ArrayList<>();
+    private void doorSettings() {
+        getList("blocks.door.requires-redstone", new ArrayList<String>()).forEach(key -> {
+            Block block = Registry.BLOCK.get(new ResourceLocation(key.toString()));
+            if (!block.defaultBlockState().isAir()) {
+                doorRequiresRedstone.add(block);
+            }
+        });
+    }
+
     public boolean baselessEndCrystalExplode = true;
     public double baselessEndCrystalExplosionPower = 6.0D;
     public boolean baselessEndCrystalExplosionFire = false;
