Skip to content

Commit d5e6c14

Browse files
committed
Require that output slots be locked when multiple recipes match the input
1 parent 89b889f commit d5e6c14

File tree

24 files changed

+309
-48
lines changed

24 files changed

+309
-48
lines changed

src/client/java/aztech/modern_industrialization/machines/GuiComponentsClient.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@
2424
package aztech.modern_industrialization.machines;
2525

2626
import aztech.modern_industrialization.machines.gui.GuiComponentClient;
27-
import aztech.modern_industrialization.machines.guicomponents.AutoExtractClient;
28-
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGuiClient;
29-
import aztech.modern_industrialization.machines.guicomponents.EnergyBarClient;
30-
import aztech.modern_industrialization.machines.guicomponents.GunpowderOverclockGuiClient;
31-
import aztech.modern_industrialization.machines.guicomponents.LargeTankFluidDisplayClient;
32-
import aztech.modern_industrialization.machines.guicomponents.NuclearReactorGuiClient;
33-
import aztech.modern_industrialization.machines.guicomponents.ProgressBarClient;
34-
import aztech.modern_industrialization.machines.guicomponents.RecipeEfficiencyBarClient;
35-
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLockingClient;
36-
import aztech.modern_industrialization.machines.guicomponents.ShapeSelectionClient;
37-
import aztech.modern_industrialization.machines.guicomponents.SlotPanelClient;
38-
import aztech.modern_industrialization.machines.guicomponents.TemperatureBarClient;
27+
import aztech.modern_industrialization.machines.guicomponents.*;
3928
import java.util.HashMap;
4029
import java.util.Map;
4130
import net.minecraft.resources.ResourceLocation;
@@ -58,6 +47,7 @@ public static void register(ResourceLocation id, GuiComponentClient.Factory clie
5847
register(GuiComponents.CRAFTING_MULTIBLOCK_GUI, CraftingMultiblockGuiClient::new);
5948
register(GuiComponents.ENERGY_BAR, EnergyBarClient::new);
6049
register(GuiComponents.LARGE_TANK_FLUID_DISPLAY, LargeTankFluidDisplayClient::new);
50+
register(GuiComponents.MACHINE_PROBLEMS_DISPLAY, MachineProblemsDisplayClient::new);
6151
register(GuiComponents.GUNPOWDER_OVERCLOCK_GUI, GunpowderOverclockGuiClient::new);
6252
register(GuiComponents.NUCLEAR_REACTOR_GUI, NuclearReactorGuiClient::new);
6353
register(GuiComponents.PROGRESS_BAR, ProgressBarClient::new);

src/client/java/aztech/modern_industrialization/machines/gui/ClientComponentRenderer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ default void addButtons(ButtonContainer container) {
4040

4141
void renderBackground(GuiGraphics guiGraphics, int leftPos, int topPos);
4242

43-
default void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int leftPos, int topPos, int cursorX, int cursorY) {
43+
/**
44+
* @return true if a tooltip was rendered, false otherwise
45+
*/
46+
default boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int leftPos, int topPos, int cursorX, int cursorY) {
47+
return false;
4448
}
4549

4650
default void addExtraBoxes(List<Rectangle> rectangles, int leftPos, int topPos) {

src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
189189
// Normal render - handles background and slots
190190
super.render(guiGraphics, mouseX, mouseY, delta);
191191
// Tooltips
192-
renderConfigurableSlotTooltips(guiGraphics, mouseX, mouseY);
193192
for (ClientComponentRenderer renderer : renderers) {
194-
renderer.renderTooltip(this, font, guiGraphics, leftPos, topPos, mouseX, mouseY);
193+
if (renderer.renderTooltip(this, font, guiGraphics, leftPos, topPos, mouseX, mouseY)) {
194+
return;
195+
}
195196
}
197+
renderConfigurableSlotTooltips(guiGraphics, mouseX, mouseY);
196198
}
197199

198200
@Override

src/client/java/aztech/modern_industrialization/machines/guicomponents/CraftingMultiblockGuiClient.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
import net.minecraft.client.gui.Font;
3434
import net.minecraft.client.gui.GuiGraphics;
3535
import net.minecraft.network.RegistryFriendlyByteBuf;
36+
import net.minecraft.network.chat.Component;
3637
import net.minecraft.resources.ResourceLocation;
3738

3839
public class CraftingMultiblockGuiClient implements GuiComponentClient {
3940
public boolean isShapeValid;
4041
boolean hasActiveRecipe;
42+
boolean matchesMultipleRecipes;
4143
float progress;
4244
int efficiencyTicks;
4345
int maxEfficiencyTicks;
@@ -60,6 +62,8 @@ public void readCurrentData(RegistryFriendlyByteBuf buf) {
6062
maxEfficiencyTicks = buf.readInt();
6163
currentRecipeEu = buf.readLong();
6264
baseRecipeEu = buf.readLong();
65+
} else {
66+
matchesMultipleRecipes = buf.readBoolean();
6367
}
6468
}
6569
remainingOverclockTicks = buf.readVarInt();
@@ -73,6 +77,16 @@ public ClientComponentRenderer createRenderer(MachineScreen machineScreen) {
7377
public class Renderer implements ClientComponentRenderer {
7478
private static final ResourceLocation TEXTURE = MI.id("textures/gui/container/multiblock_info.png");
7579

80+
private static int drawWordWrap(GuiGraphics guiGraphics, Font font, Component text, int x, int y, int lineWidth, int lineHeight, int color,
81+
boolean dropShadow) {
82+
int deltaY = 0;
83+
for (var line : font.split(text, lineWidth)) {
84+
guiGraphics.drawString(font, line, x, y + deltaY, color, dropShadow);
85+
deltaY += lineHeight;
86+
}
87+
return deltaY;
88+
}
89+
7690
@Override
7791
public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
7892

@@ -81,7 +95,7 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
8195
CraftingMultiblockGui.W, CraftingMultiblockGui.H, CraftingMultiblockGui.W, CraftingMultiblockGui.H);
8296
Font font = minecraftClient.font;
8397

84-
int deltaY = 23;
98+
int deltaY = 21;
8599

86100
guiGraphics.drawString(font, isShapeValid ? MIText.MultiblockShapeValid.text() : MIText.MultiblockShapeInvalid.text(), x + 10, y + deltaY,
87101
isShapeValid ? 0xFFFFFF : 0xFF0000, false);
@@ -109,6 +123,14 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
109123
guiGraphics.drawString(font, MIText.CurrentEuRecipe.text(TextHelper.getEuTextTick(currentRecipeEu)), x + 10, y + deltaY, 0xFFFFFF,
110124
false);
111125
deltaY += 11;
126+
} else if (matchesMultipleRecipes) {
127+
int lineWidth = CraftingMultiblockGui.W - 10;
128+
129+
deltaY += drawWordWrap(guiGraphics, font, MIText.MachineMultipleRecipes1.text(), x + 10, y + deltaY, lineWidth, 11, 0xFF0000,
130+
false);
131+
132+
deltaY += drawWordWrap(guiGraphics, font, MIText.MachineMultipleRecipes2.text(), x + 10, y + deltaY, lineWidth, 11, 0xFF0000,
133+
false);
112134
}
113135
}
114136

