Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/15.x-1.20.5' into 16.x-1.21
Browse files Browse the repository at this point in the history
# Conflicts:
#	runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
  • Loading branch information
shedaniel committed Sep 17, 2024
2 parents dcac5f4 + 15a46dc commit 3251f01
Show file tree
Hide file tree
Showing 31 changed files with 1,124 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.common.entry.EntryStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

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

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

@ApiStatus.Experimental
@ApiStatus.Internal
public abstract Slot withEntriesListener(Consumer<Slot> listener);

public abstract EntryStack<?> getCurrentEntry();

public abstract List<EntryStack<?>> getEntries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import me.shedaniel.rei.api.common.display.SimpleDisplaySerializer;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.impl.common.InternalRegistryAccess;
import me.shedaniel.rei.impl.Internals;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
Expand Down Expand Up @@ -59,7 +59,7 @@ public BasicDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs,

@ApiStatus.Experimental
public static RegistryAccess registryAccess() {
return InternalRegistryAccess.getInstance().get();
return Internals.getRegistryAccess();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
package me.shedaniel.rei.api.common.plugins;

import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.common.registry.ReloadStage;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.impl.Internals;
import me.shedaniel.rei.impl.common.plugins.PluginReloadContext;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -62,18 +62,25 @@ public void registerPlugin(REIPluginProvider<? extends P> plugin) {
}

@Override
public void pre(ReloadStage stage) {
PluginView.this.pre(stage);
public void pre(PluginReloadContext context) throws InterruptedException {
PluginView.this.pre(context);
}

@Override
public void post(ReloadStage stage) {
PluginView.this.post(stage);
public void reload(PluginReloadContext context) throws InterruptedException {
PluginView.this.reload(context);
}

@Override
public void post(PluginReloadContext context) throws InterruptedException {
PluginView.this.post(context);
}
};
}

void pre(ReloadStage stage);
void pre(PluginReloadContext context) throws InterruptedException;

void reload(PluginReloadContext context) throws InterruptedException;

void post(ReloadStage stage);
void post(PluginReloadContext context) throws InterruptedException;
}
6 changes: 6 additions & 0 deletions api/src/main/java/me/shedaniel/rei/impl/Internals.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
import me.shedaniel.rei.impl.common.InternalLogger;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -56,6 +57,7 @@ public final class Internals {
private static Function<String, CategoryIdentifier<?>> categoryIdentifier = (object) -> throwNotSetup();
private static Supplier<MenuInfoRegistry> stubMenuInfoRegistry = Internals::throwNotSetup;
private static Supplier<InternalLogger> logger = Internals::throwNotSetup;
private static Supplier<RegistryAccess> registryAccess = Internals::throwNotSetup;

private static <T> T throwNotSetup() {
throw new AssertionError("REI Internals have not been initialized!");
Expand Down Expand Up @@ -118,6 +120,10 @@ public static InternalLogger getInternalLogger() {
return logger.get();
}

public static RegistryAccess getRegistryAccess() {
return registryAccess.get();
}

public interface EntryStackProvider {
EntryStack<Unit> empty();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.impl.common.plugins;

import me.shedaniel.rei.api.common.registry.ReloadStage;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface PluginReloadContext {
ReloadStage stage();

ReloadInterruptionContext interruptionContext();

static PluginReloadContext of(ReloadStage stage, ReloadInterruptionContext interruptionContext) {
return new PluginReloadContext() {
@Override
public ReloadStage stage() {
return stage;
}

@Override
public ReloadInterruptionContext interruptionContext() {
return interruptionContext;
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.impl.common.plugins;

import me.shedaniel.rei.impl.common.InternalLogger;
import org.jetbrains.annotations.ApiStatus;

@FunctionalInterface
@ApiStatus.Internal
public interface ReloadInterruptionContext {
boolean isInterrupted();

default void checkInterrupted() throws InterruptedException {
if (isInterrupted()) {
InternalLogger.getInstance().debug("Plugin reload interrupted!");
throw new InterruptedException();
}
}

default ReloadInterruptionContext withJob(Runnable ifInterrupted) {
return new ReloadInterruptionContext() {
@Override
public boolean isInterrupted() {
return ReloadInterruptionContext.this.isInterrupted();
}

@Override
public void checkInterrupted() throws InterruptedException {
try {
ReloadInterruptionContext.this.checkInterrupted();
} catch (InterruptedException e) {
ifInterrupted.run();
throw e;
}
}
};
}

static ReloadInterruptionContext ofNever() {
return () -> false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
import me.shedaniel.rei.plugin.common.displays.DefaultSmithingDisplay;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Blocks;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.jetbrains.annotations.ApiStatus;

import java.util.List;

Expand Down Expand Up @@ -65,19 +72,38 @@ public List<Widget> setupDisplay(DefaultSmithingDisplay display, Rectangle bound
widgets.add(Widgets.createArrow(new Point(startPoint.x + 27 + offsetX, startPoint.y + 4)));
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)));
if (!legacy) {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 18 * 2 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 18 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(1)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(2)).markInput());
Slot templateSlot, baseSlot, additionSlot, resultSlot;
MutableBoolean dirty = new MutableBoolean(true);
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());
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());
widgets.add(additionSlot = Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(2)).withEntriesListener(slot -> dirty.setTrue()).markInput());
widgets.add(resultSlot = Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
widgets.add(Widgets.createDrawableWidget((graphics, mouseX, mouseY, delta) -> {
if (dirty.booleanValue()) {
resultSlot.clearEntries().entries(getOutput(display, BasicDisplay.registryAccess(), templateSlot.getCurrentEntry(), baseSlot.getCurrentEntry(), additionSlot.getCurrentEntry()));
dirty.setFalse();
}
}));
} else {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 - 22 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(0)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 4 + offsetX, startPoint.y + 5)).entries(display.getInputEntries().get(1)).markInput());
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
}
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61 + offsetX, startPoint.y + 5)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
return widgets;
}

@Override
public int getDisplayHeight() {
return 36;
}

@ApiStatus.Experimental
private static EntryIngredient getOutput(DefaultSmithingDisplay display, RegistryAccess registryAccess, EntryStack<?> template, EntryStack<?> base, EntryStack<?> addition) {
if (display.getType() == DefaultSmithingDisplay.SmithingRecipeType.TRIM) {
EntryIngredient output = DefaultSmithingDisplay.getTrimmingOutput(registryAccess, template, base, addition);
if (!output.isEmpty()) return output;
}

return display.getOutputEntries().get(0);
}
}
Loading

0 comments on commit 3251f01

Please sign in to comment.