From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Sun, 21 Mar 2021 15:49:15 -0500
Subject: [PATCH] Sneak to bulk process composter


diff --git a/src/main/java/net/minecraft/world/level/block/BlockComposter.java b/src/main/java/net/minecraft/world/level/block/BlockComposter.java
index e4e519ba773388b8d26a8f794a6eff51e3d8f72e..c0b235d5edf3cd14021696d1b4f76ce3de41f5d5 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockComposter.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockComposter.java
@@ -44,7 +44,7 @@ import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
 
 public class BlockComposter extends Block implements IInventoryHolder {
 
-    public static final BlockStateInteger a = BlockProperties.as;
+    public static final BlockStateInteger a = BlockProperties.as; public static BlockStateInteger level() { return BlockComposter.a; } // Purpur - OBFHELPER
     public static final Object2FloatMap<IMaterial> b = new Object2FloatOpenHashMap();
     private static final VoxelShape c = VoxelShapes.b();
     private static final VoxelShape[] d = (VoxelShape[]) SystemUtils.a((new VoxelShape[9]), (avoxelshape) -> { // CraftBukkit - decompile error
@@ -203,6 +203,25 @@ public class BlockComposter extends Block implements IInventoryHolder {
     public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, Entity entity) { // CraftBukkit
         int i = (Integer) iblockdata.get(BlockComposter.a);
 
+        // Purpur start
+        IBlockData newState = process(i, iblockdata, worldserver, itemstack, blockposition, entity);
+
+        if (worldserver.purpurConfig.composterBulkProcess && entity.isSneaking()) {
+            IBlockData oldState;
+            int oldCount, newCount, oldLevel, newLevel;
+            do {
+                oldState = newState;
+                oldCount = itemstack.getCount();
+                oldLevel = oldState.get(BlockComposter.level());
+                newState = process(oldLevel, oldState, worldserver, itemstack, blockposition, entity);
+                newCount = itemstack.getCount();
+                newLevel = newState.get(BlockComposter.level());
+            } while (newCount > 0 && (newCount != oldCount || newLevel != oldLevel || newState != oldState));
+        }
+        return newState;
+    }
+    private static IBlockData process(int i, IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, Entity entity) {
+        // Purpur end
         if (i < 7 && BlockComposter.b.containsKey(itemstack.getItem())) {
             // CraftBukkit start
             double rand = worldserver.getRandom().nextDouble();
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 58f2440498039bfa0af030f34372d0b1e6e82bed..0e1f6e0bda27547a59c2116f9eec3e29be9f36eb 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -456,6 +456,11 @@ public class PurpurWorldConfig {
         chestOpenWithBlockOnTop = getBoolean("blocks.chest.open-with-solid-block-on-top", chestOpenWithBlockOnTop);
     }
 
+    public boolean composterBulkProcess = false;
+    private void composterSettings() {
+        composterBulkProcess = getBoolean("blocks.composter.sneak-to-bulk-process", composterBulkProcess);
+    }
+
     public boolean dispenserApplyCursedArmor = true;
     public boolean dispenserPlaceAnvils = false;
     private void dispenserSettings() {
