|
| 1 | +package de.dafuqs.spectrum; |
| 2 | + |
| 3 | +import net.minecraft.resources.*; |
| 4 | +import net.minecraft.server.*; |
| 5 | +import net.minecraft.tags.*; |
| 6 | +import net.minecraft.world.item.*; |
| 7 | +import net.minecraft.world.item.crafting.*; |
| 8 | +import net.minecraft.world.level.*; |
| 9 | +import net.neoforged.bus.api.*; |
| 10 | +import net.neoforged.fml.common.*; |
| 11 | +import org.jetbrains.annotations.*; |
| 12 | +import org.slf4j.*; |
| 13 | + |
| 14 | +import java.util.*; |
| 15 | + |
| 16 | +@Mod(SpectrumCommon.MOD_ID) |
| 17 | +public class SpectrumCommon { |
| 18 | + |
| 19 | + public static final String MOD_ID = "spectrum"; |
| 20 | + |
| 21 | + public static final Logger LOGGER = LoggerFactory.getLogger("Spectrum"); |
| 22 | + public static final Map<ResourceLocation, TagKey<Item>> CACHED_ITEM_TAG_MAP = new HashMap<>(); |
| 23 | + // TODO PORT |
| 24 | +// public static SpectrumConfig CONFIG; |
| 25 | + |
| 26 | + public static void logInfo(String message) { |
| 27 | + LOGGER.info("[Spectrum] {}", message); |
| 28 | + } |
| 29 | + |
| 30 | + public static void logWarning(String message) { |
| 31 | + LOGGER.warn("[Spectrum] {}", message); |
| 32 | + } |
| 33 | + |
| 34 | + public static void logError(String message) { |
| 35 | + LOGGER.error("[Spectrum] {}", message); |
| 36 | + } |
| 37 | + |
| 38 | + public static ResourceLocation locate(String name) { |
| 39 | + return ResourceLocation.fromNamespaceAndPath(MOD_ID, name); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * This is the Spectrum analogue of Identifier.of, but instead of defaulting to the namespace 'minecraft', it defaults to 'spectrum'. |
| 44 | + * |
| 45 | + * @param id The stringified identifier to parse |
| 46 | + * @return The parsed identifier |
| 47 | + */ |
| 48 | + public static ResourceLocation ofSpectrumDefaulted(String id) { |
| 49 | + int i = id.indexOf(':'); |
| 50 | + String path = id.substring(i + 1); |
| 51 | + String namespace = i > 0 ? id.substring(0, i) : SpectrumCommon.MOD_ID; |
| 52 | + return ResourceLocation.fromNamespaceAndPath(namespace, path); |
| 53 | + } |
| 54 | + |
| 55 | + // Will be null when playing on a dedicated server! |
| 56 | + @Nullable |
| 57 | + public static MinecraftServer minecraftServer; |
| 58 | + |
| 59 | + public SpectrumCommon(IEventBus modBus) { |
| 60 | + logInfo("Starting Common Startup"); |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * When initializing a block entity, world can still be null |
| 66 | + * Therefore we use the RecipeManager reference from MinecraftServer |
| 67 | + * This in turn does not work on clients connected to dedicated servers, though |
| 68 | + * since SpectrumCommon.minecraftServer is null |
| 69 | + */ |
| 70 | + public static Optional<RecipeManager> getRecipeManager(@Nullable Level world) { |
| 71 | + return world == null ? minecraftServer == null ? Optional.empty() : Optional.of(minecraftServer.getRecipeManager()) : Optional.of(world.getRecipeManager()); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments