Skip to content

Commit

Permalink
Fix bugs with command keycode
Browse files Browse the repository at this point in the history
  • Loading branch information
telvarost committed Sep 18, 2024
1 parent 956b499 commit 5f48957
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fix small bug with chat screen null point exception
- Fix bugs with command keybinding
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=b1.7.3+build.8
loader_version=0.14.24-babric.1

# Mod Properties
mod_version = 2.0.2
mod_version = 2.0.3
maven_group = pl.telvarost
archives_base_name = mojangfixstationapi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.GameOptions;
import org.lwjgl.input.Keyboard;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -39,10 +40,16 @@ public abstract class MinecraftMixin {
@Shadow
public abstract boolean isWorldRemote();

@Shadow public GameOptions options;

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;isWorldRemote()Z", ordinal = 0))
private void onKey(CallbackInfo ci) {
if ((this.isWorldRemote() || FabricLoader.getInstance().isModLoaded("spc")) && Keyboard.getEventKey() == MojangFixStationApiClientMod.COMMAND_KEYBIND.code) {
this.setScreen(((ChatScreenAccessor) new ChatScreen()).setInitialMessage("/"));
if (this.isWorldRemote() || FabricLoader.getInstance().isModLoaded("spc")) {
if (Keyboard.getEventKey() == MojangFixStationApiClientMod.COMMAND_KEYBIND.code) {
this.setScreen(((ChatScreenAccessor) new ChatScreen()).setInitialMessage("/"));
} else if (Keyboard.getEventKey() == this.options.chatKey.code) {
this.setScreen(((ChatScreenAccessor) new ChatScreen()).setInitialMessage(""));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ChatScreen setInitialMessage(String message) {

@Inject(method = "init", at = @At("RETURN"))
private void onInit(CallbackInfo ci) {
text = initialMessage;
textField = new TextFieldWidget(this, textRenderer, 2, height - 14, width - 2, height - 2, initialMessage);
textField.setFocused(true);
textField.setMaxLength(100);
Expand Down

0 comments on commit 5f48957

Please sign in to comment.