Skip to content

Commit

Permalink
updated user accessibility with keybinding entries and lockable mouse…
Browse files Browse the repository at this point in the history
… scrolling (config) #7
  • Loading branch information
JR1811 committed Feb 5, 2024
1 parent 8e8f950 commit 45d3f7e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/main/java/net/shirojr/boatism/config/BoatismConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
@Config(name = "boatism")
@Config.Gui.Background("minecraft:textures/block/stone.png")
public class BoatismConfig implements ConfigData {
@ConfigEntry.Category("general_engine_data")
@ConfigEntry.Category(("general"))
@Comment("Use Scrolling in a boat to change Power Level")
public boolean powerLevelScrolling = true;
@ConfigEntry.Category("engine_data")
@Comment("General Health value")
@ConfigEntry.Gui.RequiresRestart
public float health = 6.0f;
@ConfigEntry.Category("general_engine_data")
@ConfigEntry.Category("engine_data")
@Comment("Indication of low health")
@ConfigEntry.Gui.RequiresRestart
public float lowHealth = 3.0f;
@ConfigEntry.Category("general_engine_data")
@ConfigEntry.Category("engine_data")
@Comment("Base fuel capacity")
@ConfigEntry.Gui.RequiresRestart
public int maxBaseFuel = 1000;
@ConfigEntry.Category("general_engine_data")
@ConfigEntry.Category("engine_data")
@Comment("Overheat limit")
@ConfigEntry.Gui.RequiresRestart
public int maxBaseOverheat = 1000;
}
3 changes: 2 additions & 1 deletion src/main/java/net/shirojr/boatism/event/BoatismEvents.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package net.shirojr.boatism.event;

import net.shirojr.boatism.event.custom.CommandRegistrationEvents;
import net.shirojr.boatism.event.custom.KeyBindEvents;

public class BoatismEvents {
public static void registerEvents() {
CommandRegistrationEvents.register();
}

public static void registerClientEvents() {

KeyBindEvents.register();
}
}
44 changes: 44 additions & 0 deletions src/main/java/net/shirojr/boatism/event/custom/KeyBindEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.shirojr.boatism.event.custom;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.network.PacketByteBuf;
import net.shirojr.boatism.Boatism;
import net.shirojr.boatism.network.BoatismNetworkIdentifiers;

public class KeyBindEvents {
private static KeyBinding POWER_LEVEL_UP;
private static KeyBinding POWER_LEVEL_DOWN;

private static final String BOATISM_KEYBINDINGS_GROUP = "key.%s.group".formatted(Boatism.MODID);
public static void register() {
POWER_LEVEL_UP = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.%s.power_level_up".formatted(Boatism.MODID),
InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), BOATISM_KEYBINDINGS_GROUP)
);
POWER_LEVEL_DOWN = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.%s.power_level_down".formatted(Boatism.MODID),
InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), BOATISM_KEYBINDINGS_GROUP)
);

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.player == null) return;
while (POWER_LEVEL_UP.wasPressed()) {
sendPowerLevelChangePacket(1);
}
while (POWER_LEVEL_DOWN.wasPressed()) {
sendPowerLevelChangePacket(-1);
}
});
}

private static void sendPowerLevelChangePacket(int delta) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeDouble(delta);
ClientPlayNetworking.send(BoatismNetworkIdentifiers.SCROLLED.getIdentifier(), buf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.option.GameOptions;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.network.PacketByteBuf;
import net.shirojr.boatism.Boatism;
import net.shirojr.boatism.entity.custom.BoatEngineEntity;
import net.shirojr.boatism.network.BoatismNetworkIdentifiers;
import net.shirojr.boatism.api.BoatEngineCoupler;
Expand All @@ -30,6 +31,7 @@ public class MouseMixin {

@Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;scrollInHotbar(D)V"), cancellable = true)
private void boatism$onScroll(long window, double horizontal, double vertical, CallbackInfo ci) {
if (!Boatism.CONFIG.powerLevelScrolling) return;
GameOptions options = client.options;
boolean mouseScrolled = options.getDiscreteMouseScroll().getValue();
double delta = (mouseScrolled ? Math.signum(horizontal) : vertical) * options.getMouseWheelSensitivity().getValue();
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/assets/boatism/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"gamerule.destructive_engine_explosion": "Overheated engines explode destructively (plating can mitigate)",

"mouse.boatism.power_level": "Power Level: §a%s§r",
"key.boatism.group": "Boatism",
"key.boatism.power_level_up": "Power Level Up",
"key.boatism.power_level_down": "Power Level Down",

"sound.boatism.boat_engine.default": "Running Engine",
"sound.boatism.boat_engine.underwater": "Running submerged Engine",
Expand All @@ -41,11 +44,13 @@

"text.autoconfig.boatism.title": "Boatism configurations",

"text.autoconfig.boatism.category.general_engine_data": "Boat Engine Settings",
"text.autoconfig.boatism.category.general": "General Settings",
"text.autoconfig.boatism.category.engine_data": "Boat Engine Settings",

"text.autoconfig.boatism.option.powerLevelScrolling": "Remap scrolling to change Power Level",
"text.autoconfig.boatism.option.health": "Base health",
"text.autoconfig.boatism.option.lowHealth": "Low health warning",
"text.autoconfig.boatism.option.maxFuel": "Maximum base fuel capacity",
"text.autoconfig.boatism.option.maxBaseFuel": "Maximum base fuel capacity",
"text.autoconfig.boatism.option.lowFuel": "Low fuel warning",
"text.autoconfig.boatism.option.maxOverheat": "Base overheat mitigation"
"text.autoconfig.boatism.option.maxBaseOverheat": "Base overheat mitigation"
}

0 comments on commit 45d3f7e

Please sign in to comment.