Skip to content

Commit d3cdeb7

Browse files
committed
Changed the interaction with the configured items in machinery item input hatches to align with AE2
1 parent bb6cef7 commit d3cdeb7

File tree

3 files changed

+57
-90
lines changed

3 files changed

+57
-90
lines changed

src/main/java/github/kasuminova/mmce/client/gui/GuiMEItemInputBus.java

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -43,83 +43,30 @@ public class GuiMEItemInputBus extends GuiMEItemBus implements IJEIGhostIngredie
4343
private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png");
4444

4545
protected final Map<IGhostIngredientHandler.Target<?>, Object> mapTargetSlot = new HashMap<>();
46-
private int invActionAmount = 0;
4746

4847
public GuiMEItemInputBus(final MEItemInputBus te, final EntityPlayer player) {
4948
super(new ContainerMEItemInputBus(te, player));
5049
this.ySize = 204;
5150
}
5251

53-
private static int getAddAmount() {
54-
int addAmount;
55-
// SHIFT + CTRL + ALT 1000000
56-
// ALT + CTRL 100000
57-
// ALT + SHIFT 10000
58-
// SHIFT + CTRL 1000
59-
// CTRL 100
60-
// SHIFT 10
61-
if (isShiftDown() && isControlDown() && isAltDown()) {
62-
addAmount = 1_000_000;
63-
} else if (isAltDown() && isControlDown()) {
64-
addAmount = 100_000;
65-
} else if (isAltDown() && isShiftDown()) {
66-
addAmount = 10_000;
67-
} else if (isShiftDown() && isControlDown()) {
68-
addAmount = 1_000;
69-
} else if (isControlDown()) {
70-
addAmount = 100;
71-
} else if (isShiftDown()) {
72-
addAmount = 10;
73-
} else {
74-
addAmount = 1;
75-
}
76-
return addAmount;
77-
}
78-
7952
private static List<String> getAddActionInfo() {
8053
List<String> tooltip = new ArrayList<>();
8154
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action"));
8255
// Quite a sight, isn't it?
83-
String addAmount = MiscUtils.formatDecimal(getAddAmount());
84-
if (isShiftDown() && isControlDown() && isAltDown()) {
85-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
86-
"SHIFT + CTRL + ALT", addAmount));
87-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
88-
"SHIFT + CTRL + ALT", addAmount));
89-
} else if (isAltDown() && isControlDown()) {
90-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
91-
"CTRL + ALT", addAmount));
92-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
93-
"CTRL + ALT", addAmount));
94-
} else if (isAltDown() && isShiftDown()) {
95-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
96-
"SHIFT + ALT", addAmount));
97-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
98-
"SHIFT + ALT", addAmount));
99-
} else if (isShiftDown() && isControlDown()) {
100-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
101-
"SHIFT + CTRL", addAmount));
102-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
103-
"SHIFT + CTRL", addAmount));
104-
} else if (isControlDown()) {
105-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
106-
"CTRL", addAmount));
107-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
108-
"CTRL", addAmount));
109-
} else if (isShiftDown()) {
110-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
111-
"SHIFT", addAmount));
112-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
113-
"SHIFT", addAmount));
56+
// It was truly a beautiful sight...
57+
58+
if (isShiftDown() && isControlDown()) {
59+
String keyCombination = "SHIFT + CTRL";
60+
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.multiply",
61+
keyCombination));
62+
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.divide",
63+
keyCombination));
11464
} else {
11565
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase.normal"));
11666
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease.normal"));
11767
}
118-
return tooltip;
119-
}
12068

121-
private static boolean isAltDown() {
122-
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
69+
return tooltip;
12370
}
12471

