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.minecraftforge.client.event.ViewportEvent;
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.entity.ScreenBlockEntity;
import net.montoyo.wd.entity.ScreenData;
@ -78,14 +79,22 @@ public class KeyboardCamera {
if (lock.hasFocused()) {
ScreenData scr = tes.getScreen(side);
if (scr != null) {
nextX = lock.getX();
nextY = lock.getY();
Vec2 c;
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;
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);
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",
"Also, higher values will invariably lag more",
"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")
@IntRange(minV = 0, maxV = Integer.MAX_VALUE)
@ -54,54 +54,69 @@ public class ClientConfig {
@Default(valueBoolean = 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({
"AutoVolume makes audio fade off based on distance",
"Currently, this seems to not work"
"Options relating to input handling"
})
@CFGSegment("auto_volume")
public static class AutoVolumeControl {
@Name("enabled")
@Comment("Whether or not auto volume should be enabled")
@Translation("config.webdisplays.auto_vol")
@CFGSegment("input")
public static class Input {
@Name("keyboard_camera")
@Comment({
"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)
public static boolean enableAutoVolume = true;
public static boolean keyboardCamera = 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")
@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 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;
public static boolean switchButtons = true;
}
// @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")
public static void postLoad() {
if (unloadDistance < loadDistance + 2.0)
unloadDistance = loadDistance + 2.0;
if (AutoVolumeControl.dist0 < AutoVolumeControl.dist100 + 0.1)
AutoVolumeControl.dist0 = AutoVolumeControl.dist100 + 0.1;
// if (AutoVolumeControl.dist0 < AutoVolumeControl.dist100 + 0.1)
// AutoVolumeControl.dist0 = AutoVolumeControl.dist100 + 0.1;
// cache pad resolution
WebDisplays.INSTANCE.padResY = padResolution;
@ -111,8 +126,8 @@ public class ClientConfig {
WebDisplays.INSTANCE.unloadDistance2 = unloadDistance * unloadDistance;
WebDisplays.INSTANCE.loadDistance2 = loadDistance * loadDistance;
WebDisplays.INSTANCE.ytVolume = (float) AutoVolumeControl.ytVolume;
WebDisplays.INSTANCE.avDist100 = (float) AutoVolumeControl.dist100;
WebDisplays.INSTANCE.avDist0 = (float) AutoVolumeControl.dist0;
// WebDisplays.INSTANCE.ytVolume = (float) AutoVolumeControl.ytVolume;
// WebDisplays.INSTANCE.avDist100 = (float) AutoVolumeControl.dist100;
// 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) {
if (button <= 1 && ClientConfig.switchButtons)
if (button <= 1 && ClientConfig.Input.switchButtons)
button = 1 - button;
if (button == 0) left = press;

View File

@ -78,7 +78,7 @@ public class ItemOwnershipThief extends Item implements WDItem {
return InteractionResult.SUCCESS;
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);
BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock());

View File

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