|
27 | 27 | import me.shedaniel.math.Point;
|
28 | 28 | import me.shedaniel.math.Rectangle;
|
29 | 29 | import me.shedaniel.rei.api.client.gui.Renderer;
|
| 30 | +import me.shedaniel.rei.api.client.gui.widgets.Slot; |
30 | 31 | import me.shedaniel.rei.api.client.gui.widgets.Widget;
|
31 | 32 | import me.shedaniel.rei.api.client.gui.widgets.Widgets;
|
32 | 33 | import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
|
33 | 34 | import me.shedaniel.rei.api.common.category.CategoryIdentifier;
|
| 35 | +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; |
| 36 | +import me.shedaniel.rei.api.common.entry.EntryIngredient; |
| 37 | +import me.shedaniel.rei.api.common.entry.EntryStack; |
34 | 38 | import me.shedaniel.rei.api.common.util.EntryStacks;
|
35 | 39 | import me.shedaniel.rei.plugin.common.BuiltinPlugin;
|
36 | 40 | import me.shedaniel.rei.plugin.common.displays.DefaultSmithingDisplay;
|
| 41 | +import net.minecraft.core.RegistryAccess; |
37 | 42 | import net.minecraft.network.chat.Component;
|
38 | 43 | import net.minecraft.world.level.block.Blocks;
|
| 44 | +import org.apache.commons.lang3.mutable.MutableBoolean; |
| 45 | +import org.jetbrains.annotations.ApiStatus; |
39 | 46 |
|
40 | 47 | import java.util.List;
|
41 | 48 |
|
@@ -65,19 +72,38 @@ public List<Widget> setupDisplay(DefaultSmithingDisplay display, Rectangle bound
|
65 | 72 | widgets.add(Widgets.createArrow(new Point(startPoint.x + 27 + offsetX, startPoint.y + 4)));
|
66 | 73 | widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)));
|
67 | 74 | if (!legacy) {
|
68 |
| - widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 18 * 2 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput()); |
69 |
| - widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 18 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(1)).markInput()); |
70 |
| - widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(2)).markInput()); |
| 75 | + Slot templateSlot, baseSlot, additionSlot, resultSlot; |
| 76 | + MutableBoolean dirty = new MutableBoolean(true); |
| 77 | + widgets.add(templateSlot = Widgets.createSlot(new Point(startPoint.x + 4 - 18 * 2 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).withEntriesListener(slot -> dirty.setTrue()).markInput()); |
| 78 | + widgets.add(baseSlot = Widgets.createSlot(new Point(startPoint.x + 4 - 18 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(1)).withEntriesListener(slot -> dirty.setTrue()).markInput()); |
| 79 | + widgets.add(additionSlot = Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(2)).withEntriesListener(slot -> dirty.setTrue()).markInput()); |
| 80 | + widgets.add(resultSlot = Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput()); |
| 81 | + widgets.add(Widgets.createDrawableWidget((graphics, mouseX, mouseY, delta) -> { |
| 82 | + if (dirty.booleanValue()) { |
| 83 | + resultSlot.clearEntries().entries(getOutput(display, BasicDisplay.registryAccess(), templateSlot.getCurrentEntry(), baseSlot.getCurrentEntry(), additionSlot.getCurrentEntry())); |
| 84 | + dirty.setFalse(); |
| 85 | + } |
| 86 | + })); |
71 | 87 | } else {
|
72 | 88 | widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 22 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput());
|
73 | 89 | widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(1)).markInput());
|
| 90 | + widgets.add(Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput()); |
74 | 91 | }
|
75 |
| - widgets.add(Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput()); |
76 | 92 | return widgets;
|
77 | 93 | }
|
78 | 94 |
|
79 | 95 | @Override
|
80 | 96 | public int getDisplayHeight() {
|
81 | 97 | return 36;
|
82 | 98 | }
|
| 99 | + |
| 100 | + @ApiStatus.Experimental |
| 101 | + private static EntryIngredient getOutput(DefaultSmithingDisplay display, RegistryAccess registryAccess, EntryStack<?> template, EntryStack<?> base, EntryStack<?> addition) { |
| 102 | + if (display.getType() == DefaultSmithingDisplay.SmithingRecipeType.TRIM) { |
| 103 | + EntryIngredient output = DefaultSmithingDisplay.getTrimmingOutput(registryAccess, template, base, addition); |
| 104 | + if (!output.isEmpty()) return output; |
| 105 | + } |
| 106 | + |
| 107 | + return display.getOutputEntries().get(0); |
| 108 | + } |
83 | 109 | }
|
0 commit comments