|
31 | 31 | public class GuiMEItemInputBus extends GuiMEItemBus { |
32 | 32 | private static final ResourceLocation TEXTURES_INPUT_BUS = new ResourceLocation(ModularMachinery.MODID, "textures/gui/meiteminputbus.png"); |
33 | 33 |
|
34 | | - private int invActionAmount = 0; |
35 | | - |
36 | 34 | public GuiMEItemInputBus(final MEItemInputBus te, final EntityPlayer player) { |
37 | 35 | super(new ContainerMEItemInputBus(te, player)); |
38 | 36 | this.ySize = 204; |
39 | 37 | } |
40 | 38 |
|
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 | | - |
67 | 39 | private static List<String> getAddActionInfo() { |
68 | 40 | List<String> tooltip = new ArrayList<>(); |
69 | 41 | tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action")); |
70 | 42 | // 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)); |
102 | 51 | } else { |
103 | 52 | tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.increase.normal")); |
104 | 53 | tooltip.add(TextFormatting.GRAY + I18n.format("gui.meiteminputbus.inv_action.decrease.normal")); |
105 | 54 | } |
106 | | - return tooltip; |
107 | | - } |
108 | 55 |
|
109 | | - private static boolean isAltDown() { |
110 | | - return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU); |
| 56 | + return tooltip; |
111 | 57 | } |
112 | 58 |
|
113 | 59 | private static boolean isControlDown() { |
@@ -146,29 +92,53 @@ protected void onMouseWheelEvent(final int x, final int y, final int wheel) { |
146 | 92 | return; |
147 | 93 | } |
148 | 94 |
|
149 | | - int amount = wheel < 0 ? -getAddAmount() : getAddAmount(); |
150 | 95 | int stackCount = stack.getCount(); |
| 96 | + int countToSend = getUpdatedCount(isScrollingUp(wheel), stackCount); |
151 | 97 |
|
152 | | - if (amount > 0) { |
153 | | - if (stackCount + amount > slot.getSlotStackLimit()) { |
| 98 | + if (countToSend > 0) { |
| 99 | + if (countToSend > slot.getSlotStackLimit()) { |
154 | 100 | return; |
155 | 101 | } |
156 | | - } else if (stackCount - amount <= 0) { |
157 | | - return; |
158 | 102 | } |
159 | 103 |
|
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 | + } |
162 | 133 | } |
163 | 134 |
|
164 | | - public void sendInvActionToServer(int slotNumber) { |
165 | | - if (invActionAmount == 0) { |
| 135 | + public void sendInvActionToServer(int slotNumber, int amountToSend) { |
| 136 | + if (amountToSend == 0) { |
166 | 137 | return; |
167 | 138 | } |
168 | 139 | ModularMachinery.NET_CHANNEL.sendToServer(new PktMEInputBusInvAction( |
169 | | - invActionAmount, slotNumber |
| 140 | + amountToSend, slotNumber |
170 | 141 | )); |
171 | | - invActionAmount = 0; |
172 | 142 | } |
173 | 143 |
|
174 | 144 | @Override |
|
0 commit comments