Skip to content

Commit

Permalink
fabric already unzips them
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed Oct 20, 2024
1 parent 78ed234 commit 23bd8ab
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx4G
fabric_versions=1.20.1, 1.21.1
neoforge_versions=1.21.1

mod_version=2.1.1
mod_version=2.1.2
mod_group=com.bawnorton
mod_id=configurable
mod_name=Configurable
Expand Down
44 changes: 43 additions & 1 deletion src/main/java/com/bawnorton/configurable/ConfigurableMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static void init() {
Networking.init();

Platform.forEachJar(path -> {
List<Path> sourceSetSettings = new ArrayList<>();
//? if neoforge {
/*List<Path> sourceSetSettings = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(path.toFile())) {
zipFile.stream()
.filter(entry -> entry.getName().startsWith("configurable/") && !entry.isDirectory())
Expand Down Expand Up @@ -91,7 +92,48 @@ public static void init() {
}
}
} catch (IOException ignored) {}
*///?} else {
Path configurable = path.resolve("configurable");
if (!(Files.exists(configurable) && Files.isDirectory(configurable))) return;

List<Path> sourceSetSettings = new ArrayList<>();
try (Stream<Path> stream = Files.list(configurable)) {
stream.filter(Files::isRegularFile).forEach(sourceSetSettings::add);
} catch (IOException e) {
ConfigurableMain.LOGGER.error("Could not find configurable settings", e);
}

for(Path sourceSetSetting : sourceSetSettings) {
ConfigurableSettings settings;
try {
settings = GSON.fromJson(Files.newBufferedReader(sourceSetSetting), ConfigurableSettings.class);
} catch (IOException e) {
LOGGER.error("Could not load configurable settings", e);
return;
}

String configName = settings.name();
String sourceSet = settings.sourceSet();

if(WRAPPERS.containsKey(configName)) {
Map<String, ConfigurableWrapper> wrappers = WRAPPERS.get(configName);
if(wrappers.containsKey(sourceSet)) {
throw new IllegalStateException("Conflicting config name \"%s\" for source set \"%s\" found in \"%s\"".formatted(configName, sourceSet, sourceSetSetting));
}
}

try {
ConfigurableWrapper wrapper = new ConfigurableWrapper(ConfigurableApiImplLoader.getImpl(configName));
WRAPPERS.computeIfAbsent(configName, k -> new HashMap<>()).put(sourceSet, wrapper);
addToWrapped(settings::fullyQualifiedLoader, wrapper::setLoader, configName);
if(settings.hasScreenFactory() && !Platform.isServer()) {
addToWrapped(settings::fullyQualifiedScreenFactory, wrapper::setScreenFactory, configName);
}
} catch (IllegalStateException e) {
LOGGER.error("Could not create configurable wrapper for \"%s\"".formatted(configName), e);
}
}
//?}
});
WRAPPERS.values().forEach(sourceSetWrappers -> sourceSetWrappers.values().forEach(wrapper -> {
wrapper.loadConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//? if fabric {

/*import com.google.gson.Gson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import javax.annotation.processing.Filer;
Expand Down Expand Up @@ -46,4 +46,4 @@ public String getName() {
return fmj.get("id").getAsString();
}
}
*///?}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//? if neoforge {

import com.electronwill.nightconfig.core.Config;
/*import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.toml.TomlParser;
import javax.annotation.processing.Filer;
import java.io.IOException;
Expand Down Expand Up @@ -42,4 +42,4 @@ public String getName() {
return config.<ArrayList<Config>>get("mods").getFirst().get("modId");
}
}
//?}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public final class SourceProviders {

public static void registerDefaultSourceProviders() {
//? if fabric
/*registerSourceProvider(FabricSourceProvider::new);*/
registerSourceProvider(FabricSourceProvider::new);
//? if neoforge
registerSourceProvider(NeoForgeSourceProvider::new);
/*registerSourceProvider(NeoForgeSourceProvider::new);*/
}

public static void registerSourceProvider(SourceProviderFactory factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ default FieldNamingStrategy defaultFieldNamingStrategy() {
}

//? if !fabric {
/**
/*/^*
* The name of the config this API impl belongs to, this is necessary for non-fabric implementations
* <br>
* <b>THIS DOES NOT SET THE NAME OF THE CONFIG</b>
*/
^/
default String getConfigName() {
throw new UnsupportedOperationException();
}
//?}
*///?}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.spongepowered.asm.mixin.Mixin;

//? if fabric {
/*import com.bawnorton.configurable.ConfigurableMain;
import com.bawnorton.configurable.ConfigurableMain;
import com.bawnorton.configurable.load.ConfigurableWrapper;
import com.terraformersmc.modmenu.ModMenu;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
Expand All @@ -25,10 +25,10 @@ public abstract class ModMenuMixin {

@Shadow @Final private static List<ModMenuApi> apiImplementations;
//?} else {
/^@Shadow private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
/*@Shadow private static Map<String, ConfigScreenFactory<?>> configScreenFactories;
@Shadow private static List<Map<String, ConfigScreenFactory<?>>> delayedScreenFactoryProviders;
^///?}
*///?}


@Inject(
Expand Down Expand Up @@ -59,14 +59,14 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
//? if >=1.21 {
apiImplementations.add(api);
//?} else {
/^delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories());
^///?}
/*delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories());
*///?}
}));
}
}
*///?} else {
import com.bawnorton.configurable.client.ConfigurableClient;
//?} else {
/*import com.bawnorton.configurable.client.ConfigurableClient;
@Mixin(ConfigurableClient.class)
public abstract class ModMenuMixin {}
//?}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import com.bawnorton.configurable.client.ConfigurableClient;

//? if fabric {
/*import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ClientModInitializer;

public final class ConfigurableClientWrapper implements ClientModInitializer {
@Override
public void onInitializeClient() {
ConfigurableClient.init();
}
}
*///?} elif neoforge {
import com.bawnorton.configurable.ConfigurableMain;
//?} elif neoforge {
/*import com.bawnorton.configurable.ConfigurableMain;
import com.bawnorton.configurable.platform.Platform;
import net.minecraft.client.MinecraftClient;
import net.neoforged.api.distmarker.Dist;
Expand Down Expand Up @@ -43,4 +43,4 @@ public ConfigurableClientWrapper() {
}));
}
}
//?}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
import java.util.Map;

//? if fabric {
/*import net.fabricmc.loader.api.FabricLoader;
*///?} elif neoforge {
import java.util.ServiceLoader;
//?}
import net.fabricmc.loader.api.FabricLoader;
//?} elif neoforge {
/*import java.util.ServiceLoader;
*///?}

