Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/11.x-1.19.4' into 12.x-1.20
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java
  • Loading branch information
shedaniel committed Sep 17, 2024
2 parents ccf3dcd + 644c3f5 commit 9856139
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 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 @@ -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

0 comments on commit 9856139

Please sign in to comment.