Skip to content

Commit ed0f9e0

Browse files
committed
Merge remote-tracking branch 'origin/13.x-1.20.2' into 14.x-1.20.4
2 parents 8442364 + 93c6793 commit ed0f9e0

File tree

29 files changed

+1126
-242
lines changed

29 files changed

+1126
-242
lines changed

api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Slot.java

+6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525

2626
import me.shedaniel.math.Rectangle;
2727
import me.shedaniel.rei.api.common.entry.EntryStack;
28+
import org.jetbrains.annotations.ApiStatus;
2829
import org.jetbrains.annotations.Nullable;
2930

3031
import java.util.Collection;
3132
import java.util.List;
33+
import java.util.function.Consumer;
3234

3335
public abstract class Slot extends WidgetWithBounds {
3436
public static final byte UN_MARKED = 0;
@@ -133,6 +135,10 @@ public final Slot disableBackground() {
133135

134136
public abstract Slot entries(Collection<? extends EntryStack<?>> stacks);
135137

138+
@ApiStatus.Experimental
139+
@ApiStatus.Internal
140+
public abstract Slot withEntriesListener(Consumer<Slot> listener);
141+
136142
public abstract EntryStack<?> getCurrentEntry();
137143

138144
public abstract List<EntryStack<?>> getEntries();

api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323

2424
package me.shedaniel.rei.api.common.display.basic;
2525

26-
import dev.architectury.utils.EnvExecutor;
27-
import dev.architectury.utils.GameInstance;
2826
import me.shedaniel.rei.api.common.display.Display;
2927
import me.shedaniel.rei.api.common.display.SimpleDisplaySerializer;
3028
import me.shedaniel.rei.api.common.entry.EntryIngredient;
3129
import me.shedaniel.rei.api.common.util.EntryIngredients;
30+
import me.shedaniel.rei.impl.Internals;
3231
import net.minecraft.core.RegistryAccess;
3332
import net.minecraft.nbt.CompoundTag;
3433
import net.minecraft.nbt.Tag;
@@ -38,16 +37,12 @@
3837

3938
import java.util.List;
4039
import java.util.Optional;
41-
import java.util.function.Supplier;
4240

4341
/**
4442
* A basic implementation of a display, consisting of a list of inputs, a list of outputs
4543
* and a possible display location.
4644
*/
4745
public abstract class BasicDisplay implements Display {
48-
protected static final Supplier<RegistryAccess> REGISTRY_ACCESS =
49-
EnvExecutor.getEnvSpecific(() -> () -> () -> GameInstance.getClient().player.level().registryAccess(),
50-
() -> () -> () -> GameInstance.getServer().registryAccess());
5146
protected List<EntryIngredient> inputs;
5247
protected List<EntryIngredient> outputs;
5348
protected Optional<ResourceLocation> location;
@@ -64,7 +59,7 @@ public BasicDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs,
6459

6560
@ApiStatus.Experimental
6661
public static RegistryAccess registryAccess() {
67-
return REGISTRY_ACCESS.get();
62+
return Internals.getRegistryAccess();
6863
}
6964

7065
/**

api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
package me.shedaniel.rei.api.common.plugins;
2525

2626
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
27-
import me.shedaniel.rei.api.common.registry.ReloadStage;
2827
import me.shedaniel.rei.impl.ClientInternals;
2928
import me.shedaniel.rei.impl.Internals;
29+
import me.shedaniel.rei.impl.common.plugins.PluginReloadContext;
3030
import net.fabricmc.api.EnvType;
3131
import net.fabricmc.api.Environment;
3232
import org.jetbrains.annotations.ApiStatus;
@@ -62,18 +62,25 @@ public void registerPlugin(REIPluginProvider<? extends P> plugin) {
6262
}
6363

6464
@Override
65-
public void pre(ReloadStage stage) {
66-
PluginView.this.pre(stage);
65+
public void pre(PluginReloadContext context) throws InterruptedException {
66+
PluginView.this.pre(context);
6767
}
6868

6969
@Override
70-
public void post(ReloadStage stage) {
71-
PluginView.this.post(stage);
70+
public void reload(PluginReloadContext context) throws InterruptedException {
71+
PluginView.this.reload(context);
72+
}
73+
74+
@Override
75+
public void post(PluginReloadContext context) throws InterruptedException {
76+
PluginView.this.post(context);
7277
}
7378
};
7479
}
7580

76-
void pre(ReloadStage stage);
81+
void pre(PluginReloadContext context) throws InterruptedException;
82+
83+
void reload(PluginReloadContext context) throws InterruptedException;
7784

78-
void post(ReloadStage stage);
85+
void post(PluginReloadContext context) throws InterruptedException;
7986
}

api/src/main/java/me/shedaniel/rei/impl/Internals.java

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
3636
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
3737
import me.shedaniel.rei.impl.common.InternalLogger;
38+
import net.minecraft.core.RegistryAccess;
3839
import net.minecraft.nbt.Tag;
3940
import net.minecraft.resources.ResourceLocation;
4041
import net.minecraft.util.Unit;
@@ -55,6 +56,7 @@ public final class Internals {
5556
private static Function<String, CategoryIdentifier<?>> categoryIdentifier = (object) -> throwNotSetup();
5657
private static Supplier<MenuInfoRegistry> stubMenuInfoRegistry = Internals::throwNotSetup;
5758
private static Supplier<InternalLogger> logger = Internals::throwNotSetup;
59+
private static Supplier<RegistryAccess> registryAccess = Internals::throwNotSetup;
5860

5961
private static <T> T throwNotSetup() {
6062
throw new AssertionError("REI Internals have not been initialized!");
@@ -117,6 +119,10 @@ public static InternalLogger getInternalLogger() {
117119
return logger.get();
118120
}
119121

122+
public static RegistryAccess getRegistryAccess() {
123+
return registryAccess.get();
124+
}
125+
120126
public interface EntryStackProvider {
121127
EntryStack<Unit> empty();
122128

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is licensed under the MIT License, part of Roughly Enough Items.
3+
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
package me.shedaniel.rei.impl.common.plugins;
25+
26+
import me.shedaniel.rei.api.common.registry.ReloadStage;
27+
import org.jetbrains.annotations.ApiStatus;
28+
29+
@ApiStatus.Internal
30+
public interface PluginReloadContext {
31+
ReloadStage stage();
32+
33+
ReloadInterruptionContext interruptionContext();
34+
35+
static PluginReloadContext of(ReloadStage stage, ReloadInterruptionContext interruptionContext) {
36+
return new PluginReloadContext() {
37+
@Override
38+
public ReloadStage stage() {
39+
return stage;
40+
}
41+
42+
@Override
43+
public ReloadInterruptionContext interruptionContext() {
44+
return interruptionContext;
45+
}
46+
};
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is licensed under the MIT License, part of Roughly Enough Items.
3+
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
package me.shedaniel.rei.impl.common.plugins;
25+
26+
import me.shedaniel.rei.impl.common.InternalLogger;
27+
import org.jetbrains.annotations.ApiStatus;
28+
29+
@FunctionalInterface
30+
@ApiStatus.Internal
31+
public interface ReloadInterruptionContext {
32+
boolean isInterrupted();
33+
34+
default void checkInterrupted() throws InterruptedException {
35+
if (isInterrupted()) {
36+
InternalLogger.getInstance().debug("Plugin reload interrupted!");
37+
throw new InterruptedException();
38+
}
39+
}
40+
41+
default ReloadInterruptionContext withJob(Runnable ifInterrupted) {
42+
return new ReloadInterruptionContext() {
43+
@Override
44+
public boolean isInterrupted() {
45+
return ReloadInterruptionContext.this.isInterrupted();
46+
}
47+
48+
@Override
49+
public void checkInterrupted() throws InterruptedException {
50+
try {
51+
ReloadInterruptionContext.this.checkInterrupted();
52+
} catch (InterruptedException e) {
53+
ifInterrupted.run();
54+
throw e;
55+
}
56+
}
57+
};
58+
}
59+
60+
static ReloadInterruptionContext ofNever() {
61+
return () -> false;
62+
}
63+
}

default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultSmithingCategory.java

+30-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@
2727
import me.shedaniel.math.Point;
2828
import me.shedaniel.math.Rectangle;
2929
import me.shedaniel.rei.api.client.gui.Renderer;
30+
import me.shedaniel.rei.api.client.gui.widgets.Slot;
3031
import me.shedaniel.rei.api.client.gui.widgets.Widget;
3132
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
3233
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
3334
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;
3438
import me.shedaniel.rei.api.common.util.EntryStacks;
3539
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
3640
import me.shedaniel.rei.plugin.common.displays.DefaultSmithingDisplay;
41+
import net.minecraft.core.RegistryAccess;
3742
import net.minecraft.network.chat.Component;
3843
import net.minecraft.world.level.block.Blocks;
44+
import org.apache.commons.lang3.mutable.MutableBoolean;
45+
import org.jetbrains.annotations.ApiStatus;
3946

4047
import java.util.List;
4148

@@ -65,19 +72,38 @@ public List<Widget> setupDisplay(DefaultSmithingDisplay display, Rectangle bound
6572
widgets.add(Widgets.createArrow(new Point(startPoint.x + 27 + offsetX, startPoint.y + 4)));
6673
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)));
6774
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+
}));
7187
} else {
7288
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 22 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput());
7389
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());
7491
}
75-
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
7692
return widgets;
7793
}
7894

7995
@Override
8096
public int getDisplayHeight() {
8197
return 36;
8298
}
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+
}
83109
}

0 commit comments

Comments
 (0)