Skip to content

Commit ef60e73

Browse files
authored
Merge pull request #168 from Alecsioo/improve_consistency_machinery_inputs
Changed the interaction with the configured items in machinery item hatches
2 parents dc72f2a + 2c7284d commit ef60e73

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
@@ -44,83 +44,30 @@ public class GuiMEItemInputBus extends GuiMEItemBus implements IJEIGhostIngredie
4444
private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png");
4545

4646
protected final Map<IGhostIngredientHandler.Target<?>, Object> mapTargetSlot = new Object2ObjectOpenHashMap<>();
47-
private int invActionAmount = 0;
4847

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

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

122-
private static boolean isAltDown() {
123-
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
70+
return tooltip;
12471
}
12572

12673
private static boolean isControlDown() {
@@ -159,29 +106,53 @@ protected void onMouseWheelEvent(final int x, final int y, final int wheel) {
159106
return;
160107
}
161108

162-
int amount = wheel < 0 ? -getAddAmount() : getAddAmount();
163109
int stackCount = stack.getCount();
110+
int countToSend = getUpdatedCount(isScrollingUp(wheel), stackCount);
164111

165-
if (amount > 0) {
166-
if (stackCount + amount > slot.getSlotStackLimit()) {
112+
if (countToSend > 0) {
113+
if (countToSend > slot.getSlotStackLimit()) {
167114
return;
168115
}
169-
} else if (stackCount - amount <= 0) {
170-
return;
171116
}
172117

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

177-
public void sendInvActionToServer(int slotNumber) {
178-
if (invActionAmount == 0) {
149+
public void sendInvActionToServer(int slotNumber, int amountToSend) {
150+
if (amountToSend == 0) {
179151
return;
180152
}
181153
ModularMachinery.NET_CHANNEL.sendToServer(new PktMEInputBusInvAction(
182-
invActionAmount, slotNumber
154+
amountToSend, slotNumber
183155
));
184-
invActionAmount = 0;
185156
}
186157

187158
@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)