keyboard camera mode config, fix some bugs with the ElementCenterQuery, fix ownership theif interacting with the wrong side

This commit is contained in:
GiantLuigi4 2023-11-27 18:05:18 -05:00
parent cc0803de11
commit 21ffc08fcf
5 changed files with 72 additions and 48 deletions

View File

@ -8,6 +8,7 @@ import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.ViewportEvent; import net.minecraftforge.client.event.ViewportEvent;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.montoyo.wd.config.ClientConfig;
import net.montoyo.wd.utilities.browser.handlers.js.queries.ElementCenterQuery; import net.montoyo.wd.utilities.browser.handlers.js.queries.ElementCenterQuery;
import net.montoyo.wd.entity.ScreenBlockEntity; import net.montoyo.wd.entity.ScreenBlockEntity;
import net.montoyo.wd.entity.ScreenData; import net.montoyo.wd.entity.ScreenData;
@ -78,14 +79,22 @@ public class KeyboardCamera {
if (lock.hasFocused()) { if (lock.hasFocused()) {
ScreenData scr = tes.getScreen(side); ScreenData scr = tes.getScreen(side);
if (scr != null) { if (scr != null) {
nextX = lock.getX(); Vec2 c;
nextY = lock.getY(); if (ClientConfig.Input.keyboardCamera) {
nextX = lock.getX();
nextY = lock.getY();
Vec2 c = pxToHit(scr, new Vec2((float) nextX, (float) nextY)); c = pxToHit(scr, new Vec2((float) nextX, (float) nextY));
} else c = new Vec2(scr.size.x / 2f, scr.size.y / 2f);
nextX = c.x; nextX = c.x;
nextY = c.y; nextY = c.y;
if (nextX < 0) nextX = 0;
else if (nextX > scr.size.x) nextX = scr.size.x;
if (nextY < 0) nextY = 0;
else if (nextY > scr.size.y) nextY = scr.size.y;
float scl = Math.max(scr.size.x, scr.size.y); float scl = Math.max(scr.size.x, scr.size.y);
double mx = Minecraft.getInstance().mouseHandler.xpos(); double mx = Minecraft.getInstance().mouseHandler.xpos();

View File

@ -38,7 +38,7 @@ public class ClientConfig {
"Due to how web browsers work however, the larger this value is, the smaller text is", "Due to how web browsers work however, the larger this value is, the smaller text is",
"Also, higher values will invariably lag more", "Also, higher values will invariably lag more",
"A good goto value for this would be the height of your monitor, in pixels", "A good goto value for this would be the height of your monitor, in pixels",
"A standard monitor is (at least currently) 1080" "A standard monitor is (at least currently) 1080",
}) })
@Translation("config.webdisplays.pad_res") @Translation("config.webdisplays.pad_res")
@IntRange(minV = 0, maxV = Integer.MAX_VALUE) @IntRange(minV = 0, maxV = Integer.MAX_VALUE)
@ -53,55 +53,70 @@ public class ClientConfig {
@Translation("config.webdisplays.side_pad") @Translation("config.webdisplays.side_pad")
@Default(valueBoolean = true) @Default(valueBoolean = true)
public static boolean sidePad = true; public static boolean sidePad = true;
@Name("switch_buttons")
@Comment("If the left and right buttons should be swapped when using a laser")
@Translation("config.webdisplays.switch_buttons")
@DoubleRange(minV = 0, maxV = Double.MAX_VALUE)
@Default(valueD = 30)
public static boolean switchButtons = true;
@Comment({ @Comment({
"AutoVolume makes audio fade off based on distance", "Options relating to input handling"
"Currently, this seems to not work"
}) })
@CFGSegment("auto_volume") @CFGSegment("input")
public static class AutoVolumeControl { public static class Input {
@Name("enabled") @Name("keyboard_camera")
@Comment("Whether or not auto volume should be enabled") @Comment({
@Translation("config.webdisplays.auto_vol") "If this is on, then the camera will try to focus on the selected element while a keyboard is in use",
"Elsewise, it'll try to focus on the center of the screen",
})
@Translation("config.webdisplays.keyboard_camera")
@Default(valueBoolean = true) @Default(valueBoolean = true)
public static boolean enableAutoVolume = true; public static boolean keyboardCamera = true;
@Name("youtube_volume") @Name("switch_buttons")
@Comment("How loud youtube should be by default") @Comment("If the left and right buttons should be swapped when using a laser")
@Translation("config.webdisplays.yt_vol") @Translation("config.webdisplays.switch_buttons")
@DoubleRange(minV = 0, maxV = 100)
@Default(valueD = 100)
public static double ytVolume = 100.0;
@Name("dist0")
@Comment("Distance after which you can't hear anything (in blocks)")
@Translation("config.webdisplays.d0")
@DoubleRange(minV = 0, maxV = Double.MAX_VALUE) @DoubleRange(minV = 0, maxV = Double.MAX_VALUE)
@Default(valueD = 30) @Default(valueD = 30)
public static double dist0 = 30.0; public static boolean switchButtons = true;
@Name("dist100")
@Comment("Distance after which the sound starts dropping (in blocks)")
@Translation("config.webdisplays.d100")
@DoubleRange(minV = 0, maxV = Double.MAX_VALUE)
@Default(valueD = 10)
public static double dist100 = 10.0;
} }
// @Comment({
// "AutoVolume makes audio fade off based on distance",
// "Currently, this seems to not work"
// })
// @CFGSegment("auto_volume")
// public static class AutoVolumeControl {
// @Name("enabled")
// @Comment("Whether or not auto volume should be enabled")
// @Translation("config.webdisplays.auto_vol")
// @Default(valueBoolean = true)
// public static boolean enableAutoVolume = true;
//
// @Name("youtube_volume")
// @Comment("How loud youtube should be by default")
// @Translation("config.webdisplays.yt_vol")
// @DoubleRange(minV = 0, maxV = 100)
// @Default(valueD = 100)
// public static double ytVolume = 100.0;
//
// @Name("dist0")
// @Comment("Distance after which you can't hear anything (in blocks)")
// @Translation("config.webdisplays.d0")
// @DoubleRange(minV = 0, maxV = Double.MAX_VALUE)
// @Default(valueD = 30)
// public static double dist0 = 30.0;
//
// @Name("dist100")
// @Comment("Distance after which the sound starts dropping (in blocks)")
// @Translation("config.webdisplays.d100")
// @DoubleRange(minV = 0, maxV = Double.MAX_VALUE)
// @Default(valueD = 10)
// public static double dist100 = 10.0;
// }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void postLoad() { public static void postLoad() {
if (unloadDistance < loadDistance + 2.0) if (unloadDistance < loadDistance + 2.0)
unloadDistance = loadDistance + 2.0; unloadDistance = loadDistance + 2.0;
if (AutoVolumeControl.dist0 < AutoVolumeControl.dist100 + 0.1) // if (AutoVolumeControl.dist0 < AutoVolumeControl.dist100 + 0.1)
AutoVolumeControl.dist0 = AutoVolumeControl.dist100 + 0.1; // AutoVolumeControl.dist0 = AutoVolumeControl.dist100 + 0.1;
// cache pad resolution // cache pad resolution
WebDisplays.INSTANCE.padResY = padResolution; WebDisplays.INSTANCE.padResY = padResolution;
@ -111,8 +126,8 @@ public class ClientConfig {
WebDisplays.INSTANCE.unloadDistance2 = unloadDistance * unloadDistance; WebDisplays.INSTANCE.unloadDistance2 = unloadDistance * unloadDistance;
WebDisplays.INSTANCE.loadDistance2 = loadDistance * loadDistance; WebDisplays.INSTANCE.loadDistance2 = loadDistance * loadDistance;
WebDisplays.INSTANCE.ytVolume = (float) AutoVolumeControl.ytVolume; // WebDisplays.INSTANCE.ytVolume = (float) AutoVolumeControl.ytVolume;
WebDisplays.INSTANCE.avDist100 = (float) AutoVolumeControl.dist100; // WebDisplays.INSTANCE.avDist100 = (float) AutoVolumeControl.dist100;
WebDisplays.INSTANCE.avDist0 = (float) AutoVolumeControl.dist0; // WebDisplays.INSTANCE.avDist0 = (float) AutoVolumeControl.dist0;
} }
} }

