Skip to content

Commit

Permalink
Empty out QuarkModule
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 19, 2023
1 parent 8068ab7 commit 0a3c32e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 68 deletions.
31 changes: 0 additions & 31 deletions src/main/java/vazkii/quark/base/module/QuarkModule.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
package vazkii.quark.base.module;

import com.google.common.collect.Lists;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.loading.FMLEnvironment;
import vazkii.quark.base.module.config.ConfigFlagManager;
import vazkii.zeta.module.ZetaModule;

import java.util.List;

public class QuarkModule extends ZetaModule {

@Deprecated
public boolean hasSubscriptions = false;
@Deprecated
public List<Dist> subscriptionTarget = Lists.newArrayList(Dist.CLIENT, Dist.DEDICATED_SERVER);

public QuarkModule() {
// yep
}

public void pushFlags(ConfigFlagManager manager) {
// NO-OP
}

@Override
protected boolean legacySubscribe(boolean nowEnabled) {
if(hasSubscriptions && subscriptionTarget.contains(FMLEnvironment.dist)) {
if(nowEnabled)
MinecraftForge.EVENT_BUS.register(this);
else
MinecraftForge.EVENT_BUS.unregister(this);
}

return subscriptionTarget.contains(FMLEnvironment.dist);
}
}
13 changes: 10 additions & 3 deletions src/main/java/vazkii/quark/base/module/config/ConfigResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class ConfigResolver {
Expand Down Expand Up @@ -193,9 +194,15 @@ private void buildModule(IConfigBuilder builder, ZetaModule module, Runnable set
}

refreshRunnables.add(() -> {
//TODO ZETA: figure out how flags interact with modules
if(module instanceof QuarkModule qm)
qm.pushFlags(flagManager);
//TODO ZETA: cheap hack to remove QuarkModule, TODO figure out what to do with this
if(module.getClass().getName().contains("MoreStoneVariantsModule")) {
flagManager.putFlag(module, "granite", true);
flagManager.putFlag(module, "diorite", true);
flagManager.putFlag(module, "andesite", true);
flagManager.putFlag(module, "calcite", true);
flagManager.putFlag(module, "dripstone", true);
flagManager.putFlag(module, "tuff", true);
}
});

builder.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ public static void expandVanillaStone(QuarkModule module, Block raw, String name
NewStoneTypesModule.makeStone(module, raw, name, null, null, () -> true, null, QuarkBlock::new);
}

@Override
public void pushFlags(ConfigFlagManager manager) {
manager.putFlag(this, "granite", true);
manager.putFlag(this, "diorite", true);
manager.putFlag(this, "andesite", true);
manager.putFlag(this, "calcite", true);
manager.putFlag(this, "dripstone", true);
manager.putFlag(this, "tuff", true);
}

private void add(String name, MaterialColor color, SoundType sound, BooleanSupplier cond) {
add(name, color, sound, cond, QuarkBlock::new, QuarkPillarBlock::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public static class Client extends EndermoshMusicDiscModule {

@PlayEvent
public void tick(ZEndClientTickEvent event) {
System.out.println(playEndermoshDuringEnderdragonFight);

if(playEndermoshDuringEnderdragonFight) {
boolean wasFightingDragon = isFightingDragon;

Expand Down
34 changes: 23 additions & 11 deletions src/main/java/vazkii/zeta/module/ZetaModule.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package vazkii.zeta.module;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.loading.FMLEnvironment;
import vazkii.quark.base.module.ModuleLoader;
import vazkii.quark.base.module.hint.HintManager;
import vazkii.quark.base.module.hint.HintObject;
import vazkii.zeta.Zeta;
import vazkii.zeta.event.ZGatherHints;
import vazkii.zeta.event.bus.PlayEvent;

/**
* @see vazkii.quark.base.module.QuarkModule
*/
public class ZetaModule {
public ZetaCategory category = null;

Expand Down Expand Up @@ -59,8 +59,9 @@ else if(!ignoreAntiOverlap && antiOverlap != null && antiOverlap.stream().anyMat
public final void setEnabledAndManageSubscriptions(Zeta z, boolean nowEnabled) {
if(firstLoad || (this.enabled != nowEnabled)) {

//TODO: Haxx for QuarkModule's @SubscribeEvent and sidedness
boolean actuallySubscribe = legacySubscribe(nowEnabled);
//TODO: Cheap hacks to keep non-Zeta Quark modules on life support.
// When all the Forge events are removed, this can be removed too.
boolean actuallySubscribe = LEGACY_doForgeEventBusSubscription(nowEnabled);
if(actuallySubscribe) {
if(nowEnabled)
z.playBus.subscribe(this.getClass()).subscribe(this);
Expand All @@ -72,11 +73,6 @@ public final void setEnabledAndManageSubscriptions(Zeta z, boolean nowEnabled) {
this.enabled = nowEnabled;
}

@Deprecated
protected boolean legacySubscribe(boolean nowEnabled) {
return true;
}

@PlayEvent
public final void addAnnotationHints(ZGatherHints event) {
if(annotationHints == null)
Expand All @@ -85,4 +81,20 @@ public final void addAnnotationHints(ZGatherHints event) {
for(HintObject hint : annotationHints)
hint.apply(event);
}

@Deprecated public boolean LEGACY_hasSubscriptions = false;
@Deprecated public List<Dist> LEGACY_subscriptionTarget = null;

private boolean LEGACY_doForgeEventBusSubscription(boolean nowEnabled) {
if(LEGACY_subscriptionTarget == null) return true;

if(LEGACY_hasSubscriptions && LEGACY_subscriptionTarget.contains(FMLEnvironment.dist)) {
if(nowEnabled)
MinecraftForge.EVENT_BUS.register(this);
else
MinecraftForge.EVENT_BUS.unregister(this);
}

return LEGACY_subscriptionTarget.contains(FMLEnvironment.dist);
}
}
26 changes: 15 additions & 11 deletions src/main/java/vazkii/zeta/module/ZetaModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import net.minecraftforge.fml.loading.FMLEnvironment;
import org.jetbrains.annotations.Nullable;
import vazkii.quark.base.module.LoadModule;
import vazkii.quark.base.module.QuarkModule;
import vazkii.zeta.Zeta;
import vazkii.zeta.event.ZModulesReady;
Expand Down Expand Up @@ -144,23 +145,26 @@ public void load(ModuleFinder finder) {
}

private ZetaModule constructAndSetup(TentativeModule t) {
if(QuarkModule.class.isAssignableFrom(t.clazz()))
z.log.info("Constructing module {}... (is a QuarkModule)", t.displayName());
boolean isLegacy = t.clazz().isAnnotationPresent(LoadModule.class); //as opposed to ZetaLoadModule
if(isLegacy)
z.log.info("Constructing module {}... (LEGACY MODULE)", t.displayName());
else
z.log.info("Constructing module {}...", t.displayName());


//construct, set properties
ZetaModule module = construct(t.clazz());

//TODO: Cheap hack for managing QuarkModule's Forge event bus subscriptions.
// The main purpose of these is preventing client modules from trying to subscribe to events on the server.
// Once Zeta has real client-only modules, there is not much purpose for this feature anymore, i dont think
boolean LEGACY_actuallySubscribe = true;
if(module instanceof QuarkModule qm) {
qm.hasSubscriptions = t.LEGACY_hasSubscriptions();
qm.subscriptionTarget = t.LEGACY_subscribeOn();
LEGACY_actuallySubscribe = qm.subscriptionTarget.contains(FMLEnvironment.dist);
//TODO: Cheap hacks to keep non-Zeta Quark modules on life support.
// When all the Forge events are removed, this can be removed too.
boolean LEGACY_actuallySubscribe;
if(isLegacy) {
module.LEGACY_hasSubscriptions = t.LEGACY_hasSubscriptions();
module.LEGACY_subscriptionTarget = t.LEGACY_subscribeOn();
LEGACY_actuallySubscribe = module.LEGACY_subscriptionTarget.contains(FMLEnvironment.dist);
} else {
module.LEGACY_hasSubscriptions = false;
module.LEGACY_subscriptionTarget = null;
LEGACY_actuallySubscribe = true;
}

module.category = t.category();
Expand Down

0 comments on commit 0a3c32e

Please sign in to comment.