mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
105 lines
5.5 KiB
Diff
105 lines
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
Date: Sun, 7 May 2023 22:26:59 -0700
|
|
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 24b1715397ba8e6f5e9841a030d0e3d964356f89..1ab35b3123c25a80706e6557b4152279bfe8f50f 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -578,7 +578,7 @@ public class ServerPlayerGameMode {
|
|
ItemStack itemstack1 = stack.copy();
|
|
InteractionResult enuminteractionresult;
|
|
|
|
- if (!flag1) {
|
|
+ if (!flag1 || (player.level().purpurConfig.composterBulkProcess && iblockdata.is(Blocks.COMPOSTER))) { // Purpur
|
|
ItemInteractionResult iteminteractionresult = iblockdata.useItemOn(player.getItemInHand(hand), world, player, hand, hitResult);
|
|
|
|
if (iteminteractionresult.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 d3d12f9114173f4971f95d7ef895a4374705bd3f..f34159f8d6c51af2341bf49db0d6d6f0417919cf 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java
|
|
@@ -237,18 +237,27 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
int i = (Integer) state.getValue(ComposterBlock.LEVEL);
|
|
|
|
if (i < 8 && ComposterBlock.COMPOSTABLES.containsKey(stack.getItem())) {
|
|
- if (i < 7 && !world.isClientSide) {
|
|
- BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, stack);
|
|
- // Paper start - handle cancelled events
|
|
- if (iblockdata1 == null) {
|
|
- return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
|
|
- }
|
|
- // Paper end
|
|
-
|
|
- world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
|
|
- player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
|
|
- stack.consume(1, player);
|
|
+ // Purpur start - sneak to bulk process composter
|
|
+ BlockState newState = process(i, player, state, world, pos, stack);
|
|
+ if (newState == null) {
|
|
+ return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
|
|
}
|
|
+ if (world.purpurConfig.composterBulkProcess && player.isShiftKeyDown() && newState != state) {
|
|
+ BlockState oldState;
|
|
+ int oldCount, newCount, oldLevel, newLevel;
|
|
+ do {
|
|
+ oldState = newState;
|
|
+ oldCount = stack.getCount();
|
|
+ oldLevel = oldState.getValue(ComposterBlock.LEVEL);
|
|
+ newState = process(oldLevel, player, oldState, world, pos, stack);
|
|
+ if (newState == null) {
|
|
+ return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
|
|
+ }
|
|
+ newCount = stack.getCount();
|
|
+ newLevel = newState.getValue(ComposterBlock.LEVEL);
|
|
+ } while (newCount > 0 && (newCount != oldCount || newLevel != oldLevel || newState != oldState));
|
|
+ }
|
|
+ // Purpur end
|
|
|
|
return ItemInteractionResult.sidedSuccess(world.isClientSide);
|
|
} else {
|
|
@@ -256,6 +265,25 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
}
|
|
}
|
|
|
|
+ // Purpur start - sneak to bulk process composter
|
|
+ private static @Nullable BlockState process(int level, Player player, BlockState state, Level world, BlockPos pos, ItemStack stack) {
|
|
+ if (level < 7 && !world.isClientSide) {
|
|
+ BlockState iblockdata1 = ComposterBlock.addItem(player, state, world, pos, stack);
|
|
+ // Paper start - handle cancelled events
|
|
+ if (iblockdata1 == null) {
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
+ world.levelEvent(1500, pos, state != iblockdata1 ? 1 : 0);
|
|
+ player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
|
|
+ stack.consume(1, player);
|
|
+ return iblockdata1;
|
|
+ }
|
|
+ return state;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
|
|
int i = (Integer) state.getValue(ComposterBlock.LEVEL);
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
index 1081ac687fbf92aaca0d64703969b11b29e5fb41..77d785534e8186c3b930efe27469a9223b30f6c6 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
@@ -470,6 +470,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() {
|