Skip to content

Commit

Permalink
Add ability to do shift click crafting to craft all at once
Browse files Browse the repository at this point in the history
  • Loading branch information
telvarost committed Nov 10, 2024
1 parent 5360b81 commit 98128cc
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'fabric-loom' version '1.7.4'
id 'babric-loom-extension' version '1.7.5'
id 'fabric-loom' version '1.8.12'
id 'babric-loom-extension' version '1.8.9'
id 'maven-publish'
}

Expand Down
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+c6a9668
loader_version=0.15.6-babric.1

# Mod Properties
mod_version=2.2.0
mod_version=2.3.0
maven_group=com.github.telvarost
archives_base_name=InventoryTweaks

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public static class ModernMinecraftConfig {
@ConfigEntry(name = "Enable [Right-Click + Drag]")
public Boolean EnableRightClickDrag = true;

@ConfigEntry(name = "Enable [Shift-Click] crafting")
public Boolean EnableShiftClickCrafting = true;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.telvarost.inventorytweaks.mixin;

import com.github.telvarost.inventorytweaks.Config;
import net.minecraft.screen.slot.CraftingResultSlot;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -25,12 +26,19 @@

@Mixin(HandledScreen.class)
public abstract class ContainerBaseMixin extends Screen {

@Shadow
protected abstract Slot getSlotAt(int x, int y);
protected int backgroundWidth;

@Shadow
protected int backgroundHeight;

@Shadow
public net.minecraft.screen.ScreenHandler container;

@Shadow
protected abstract Slot getSlotAt(int x, int y);

@Shadow
protected abstract boolean isPointOverSlot(Slot slot, int x, int Y);

Expand Down Expand Up @@ -81,6 +89,16 @@ public abstract class ContainerBaseMixin extends Screen {
protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) {
isLeftClickDragMouseTweaksStarted = false;

/** - Handle shift click crafting */
if (Config.INVENTORY_TWEAKS_CONFIG.MODERN_MINECRAFT_CONFIG.EnableShiftClickCrafting) {
if (inventoryTweaks_handleShiftClickCrafting(mouseX, mouseY, button)) {
/** - Handle if a button was clicked */
super.mouseClicked(mouseX, mouseY, button);
ci.cancel();
return;
}
}

/** - Check if client is on a server */
boolean isClientOnServer = minecraft.world.isRemote;

Expand Down Expand Up @@ -137,6 +155,49 @@ protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button,
}
}

@Unique private boolean inventoryTweaks_handleShiftClickCrafting(int mouseX, int mouseY, int button) {
Slot slot = this.getSlotAt(mouseX, mouseY);

if (slot instanceof CraftingResultSlot) {
boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
if (true == isShiftKeyDown && slot.hasStack()) {
for (int craftingAttempts = 0; craftingAttempts < 256; craftingAttempts++) {
if (slot.hasStack()) {
inventoryTweaks_internalMouseClicked(mouseX, mouseY, button);
} else {
break;
}
}
return true;
}
}

return false;
}

@Unique private void inventoryTweaks_internalMouseClicked(int mouseX, int mouseY, int button) {
super.mouseClicked(mouseX, mouseY, button);
if (button == 0 || button == 1) {
Slot var4 = this.getSlotAt(mouseX, mouseY);
int var5 = (this.width - this.backgroundWidth) / 2;
int var6 = (this.height - this.backgroundHeight) / 2;
boolean var7 = mouseX < var5 || mouseY < var6 || mouseX >= var5 + this.backgroundWidth || mouseY >= var6 + this.backgroundHeight;
int var8 = -1;
if (var4 != null) {
var8 = var4.id;
}

if (var7) {
var8 = -999;
}

if (var8 != -1) {
boolean var9 = var8 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
this.minecraft.interactionManager.clickSlot(this.container.syncId, var8, button, var9, this.minecraft.player);
}
}
}

@Inject(method = "mouseReleased", at = @At("RETURN"), cancellable = true)
private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int button, CallbackInfo ci) {
slot = this.getSlotAt(mouseX, mouseY);
Expand Down
10 changes: 2 additions & 8 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@

"environment": "client",
"entrypoints": {
"stationapi:event_bus": [
],
"stationapi:event_bus_client": [
],
"stationapi:event_bus_server": [
],
"gcapi3": [
"com.github.telvarost.inventorytweaks.Config"
]
Expand All @@ -35,11 +29,11 @@

"depends": {
"minecraft": "1.0.0-beta.7.3",
"gcapi3": ">=3.0.1",
"stationapi": "*"
"gcapi3": ">=3.0.1"
},

"recommends": {
"stationapi": "*",
"modmenu": "*"
},

Expand Down

0 comments on commit 98128cc

Please sign in to comment.