12572
private static boolean isControlDown() {
@@ -158,29 +105,53 @@ protected void onMouseWheelEvent(final int x, final int y, final int wheel) {
158105
return;
159106
}
160107

161-
int amount = wheel < 0 ? -getAddAmount() : getAddAmount();
162108
int stackCount = stack.getCount();
109+
int countToSend = getUpdatedCount(isScrollingUp(wheel), stackCount);
163110

164-
if (amount > 0) {
165-
if (stackCount + amount > slot.getSlotStackLimit()) {
111+
if (countToSend > 0) {
112+
if (countToSend > slot.getSlotStackLimit()) {
166113
return;
167114
}
168-
} else if (stackCount - amount <= 0) {
169-
return;
170115
}
171116

172-
this.invActionAmount += amount;
173-
ClientProxy.clientScheduler.addRunnable(() -> sendInvActionToServer(slot.slotNumber), 0);
117+
ClientProxy.clientScheduler.addRunnable(() -> sendInvActionToServer(slot.slotNumber, countToSend), 0);
118+
}
119+
120+
private boolean isScrollingUp(int wheel) {
121+
return wheel >= 0;
122+
}
123+
124+
private int getUpdatedCount(boolean isScrollingUp, int currentAmount) {
125+
if (isShiftDown() && isControlDown()) {
126+
if (isScrollingUp) {
127+
// Overflow protection
128+
if (currentAmount <= Integer.MAX_VALUE / 2) {
129+
return 2 * currentAmount;
130+
}
131+
return Integer.MAX_VALUE;
132+
} else {
133+
return Math.max(1, currentAmount / 2);
134+
}
135+
} else {
136+
if (isScrollingUp) {
137+
// Overflow protection
138+
if (currentAmount < Integer.MAX_VALUE) {
139+
return 1 + currentAmount;
140+
}
141+
return Integer.MAX_VALUE;
142+
} else {
143+
return Math.max(1, currentAmount - 1);
144+
}
145+
}
174146
}
175147

176-
public void sendInvActionToServer(int slotNumber) {
177-
if (invActionAmount == 0) {
148+
public void sendInvActionToServer(int slotNumber, int amountToSend) {
149+
if (amountToSend == 0) {
178150
return;
179151
}
180152
ModularMachinery.NET_CHANNEL.sendToServer(new PktMEInputBusInvAction(
181-
invActionAmount, slotNumber
153+
amountToSend, slotNumber
182154
));
183-
invActionAmount = 0;
184155
}
185156

186157
@Override

src/main/java/github/kasuminova/mmce/common/network/PktMEInputBusInvAction.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
1212

1313
public class PktMEInputBusInvAction implements IMessage, IMessageHandler<PktMEInputBusInvAction, IMessage> {
14-
private int addAmount = 0;
14+
private int newAmount = 0;
1515
private int slotID = 0;
1616

1717
public PktMEInputBusInvAction() {
1818
}
1919

20-
public PktMEInputBusInvAction(final int addAmount, final int slotID) {
21-
this.addAmount = addAmount;
20+
public PktMEInputBusInvAction(final int newAmount, final int slotID) {
21+
this.newAmount = newAmount;
2222
this.slotID = slotID;
2323
}
2424

2525
@Override
2626
public void fromBytes(final ByteBuf buf) {
27-
this.addAmount = buf.readInt();
27+
this.newAmount = buf.readInt();
2828
this.slotID = buf.readInt();
2929
}
3030

3131
@Override
3232
public void toBytes(final ByteBuf buf) {
33-
buf.writeInt(addAmount);
33+
buf.writeInt(newAmount);
3434
buf.writeInt(slotID);
3535
}
3636

@@ -51,20 +51,14 @@ public IMessage onMessage(final PktMEInputBusInvAction message, final MessageCon
5151
return null;
5252
}
5353

54-
int addAmount = message.addAmount;
55-
if (addAmount == 0) {
54+
int newAmount = message.newAmount;
55+
if (newAmount == 0) {
5656
return null;
5757
}
5858

59-
int count = stack.getCount();
60-
if (addAmount > 0) {
61-
stack.grow(Math.min(slot.getSlotStackLimit() - count, addAmount));
62-
slot.onSlotChanged();
63-
} else {
64-
int decrAmount = -addAmount;
65-
stack.shrink(Math.min(count - 1, decrAmount));
66-
slot.onSlotChanged();
67-
}
59+
ItemStack newStack = stack.copy();
60+
newStack.setCount(newAmount);
61+
slot.putStack(newStack);
6862

6963
return null;
7064
}

src/main/resources/assets/modularmachinery/lang/en_US.lang

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ gui.upgradebus.incompatible=§eWarning: %s is not compatible with this machinery
5959
gui.meitemoutputbus.title=ME Machinery Item Output Bus
6060
gui.meiteminputbus.title=ME Machinery Item Input Bus
6161

62-
gui.meiteminputbus.inv_action=Use the scroll wheel and the SHIFT, CONTROL, ALT key combination to modify the number of marked items.
62+
gui.meiteminputbus.inv_action=Use the scroll wheel and the SHIFT and CONTROL key combination to modify the number of marked items.
6363
gui.meiteminputbus.inv_action.increase.normal=Scroll the wheel up to increase the number of items by 1.
6464
gui.meiteminputbus.inv_action.decrease.normal=Scroll the wheel down or right-click on an item to decrease the number of items by 1.
6565
gui.meiteminputbus.inv_action.increase=Press the %s key combination to increase the number of %s items while the wheel is scrolling up.
6666
gui.meiteminputbus.inv_action.decrease=Press the %s key combination to decrease the number of %s items while the wheel is scrolling up.
67+
gui.meiteminputbus.inv_action.multiply=Press the %s key combination to double the number of items while the wheel is scrolling up.
68+
gui.meiteminputbus.inv_action.divide=Press the %s key combination to halve the number of items while the wheel is scrolling down.
6769
gui.meiteminputbus.items_marked=Items marked: %s
6870
gui.meitembus.item_cached=Items Cached: %s
6971
gui.meitembus.nbt_stored=Items have been stored internally.

0 commit comments

Comments
 (0)