Skip to content

Commit

Permalink
Fix #193
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Feb 10, 2024
1 parent 5b9002d commit ab52a24
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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<ResourceLocation> tags;
public final Set<Flag> flags;

public Modifier(VariantFilter variantFilter, BlockPropsModifier properties, List<ResourceLocation> tags, Set<Flag> flags) {
public Modifier(VariantFilter variantFilter, @Nullable BlockPropsModifier properties, List<ResourceLocation> tags, Set<Flag> flags) {
this.variantFilter = variantFilter;
this.properties = properties;
this.tags = tags;
Expand All @@ -50,8 +51,8 @@ public final ResourceKey<Modifier> getKeyOrThrow() {
}

public static class Builder {
private VariantFilter variantFilter;
private BlockPropsModifier properties;
private @Nullable VariantFilter variantFilter;
private @Nullable BlockPropsModifier properties;
private final List<ResourceLocation> tags = new ArrayList<>();
private final Set<Flag> flags = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,19 +46,22 @@ private ExcavatedVariants() {}

public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
public static final List<Supplier<Item>> 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<Ore, List<Stone>> NEW_VARIANTS_MAP;
private static @Nullable Map<Ore, List<Stone>> NEW_VARIANTS_MAP;
private static final List<VariantFuture> NEW_VARIANTS = new ArrayList<>();
public static final Map<ResourceKey<Block>, List<VariantFuture>> NEEDED_KEYS = new IdentityHashMap<>();
public static final Map<VariantFuture, List<ResourceKey<Block>>> REVERSE_NEEDED_KEYS = new IdentityHashMap<>();
public static final Deque<VariantFuture> READY_QUEUE = new ArrayDeque<>();
public static final Map<VariantFuture, ModifiedOreBlock> BLOCKS = new IdentityHashMap<>();
public static final List<VariantFuture> 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<Ore, List<Stone>> newVariants = new HashMap<>();
Map<Ore, Set<Stone>> newVariantsSet = new HashMap<>();
Expand Down Expand Up @@ -118,7 +122,7 @@ public static void init() {

setupMap();

for (Map.Entry<Ore, List<Stone>> entry : NEW_VARIANTS_MAP.entrySet()) {
for (Map.Entry<Ore, List<Stone>> entry : Objects.requireNonNull(NEW_VARIANTS_MAP, "New variants map was not set up").entrySet()) {
Ore ore = entry.getKey();
List<Stone> stones = entry.getValue();
for (Stone stone : stones) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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<Block> foundOreKey = null;
public Stone foundSourceStone = null;
public @Nullable Block foundStone = null;
public @Nullable Block foundOre = null;
public @Nullable ResourceKey<Block> foundOreKey = null;
public @Nullable Stone foundSourceStone = null;
public final Set<Flag> flags = new HashSet<>();
public final List<BlockPropsModifier> propsModifiers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ab52a24

Please sign in to comment.