src/client/java/aztech/modern_industrialization/machines/guicomponents/EnergyBarClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
7575
}
7676

7777
@Override
78-
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
78+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
7979
if (RenderHelper.isPointWithinRectangle(params.renderX, params.renderY, WIDTH, HEIGHT, cursorX - x, cursorY - y)) {
8080
Component tooltip;
8181
if (Screen.hasShiftDown()) {
@@ -85,7 +85,9 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
8585
tooltip = MIText.EuMaxed.text(maxedAmount.digit(), maxedAmount.maxDigit(), maxedAmount.unit());
8686
}
8787
guiGraphics.renderTooltip(font, Collections.singletonList(tooltip), Optional.empty(), cursorX, cursorY);
88+
return true;
8889
}
90+
return false;
8991
}
9092
}
9193
}

src/client/java/aztech/modern_industrialization/machines/guicomponents/GunpowderOverclockGuiClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
6464
}
6565

6666
@Override
67-
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
67+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
6868
if (remTick > 0) {
6969
if (RenderHelper.isPointWithinRectangle(params.renderX, params.renderY, 20, 20, cursorX - x, cursorY - y)) {
7070
guiGraphics.renderTooltip(font, formatOverclock(remTick), cursorX, cursorY);
71+
return true;
7172
}
7273
}
74+
return false;
7375
}
7476

