Skip to content

Commit

Permalink
Use KeyMapping for tab key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 21, 2023
1 parent 56cc76d commit 9fe979f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
8 changes: 8 additions & 0 deletions common/src/main/java/cn/zbx1425/worldcomment/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
import cn.zbx1425.worldcomment.network.PacketCollectionDataS2C;
import cn.zbx1425.worldcomment.network.PacketRegionDataS2C;
import cn.zbx1425.worldcomment.network.PacketEntryUpdateS2C;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;

public class MainClient {

public static final KeyMapping KEY_COMMENT_DETAIL = new KeyMapping("key.worldcomment.comment_detail",
InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_TAB, "key.categories.misc");

public static void init() {
ClientPlatform.registerNetworkReceiver(
PacketRegionDataS2C.IDENTIFIER, PacketRegionDataS2C.ClientLogics::handle);
Expand All @@ -18,6 +24,8 @@ public static void init() {
ClientPlatform.registerPlayerJoinEvent(ignored -> {
ClientWorldData.INSTANCE.clear();
});

ClientPlatform.registerKeyBinding(KEY_COMMENT_DETAIL);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public static boolean handleKeyTab() {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.player == null) return false;

if (ClientRayPicking.pickedComments.size() == 0) return false;
if (ClientRayPicking.pickedComments.isEmpty()) return false;

minecraft.execute(() -> {
if (minecraft.screen instanceof CommentListScreen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@ private void matches(int keysym, int scancode, CallbackInfoReturnable<Boolean> c
if (Screenshot.handleKeyF2()) cir.setReturnValue(false);
}
}

@Inject(method = "isDown", at = @At("RETURN"), cancellable = true)
private void isDown(CallbackInfoReturnable<Boolean> cir) {
if (!cir.getReturnValue()) return;
Options options = Minecraft.getInstance().options;
if ((Object)this == options.keyPlayerList) {
if (CommentListScreen.handleKeyTab()) cir.setReturnValue(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cn.zbx1425.worldcomment.mixin;

import cn.zbx1425.worldcomment.MainClient;
import cn.zbx1425.worldcomment.data.client.ClientWorldData;
import cn.zbx1425.worldcomment.data.client.ClientRayPicking;
import cn.zbx1425.worldcomment.gui.CommentListScreen;
import cn.zbx1425.worldcomment.render.CommentWorldRenderer;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
Expand All @@ -27,6 +29,11 @@ public class LevelRendererMixin {
private void afterEntities(PoseStack matrices, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
ClientWorldData.INSTANCE.tick();
ClientRayPicking.tick(partialTick, 20);

if (MainClient.KEY_COMMENT_DETAIL.consumeClick()) {
CommentListScreen.handleKeyTab();
}

matrices.pushPose();
Vec3 cameraPos = camera.getPosition();
matrices.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
"gui.worldcomment.send_upload_incomplete": "§bYour image is still being uploaded. Please wait.",
"gui.worldcomment.send_insufficient_clearance": "Please choose a place with more clearance as the comment object is 3 blocks tall.",
"gui.worldcomment.send_finish": "§aYour message is sent successfully.",
"gui.worldcomment.send_fail": "§c§lError occurred when processing your message: %s\n §c§lError occurred when processing your message."
"gui.worldcomment.send_fail": "§c§lError occurred when processing your message: %s\n §c§lError occurred when processing your message.",

"key.worldcomment.comment_detail": "View Comment Detail"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
"gui.worldcomment.send_upload_incomplete": "§b您的评论图片还没有完成上传,请您稍等。",
"gui.worldcomment.send_finish": "§a您的评论已成功发送。",
"gui.worldcomment.send_fail": "§c§l处理您的评论时发生了错误: %s\n §c§l处理您的评论时发生了错误。",
"gui.worldcomment.send_insufficient_clearance": "§6请选择一处更开阔的地方,因为评论物件有 3 格高。"
"gui.worldcomment.send_insufficient_clearance": "§6请选择一处更开阔的地方,因为评论物件有 3 格高。",

"key.worldcomment.comment_detail": "查看评论详情"
}

0 comments on commit 9fe979f

Please sign in to comment.