public final class ConfigurableApiImplLoader {
//? if neoforge
private static final ServiceLoader<ConfigurableApi> serviceLoader = ServiceLoader.load(ConfigurableApi.class);
/*private static final ServiceLoader<ConfigurableApi> serviceLoader = ServiceLoader.load(ConfigurableApi.class);*/
private static final Map<String, ConfigurableApi> impls = new HashMap<>();

public static void load() {
//? if fabric {
/*FabricLoader.getInstance().getEntrypointContainers("configurable", ConfigurableApi.class).forEach(container -> {
FabricLoader.getInstance().getEntrypointContainers("configurable", ConfigurableApi.class).forEach(container -> {
String id = container.getProvider().getMetadata().getId();
try {
impls.put(id, container.getEntrypoint());
} catch (Throwable e) {
ConfigurableMain.LOGGER.error("Mod {} provides a broken ConfigurableApi implemenation", id, e);
}
});
*///?} elif neoforge {
serviceLoader.forEach(apiImpl -> impls.put(apiImpl.getConfigName(), apiImpl));
//?}
//?} elif neoforge {
/*serviceLoader.forEach(apiImpl -> impls.put(apiImpl.getConfigName(), apiImpl));
*///?}
}

public static ConfigurableApi getImpl(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import com.bawnorton.configurable.ConfigurableMain;

//? if fabric {
/*import net.fabricmc.api.ModInitializer;
import net.fabricmc.api.ModInitializer;

public final class ConfigurableMainWrapper implements ModInitializer {
@Override
public void onInitialize() {
ConfigurableMain.init();
}
}
*///?} elif neoforge {
import net.neoforged.fml.common.Mod;
//?} elif neoforge {
/*import net.neoforged.fml.common.Mod;
@Mod(ConfigurableMain.MOD_ID)
public final class ConfigurableMainWrapper {
public ConfigurableMainWrapper() {
ConfigurableMain.init();
}
}
//?}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.function.Consumer;

//? if fabric {
/*import net.fabricmc.api.EnvType;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import java.util.List;

Expand Down Expand Up @@ -35,8 +35,8 @@ public static boolean isServer() {
}
}

*///?} elif neoforge {
import net.neoforged.fml.ModContainer;
//?} elif neoforge {
/*import net.neoforged.fml.ModContainer;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.fml.loading.LoadingModList;
Expand Down Expand Up @@ -80,4 +80,4 @@ public static boolean isServer() {
return FMLEnvironment.dist.isDedicatedServer();
}
}
//?}
*///?}
2 changes: 1 addition & 1 deletion stonecutter.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("dev.kikugie.stonecutter")
}
stonecutter active "1.21.1-neoforge-yarn" /* [SC] DO NOT EDIT */
stonecutter active "1.21.1-fabric-yarn" /* [SC] DO NOT EDIT */

stonecutter registerChiseled tasks.register("chiseledBuildAndCollect", stonecutter.chiseled) {
group = "project"
Expand Down

0 comments on commit 23bd8ab

Please sign in to comment.