diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/api/data/modifier/Modifier.java b/common/src/main/java/dev/lukebemish/excavatedvariants/api/data/modifier/Modifier.java index 0c99b16..5e928bb 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/api/data/modifier/Modifier.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/api/data/modifier/Modifier.java @@ -14,6 +14,7 @@ import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import org.jspecify.annotations.Nullable; import java.util.*; @@ -30,11 +31,11 @@ public class Modifier { ).apply(instance, (filter, properties, flags, tags) -> new Modifier(filter, properties.orElse(null), tags, flags))); public final VariantFilter variantFilter; - public final BlockPropsModifier properties; + public final @Nullable BlockPropsModifier properties; public final List tags; public final Set flags; - public Modifier(VariantFilter variantFilter, BlockPropsModifier properties, List tags, Set flags) { + public Modifier(VariantFilter variantFilter, @Nullable BlockPropsModifier properties, List tags, Set flags) { this.variantFilter = variantFilter; this.properties = properties; this.tags = tags; @@ -50,8 +51,8 @@ public final ResourceKey getKeyOrThrow() { } public static class Builder { - private VariantFilter variantFilter; - private BlockPropsModifier properties; + private @Nullable VariantFilter variantFilter; + private @Nullable BlockPropsModifier properties; private final List tags = new ArrayList<>(); private final Set flags = new HashSet<>(); diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ExcavatedVariants.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ExcavatedVariants.java index 5b0e701..eab308c 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ExcavatedVariants.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ExcavatedVariants.java @@ -28,6 +28,7 @@ import net.minecraft.world.level.block.Block; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jspecify.annotations.Nullable; import java.util.*; import java.util.function.BiConsumer; @@ -45,9 +46,9 @@ private ExcavatedVariants() {} public static final Logger LOGGER = LogManager.getLogger(MOD_ID); public static final List> ITEMS = new ArrayList<>(); - private static ModConfig CONFIG; + private static @Nullable ModConfig CONFIG; public static final DataResourceCache DATA_CACHE = ResourceCache.register(new DataResourceCache(new ResourceLocation(MOD_ID, "data"))); - private static Map> NEW_VARIANTS_MAP; + private static @Nullable Map> NEW_VARIANTS_MAP; private static final List NEW_VARIANTS = new ArrayList<>(); public static final Map, List> NEEDED_KEYS = new IdentityHashMap<>(); public static final Map>> REVERSE_NEEDED_KEYS = new IdentityHashMap<>(); @@ -55,9 +56,12 @@ private ExcavatedVariants() {} public static final Map BLOCKS = new IdentityHashMap<>(); public static final List COMPLETE_VARIANTS = new ArrayList<>(); public static final RecipePlanner RECIPE_PLANNER = new RecipePlanner(); - public static MappingsCache MAPPINGS_CACHE; + public static @Nullable MappingsCache MAPPINGS_CACHE; public synchronized static void setupMap() { + if (ModLifecycle.getLifecyclePhase() != ModLifecycle.PRE_INITIALIZATION) { + return; + } if (NEW_VARIANTS_MAP == null) { Map> newVariants = new HashMap<>(); Map> newVariantsSet = new HashMap<>(); @@ -118,7 +122,7 @@ public static void init() { setupMap(); - for (Map.Entry> entry : NEW_VARIANTS_MAP.entrySet()) { + for (Map.Entry> entry : Objects.requireNonNull(NEW_VARIANTS_MAP, "New variants map was not set up").entrySet()) { Ore ore = entry.getKey(); List stones = entry.getValue(); for (Stone stone : stones) { @@ -202,7 +206,7 @@ public static synchronized void initPostRegister() { // No reason to keep any of this around; this way some of it can be GCed... NEW_VARIANTS.clear(); - NEW_VARIANTS_MAP.clear(); + Objects.requireNonNull(NEW_VARIANTS_MAP, "New variants map was not set up").clear(); NEEDED_KEYS.clear(); REVERSE_NEEDED_KEYS.clear(); READY_QUEUE.clear(); @@ -254,7 +258,7 @@ else if (tag.getPath().startsWith("items/")) if (getConfig().addConversionRecipes) { for (VariantFuture future : COMPLETE_VARIANTS) { planItemTag(future.ore.getConvertibleTagKey().location(), new ResourceLocation(ExcavatedVariants.MOD_ID, future.fullId)); - RECIPE_PLANNER.oreToBaseOreMap.put(future.ore.getConvertibleTagKey(), future.foundOreKey); + RECIPE_PLANNER.oreToBaseOreMap.put(future.ore.getConvertibleTagKey(), Objects.requireNonNull(future.foundOreKey)); } } @@ -275,7 +279,7 @@ else if (tag.getPath().startsWith("items/")) TAG_QUEUE.queue(tierHolder); - MAPPINGS_CACHE.update(); + Objects.requireNonNull(MAPPINGS_CACHE, "Mappings cache was not set up").update(); MAPPINGS_CACHE.save(); ModLifecycle.setLifecyclePhase(ModLifecycle.POST); @@ -359,10 +363,10 @@ public static class VariantFuture { public final Stone stone; public final String fullId; public boolean done = false; - public Block foundStone = null; - public Block foundOre = null; - public ResourceKey foundOreKey = null; - public Stone foundSourceStone = null; + public @Nullable Block foundStone = null; + public @Nullable Block foundOre = null; + public @Nullable ResourceKey foundOreKey = null; + public @Nullable Stone foundSourceStone = null; public final Set flags = new HashSet<>(); public final List propsModifiers = new ArrayList<>(); diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreFinderUtil.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreFinderUtil.java index 1189dad..e8b72ae 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreFinderUtil.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreFinderUtil.java @@ -38,7 +38,7 @@ private OreFinderUtil() { public static void setupBlocks() { if (ModLifecycle.getLifecyclePhase() != ModLifecycle.POST) { var e = new IllegalStateException("Something has gone badly wrong with load ordering. Please report this to Excavated Variants alongside a log!"); - ExcavatedVariants.LOGGER.error("...huh? Where are we?", e); + ExcavatedVariants.LOGGER.error("...huh? Where are we? Expected {}, but in {}", ModLifecycle.POST.name(), ModLifecycle.getLifecyclePhase().name(), e); throw e; }