m o u s e
This commit is contained in:
parent
53b12a3294
commit
0219b56d26
|
|
@ -11,6 +11,8 @@ import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -23,7 +25,11 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.client.event.RenderHighlightEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
|
|
@ -40,18 +46,18 @@ import net.minecraftforge.fml.loading.FMLEnvironment;
|
|||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.montoyo.wd.block.BlockScreen;
|
||||
import net.montoyo.wd.config.ModConfig;
|
||||
import net.montoyo.wd.controls.ScreenControlRegistry;
|
||||
import net.montoyo.wd.core.*;
|
||||
import net.montoyo.wd.entity.TileEntityScreen;
|
||||
import net.montoyo.wd.init.BlockInit;
|
||||
import net.montoyo.wd.init.ItemInit;
|
||||
import net.montoyo.wd.init.TileInit;
|
||||
import net.montoyo.wd.miniserv.server.Server;
|
||||
import net.montoyo.wd.net.WDNetworkRegistry;
|
||||
import net.montoyo.wd.net.client_bound.S2CMessageServerInfo;
|
||||
import net.montoyo.wd.utilities.DistSafety;
|
||||
import net.montoyo.wd.utilities.Log;
|
||||
import net.montoyo.wd.utilities.Util;
|
||||
import net.montoyo.wd.utilities.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -166,6 +172,8 @@ public class WebDisplays {
|
|||
ItemInit.registerComponents();
|
||||
TileInit.init(bus);
|
||||
|
||||
MinecraftForge.EVENT_BUS.addListener(WebDisplays::onDrawSelection);
|
||||
|
||||
PROXY.preInit();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
|
@ -191,6 +199,30 @@ public class WebDisplays {
|
|||
ScreenControlRegistry.init();
|
||||
}
|
||||
}
|
||||
|
||||
private static void onDrawSelection(RenderHighlightEvent event) {
|
||||
if (event.getTarget() instanceof BlockHitResult bhr) {
|
||||
BlockState state = Minecraft.getInstance().level.getBlockState(bhr.getBlockPos());
|
||||
if (state.getBlock() instanceof BlockScreen screen) {
|
||||
Vector3i vec = new Vector3i(bhr.getBlockPos().getX(), bhr.getBlockPos().getY(), bhr.getBlockPos().getZ());
|
||||
BlockSide side = BlockSide.fromInt(bhr.getDirection().ordinal());
|
||||
Multiblock.findOrigin(
|
||||
Minecraft.getInstance().level, vec,
|
||||
side, null
|
||||
);
|
||||
|
||||
BlockPos pos = new BlockPos(vec.x, vec.y, vec.z);
|
||||
BlockEntity be = Minecraft.getInstance().level.getBlockEntity(
|
||||
pos
|
||||
);
|
||||
if (be instanceof TileEntityScreen tes) {
|
||||
if (tes.getScreen(side) != null) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAttachPlayerCap(AttachCapabilitiesEvent<Entity> event) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package net.montoyo.wd.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
|
@ -38,12 +39,15 @@ public class GuiMinePad extends WDScreen {
|
|||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
vw = ((double) width) - 32.0f;
|
||||
vh = vw / WebDisplays.PAD_RATIO;
|
||||
vx = 16.0f;
|
||||
vy = (((double) height) - vh) / 2.0f;
|
||||
|
||||
this.width = (int) vw;
|
||||
this.height = (int) vh;
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
private static void addRect(BufferBuilder bb, double x, double y, double w, double h) {
|
||||
|
|
@ -81,71 +85,103 @@ public class GuiMinePad extends WDScreen {
|
|||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
key(keyCode, scanCode, true);
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
return this.keyChanged(keyCode, scanCode, modifiers, true) || super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
key(keyCode, scanCode, false);
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
return this.keyChanged(keyCode, scanCode, modifiers, false) || super.keyReleased(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
public void key(int keyCode, int scanCode, boolean pressed) {
|
||||
Optional<Character> key = getChar(keyCode, scanCode);
|
||||
|
||||
if (pad.view != null && key.isPresent()) {
|
||||
char c = key.get();
|
||||
|
||||
if (pressed)
|
||||
pad.view.injectKeyPressedByKeyCode(keyCode, c, 0);
|
||||
else
|
||||
pad.view.injectKeyReleasedByKeyCode(keyCode, c, 0);
|
||||
|
||||
if (c != 0)
|
||||
pad.view.injectKeyTyped(c, 0);
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char codePoint, int modifiers) {
|
||||
if (pad.view != null) {
|
||||
pad.view.injectKeyTyped((int) codePoint, modifiers);
|
||||
return true;
|
||||
} else {
|
||||
return super.charTyped(codePoint, modifiers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* copied from MCEF */
|
||||
public boolean keyChanged(int keyCode, int scanCode, int modifiers, boolean pressed) {
|
||||
assert minecraft != null;
|
||||
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
minecraft.setScreen(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
InputConstants.Key iuKey = InputConstants.getKey(keyCode, scanCode);
|
||||
String keystr = iuKey.getDisplayName().getString();
|
||||
// System.out.println("KEY STR " + keystr);
|
||||
if (keystr.length() == 0)
|
||||
return false;
|
||||
|
||||
char key = keystr.charAt(keystr.length() - 1);
|
||||
|
||||
if(keystr.equals("Enter"))
|
||||
key = '\r';
|
||||
|
||||
if (pad.view != null) { //Inject events into browser
|
||||
// System.out.println("Sent keystroke " + keystr);
|
||||
if (pressed)
|
||||
pad.view.injectKeyPressedByKeyCode(keyCode, key, modifiers);
|
||||
else
|
||||
pad.view.injectKeyReleasedByKeyCode(keyCode, key, modifiers);
|
||||
|
||||
if(key == '\r')
|
||||
pad.view.injectKeyTyped(key, 0);
|
||||
return true; // Something did happen
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(double mouseX, double mouseY) {
|
||||
super.mouseMoved(mouseX, mouseY);
|
||||
mouse(-1, false, (int) mouseX, (int) mouseY);
|
||||
mouse(-1, false, (int) mouseX, (int) mouseY, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
mouse(button, true, (int) mouseX, (int) mouseY);
|
||||
mouse(button, true, (int) mouseX, (int) mouseY, 0);
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
mouse(button, false, (int) mouseX, (int) mouseY);
|
||||
mouse(button, false, (int) mouseX, (int) mouseY, 0);
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
mouse(button, true, (int) mouseX, (int) mouseY, 0);
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
mouse(-1, false, (int) mouseX, (int) mouseY, amount);
|
||||
return super.mouseScrolled(mouseX, mouseY, amount);
|
||||
}
|
||||
|
||||
public void mouse(int btn, boolean pressed, int sx, int sy) {
|
||||
public void mouse(int btn, boolean pressed, int sx, int sy, double scrollAmount) {
|
||||
double mx = (sx - vx) / vw;
|
||||
double my = (sy - vy) / vh;
|
||||
|
||||
int vx = screen2DisplayX((int) this.vx);
|
||||
int vy = screen2DisplayY((int) this.vy);
|
||||
int vh = screen2DisplayX((int) this.vh);
|
||||
int vw = screen2DisplayY((int) this.vw);
|
||||
|
||||
if (pad.view != null && sx >= vx && sx <= vx + vw && sy >= vy && sy <= vy + vh) {
|
||||
sx -= vx;
|
||||
sy -= vy;
|
||||
sy = vh - sy;
|
||||
if (pad.view != null && mx >= 0 && mx <= 1) {
|
||||
int wheel = (int) scrollAmount;
|
||||
|
||||
//Scale again according to the webview
|
||||
sx = (int) (((double) sx) / ((double) vw) * WebDisplays.INSTANCE.padResX);
|
||||
sy = (int) (((double) sy) / ((double) vh) * WebDisplays.INSTANCE.padResY);
|
||||
|
||||
if (btn == -1)
|
||||
pad.view.injectMouseMove(sx, sy, 0, false);
|
||||
sx = (int) (mx * WebDisplays.INSTANCE.padResX);
|
||||
sy = (int) (my * WebDisplays.INSTANCE.padResY);
|
||||
|
||||
if (wheel != 0)
|
||||
pad.view.injectMouseWheel(sx, sy, (hasControlDown() && ! hasAltDown() && !hasShiftDown()) ? GLFW.GLFW_MOD_CONTROL : 0, wheel, 0);
|
||||
else if (btn == -1)
|
||||
pad.view.injectMouseMove(sx, sy, 0, sy < 0);
|
||||
else
|
||||
pad.view.injectMouseButton(sx, sy, 0, btn + 1, pressed, 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,9 +53,6 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
sinSwingProg1 = (float) Math.sin(swingProgress * PI);
|
||||
sinSwingProg2 = (float) Math.sin(swingProgress * swingProgress * PI);
|
||||
|
||||
RenderSystem.disableCull();
|
||||
// glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
//Render arm
|
||||
stack.pushPose();
|
||||
renderArmFirstPerson(stack, multiBufferSource, packedLight, equipProgress, handSideSign);
|
||||
|
|
@ -93,13 +90,12 @@ public final class MinePadRenderer implements IItemRenderer {
|
|||
|
||||
if(pd != null) {
|
||||
stack.translate(0.063f, 0.28f, 0.001f);
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.setShaderTexture(0, tex);
|
||||
pd.view.draw(stack,0.0, 0.0, 27.65 / 32.0 + 0.01, 14.0 / 32.0 + 0.002);
|
||||
}
|
||||
}
|
||||
|
||||
stack.popPose();
|
||||
// glDisable(GL_RESCALE_NORMAL);
|
||||
RenderSystem.enableCull();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ logoFile= "" #optional
|
|||
|
||||
credits="" #optional
|
||||
|
||||
authors="Mysticpasta1, WaterPicker, Montoyo" #optional
|
||||
authors="Mysticpasta1, WaterPicker, Montoyo, GiantLuigi4" #optional
|
||||
|
||||
description='''
|
||||
'''
|
||||
|
|
@ -44,4 +44,11 @@ modId="forgecef"
|
|||
mandatory=true
|
||||
versionRange="[1.0.0, )"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.webdisplays]]
|
||||
modId="cloth_config"
|
||||
mandatory=true
|
||||
versionRange="[8.2.88, )"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
Loading…
Reference in New Issue
Block a user