7577
public static Component formatOverclock(int remTick) {

src/client/java/aztech/modern_industrialization/machines/guicomponents/LargeTankFluidDisplayClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ public void renderBackground(GuiGraphics guiGraphics, int leftPos, int topPos) {
9393
}
9494

9595
@Override
96-
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
96+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
9797
if (RenderHelper.isPointWithinRectangle(posX + 7, posY + 7, 32, 48, cursorX - x, cursorY - y)) {
9898
guiGraphics.renderTooltip(font,
9999
FluidHelper.getTooltipForFluidStorage(fluidData.fluid(), fluidData.amount(), fluidData.capacity()),
100100
Optional.empty(),
101101
cursorX, cursorY);
102+
return true;
102103
}
104+
return false;
103105
}
104106
};
105107
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.machines.guicomponents;
25+
26+
import aztech.modern_industrialization.MI;
27+
import aztech.modern_industrialization.MIText;
28+
import aztech.modern_industrialization.inventory.AbstractConfigurableStack;
29+
import aztech.modern_industrialization.inventory.MIInventory;
30+
import aztech.modern_industrialization.inventory.SlotPositions;
31+
import aztech.modern_industrialization.machines.gui.ClientComponentRenderer;
32+
import aztech.modern_industrialization.machines.gui.GuiComponent;
33+
import aztech.modern_industrialization.machines.gui.GuiComponentClient;
34+
import aztech.modern_industrialization.machines.gui.MachineScreen;
35+
import java.util.List;
36+
import net.minecraft.ChatFormatting;
37+
import net.minecraft.client.gui.Font;
38+
import net.minecraft.client.gui.GuiGraphics;
39+
import net.minecraft.network.RegistryFriendlyByteBuf;
40+
import net.minecraft.resources.ResourceLocation;
41+
42+
public class MachineProblemsDisplayClient implements GuiComponentClient {
43+
private static final ResourceLocation SLOT_PROBLEM = MI.id("textures/gui/container/slot_problem.png");
44+
45+
public boolean hasProblems;
46+
47+
private MIInventory inventory;
48+
49+
public MachineProblemsDisplayClient(RegistryFriendlyByteBuf buf) {
50+
readCurrentData(buf);
51+
}
52+
53+
@Override
54+
public void readCurrentData(RegistryFriendlyByteBuf buf) {
55+
hasProblems = buf.readBoolean();
56+
}
57+
58+
@Override
59+
public void setupMenu(GuiComponent.MenuFacade menu) {
60+
this.inventory = menu.getMachineInventory();
61+
}
62+
63+
@Override
64+
public ClientComponentRenderer createRenderer(MachineScreen machineScreen) {
65+
return new Renderer();
66+
}
67+
68+
public class Renderer implements ClientComponentRenderer {
69+
private static void renderSlotProblems(GuiGraphics guiGraphics, int x, int y, List<? extends AbstractConfigurableStack> stacks,
70+
SlotPositions positions) {
71+
for (int index = 0; index < positions.size(); index++) {
72+
// Only display the border on output slots
73+
if (!stacks.get(index).canPlayerInsert()) {
74+
int sx = positions.getX(index);
75+
int sy = positions.getY(index);
76+
int px = x + sx - 2;
77+
int py = y + sy - 2;
78+
guiGraphics.blit(SLOT_PROBLEM, px, py, sx, sy, 20, 20, 20, 20);
79+
}
80+
}
81+
}
82+
83+
private static boolean renderSlotProblemTooltip(Font font, GuiGraphics guiGraphics, int x, int y,
84+
List<? extends AbstractConfigurableStack> stacks, SlotPositions positions, int cursorX, int cursorY) {
85+
for (int index = 0; index < positions.size(); index++) {
86+
// Only display tooltips on output slots
87+
if (!stacks.get(index).canPlayerInsert()) {
88+
int sx = positions.getX(index);
89+
int sy = positions.getY(index);
90+
int px = x + sx - 1;
91+
int py = y + sy - 1;
92+
if (cursorX >= px && cursorX < px + 18 && cursorY >= py && cursorY < py + 18) {
93+
guiGraphics.renderComponentTooltip(font, List.of(MIText.MachineMultipleRecipes1.text().withStyle(ChatFormatting.RED),
94+
MIText.MachineMultipleRecipes2.text().withStyle(ChatFormatting.RED)), cursorX, cursorY);
95+
return true;
96+
}
97+
}
98+
}
99+
return false;
100+
}
101+
102+
@Override
103+
public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
104+
if (hasProblems) {
105+
renderSlotProblems(guiGraphics, x, y, inventory.getItemStacks(), inventory.itemPositions);
106+
renderSlotProblems(guiGraphics, x, y, inventory.getFluidStacks(), inventory.fluidPositions);
107+
}
108+
}
109+
110+
@Override
111+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int leftPos, int topPos, int cursorX, int cursorY) {
112+
if (hasProblems) {
113+
return renderSlotProblemTooltip(font, guiGraphics, leftPos, topPos, inventory.getItemStacks(), inventory.itemPositions, cursorX,
114+
cursorY) ||
115+
renderSlotProblemTooltip(font, guiGraphics, leftPos, topPos, inventory.getFluidStacks(), inventory.fluidPositions, cursorX,
116+
cursorY);
117+
}
118+
return false;
119+
}
120+
}
121+
}

