Skip to content

Commit d01dec7

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

File tree

3 files changed

+58
-91
lines changed

3 files changed

+58
-91
lines changed

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

Lines changed: 44 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,83 +31,29 @@
3131
public class GuiMEItemInputBus extends GuiMEItemBus {
3232
private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png");
3333

34-
private int invActionAmount = 0;
35-
3634
public GuiMEItemInputBus(final MEItemInputBus te, final EntityPlayer player) {
3735
super(new ContainerMEItemInputBus(te, player));
3836
this.ySize = 204;
3937
}
4038

41-
private static int getAddAmount() {
42-
int addAmount;
43-
// SHIFT + CTRL + ALT 1000000
44-
// ALT + CTRL 100000
45-
// ALT + SHIFT 10000
46-
// SHIFT + CTRL 1000
47-
// CTRL 100
48-
// SHIFT 10
49-
if (isShiftDown() && isControlDown() && isAltDown()) {
50-
addAmount = 1_000_000;
51-
} else if (isAltDown() && isControlDown()) {
52-
addAmount = 100_000;
53-
} else if (isAltDown() && isShiftDown()) {
54-
addAmount = 10_000;
55-
} else if (isShiftDown() && isControlDown()) {
56-
addAmount = 1_000;
57-
} else if (isControlDown()) {
58-
addAmount = 100;
59-
} else if (isShiftDown()) {
60-
addAmount = 10;
61-
} else {
62-
addAmount = 1;
63-
}
64-
return addAmount;
65-
}
66-
6739
private static List<String> getAddActionInfo() {
6840
List<String> tooltip = new ArrayList<>();
6941
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action"));
7042
// Quite a sight, isn't it?
71-
String addAmount = MiscUtils.formatDecimal(getAddAmount());
72-
if (isShiftDown() && isControlDown() && isAltDown()) {
73-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
74-
"SHIFT + CTRL + ALT", addAmount));
75-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
76-
"SHIFT + CTRL + ALT", addAmount));
77-
} else if (isAltDown() && isControlDown()) {
78-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
79-
"CTRL + ALT", addAmount));
80-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
81-
"CTRL + ALT", addAmount));
82-
} else if (isAltDown() && isShiftDown()) {
83-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
84-
"SHIFT + ALT", addAmount));
85-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
86-
"SHIFT + ALT", addAmount));
87-
} else if (isShiftDown() && isControlDown()) {
88-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
89-
"SHIFT + CTRL", addAmount));
90-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
91-
"SHIFT + CTRL", addAmount));
92-
} else if (isControlDown()) {
93-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
94-
"CTRL", addAmount));
95-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
96-
"CTRL", addAmount));
97-
} else if (isShiftDown()) {
98-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase",
99-
"SHIFT", addAmount));
100-
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease",
101-
"SHIFT", addAmount));
43+
// It was truly a beautiful sight...
44+
45+
if (isShiftDown() && isControlDown()) {
46+
String keyCombination = "SHIFT + CTRL";
47+
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.multiply",
48+
keyCombination));
49+
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.divide",
50+
keyCombination));
10251
} else {
10352
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase.normal"));
10453
tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease.normal"));
10554
}
106-
return tooltip;
107-
}
10855

109-
private static boolean isAltDown() {
110-
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
56+
return tooltip;
11157
}
11258

11359
private static boolean isControlDown() {
@@ -146,29 +92,53 @@ protected void onMouseWheelEvent(final int x, final int y, final int wheel) {
14692
return;
14793
}
14894

149-
int amount = wheel < 0 ? -getAddAmount() : getAddAmount();
15095
int stackCount = stack.getCount();
96+
int countToSend = getUpdatedCount(isScrollingUp(wheel), stackCount);
15197

152-
if (amount > 0) {
153-
if (stackCount + amount > slot.getSlotStackLimit()) {
98+
if (countToSend > 0) {
99+
if (countToSend > slot.getSlotStackLimit()) {
154100
return;
155101
}
156-
} else if (stackCount - amount <= 0) {
157-
return;
158102
}
159103

160-
this.invActionAmount += amount;
161-
ClientProxy.clientScheduler.addRunnable(() -> sendInvActionToServer(slot.slotNumber), 0);
104+
ClientProxy.clientScheduler.addRunnable(() -> sendInvActionToServer(slot.slotNumber, countToSend), 0);
105+
}
106+
107+
private boolean isScrollingUp(int wheel) {
108+
return wheel >= 0;
109+
}
110+
111+
private int getUpdatedCount(boolean isScrollingUp, int currentAmount) {
112+
if (isShiftDown() && isControlDown()) {
113+
if (isScrollingUp) {
114+
// Overflow protection
115+
if (currentAmount <= Integer.MAX_VALUE / 2) {
116+
return 2 * currentAmount;
117+
}
118+
return Integer.MAX_VALUE;
119+
} else {
120+
return Math.max(1, currentAmount / 2);
121+
}
122+
} else {
123+
if (isScrollingUp) {
124+
// Overflow protection
125+
if (currentAmount < Integer.MAX_VALUE) {
126+
return 1 + currentAmount;
127+
}
128+
return Integer.MAX_VALUE;
129+
} else {
130+
return Math.max(1, currentAmount - 1);
131+
}
132+
}
162133
}
163134

164-
public void sendInvActionToServer(int slotNumber) {
165-
if (invActionAmount == 0) {
135+
public void sendInvActionToServer(int slotNumber, int amountToSend) {
136+
if (amountToSend == 0) {
166137
return;
167138
}
168139
ModularMachinery.NET_CHANNEL.sendToServer(new PktMEInputBusInvAction(
169-
invActionAmount, slotNumber
140+
amountToSend, slotNumber
170141
));
171-
invActionAmount = 0;
172142
}
173143

174144
@Override

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

Lines changed: 11 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,15 @@ 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);
62+
slot.onSlotChanged();
6863

6964
return null;
7065
}

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)