From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <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/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index e97e3b4de132a452d560c19a1dcecd28f8010c62..0011b8305a95d5570f85cdac87655e66bbab94f1 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -582,7 +582,7 @@ public class ServerPlayerGameMode {
             boolean flag1 = player.isSecondaryUseActive() && flag;
             ItemStack itemstack1 = stack.copy();
 
-            if (!flag1) {
+            if (!flag1 || (player.level.purpurConfig.composterBulkProcess && iblockdata.is(Blocks.COMPOSTER))) { // Purpur
                 enuminteractionresult = iblockdata.use(world, player, hand, hitResult);
 
                 if (enuminteractionresult.consumesAction()) {
diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
index 4c9ae6bdb2f0358798f84928271a2d783dcba7b4..47bf769a031ae39cc72d2191195d13787f1568d4 100644
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
@@ -218,16 +218,21 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
         ItemStack itemstack = player.getItemInHand(hand);
 
         if (i < 8 && ComposterBlock.COMPOSTABLES.containsKey(itemstack.getItem())) {
-            if (i < 7 && !world.isClientSide) {
-                BlockState iblockdata1 = ComposterBlock.addItem(state, (LevelAccessor) world, pos, itemstack);
-
-                world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
-                player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
-                if (!player.getAbilities().instabuild) {
-                    itemstack.shrink(1);
-                }
+            // Purpur start
+            BlockState newState = process(i, state, world, itemstack, pos, player);
+            if (world.purpurConfig.composterBulkProcess && player.isShiftKeyDown()) {
+                BlockState oldState;
+                int oldCount, newCount, oldLevel, newLevel;
+                do {
+                    oldState = newState;
+                    oldCount = itemstack.getCount();
+                    oldLevel = oldState.getValue(ComposterBlock.LEVEL);
+                    newState = process(oldLevel, oldState, world, itemstack, pos, player);
+                    newCount = itemstack.getCount();
+                    newLevel = newState.getValue(ComposterBlock.LEVEL);
+                } while (newCount > 0 && (newCount != oldCount || newLevel != oldLevel || newState != oldState));
             }
-
+            // Purpur end
             return InteractionResult.sidedSuccess(world.isClientSide);
         } else if (i == 8) {
             ComposterBlock.d(state, world, pos, (Entity) null); // CraftBukkit - no event for players
@@ -237,6 +242,21 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
         }
     }
 
+    // Purpur start
+    private static BlockState process(int level, BlockState state, Level world, ItemStack itemstack, BlockPos pos, Player player) {
+        if (level < 7) {
+            BlockState state1 = ComposterBlock.addItem(state, world, pos, itemstack);
+            world.levelEvent(1500, pos, state != state1 ? 1 : 0);
+            player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
+            if (!player.getAbilities().instabuild) {
+                itemstack.shrink(1);
+            }
+            return state1;
+        }
+        return state;
+    }
+    // Purpur end
+
     public static BlockState a(BlockState iblockdata, ServerLevel worldserver, ItemStack itemstack, BlockPos blockposition, Entity entity) { // CraftBukkit
         int i = (Integer) iblockdata.getValue(ComposterBlock.LEVEL);
 
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index c9bebc201fdf944281e75ff0f614be845c3e8823..d9bd87e63f5f9e0dc3c7e5c0855625e12bb4f7e2 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -490,6 +490,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() {
