Skip to content

Commit a3e8226

Browse files
committed
Run closeContainer synchronously and pause scripts for 1 tick. Fixes #141
1 parent 47a5919 commit a3e8226

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/clientcommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ declare class ControllablePlayer extends Player {
245245
openContainer(entity: Entity, expectedContainerType: string | ((containerType: string) => boolean)): boolean;
246246

247247
/**
248-
* Closes the currently opened container, if any is open
248+
* Closes the currently opened container, if any is open. Due to a threading issue in 1.16, this method delays
249+
* the script by 1 tick, if a container was open.
249250
*/
250251
closeContainer(): void;
251252

src/main/java/net/earthcomputer/clientcommands/script/ScriptPlayer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ private boolean openContainer0(BooleanSupplier rightClickFunction, Object contai
354354
}
355355

356356
public void closeContainer() {
357-
if (getPlayer().currentScreenHandler != getPlayer().playerScreenHandler)
358-
getPlayer().closeHandledScreen();
357+
if (getPlayer().currentScreenHandler != getPlayer().playerScreenHandler) {
358+
MinecraftClient.getInstance().execute(getPlayer()::closeHandledScreen);
359+
ScriptManager.passTick();
360+
}
359361
}
360362

361363
public int craft(Object result, int count, String[] pattern, JSObject ingredients) {

0 commit comments

Comments
 (0)