Skip to content

Commit

Permalink
migrate the config once per instance
Browse files Browse the repository at this point in the history
closes #64
  • Loading branch information
deirn committed Aug 12, 2023
1 parent 09f435e commit bc47f42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object versions {
object deps {
val minecraft = "com.mojang:minecraft:${versions.minecraft}"
val yarn = "net.fabricmc:yarn:1.19.2+build.8:v2"
val fabricLoader = "net.fabricmc:fabric-loader:0.14.15"
val fabricLoader = "net.fabricmc:fabric-loader:0.14.22"

val wthit = "mcp.mobius.waila:wthit:fabric-5.17.0"

Expand Down Expand Up @@ -55,6 +55,7 @@ object deps {
fun DependencyHandlerScope.modImpl(dep: String, dependencyConfiguration: ExternalModuleDependency.() -> Unit = {}) {
"modImplementation"(dep) {
if (!dep.startsWith("net.fabricmc.fabric-api")) exclude(group = "net.fabricmc.fabric-api")
exclude("net.fabricmc:fabric-loader")
dependencyConfiguration()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class MeganeConfig {
private boolean spawnEgg = true;
private boolean playerHead = true;

private boolean pluginConfigMigrated = false;
private final Set<Identifier> migratedBlacklist = new HashSet<>();

public int getConfigVersion() {
return configVersion;
}
Expand All @@ -44,6 +47,14 @@ public boolean getPlayerHead() {
return playerHead;
}

public boolean isPluginConfigMigrated() {
return pluginConfigMigrated;
}

public Set<Identifier> getMigratedBlacklist() {
return migratedBlacklist;
}

public void setCatchServerErrors(boolean catchServerErrors) {
this.catchServerErrors = catchServerErrors;
}
Expand All @@ -56,6 +67,10 @@ public void setPlayerHead(boolean playerHead) {
this.playerHead = playerHead;
}

public void setPluginConfigMigrated(boolean pluginConfigMigrated) {
this.pluginConfigMigrated = pluginConfigMigrated;
}

public interface Base {

boolean isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@
@Mixin(ExtraBlacklistConfig.Adapter.class)
public abstract class MixinExtraBlacklistConfigAdapter {

@Unique
private boolean megane_migrated = false;

@Shadow
@Final
private Identifier tagId;

@Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lmcp/mobius/waila/plugin/extra/config/ExtraBlacklistConfig;", at = @At("RETURN"), remap = false)
private void migrateBlacklist(JsonElement json, Type typeOfT, JsonDeserializationContext context, CallbackInfoReturnable<ExtraBlacklistConfig> cir) {
if (megane_migrated) return;
MeganeConfig config = MeganeUtils.config();
if (config.getMigratedBlacklist().contains(tagId)) return;

ExtraBlacklistConfig out = cir.getReturnValue();
AccessorExtraBlacklistConfig access = (AccessorExtraBlacklistConfig) out;
MeganeConfig config = MeganeUtils.config();

if (tagId.equals(new Identifier("waila:extra/energy_blacklist"))) {
add(out.blocks, access.getBlockIds(), Registry.BLOCK, config.energy.getBlacklist());
Expand All @@ -48,7 +45,8 @@ private void migrateBlacklist(JsonElement json, Type typeOfT, JsonDeserializatio
}

MeganeUtils.LOGGER.info("[megane] migrated {}", tagId);
megane_migrated = true;
config.getMigratedBlacklist().add(tagId);
MeganeUtils.CONFIG.save();
}

@Unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
@Mixin(PluginConfig.class)
public abstract class MixinPluginConfig {

@Unique
private static boolean megane_migrated = false;

@Inject(method = "reload", at = @At("RETURN"), remap = false)
private static void migrateConfig(CallbackInfo ci) {
if (megane_migrated) return;

MeganeConfig config = MeganeUtils.config();
if (config.isPluginConfigMigrated()) return;

set(new Identifier("wailax:energy.enabled_block"), config.energy.isEnabled());
set(new Identifier("wailax:fluid.enabled_block"), config.fluid.isEnabled());
set(new Identifier("wailax:item.enabled_block"), config.inventory.isEnabled());
Expand All @@ -31,7 +28,8 @@ private static void migrateConfig(CallbackInfo ci) {
MeganeUtils.LOGGER.info("[megane] Migrated plugin config");

save();
megane_migrated = true;
config.setPluginConfigMigrated(true);
MeganeUtils.CONFIG.save();
}

@Shadow
Expand Down

0 comments on commit bc47f42

Please sign in to comment.