diff --git a/build.gradle b/build.gradle index e88f3e6..ed5d756 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ dependencies { } forge "net.minecraftforge:forge:${project.forge_version}" - modImplementation "com.github.Mysticpasta1:mcef-forge:805b7eec8a" + modImplementation "com.github.Mysticpasta1:mcef-forge:11826a2d11" modImplementation "curse.maven:cloth_config_forge-348521:3546623" // Uncomment the following line to enable the deprecated Fabric API modules. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java index a3942cb..682ce23 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardLeft.java @@ -186,10 +186,11 @@ public class BlockKeyboardLeft extends BlockPeripheral { if(!world.isEmptyBlock(pos.below()) && BlockKeyboardRight.checkNeighborhood(world, pos, null)) { if(world.isEmptyBlock(right) && !world.isEmptyBlock(right.below()) && BlockKeyboardRight.checkNeighborhood(world, right, pos)) { world.setBlock(right, BlockInit.blockKbRight.get().defaultBlockState().setValue(BlockKeyboardRight.facing, f), 3); + world.setBlock(pos.offset(f.getNormal()), BlockInit.blockKeyBoard.get().defaultBlockState().setValue(BlockKeyboardRight.facing, f), 3); return; } else if(world.isEmptyBlock(left) && !world.isEmptyBlock(left.below()) && BlockKeyboardRight.checkNeighborhood(world, left, pos)) { world.setBlock(left, state, 3); - world.setBlock(pos, BlockInit.blockKbRight.get().defaultBlockState().setValue(BlockKeyboardRight.facing, f), 3); + world.setBlock(pos.offset(f.getNormal()), BlockInit.blockKeyBoard.get().defaultBlockState().setValue(BlockKeyboardRight.facing, f), 3); return; } } diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index cda8d6e..6d6f1b0 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -72,7 +72,7 @@ public class BlockScreen extends BaseEntityBlock { @Override public RenderShape getRenderShape(BlockState state) { - return RenderShape.INVISIBLE; + return RenderShape.MODEL; } public static boolean isntScreenBlock(Level world, Vector3i pos) { @@ -179,7 +179,7 @@ public class BlockScreen extends BaseEntityBlock { } Vector2i tmp = new Vector2i(); - if(hit2pixels(side, hit.getBlockPos(), pos, scr, (float) hit.getBlockPos().getX(), (float) hit.getBlockPos().getY(), (float) hit.getBlockPos().getZ(), tmp)) + if(hit2pixels(side, hit.getBlockPos(), pos, scr, (float) hit.getLocation().x, (float) hit.getLocation().y, (float) hit.getLocation().z, tmp)) te.click(side, tmp); return InteractionResult.SUCCESS; @@ -244,19 +244,18 @@ public class BlockScreen extends BaseEntityBlock { if(side.right.z < 0 || side == BlockSide.TOP || side == BlockSide.BOTTOM) hitZ -= 1.f; - Vector3f rel = new Vector3f(bpos.getX(), bpos.getY(), bpos.getZ()); - rel.sub((float) pos.x, (float) pos.y, (float) pos.z); - rel.add(hitX, hitY, hitZ); + Vector3f rel = new Vector3f(pos.toBlock().getX(), pos.toBlock().getY(), pos.toBlock().getZ()); + rel.sub(hitX, hitY, hitZ); - float cx = rel.dot(side.right.toFloat()) - 2.f / 16.f; - float cy = rel.dot(side.up.toFloat()) - 2.f / 16.f; + float cx = Math.abs(rel.dot(side.right.toFloat()) - 2.f / 16.f); + float cy = Math.abs(rel.dot(side.up.toFloat()) - 2.f / 16.f); float sw = ((float) scr.size.x) - 4.f / 16.f; float sh = ((float) scr.size.y) - 4.f / 16.f; cx /= sw; cy /= sh; - if(cx >= 0.f && cx <= 1.0 && cy >= 0.f && cy <= 1.f) { + if(cx >= -0.1f && cx <= 1.1f && cy >= -0.1f && cy <= 1.1f) { if(side != BlockSide.BOTTOM) cy = 1.f - cy; diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 975fd32..dff34dd 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -13,6 +13,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.ContainerScreen; import net.minecraft.client.multiplayer.ClientAdvancements; +import net.minecraft.client.renderer.ItemBlockRenderTypes; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; @@ -85,6 +87,7 @@ import java.lang.reflect.Field; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.*; +import java.util.stream.Stream; @Mod.EventBusSubscriber(modid = "webdisplays", value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQueryHandler, ResourceManagerReloadListener { @@ -141,12 +144,16 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { BlockEntityRenderers.register(TileInit.SCREEN_BLOCK_ENTITY.get(), new ScreenRenderer.ScreenRendererProvider()); - } @SubscribeEvent public static void onModelRegistryEvent(ModelRegistryEvent event) { ModelLoaderRegistry.registerLoader(ScreenModelLoader.SCREEN_LOADER, new ScreenModelLoader()); + registerBlockRenderLayers(RenderType.cutout(), BlockInit.blockKeyBoard.get(), BlockInit.blockKbRight.get()); + } + + private static void registerBlockRenderLayers(RenderType layer, Block... blocks) { + Stream.of(blocks).forEach(block -> ItemBlockRenderTypes.setRenderLayer(block, layer)); } @Override diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java index c2dd9ed..04fdac8 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java @@ -4,11 +4,19 @@ package net.montoyo.wd.client.gui; +import com.mojang.blaze3d.platform.InputConstants; +import com.sun.jna.platform.unix.X11; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.EditBox; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.loading.FMLPaths; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.gui.controls.Button; @@ -22,12 +30,20 @@ import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Log; import net.montoyo.wd.utilities.TypeData; import net.montoyo.wd.utilities.Util; +import org.apache.commons.lang3.CharUtils; +import org.cef.browser.CefBrowserOsr; +import org.jline.utils.Display; import org.lwjgl.glfw.GLFW; +import java.awt.event.KeyEvent; import java.io.*; import java.util.ArrayList; +import java.util.Locale; import java.util.Map; +import static com.mojang.blaze3d.platform.InputConstants.*; +import static java.awt.event.KeyEvent.*; + @OnlyIn(Dist.CLIENT) public class GuiKeyboard extends WDScreen { @@ -98,8 +114,10 @@ public class GuiKeyboard extends WDScreen { } } } else { - minecraft.setWindowActive(true); - minecraft.mouseHandler.grabMouse(); + if (!minecraft.isWindowActive()) { + minecraft.setWindowActive(true); + minecraft.mouseHandler.grabMouse(); + } } defaultBackground = showWarning; @@ -108,44 +126,54 @@ public class GuiKeyboard extends WDScreen { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - key(keyCode, scanCode, true); + key(keyCode, scanCode, true, modifiers); return super.keyPressed(keyCode, scanCode, modifiers); } @Override public boolean keyReleased(int keyCode, int scanCode, int modifiers) { - key(keyCode, scanCode, false); + key(keyCode, scanCode, false, modifiers); return super.keyPressed(keyCode, scanCode, modifiers); } - public void key(int keyCode, int scanCode, boolean pressed) { - char chr = getChar(keyCode, scanCode); + public void key(int keyCode, int scanCode, boolean pressed, int mod) { if (pressed) { - int kc = keyCode; + if(quitOnEscape && keyCode == GLFW.GLFW_KEY_ESCAPE) { + Minecraft.getInstance().setScreen(null); + } - evStack.add(new TypeData(TypeData.Action.PRESS, kc, chr)); - evStack.add(new TypeData(TypeData.Action.RELEASE, kc, chr)); + int chr = getChar(keyCode, scanCode); + evStack.add(new TypeData(TypeData.Action.PRESS, chr, mod)); + evStack.add(new TypeData(TypeData.Action.RELEASE, chr, mod)); + + if (keyCode != 0) + evStack.add(new TypeData(TypeData.Action.TYPE, chr, mod)); + + if (!evStack.isEmpty() && !syncRequested()) + requestSync(); } - - if (chr != 0) - evStack.add(new TypeData(TypeData.Action.TYPE, 0, chr)); - - if (!evStack.isEmpty() && !syncRequested()) - requestSync(); } - public char getChar(int keyCode, int scanCode) { + public int getChar(int keyCode, int scanCode) { String keystr = GLFW.glfwGetKeyName(keyCode, scanCode); if(keystr == null){ keystr = "\0"; } if(keyCode == GLFW.GLFW_KEY_ENTER){ - keystr = "\n"; + return 13; + } + if (keyCode == GLFW.GLFW_KEY_SPACE) { + return 32; } if(keystr.length() == 0){ - return (char) -1; + return -1; + } + if(hasShiftDown()) { + keystr = keystr.toUpperCase(Locale.ROOT); + return CefBrowserOsr.remapKeycode(keyCode, keystr.charAt(keystr.length() - 1)); + } else { + return CefBrowserOsr.remapKeycode(keyCode, keystr.charAt(keystr.length() - 1)); } - return keystr.charAt(keystr.length() - 1); } @Override diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiServer.java b/src/main/java/net/montoyo/wd/client/gui/GuiServer.java index 11e5756..d17d256 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiServer.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiServer.java @@ -215,7 +215,7 @@ public class GuiServer extends WDScreen { public boolean keyPressed(int keyCode, int scanCode, int modifiers) { getChar(keyCode, scanCode).ifPresent(c -> { try { - keyTyped(c, keyCode); + keyTyped(c, keyCode, modifiers); } catch (IOException e) { e.printStackTrace(); } @@ -309,10 +309,11 @@ public class GuiServer extends WDScreen { @Override public boolean charTyped(char codePoint, int modifiers) { return super.charTyped(codePoint, modifiers); + } - protected void keyTyped(char typedChar, int keyCode) throws IOException { -// super.keyTyped(typedChar, keyCode); + protected void keyTyped(char typedChar, int keyCode, int modifier) throws IOException { + //this.charTyped(typedChar, modifier); if(uploadWizard) { boolean found = false; diff --git a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java index 8643944..cd1d251 100644 --- a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java +++ b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java @@ -126,11 +126,6 @@ public abstract class WDScreen extends Screen { @Override public boolean charTyped(char codePoint, int modifiers) { - if(quitOnEscape && codePoint == GLFW.GLFW_KEY_ESCAPE) { - minecraft.setScreen(null); - return false; - } - boolean typed = false; for(Control ctrl: controls) @@ -213,10 +208,14 @@ public abstract class WDScreen extends Screen { public boolean keyPressed(int keyCode, int scanCode, int modifiers) { boolean down = false; - for(Control ctrl : controls) + for (Control ctrl : controls) down = down || ctrl.keyDown(keyCode); - return new GuiServer(new Vector3i(), new NameUUIDPair()).keyPressed(keyCode, scanCode, modifiers); + if (Minecraft.getInstance().screen instanceof GuiKeyboard) { + return down; + } else { + return new GuiServer(new Vector3i(), new NameUUIDPair()).keyPressed(keyCode, scanCode, modifiers); + } } @Override diff --git a/src/main/java/net/montoyo/wd/client/gui/controls/Control.java b/src/main/java/net/montoyo/wd/client/gui/controls/Control.java index 83601f9..478abc2 100644 --- a/src/main/java/net/montoyo/wd/client/gui/controls/Control.java +++ b/src/main/java/net/montoyo/wd/client/gui/controls/Control.java @@ -9,6 +9,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import com.mojang.math.Matrix4f; +import net.minecraft.client.KeyboardHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.resources.language.I18n; diff --git a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java index cbc2ac4..7202fb7 100644 --- a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java +++ b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java @@ -75,11 +75,11 @@ public class ScreenRenderer implements BlockEntityRenderer { switch(scr.side) { case BOTTOM: - poseStack.mulPose(XP.rotation(90.f)); + poseStack.mulPose(XP.rotation(90.f + 49.8f)); break; case TOP: - poseStack.mulPose(XN.rotation(90.f)); + poseStack.mulPose(XN.rotation(90.f + 49.8f)); break; case NORTH: @@ -110,8 +110,8 @@ public class ScreenRenderer implements BlockEntityRenderer { poseStack.scale(ft, ft, 1.0f); } - // if(!scr.rotation.isNull) - // poseStack.mulPose(YP.rotationDegrees(scr.rotation.angle)); + if(!scr.rotation.isNull) + poseStack.mulPose(ZP.rotationDegrees(scr.rotation.angle)); float sw = ((float) scr.size.x) * 0.5f - 2.f / 16.f; float sh = ((float) scr.size.y) * 0.5f - 2.f / 16.f; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java b/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java index 7bd3764..ac857af 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java @@ -320,7 +320,7 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase { code = ((Double) oCode).intValue(); } - data.add(new TypeData(dataAction, code, strChr.charAt(0))); + data.add(new TypeData(dataAction, code, 0)); } return realType(WebDisplays.GSON.toJson(data)); diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 2f75c16..8eaf9cd 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -4,6 +4,7 @@ package net.montoyo.wd.entity; +import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -42,9 +43,11 @@ import net.montoyo.wd.net.client.CMessageJSResponse; import net.montoyo.wd.net.client.CMessageScreenUpdate; import net.montoyo.wd.net.server.SMessageRequestTEData; import net.montoyo.wd.utilities.*; +import org.lwjgl.glfw.GLFW; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Collections; import java.util.UUID; @@ -789,9 +792,9 @@ public class TileEntityScreen extends BlockEntity{ for(TypeData ev : data) { switch (ev.getAction()) { - case PRESS -> scr.browser.injectKeyPressedByKeyCode(ev.getKeyCode(), ev.getKeyChar(), 0); - case RELEASE -> scr.browser.injectKeyReleasedByKeyCode(ev.getKeyCode(), ev.getKeyChar(), 0); - case TYPE -> scr.browser.injectKeyTyped(ev.getKeyChar(), 0); + case PRESS -> scr.browser.injectKeyPressedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), 0); + case RELEASE -> scr.browser.injectKeyReleasedByKeyCode(ev.getKeyCode(), (char) ev.getKeyCode(), 0); + case TYPE -> scr.browser.injectKeyTyped(ev.getKeyCode(), 0); default -> throw new RuntimeException("Invalid type action '" + ev.getAction() + '\''); } } diff --git a/src/main/java/net/montoyo/wd/net/server/SMessageScreenCtrl.java b/src/main/java/net/montoyo/wd/net/server/SMessageScreenCtrl.java index aa23bf1..2150c2b 100644 --- a/src/main/java/net/montoyo/wd/net/server/SMessageScreenCtrl.java +++ b/src/main/java/net/montoyo/wd/net/server/SMessageScreenCtrl.java @@ -296,7 +296,7 @@ public class SMessageScreenCtrl implements Runnable { bs.getBlock() != BlockInit.blockKeyBoard.get() && bs.getBlock() != BlockInit.blockRedControl.get() && bs.getValue(BlockPeripheral.type) != DefaultPeripheral.REMOTE_CONTROLLER) return; //I call it hax... - } else if(player.shouldRenderAtSqrDistance(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()))) + } else if(player.distanceToSqr(bp.getX(), bp.getY(), bp.getZ()) > (128 * 128)) return; //Out of range (range problem) BlockEntity te = world.getBlockEntity(bp); diff --git a/src/main/java/net/montoyo/wd/utilities/TypeData.java b/src/main/java/net/montoyo/wd/utilities/TypeData.java index 70dcbbd..32c3add 100644 --- a/src/main/java/net/montoyo/wd/utilities/TypeData.java +++ b/src/main/java/net/montoyo/wd/utilities/TypeData.java @@ -24,30 +24,30 @@ public class TypeData { private Action a; private int k; - private int c; + private int m; public TypeData() { a = Action.INVALID; k = 0; - c = 0; + m = 0; } - public TypeData(Action action, int code, char chr) { + public TypeData(Action action, int code, int modifier) { a = action; k = code; - c = (int) chr; + m = modifier; } public Action getAction() { return a; } - public char getKeyChar() { - return (char) c; - } - public int getKeyCode() { return k; } + public int getModifier() { + return m; + } + }