Skip to content

Commit

Permalink
Open custom GUI instead of vanilla GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
nutyworks committed Mar 17, 2024
1 parent 685b3ee commit 562c776
Show file tree
Hide file tree
Showing 10 changed files with 1,815 additions and 38 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package works.nuty.calcite.mixin.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.CommandBlockBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientConnectionState;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import works.nuty.calcite.screen.CalciteCommandScreen;

@Environment(EnvType.CLIENT)
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin extends ClientCommonNetworkHandler {
protected ClientPlayNetworkHandlerMixin(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) {
super(client, connection, connectionState);
}

@Inject(at = @At("TAIL"), method = "method_38542")
public void onBlockEntityUpdate(BlockEntityUpdateS2CPacket blockEntityUpdateS2CPacket, BlockEntity blockEntity, CallbackInfo ci) {
if (blockEntity instanceof CommandBlockBlockEntity && this.client.currentScreen instanceof CalciteCommandScreen calciteCommandScreen) {
calciteCommandScreen.updateAll();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package works.nuty.calcite.mixin.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.entity.CommandBlockBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import works.nuty.calcite.screen.CalciteCommandScreen;

@Environment(EnvType.CLIENT)
@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMixin {
@Shadow
@Final
protected MinecraftClient client;

@Inject(at = @At("HEAD"), method = "openCommandBlockScreen", cancellable = true)
public void openCommandBlockScreenMixin(CommandBlockBlockEntity commandBlock, CallbackInfo ci) {
this.client.setScreen(new CalciteCommandScreen(commandBlock));
ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package works.nuty.calcite.mixin.client;

import net.minecraft.client.network.DataQueryHandler;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Consumer;

@Mixin(DataQueryHandler.class)
public class DataQueryHandlerMixin {
@Shadow
private @Nullable Consumer<NbtCompound> callback;
@Shadow
private int expectedTransactionId;

@Inject(at = @At("HEAD"), method = "handleQueryResponse", cancellable = true)
public void queryBlockNbt(int transactionId, @Nullable NbtCompound nbt, CallbackInfoReturnable<Boolean> cir) {
@Nullable Consumer<NbtCompound> previousCallback = this.callback;
if (this.expectedTransactionId == transactionId && this.callback != null) {
this.callback.accept(nbt);
if (this.callback.equals(previousCallback)) {
this.callback = null;
}
cir.setReturnValue(true);
}
cir.setReturnValue(false);
cir.cancel();
}
}
Loading

0 comments on commit 562c776

Please sign in to comment.