keybinding

This commit is contained in:
GiantLuigi4 2023-06-06 17:56:54 -04:00
parent b4754dd15c
commit d6ed36063d
4 changed files with 30 additions and 4 deletions

View File

@ -120,6 +120,7 @@ public class WebDisplays {
if (FMLEnvironment.dist.isClient()) {
// proxies are annoying, so from now on, I'mma be just registering stuff in here
FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientProxy::onKeybindRegistry);
MinecraftForge.EVENT_BUS.addListener(ClientProxy::onDrawSelection);
ClientConfig.init();
}

View File

@ -11,6 +11,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.gui.Gui;
@ -46,6 +47,7 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderHighlightEvent;
import net.minecraftforge.common.MinecraftForge;
@ -681,7 +683,20 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
mc.setScreen(nextScreen);
nextScreen = null;
}
// handle r button
if (KEY_MOUSE.isDown()) {
if (!rDown) {
rDown = true;
mouseOn = !mouseOn;
}
} else rDown = false;
if (
Minecraft.getInstance().player == null ||
!(Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof ItemLaserPointer)
) mouseOn = false;
//Load/unload minePads depending on which item is in the player's hand
if (++minePadTickCounter >= 10) {
minePadTickCounter = 0;
@ -880,4 +895,13 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
}
}
}
/** KEYBINDS **/
public static final KeyMapping KEY_MOUSE = new KeyMapping("webdisplays.key.toggle_mouse", GLFW.GLFW_KEY_R, "key.categories.misc");
static boolean rDown = false;
public static boolean mouseOn = false;
public static void onKeybindRegistry(RegisterKeyMappingsEvent event) {
event.register(KEY_MOUSE);
}
}

View File

@ -4,7 +4,6 @@
package net.montoyo.wd.client.renderers;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
@ -18,9 +17,9 @@ import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.montoyo.wd.client.ClientProxy;
import net.montoyo.wd.init.ItemInit;
import net.montoyo.wd.item.ItemLaserPointer;
import org.lwjgl.glfw.GLFW;
@OnlyIn(Dist.CLIENT)
public final class LaserPointerRenderer implements IItemRenderer {
@ -36,7 +35,7 @@ public final class LaserPointerRenderer implements IItemRenderer {
Minecraft mc = Minecraft.getInstance();
return mc.player != null && mc.level != null &&
(
InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_ALT) ||
ClientProxy.mouseOn ||
ItemLaserPointer.isOn()
) &&
mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(ItemInit.itemLaserPointer.get()) &&

View File

@ -543,6 +543,8 @@ public class TileEntityScreen extends BlockEntity {
}
public void handleMouseEvent(BlockSide side, ClickControl.ControlType event, @Nullable Vector2i vec, int button) {
if (button > 1) return; // buttons above 1 crash the game
Screen scr = getScreen(side);
if (scr == null) {
Log.error("Attempt inject mouse events on non-existing screen of side %s", side.toString());