View File

@ -106,7 +106,7 @@ public class ItemLaserPointer extends Item implements WDItem {
} }
public static void press(boolean press, int button) { public static void press(boolean press, int button) {
if (button <= 1 && ClientConfig.switchButtons) if (button <= 1 && ClientConfig.Input.switchButtons)
button = 1 - button; button = 1 - button;
if (button == 0) left = press; if (button == 0) left = press;

View File

@ -78,7 +78,7 @@ public class ItemOwnershipThief extends Item implements WDItem {
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
Vector3i pos = new Vector3i(context.getClickedPos()); Vector3i pos = new Vector3i(context.getClickedPos());
BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()]; BlockSide side = BlockSide.values()[context.getClickedFace().ordinal()];
Multiblock.findOrigin(context.getLevel(), pos, side, null); Multiblock.findOrigin(context.getLevel(), pos, side, null);
BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock()); BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock());

View File

@ -12,7 +12,7 @@ public class ElementCenterQuery extends JSQueryHandler {
double x, y; double x, y;
JsonObject obj; JsonObject obj;
long start = -1; long start = -1;
String extra; String extra = "";
String elementName; String elementName;
String script = null; String script = null;
@ -23,7 +23,7 @@ public class ElementCenterQuery extends JSQueryHandler {
} }
public ElementCenterQuery addAdditional(String key, String value) { public ElementCenterQuery addAdditional(String key, String value) {
extra += "'" + key + "':" + value + " + "; extra += "'," + key + ":' + " + value + " +";
script = null; script = null;
return this; return this;
} }