Skip to content

Commit

Permalink
Add quick craft functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
PiTheGuy committed Aug 5, 2024
1 parent bb1038d commit 07fad0d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/appeng/client/gui/AEBaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ && getEmptyingAction(slot, menu.getCarried()) != null) {
InventoryAction action;
if (hasShiftDown()) {
action = InventoryAction.CRAFT_SHIFT;
} else if (hasAltDown()) {
action = InventoryAction.CRAFT_ALL;
} else {
// Craft stack on right-click, craft single on left-click
action = mouseButton == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/helpers/InventoryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum InventoryAction {
PICKUP_OR_SET_DOWN, SPLIT_OR_PLACE_SINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK,

// crafting term
CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT,
CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT, CRAFT_ALL,

// fluid term
FILL_ITEM, FILL_ITEM_MOVE_TO_PLAYER, FILL_ENTIRE_ITEM, FILL_ENTIRE_ITEM_MOVE_TO_PLAYER, EMPTY_ITEM,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/menu/AEBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public void doAction(ServerPlayer player, InventoryAction action, int slot, long
if (s instanceof CraftingTermSlot) {
switch (action) {
case CRAFT_SHIFT:
case CRAFT_ALL:
case CRAFT_ITEM:
case CRAFT_STACK:
((CraftingTermSlot) s).doClick(action, player);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/appeng/menu/slot/CraftingTermSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingInput;
Expand Down Expand Up @@ -97,10 +98,14 @@ public void doClick(InventoryAction action, Player who) {

int maxTimesToCraft;
InternalInventory target;
if (action == InventoryAction.CRAFT_SHIFT) // craft into player inventory...
if (action == InventoryAction.CRAFT_SHIFT || action == InventoryAction.CRAFT_ALL) // craft into player inventory...
{
target = new PlayerInternalInventory(who.getInventory());
maxTimesToCraft = (int) Math.floor((double) this.getItem().getMaxStackSize() / (double) howManyPerCraft);
if (action == InventoryAction.CRAFT_SHIFT) {
maxTimesToCraft = (int) Math.floor((double) this.getItem().getMaxStackSize() / (double) howManyPerCraft);
} else {
maxTimesToCraft = (int) Math.floor((double) this.getItem().getMaxStackSize() / (double) howManyPerCraft * Inventory.INVENTORY_SIZE);
}
} else if (action == InventoryAction.CRAFT_STACK) // craft into hand, full stack
{
target = new CarriedItemInventory(getMenu());
Expand Down

0 comments on commit 07fad0d

Please sign in to comment.