mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-29 16:47:56 +00:00
Use Fabric's Item Lookup for registering media providers
We'll switch to capabilities on the (Neo)Forge side for 1.21, when the capability system is less painful, and then fully deprecate in 1.21.4.
This commit is contained in:
@@ -7,6 +7,8 @@ package dan200.computercraft.impl;
|
||||
import com.google.auto.service.AutoService;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.detail.DetailRegistry;
|
||||
import dan200.computercraft.api.media.MediaLookup;
|
||||
import dan200.computercraft.api.media.MediaProvider;
|
||||
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
||||
import dan200.computercraft.shared.details.FluidDetails;
|
||||
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
|
||||
@@ -41,4 +43,9 @@ public final class ComputerCraftAPIImpl extends AbstractComputerCraftAPI impleme
|
||||
public DetailRegistry<StorageView<FluidVariant>> getFluidDetailRegistry() {
|
||||
return fluidDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMediaProvider(MediaProvider provider) {
|
||||
MediaLookup.get().registerFallback((stack, ctx) -> provider.getMedia(stack));
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.api.media.MediaLookup;
|
||||
import dan200.computercraft.api.network.wired.WiredElement;
|
||||
import dan200.computercraft.api.node.wired.WiredElementLookup;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
@@ -317,6 +319,12 @@ public class PlatformHelperImpl implements PlatformHelper {
|
||||
return new UseOnResult.Continue(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway") // NullAway doesn't like the null here.
|
||||
public @Nullable IMedia getMedia(ItemStack stack) {
|
||||
return MediaLookup.get().find(stack, null);
|
||||
}
|
||||
|
||||
private record RegistryWrapperImpl<T>(
|
||||
ResourceLocation name, Registry<T> registry
|
||||
) implements RegistryWrappers.RegistryWrapper<T> {
|
||||
|
Reference in New Issue
Block a user