Skip to content

Commit

Permalink
UDOC-0 - Remove static fields in favor of static classes
Browse files Browse the repository at this point in the history
  • Loading branch information
telvarost committed Mar 16, 2024
1 parent 7fb2717 commit 7817156
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=b1.7.3-build.2
loader_version=0.14.24-babric.1

# Mod Properties
mod_version=2.0.2
mod_version=2.0.3
maven_group=com.github.telvarost
archives_base_name=InventoryTweaks

Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/github/telvarost/inventorytweaks/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

public class Config {

@GConfig(value = "inventoryTweaks", visibleName = "InventoryTweaks Config", primary = true)
@GConfig(value = "inventoryTweaks", visibleName = "InventoryTweaks", primary = true)
public static InventoryTweaksConfig INVENTORY_TWEAKS_CONFIG = new InventoryTweaksConfig();

public static class InventoryTweaksConfig {

@ConfigCategory("Modern Minecraft Config")
public static ModernMinecraftConfig MODERN_MINECRAFT_CONFIG = new ModernMinecraftConfig();
public static final ModernMinecraftConfig MODERN_MINECRAFT_CONFIG = new ModernMinecraftConfig();

@ConfigCategory("MouseTweaks Config")
public static final MouseTweaksConfig MOUSE_TWEAKS_CONFIG = new MouseTweaksConfig();
Expand All @@ -22,60 +22,60 @@ public static class InventoryTweaksConfig {
public static class ModernMinecraftConfig {

@ConfigName("Enable [Click + Drag] graphics")
public static Boolean EnableDragGraphics = true;
public Boolean EnableDragGraphics = true;

@ConfigName("Enable [Left-Click + Drag]")
public static Boolean EnableLeftClickDrag = true;
public Boolean EnableLeftClickDrag = true;

@ConfigName("Enable [Right-Click + Drag]")
public static Boolean EnableRightClickDrag = true;
public Boolean EnableRightClickDrag = true;

@ConfigName("Prefer [Shift-Click] over [Left-Click + Drag]")
public static Boolean LMBPreferShiftClick = true;
public Boolean LMBPreferShiftClick = true;

@ConfigName("Prefer [Shift-Click] over [Right-Click + Drag]")
public static Boolean RMBPreferShiftClick = true;
public Boolean RMBPreferShiftClick = true;

@ConfigName("Use [DROP_KEY] to drop inventory items")
@Comment("Cursor must not be holding any items")
public static Boolean UseDropKeyInInventory = true;
public Boolean UseDropKeyInInventory = true;

@ConfigName("Use [LCtrl + DROP_KEY] to drop entire stack")
public static Boolean LCtrlStackDrop = true;
public Boolean LCtrlStackDrop = true;

@ConfigName("Use [NUMBER_KEYS] to swap items to hotbar")
@Comment("Hover over the slot or swap cursor item")
public static Boolean NumKeyHotbarSwap = true;
public Boolean NumKeyHotbarSwap = true;
}

public static class MouseTweaksConfig {

@ConfigCategory("Scroll Wheel Config")
public static final ScrollWheelConfig SCROLL_WHEEL_CONFIG = new ScrollWheelConfig();
public final ScrollWheelConfig SCROLL_WHEEL_CONFIG = new ScrollWheelConfig();

@ConfigName("Empty cursor [Shift + Left-Click + Drag]")
@Comment("[Shift-Click] items of any type")
public static Boolean LMBTweakShiftClickAny = true;
public Boolean LMBTweakShiftClickAny = true;

@ConfigName("Item in cursor [Shift + Left-Click + Drag]")
@Comment("[Shift-Click] items of the held type")
public static Boolean LMBTweakShiftClick = true;
public Boolean LMBTweakShiftClick = true;

@ConfigName("[Right-Click + Drag] over existing slots")
public static Boolean RMBTweak = true;
public Boolean RMBTweak = true;

@ConfigName("[Left-Click + Drag] to pick up items")
public static Boolean LMBTweakPickUp = true;
public Boolean LMBTweakPickUp = true;
}

public static class ScrollWheelConfig {

@ConfigName("Enable Scroll Wheel Tweaks")
public static Boolean enableScrollWheelTweaks = true;
public Boolean enableScrollWheelTweaks = true;

@ConfigName("Invert scroll direction: cursor/slot")
@Comment("For cursor/slot item transfer")
public static Boolean invertScrollCursorSlotDirection = false;
public Boolean invertScrollCursorSlotDirection = false;

// @ConfigName("Invert scroll direction: inventories")
// @Comment("For item transfer between inventories")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button,
if (!inventoryTweaks_cancelLeftClickDrag()) {

/** - Handle Right-click */
if (Config.ModernMinecraftConfig.EnableRightClickDrag) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.EnableRightClickDrag) {
exitFunction = inventoryTweaks_handleRightClick(mouseX, mouseY);
}
} else {
Expand All @@ -117,7 +117,7 @@ protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button,
ItemInstance cursorStack = minecraft.player.inventory.getCursorItem();
Slot clickedSlot = this.getSlot(mouseX, mouseY);
if (cursorStack != null) {
if (Config.ModernMinecraftConfig.EnableLeftClickDrag) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.EnableLeftClickDrag) {
exitFunction = inventoryTweaks_handleLeftClickWithItem(cursorStack, clickedSlot);
}
} else {
Expand All @@ -144,7 +144,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
if (slot == null)
return;

if (Config.ScrollWheelConfig.enableScrollWheelTweaks) {
if (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.SCROLL_WHEEL_CONFIG.enableScrollWheelTweaks) {
int currentWheelDegrees = Mouse.getDWheel();
if ( (0 != currentWheelDegrees)
&& (isLeftClickDragStarted == false)
Expand Down Expand Up @@ -180,7 +180,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,

if (!rightClickHoveredSlots.contains(slot)) {
inventoryTweaks_handleRightClickDrag(slotItemToExamine);
} else if (Config.MouseTweaksConfig.RMBTweak) {
} else if (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.RMBTweak) {
inventoryTweaks_handleRightClickDragMouseTweaks();
}
} else {
Expand Down Expand Up @@ -257,7 +257,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
}

@Unique private void inventoryTweaks_scrollCursorSlotTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) {
if (Config.ScrollWheelConfig.invertScrollCursorSlotDirection) {
if (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.SCROLL_WHEEL_CONFIG.invertScrollCursorSlotDirection) {
numTurns *= -1;
}

Expand Down Expand Up @@ -357,14 +357,20 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
ItemInstance cursorStack = minecraft.player.inventory.getCursorItem();

/** - Handle Right-click if an item is held */
if (cursorStack != null) {
if (null != cursorStack) {

/** - Ensure a slot was clicked */
Slot clickedSlot = this.getSlot(mouseX, mouseY);
if (clickedSlot != null) {
if (null != clickedSlot) {

/** - Record how many items are in the slot */
if (null != clickedSlot.getItem()) {

/** - Let vanilla minecraft handle right click with an item onto a different item */
if (cursorStack.itemId != clickedSlot.getItem().itemId) {
return false;
}

rightClickExistingAmount.add(clickedSlot.getItem().count);
} else {
rightClickExistingAmount.add(0);
Expand All @@ -380,7 +386,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
/** - Handle initial Right-click */
lastRMBSlotId = clickedSlot.id;
lastRMBSlot = clickedSlot;
if (Config.ModernMinecraftConfig.RMBPreferShiftClick) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.RMBPreferShiftClick) {
boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, isShiftKeyDown, this.minecraft.player);

Expand Down Expand Up @@ -474,9 +480,18 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,

@Unique private boolean inventoryTweaks_handleLeftClickWithItem(ItemInstance cursorStack, Slot clickedSlot) {
/** - Ensure a slot was clicked */
if (clickedSlot != null) {
if (null != clickedSlot) {

/** - Record how many items are in the slot and how many items are needed to fill the slot */
if (null != clickedSlot.getItem()) {

/** - Let vanilla minecraft handle left click with an item onto a different item */
if (null != cursorStack) {
if (cursorStack.itemId != clickedSlot.getItem().itemId) {
return false;
}
}

leftClickAmountToFillPersistent.add(cursorStack.getMaxStackSize() - clickedSlot.getItem().count);
leftClickExistingAmount.add(clickedSlot.getItem().count);
} else {
Expand All @@ -494,7 +509,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
/** - Handle initial Left-click */
lastLMBSlotId = clickedSlot.id;
lastLMBSlot = clickedSlot;
if (Config.ModernMinecraftConfig.LMBPreferShiftClick) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.LMBPreferShiftClick) {
boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, isShiftKeyDown, this.minecraft.player);

Expand Down Expand Up @@ -549,12 +564,12 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
if (slotItemToExamine.isDamageAndIDIdentical(leftClickMouseTweaksPersistentStack))
{
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
if (Config.MouseTweaksConfig.LMBTweakShiftClick)
if (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.LMBTweakShiftClick)
{
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, true, this.minecraft.player);
}
} else {
if (Config.MouseTweaksConfig.LMBTweakPickUp) {
if (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.LMBTweakPickUp) {
ItemInstance cursorStack = minecraft.player.inventory.getCursorItem();

if (cursorStack == null) {
Expand Down Expand Up @@ -585,7 +600,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,
}
}
}
} else if ( (Config.MouseTweaksConfig.LMBTweakShiftClickAny)
} else if ( (Config.INVENTORY_TWEAKS_CONFIG.MOUSE_TWEAKS_CONFIG.LMBTweakShiftClickAny)
&& ( (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|| (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT))
)
Expand Down Expand Up @@ -733,7 +748,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY,

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;isMouseOverSlot(Lnet/minecraft/container/slot/Slot;II)Z"))
private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) {
if (Config.ModernMinecraftConfig.EnableDragGraphics) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.EnableDragGraphics) {
return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot))
|| (drawingHoveredSlot = leftClickHoveredSlots.contains(slot))
|| isMouseOverSlot(slot, x, y)
Expand All @@ -745,7 +760,7 @@ private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;fillGradient(IIIIII)V", ordinal = 0))
private void inventoryTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) {
if (Config.ModernMinecraftConfig.EnableDragGraphics) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.EnableDragGraphics) {
if (colorStart != colorEnd) throw new AssertionError();
int color = drawingHoveredSlot ? 0x20ffffff : colorStart;
this.fillGradient(startX, startY, endX, endY, color, color);
Expand All @@ -760,14 +775,14 @@ private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInf
return;
}

if (Config.ModernMinecraftConfig.UseDropKeyInInventory) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.UseDropKeyInInventory) {
if (keyCode == this.minecraft.options.dropKey.key) {
if (this.minecraft.player.inventory.getCursorItem() != null) {
return;
}

this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player);
if (Config.ModernMinecraftConfig.LCtrlStackDrop) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.LCtrlStackDrop) {
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, -999, Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) ? 0 : 1, false, this.minecraft.player);
} else {
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, -999, 1, false, this.minecraft.player);
Expand All @@ -776,7 +791,7 @@ private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInf
}
}

if (Config.ModernMinecraftConfig.NumKeyHotbarSwap) {
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.NumKeyHotbarSwap) {
if (keyCode >= Keyboard.KEY_1 && keyCode <= Keyboard.KEY_9) {
if (this.minecraft.player.inventory.getCursorItem() == null) {
this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public abstract class PlayerMixin {
@Inject(method = "dropSelectedItem", at = @At("HEAD"), cancellable = true)
private void inventoryTweaks_dropSelectedItem(CallbackInfo ci) {
if (!Config.ModernMinecraftConfig.LCtrlStackDrop) {
if (!Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.LCtrlStackDrop) {
return;
}

Expand Down

0 comments on commit 7817156

Please sign in to comment.