Skip to content

Commit

Permalink
Merge pull request #7 from darmiel/master
Browse files Browse the repository at this point in the history
feat: reversed mouse scrolling
  • Loading branch information
nyuppo committed Jan 8, 2023
2 parents fd0625e + 2321cfa commit 2980a6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 72 deletions.
93 changes: 25 additions & 68 deletions src/main/java/com/github/nyuppo/HotbarCycleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (cycleKeyBinding.wasPressed()) {
if (client.player != null && !CONFIG.getHoldAndScroll()) {
shiftRows(client);
shiftRows(client, Direction.DOWN);
}
}
});
Expand All @@ -71,61 +71,39 @@ public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (singleCycleKeyBinding.wasPressed()) {
if (client.player != null && client.player.getInventory() != null && !CONFIG.getHoldAndScroll()) {
shiftSingle(client, client.player.getInventory().selectedSlot);
shiftSingle(client, client.player.getInventory().selectedSlot, Direction.DOWN);
}
}
});
}

public static void shiftRows(MinecraftClient client) {
@SuppressWarnings("resource")
ClientPlayerInteractionManager interactionManager = client.interactionManager;
if (interactionManager == null || client.player == null) {
return;
}

int i;
if (CONFIG.getReverseCycleDirection() ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
for (i = 0; i < 9; i++) {
if (isColumnEnabled(i)) {
clicker.swap(client, (!CONFIG.getReverseCycleDirection() ? 9 : 27) + i, i);
}
}
}
public enum Direction {
UP,
DOWN;

if (CONFIG.getEnableRow2()) {
for (i = 0; i < 9; i++) {
if (isColumnEnabled(i)) {
clicker.swap(client, 18 + i, i);
}
}
}

if (CONFIG.getReverseCycleDirection() ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
for (i = 0; i < 9; i++) {
if (isColumnEnabled(i)) {
clicker.swap(client, (!CONFIG.getReverseCycleDirection() ? 27 : 9) + i, i);
}
}
}

if (CONFIG.getPlaySound()) {
client.player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.MASTER, 0.5f, 1.5f);
public Direction reverse(final boolean reversed) {
return switch (this) {
case UP -> !reversed ? UP : DOWN;
case DOWN -> !reversed ? DOWN : UP;
};
}
}

public static void shiftRows(MinecraftClient client, boolean reverseBypass) {
public static void shiftRows(MinecraftClient client, final Direction requestedDirection) {
// invert direction if reverse cycle is enabled
final Direction direction = requestedDirection.reverse(CONFIG.getReverseCycleDirection());

@SuppressWarnings("resource")
ClientPlayerInteractionManager interactionManager = client.interactionManager;
if (interactionManager == null || client.player == null) {
return;
}

int i;
if (reverseBypass ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
if (direction != Direction.DOWN ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
for (i = 0; i < 9; i++) {
if (isColumnEnabled(i)) {
clicker.swap(client, (!reverseBypass ? 9 : 27) + i, i);
clicker.swap(client, (direction == Direction.DOWN ? 9 : 27) + i, i);
}
}
}
Expand All @@ -138,10 +116,10 @@ public static void shiftRows(MinecraftClient client, boolean reverseBypass) {
}
}

if (reverseBypass ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
if (direction != Direction.DOWN ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
for (i = 0; i < 9; i++) {
if (isColumnEnabled(i)) {
clicker.swap(client, (!reverseBypass ? 27 : 9) + i, i);
clicker.swap(client, (direction == Direction.DOWN ? 27 : 9) + i, i);
}
}
}
Expand All @@ -151,47 +129,26 @@ public static void shiftRows(MinecraftClient client, boolean reverseBypass) {
}
}

public static void shiftSingle(MinecraftClient client, int hotbarSlot) {
@SuppressWarnings("resource")
ClientPlayerInteractionManager interactionManager = client.interactionManager;
if (interactionManager == null || client.player == null) {
return;
}

if (CONFIG.getReverseCycleDirection() ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
clicker.swap(client, (!CONFIG.getReverseCycleDirection() ? 9 : 27) + hotbarSlot, hotbarSlot);
}

if (CONFIG.getEnableRow2()) {
clicker.swap(client, 18 + hotbarSlot, hotbarSlot);
}

if (CONFIG.getReverseCycleDirection() ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
clicker.swap(client, (!CONFIG.getReverseCycleDirection() ? 27 : 9) + hotbarSlot, hotbarSlot);
}

if (CONFIG.getPlaySound()) {
client.player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.MASTER, 0.5f, 1.8f);
}
}
public static void shiftSingle(MinecraftClient client, int hotbarSlot, final Direction requestedDirection) {
// invert direction if reverse cycle is enabled
final Direction direction = requestedDirection.reverse(CONFIG.getReverseCycleDirection());

public static void shiftSingle(MinecraftClient client, int hotbarSlot, boolean reverseBypass) {
@SuppressWarnings("resource")
ClientPlayerInteractionManager interactionManager = client.interactionManager;
if (interactionManager == null || client.player == null) {
return;
}

if (reverseBypass ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
clicker.swap(client, (!reverseBypass ? 9 : 27) + hotbarSlot, hotbarSlot);
if (direction == Direction.DOWN ? CONFIG.getEnableRow1() : CONFIG.getEnableRow3()) {
clicker.swap(client, (direction != Direction.DOWN ? 9 : 27) + hotbarSlot, hotbarSlot);
}

if (CONFIG.getEnableRow2()) {
clicker.swap(client, 18 + hotbarSlot, hotbarSlot);
}

if (reverseBypass ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
clicker.swap(client, (!reverseBypass ? 27 : 9) + hotbarSlot, hotbarSlot);
if (direction == Direction.DOWN ? CONFIG.getEnableRow3() : CONFIG.getEnableRow1()) {
clicker.swap(client, (direction != Direction.DOWN ? 27 : 9) + hotbarSlot, hotbarSlot);
}

if (CONFIG.getPlaySound()) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/github/nyuppo/mixin/ScrollCycleMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
public class ScrollCycleMixin {
@Inject(method = "scrollInHotbar(D)V", at = @At("HEAD"), cancellable = true)
private void hotbarcycleScrollInHotbar(double scrollAmount, CallbackInfo ci) {
int i = (int)Math.signum(scrollAmount);

final HotbarCycleClient.Direction direction = Math.signum(scrollAmount) < 0
? HotbarCycleClient.Direction.DOWN
: HotbarCycleClient.Direction.UP;
if (HotbarCycleClient.getConfig().getHoldAndScroll() && HotbarCycleClient.getCycleKeyBinding().isPressed()) {
HotbarCycleClient.shiftRows(MinecraftClient.getInstance(), i < 0);
HotbarCycleClient.shiftRows(MinecraftClient.getInstance(), direction);
ci.cancel();
} else if (HotbarCycleClient.getConfig().getHoldAndScroll() && HotbarCycleClient.getSingleCycleKeyBinding().isPressed()) {
HotbarCycleClient.shiftSingle(MinecraftClient.getInstance(), ((PlayerInventory)(Object)this).selectedSlot, i < 0);
HotbarCycleClient.shiftSingle(MinecraftClient.getInstance(), ((PlayerInventory)(Object)this).selectedSlot, direction);
ci.cancel();
}
}
Expand Down

0 comments on commit 2980a6a

Please sign in to comment.