Skip to content

Commit

Permalink
Fix funky book behavior when opening another book with a RUN_COMMAND …
Browse files Browse the repository at this point in the history
…ClickEvent (#32)
  • Loading branch information
kyrptonaught authored Mar 31, 2024
1 parent cc26473 commit cbaf99a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/eu/pb4/sgui/mixin/ServerPlayNetworkHandlerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
@Mixin(ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkHandlerMixin extends ServerCommonNetworkHandler {

@Unique
private boolean sgui$bookIgnoreClose = false;

@Unique
private ScreenHandler sgui$previousScreen = null;

Expand Down Expand Up @@ -119,6 +122,12 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co
@Inject(method = "onCloseHandledScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER), cancellable = true)
private void sgui$storeScreenHandler(CloseHandledScreenC2SPacket packet, CallbackInfo info) {
if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler) {
if (sgui$bookIgnoreClose && this.player.currentScreenHandler instanceof BookScreenHandler) {
sgui$bookIgnoreClose = false;
info.cancel();
return;
}

if (handler.getGui().canPlayerClose()) {
this.sgui$previousScreen = this.player.currentScreenHandler;
} else {
Expand Down Expand Up @@ -340,6 +349,7 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co
private void sgui$onCommand(CommandExecutionC2SPacket packet, Optional<LastSeenMessageList> optional, CallbackInfo ci) {
if (this.player.currentScreenHandler instanceof BookScreenHandler handler) {
try {
sgui$bookIgnoreClose = true;
if (handler.getGui().onCommand("/" + packet.command())) {
ci.cancel();
}
Expand Down

0 comments on commit cbaf99a

Please sign in to comment.