Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/12.x-1.20' into 13.x-1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Sep 17, 2024
2 parents 3febdc4 + 9856139 commit 93c6793
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@

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

import dev.architectury.utils.EnvExecutor;
import dev.architectury.utils.GameInstance;
import me.shedaniel.rei.api.common.display.Display;
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.Internals;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
Expand All @@ -38,16 +37,12 @@

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

/**
* A basic implementation of a display, consisting of a list of inputs, a list of outputs
* and a possible display location.
*/
public abstract class BasicDisplay implements Display {
protected static final Supplier<RegistryAccess> REGISTRY_ACCESS =
EnvExecutor.getEnvSpecific(() -> () -> () -> GameInstance.getClient().player.level().registryAccess(),
() -> () -> () -> GameInstance.getServer().registryAccess());
protected List<EntryIngredient> inputs;
protected List<EntryIngredient> outputs;
protected Optional<ResourceLocation> location;
Expand All @@ -64,7 +59,7 @@ public BasicDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs,

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

/**
Expand Down
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.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Unit;
Expand All @@ -55,6 +56,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 @@ -117,6 +119,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
Expand Up @@ -163,7 +163,7 @@ public static EntryIngredient getTrimmingOutput(RegistryAccess registryAccess, E
.orElse(null);
if (trimMaterial == null) return EntryIngredient.empty();
ArmorTrim armorTrim = new ArmorTrim(trimMaterial, trimPattern);
Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, baseItem);
Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, baseItem, true);
if (trim.isPresent() && trim.get().hasPatternAndMaterial(trimPattern, trimMaterial)) return EntryIngredient.empty();
ItemStack newItem = baseItem.copy();
newItem.setCount(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl;
import me.shedaniel.rei.impl.common.transfer.MenuInfoRegistryImpl;
import me.shedaniel.rei.impl.common.transfer.SlotAccessorRegistryImpl;
import me.shedaniel.rei.impl.common.util.InstanceHelper;
import me.shedaniel.rei.impl.init.PluginDetector;
import me.shedaniel.rei.impl.init.PrimitivePlatformAdapter;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.Unit;
Expand All @@ -69,6 +71,7 @@
import java.util.ServiceLoader;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

@ApiStatus.Internal
Expand Down Expand Up @@ -126,6 +129,7 @@ public static void attachCommonInternals() {
Internals.attachInstanceSupplier(LOGGER, "logger");
CategoryIdentifierImpl.attach();
Internals.attachInstance((Function<ResourceLocation, EntryType<?>>) DeferringEntryTypeProviderImpl.INSTANCE, "entryTypeDeferred");
Internals.attachInstance((Supplier<RegistryAccess>) () -> InstanceHelper.getInstance().registryAccess(), "registryAccess");
Internals.attachInstance(EntryStackProviderImpl.INSTANCE, Internals.EntryStackProvider.class);
Internals.attachInstance(NbtHasherProviderImpl.INSTANCE, Internals.NbtHasherProvider.class);
Internals.attachInstance(EntryIngredientImpl.INSTANCE, Internals.EntryIngredientProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
if (this.menu != null && this.menu.mouseScrolled(mouseX, mouseY, amount))
public boolean mouseScrolled(double mouseX, double mouseY, double amountX, double amountY) {
if (this.menu != null && this.menu.mouseScrolled(mouseX, mouseY, amountX, amountY))
return true;
return super.mouseScrolled(mouseX, mouseY, amount);
return super.mouseScrolled(mouseX, mouseY, amountX, amountY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void fillSortedRecipes() {
try {
addWithReason(recipe, DisplayAdditionReason.RECIPE_MANAGER);
} catch (Throwable e) {
InternalLogger.getInstance().error("Failed to fill display for recipe: %s [%s]", recipe, recipe.getId(), e);
InternalLogger.getInstance().error("Failed to fill display for recipe: %s [%s]", recipe.value(), recipe.id(), e);
}
}
}
Expand Down

0 comments on commit 93c6793

Please sign in to comment.