Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface CommonConfigAccess {
public interface ClientConfigAccess {
boolean ctrlTogglesOffStrokeOrder();

boolean disableInworldScrolling();

boolean invertSpellbookScrollDirection();

boolean invertAbacusScrollDirection();
Expand All @@ -52,6 +54,7 @@ public interface ClientConfigAccess {
boolean alwaysShowListCommas();

boolean DEFAULT_CTRL_TOGGLES_OFF_STROKE_ORDER = false;
boolean DEFAULT_DISABLE_INWORLD_SCROLLING = false;
boolean DEFAULT_INVERT_SPELLBOOK_SCROLL = false;
boolean DEFAULT_INVERT_ABACUS_SCROLL = false;
double DEFAULT_GRID_SNAP_THRESHOLD = 0.5;
Expand Down
34 changes: 34 additions & 0 deletions Common/src/main/java/at/petrak/hexcasting/client/Keybinds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package at.petrak.hexcasting.client;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;

import java.util.List;

public class Keybinds {
public static final String CATEGORY = "category.hexcasting.binds";

public static KeyMapping spellbookPrev = new KeyMapping(
"key.hexcasting.spellbook_prev",
InputConstants.UNKNOWN.getValue(),
CATEGORY
);

public static KeyMapping spellbookNext = new KeyMapping(
"key.hexcasting.spellbook_next",
InputConstants.UNKNOWN.getValue(),
CATEGORY
);

public static List<KeyMapping> ALL_BINDS = List.of(spellbookPrev, spellbookNext);

public static void clientTickEnd() {
while (spellbookPrev.consumeClick()) {
ShiftScrollListener.onScroll(-1, false);
}

while (spellbookNext.consumeClick()) {
ShiftScrollListener.onScroll(1, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static boolean onScrollInGameplay(double delta) {
return false;
}

if (HexConfig.client().disableInworldScrolling()) return false;

return onScroll(delta, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.mod.HexTags
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.client.ClientTickCounter
import at.petrak.hexcasting.client.Keybinds
import at.petrak.hexcasting.client.ShiftScrollListener
import at.petrak.hexcasting.client.ktxt.accumulatedScroll
import at.petrak.hexcasting.client.render.*
Expand Down Expand Up @@ -313,6 +314,20 @@ class GuiSpellcasting constructor(
return true
}

override fun keyPressed(key: Int, scancode: Int, modifiers: Int): Boolean {
if (super.keyPressed(key, scancode, modifiers)) return true

if (Keybinds.spellbookPrev.matches(key, scancode)) {
ShiftScrollListener.onScroll(-1.0, false)
return true
} else if (Keybinds.spellbookNext.matches(key, scancode)) {
ShiftScrollListener.onScroll(1.0, false)
return true
}

return false
}

override fun onClose() {
if (drawState == PatternDrawState.BetweenPatterns)
closeForReal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@
"gui.hexcasting": {
spellcasting: "Hex Grid",
},

"category.hexcasting": {
"binds": "Hex Casting",
},

"key.hexcasting": {
"spellbook_prev": "Previous Spellbook Page",
"spellbook_next": "Next Spellbook Page",
},

"tag.hexcasting": {
staves: "Hex Staves",
Expand Down Expand Up @@ -335,13 +344,17 @@
"": "Ctrl Toggles Off Stroke Order",
"@Tooltip": "Whether the ctrl key will instead turn *off* the color gradient on patterns",
},
disableInworldScrolling: {
"": "Disable In-World Scrolling",
"@Tooltip": "Disable scrolling input for spellbooks and abaci in the normal world, keeping keybinds and staff screen scrolling normal"
},
invertSpellbookScrollDirection: {
"": "Invert Spellbook Scroll Direction",
"@Tooltip": "Whether scrolling up (as opposed to down) will increase the page index of the spellbook, and vice versa",
},
invertAbacusScrollDirection: {
"": "Invert Abacus Scroll Direction",
"@Tooltip": "Whether scrolling up (as opposed to down) will increase the page index of the abacus, and vice versa",
"@Tooltip": "Whether scrolling up (as opposed to down) will increase the value of the abacus, and vice versa",
},
gridSnapThreshold: {
"": "Grid Snap Threshold",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.fabric

import at.petrak.hexcasting.client.ClientTickCounter
import at.petrak.hexcasting.client.Keybinds
import at.petrak.hexcasting.client.RegisterClientStuff
import at.petrak.hexcasting.client.ShiftScrollListener
import at.petrak.hexcasting.client.gui.PatternTooltipComponent
Expand All @@ -13,6 +14,7 @@ import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import at.petrak.hexcasting.interop.HexInterop
import net.fabricmc.api.ClientModInitializer
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.model.ModelLoadingRegistry
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry
Expand All @@ -37,6 +39,7 @@ object FabricHexClientInitializer : ClientModInitializer {
WorldRenderEvents.START.register { ClientTickCounter.renderTickStart(it.tickDelta()) }
ClientTickEvents.END_CLIENT_TICK.register {
ClientTickCounter.clientTickEnd()
Keybinds.clientTickEnd()
ShiftScrollListener.clientTickEnd()
}
TooltipComponentCallback.EVENT.register(PatternTooltipComponent::tryConvert)
Expand All @@ -46,6 +49,8 @@ object FabricHexClientInitializer : ClientModInitializer {

MouseScrollCallback.EVENT.register(ShiftScrollListener::onScrollInGameplay)

Keybinds.ALL_BINDS.forEach(KeyBindingHelper::registerKeyBinding)

RegisterClientStuff.init()
HexModelLayers.init { loc, defn -> EntityModelLayerRegistry.registerModelLayer(loc, defn::get) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import me.shedaniel.autoconfig.serializer.PartitioningSerializer;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;

Expand Down Expand Up @@ -129,9 +128,11 @@ public static final class Client implements HexConfig.ClientConfigAccess, Config
@ConfigEntry.Gui.Tooltip
private boolean ctrlTogglesOffStrokeOrder = DEFAULT_CTRL_TOGGLES_OFF_STROKE_ORDER;
@ConfigEntry.Gui.Tooltip
private boolean disableInworldScrolling = DEFAULT_DISABLE_INWORLD_SCROLLING;
@ConfigEntry.Gui.Tooltip
private boolean invertSpellbookScrollDirection = DEFAULT_INVERT_SPELLBOOK_SCROLL;
@ConfigEntry.Gui.Tooltip
private boolean invertAbacusScrollDirection = DEFAULT_INVERT_SPELLBOOK_SCROLL;
private boolean invertAbacusScrollDirection = DEFAULT_INVERT_ABACUS_SCROLL;
@ConfigEntry.Gui.Tooltip
private double gridSnapThreshold = DEFAULT_GRID_SNAP_THRESHOLD;
@ConfigEntry.Gui.Tooltip
Expand All @@ -149,6 +150,11 @@ public boolean ctrlTogglesOffStrokeOrder() {
return ctrlTogglesOffStrokeOrder;
}

@Override
public boolean disableInworldScrolling() {
return disableInworldScrolling;
}

@Override
public boolean invertSpellbookScrollDirection() {
return invertSpellbookScrollDirection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.forge;

import at.petrak.hexcasting.client.ClientTickCounter;
import at.petrak.hexcasting.client.Keybinds;
import at.petrak.hexcasting.client.RegisterClientStuff;
import at.petrak.hexcasting.client.ShiftScrollListener;
import at.petrak.hexcasting.client.gui.PatternTooltipComponent;
Expand Down Expand Up @@ -28,6 +29,7 @@
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

import java.io.IOException;
import java.util.function.Function;
Expand Down Expand Up @@ -73,6 +75,7 @@ public static void clientInit(FMLClientSetupEvent evt) {
evBus.addListener((TickEvent.ClientTickEvent e) -> {
if (e.phase == TickEvent.Phase.END) {
ClientTickCounter.clientTickEnd();
Keybinds.clientTickEnd();
ShiftScrollListener.clientTickEnd();
}
});
Expand Down Expand Up @@ -136,4 +139,9 @@ public static void addPlayerLayers(EntityRenderersEvent.AddLayers evt) {
skin.addLayer(new AltioraLayer<>(skin, evt.getEntityModels()));
});
}

@SubscribeEvent
public static void registerBinds(RegisterKeyMappingsEvent event) {
Keybinds.ALL_BINDS.forEach(event::register);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraft.util.RandomSource;

import java.util.List;

Expand Down Expand Up @@ -80,6 +79,7 @@ public int artifactCooldown() {

public static class Client implements HexConfig.ClientConfigAccess {
private static ForgeConfigSpec.BooleanValue ctrlTogglesOffStrokeOrder;
private static ForgeConfigSpec.BooleanValue disableInworldScrolling;
private static ForgeConfigSpec.BooleanValue invertSpellbookScrollDirection;
private static ForgeConfigSpec.BooleanValue invertAbacusScrollDirection;
private static ForgeConfigSpec.DoubleValue gridSnapThreshold;
Expand All @@ -90,6 +90,9 @@ public Client(ForgeConfigSpec.Builder builder) {
ctrlTogglesOffStrokeOrder = builder.comment(
"Whether the ctrl key will instead turn *off* the color gradient on patterns")
.define("ctrlTogglesOffStrokeOrder", DEFAULT_CTRL_TOGGLES_OFF_STROKE_ORDER);
disableInworldScrolling = builder.comment(
"Disable scrolling input for spellbooks and abaci in the normal world, keeping keybinds and staff screen scrolling normal")
.define("disableInworldScrolling", DEFAULT_DISABLE_INWORLD_SCROLLING);
invertSpellbookScrollDirection = builder.comment(
"Whether scrolling up (as opposed to down) will increase the page index of the spellbook, and " +
"vice versa")
Expand All @@ -109,6 +112,11 @@ public Client(ForgeConfigSpec.Builder builder) {
.define("alwaysShowListCommas", DEFAULT_ALWAYS_SHOW_LIST_COMMAS);
}

@Override
public boolean disableInworldScrolling() {
return disableInworldScrolling.get();
}

@Override
public boolean invertSpellbookScrollDirection() {
return invertSpellbookScrollDirection.get();
Expand Down