Skip to content

Commit

Permalink
Compatible /clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
PureGero committed Aug 11, 2024
1 parent b2d1e8a commit f1819ee
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions patches/server/0053-clear-command.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: PureGero <puregero@gmail.com>
Date: Sun, 11 Aug 2024 18:50:42 +0900
Subject: [PATCH] /clear command


diff --git a/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java b/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java
index 4e6171ca870649114d4c7460baad2982173da09e..f3efba187cfb35e08458de59a171c82bff8d3280 100644
--- a/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java
+++ b/src/main/java/net/minecraft/server/commands/ClearInventoryCommands.java
@@ -6,7 +6,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import java.util.Collection;
import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
+
+import io.multipaper.shreddedpaper.ShreddedPaper;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@@ -65,9 +68,16 @@ public class ClearInventoryCommands {
int i = 0;

for (ServerPlayer serverPlayer : targets) {
- i += serverPlayer.getInventory().clearOrCountMatchingItems(item, maxCount, serverPlayer.inventoryMenu.getCraftSlots());
- serverPlayer.containerMenu.broadcastChanges();
- serverPlayer.inventoryMenu.slotsChanged(serverPlayer.getInventory());
+ // ShreddedPaper start - run on correct thread
+ CompletableFuture<Integer> future = new CompletableFuture<>();
+ ShreddedPaper.ensureSync(serverPlayer, () -> {
+ int j = serverPlayer.getInventory().clearOrCountMatchingItems(item, maxCount, serverPlayer.inventoryMenu.getCraftSlots());
+ serverPlayer.containerMenu.broadcastChanges();
+ serverPlayer.inventoryMenu.slotsChanged(serverPlayer.getInventory());
+ future.complete(j);
+ });
+ i += future.getNow(1); // ShreddedPaper - default to 1 if player in on a different thread
+ // ShreddedPaper end - run on correct thread
}

if (i == 0) {

0 comments on commit f1819ee

Please sign in to comment.