Skip to content

Commit

Permalink
Add crude way to resolve module load order conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 6, 2023
1 parent 6d4a3e7 commit 3a8233f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;

@ZetaLoadModule(category = "building")
@ZetaLoadModule(category = "building", loadPhase = 10) //Needs to load after NewStoneTypesModule
public class MoreStoneVariantsModule extends ZetaModule {

@Config(flag = "stone_bricks") public boolean enableBricks = true;
Expand All @@ -47,16 +47,14 @@ public final void register(ZRegister event) {
add(event, "calcite", MapColor.TERRACOTTA_WHITE, SoundType.CALCITE, polishedCalcite, _true);
add(event, "dripstone", MapColor.TERRACOTTA_BROWN, SoundType.DRIPSTONE_BLOCK, polishedDripstone, _true);
add(event, "tuff", MapColor.TERRACOTTA_GRAY, SoundType.TUFF, polishedTuff, _true);

instance = this;
}

public void weirdAssHackCallMeFromNewStoneTypesToEnsureTheBlocksExistOhGod(ZRegister event) {

add(event, "limestone", MapColor.STONE, SoundType.STONE, NewStoneTypesModule.polishedBlocks.get(NewStoneTypesModule.limestoneBlock), () -> NewStoneTypesModule.enableLimestone);
add(event, "jasper", MapColor.TERRACOTTA_RED, SoundType.STONE, NewStoneTypesModule.polishedBlocks.get(NewStoneTypesModule.jasperBlock), () -> NewStoneTypesModule.enableJasper);
add(event, "shale", MapColor.ICE, SoundType.STONE, NewStoneTypesModule.polishedBlocks.get(NewStoneTypesModule.shaleBlock), () -> NewStoneTypesModule.enableShale);

add(event, "myalite", MapColor.COLOR_PURPLE, SoundType.STONE, NewStoneTypesModule.polishedBlocks.get(NewStoneTypesModule.myaliteBlock), () -> NewStoneTypesModule.enableMyalite, MyaliteBlock::new, MyalitePillarBlock::new);

add(event, "myalite", MapColor.COLOR_PURPLE, SoundType.STONE, NewStoneTypesModule.polishedBlocks.get(NewStoneTypesModule.myaliteBlock), () -> NewStoneTypesModule.enableMyalite, MyaliteBlock::new, MyalitePillarBlock::new);

instance = this;
}

@PlayEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public final void register(ZRegister event) {
jasperBlock = makeStone(event, this, "jasper", jasper, BigStoneClustersModule.jasper, () -> enableJasper, MapColor.TERRACOTTA_RED);
shaleBlock = makeStone(event, this, "shale", shale, BigStoneClustersModule.shale, () -> enableShale, MapColor.ICE);
myaliteBlock = makeStone(event, this, null, "myalite", myalite, BigStoneClustersModule.myalite, () -> enableMyalite, MapColor.COLOR_PURPLE, MyaliteBlock::new);

MoreStoneVariantsModule.instance.weirdAssHackCallMeFromNewStoneTypesToEnsureTheBlocksExistOhGod(event);
}

public static Block makeStone(ZRegister event, ZetaModule module, String name, StoneTypeConfig config, BigStoneClusterConfig bigConfig, BooleanSupplier enabledCond, MapColor color) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/violetmoon/zeta/module/TentativeModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public record TentativeModule(
Set<String> antiOverlap,
boolean enabledByDefault,

boolean clientReplacement
boolean clientReplacement,
int loadPhase
) {
@SuppressWarnings("unchecked")
public static TentativeModule from(ZetaLoadModuleAnnotationData data, Function<String, ZetaCategory> categoryResolver) {
Expand Down Expand Up @@ -66,7 +67,8 @@ public static TentativeModule from(ZetaLoadModuleAnnotationData data, Function<S
data.description(),
Set.of(data.antiOverlap()),
data.enabledByDefault(),
clientReplacement
clientReplacement,
data.loadPhase()
);
}

Expand All @@ -80,7 +82,8 @@ public TentativeModule replaceWith(TentativeModule replacement) {
this.description,
this.antiOverlap,
this.enabledByDefault,
false
false,
replacement.loadPhase
);
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/violetmoon/zeta/module/ZetaLoadModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

// IF YOU UDPATE DEFAULT VALUES: make sure to update ZetaLoadModuleAnnotationData as well, it's needed on Forge.
// Also adding enums is a pain in the ass also due to forge, ur life will be easier if you stick to strings ints bools etc
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ZetaLoadModule {
Expand Down Expand Up @@ -48,4 +50,10 @@
* Either way, the module is accessible with `FooModule.class` in APIs like ZetaModuleManager#get.
*/
boolean clientReplacement() default false;

/**
* Modules with higher loadPhases will load later.
* Ideally there aren't load-order dependencies between modules, but, yknow, shit happens.
*/
int loadPhase() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public record ZetaLoadModuleAnnotationData(
String description,
String[] antiOverlap,
boolean enabledByDefault,
boolean clientReplacement
boolean clientReplacement,
int loadPhase
) {
public static ZetaLoadModuleAnnotationData fromAnnotation(Class<?> clazz, ZetaLoadModule annotation) {
return new ZetaLoadModuleAnnotationData(
Expand All @@ -28,7 +29,8 @@ public static ZetaLoadModuleAnnotationData fromAnnotation(Class<?> clazz, ZetaLo
annotation.description(),
annotation.antiOverlap(),
annotation.enabledByDefault(),
annotation.clientReplacement()
annotation.clientReplacement(),
annotation.loadPhase()
);
}

Expand All @@ -42,7 +44,8 @@ public static ZetaLoadModuleAnnotationData fromForgeThing(Class<?> clazz, Map<St
(String) data.getOrDefault("description", ""),
((List<String>) data.getOrDefault("antiOverlap", new ArrayList<String>())).toArray(new String[0]),
(boolean) data.getOrDefault("enabledByDefault", true),
(boolean) data.getOrDefault("clientReplacement", false)
(boolean) data.getOrDefault("clientReplacement", false),
(int) data.getOrDefault("loadPhase", 0)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void load(ModuleFinder finder) {
Collection<TentativeModule> tentative = finder.get()
.map(data -> TentativeModule.from(data, this::getCategory))
.filter(tm -> tm.appliesTo(z.side))
.sorted(Comparator.comparing(TentativeModule::displayName))
.sorted(Comparator.comparing(TentativeModule::loadPhase).thenComparing(TentativeModule::displayName))
.toList();

//this is the part where we handle "client replacement" modules !!
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,11 @@ public <T> Holder.Direct<T> registerDynamic(T obj, String regname, ResourceKey<?

@SuppressWarnings("unchecked")
public <T> void performDynamicRegistration(RegistryOps.RegistryInfoLookup lookup, ResourceKey<? extends Registry<?>> registryKey, WritableRegistry<T> writable) {
Quark.ZETA.log.info("Dynamic Registration wtf {}", registryKey);

List<DynamicEntry<?>> entries = dynamicDefers.get(registryKey);
if(entries == null || entries.isEmpty())
return;

Quark.ZETA.log.info("There are {} things to register", entries.size());
Quark.ZETA.log.info("Dynamically registering {} thing{} into {}", entries.size(), entries.size() > 1 ? "s" : "", registryKey.location());

List<DynamicEntry<T>> typePun = ((List<DynamicEntry<T>>) (Object) entries);
typePun.forEach(entry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Stream<ZetaLoadModuleAnnotationData> get() {
try {
clazz = (Class<? extends ZetaModule>) Class.forName(ad.clazz().getClassName(), false, ModFileScanDataModuleFinder.class.getClassLoader());
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Exception getting QuarkModule (legacy)", e);
throw new RuntimeException("Exception getting ZetaModule class", e);
}

return ZetaLoadModuleAnnotationData.fromForgeThing(clazz, ad.annotationData());
Expand Down

0 comments on commit 3a8233f

Please sign in to comment.