src/client/java/aztech/modern_industrialization/machines/guicomponents/NuclearReactorGuiClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
231231
}
232232

233233
@Override
234-
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
234+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
235235
int i = (cursorX - (x + centerX - data.gridSizeX() * 9)) / 18;
236236
int j = (cursorY - (y + centerY - data.gridSizeY() * 9)) / 18;
237237

@@ -247,10 +247,12 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
247247
if (variantAmount > 0 & !variant.isBlank()) {
248248
if (variant instanceof ItemVariant itemVariant) {
249249
guiGraphics.renderTooltip(font, itemVariant.toStack((int) variantAmount), cursorX, cursorY);
250+
return true;
250251
} else if (variant instanceof FluidVariant fluidVariant) {
251252
guiGraphics.renderTooltip(font,
252253
FluidHelper.getTooltipForFluidStorage(fluidVariant, variantAmount, NuclearHatch.capacity, false),
253254
Optional.empty(), cursorX, cursorY);
255+
return true;
254256
}
255257
}
256258

@@ -267,12 +269,12 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
267269
}
268270

269271
guiGraphics.renderTooltip(font, tooltip, Optional.empty(), cursorX, cursorY);
270-
return;
272+
return true;
271273

272274
} else if (currentMode == Renderer.Mode.EU_GENERATION) {
273275
double euGeneration = tileData.getMeanEuGeneration();
274276
guiGraphics.renderTooltip(font, TextHelper.getEuTextTick(euGeneration, true), cursorX, cursorY);
275-
return;
277+
return true;
276278
} else {
277279
double neutronRateFast;
278280
double neutronRateThermal;
@@ -340,7 +342,7 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
340342
}
341343

342344
guiGraphics.renderTooltip(font, tooltips, Optional.empty(), cursorX, cursorY);
343-
return;
345+
return true;
344346
}
345347

346348
}
@@ -358,8 +360,10 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
358360
Component tooltip = MIText.NuclearFuelEfficiencyTooltip.text(euProduction, euFuelConsumption);
359361

360362
guiGraphics.renderTooltip(font, tooltip, cursorX, cursorY);
363+
return true;
361364
}
362365
}
366+
return false;
363367
}
364368

365369
public Component getEfficiencyText() {

src/client/java/aztech/modern_industrialization/machines/guicomponents/RecipeEfficiencyBarClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
8484
}
8585

8686
@Override
87-
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
87+
public boolean renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
8888
if (RenderHelper.isPointWithinRectangle(params.renderX, params.renderY, WIDTH, HEIGHT, cursorX - x, cursorY - y)) {
8989
List<Component> tooltip = new ArrayList<>();
9090
if (hasActiveRecipe) {
@@ -101,7 +101,9 @@ public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphi
101101
tooltip.add(MIText.EfficiencyMaxOverclock.text(maxRecipeEu));
102102

103103
guiGraphics.renderTooltip(font, tooltip, Optional.empty(), cursorX, cursorY);
104+
return true;
104105
}
106+
return false;
105107
}
106108
}
107109
}

0 commit comments

Comments
 (0)