Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 56 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,23 @@ allprojects {
}
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
var validPublishProjects = ["owo-lib", "owo-sentinel"];

if (validPublishProjects.contains(project.archives_base_name)) {
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}

repositories {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USER
password ENV.MAVEN_PASSWORD
repositories {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USER
password ENV.MAVEN_PASSWORD
}
}
}
}
Expand Down Expand Up @@ -103,6 +107,46 @@ sourceSets {
}
}

//-- Used to pull in the given AP files to be shipped under owolib as single jar

configurations {
owoConfigAPJava { canBeResolved = true }
owoConfigAPResources { canBeResolved = true }
}

tasks.named('compileJava', JavaCompile) {
dependsOn(configurations.owoConfigAPJava)
source(configurations.owoConfigAPJava)
}

processResources {
dependsOn(configurations.owoConfigAPResources)
from(configurations.owoConfigAPResources)
}

tasks.named('javadoc', Javadoc).configure {
dependsOn(configurations.owoConfigAPJava)
source(configurations.owoConfigAPJava)
}

tasks.named('sourcesJar', Jar) {
dependsOn(configurations.owoConfigAPJava)
dependsOn(configurations.owoConfigAPResources)
from(configurations.owoConfigAPJava)
from(configurations.owoConfigAPResources)
}

dependencies {
compileOnly(annotationProcessor(project(':owo-config-ap')))

owoConfigAPJava project(path: ':owo-config-ap', configuration: 'owoConfigAPJava')
owoConfigAPResources project(path: ':owo-config-ap', configuration: 'owoConfigAPResources')

//testmodImplementation(testmodAnnotationProcessor(project(':owo-config-ap')))
}

//--

loom {
runs {
testmodClient {
Expand Down Expand Up @@ -148,8 +192,7 @@ dependencies {

modCompileOnly("xyz.nucleoid:server-translations-api:${project.stapi_version}")

testmodImplementation sourceSets.main.output
testmodAnnotationProcessor sourceSets.main.output
testmodImplementation(testmodAnnotationProcessor(sourceSets.main.output))
}

javadoc {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ archives_base_name=owo-lib
fabric_version=0.131.0+1.21.8

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=19.0.809
rei_version=20.0.811

# https://maven.terraformersmc.com/releases/dev/emi/emi-fabric/
emi_version=1.1.18+1.21.1
Expand All @@ -27,3 +27,6 @@ modmenu_version=15.0.0-beta.3

# https://maven.nucleoid.xyz/xyz/nucleoid/server-translations-api/
stapi_version=2.5.0+1.21.5-rc1

# Enabled ItemViewers (rei or emi in a comma separated list)
item_viewers=rei
19 changes: 19 additions & 0 deletions owo-config-ap/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
loom {
runConfigs.client.ideConfigGenerated = true
}

configurations {
owoConfigAPJava {
canBeResolved = false
canBeConsumed = true
}
owoConfigAPResources {
canBeResolved = false
canBeConsumed = true
}
}

artifacts {
owoConfigAPJava sourceSets.main.java.sourceDirectories.singleFile
owoConfigAPResources sourceSets.main.resources.sourceDirectories.singleFile
}
1 change: 1 addition & 0 deletions owo-config-ap/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
archives_base_name=owo-config-ap
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
try {
var file = this.processingEnv.getFiler().createSourceFile(wrapperName);
try (var writer = new PrintWriter(file.openWriter())) {
writer.println(makeWrapper(wrapperName, className, this.collectFields(Option.Key.ROOT, clazz, clazz.getAnnotation(Config.class).defaultHook())));
writer.println(makeWrapper(wrapperName, className, this.collectFields(Key.ROOT, clazz, clazz.getAnnotation(Config.class).defaultHook())));
}
} catch (IOException e) {
throw new RuntimeException("Failed to generate config wrapper", e);
Expand All @@ -137,7 +137,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
return true;
}

private List<ConfigField> collectFields(Option.Key parent, TypeElement clazz, boolean defaultHook) {
private List<ConfigField> collectFields(Key parent, TypeElement clazz, boolean defaultHook) {
var messager = this.processingEnv.getMessager();
var list = new ArrayList<ConfigField>();

Expand Down Expand Up @@ -209,28 +209,28 @@ private String makeWrapper(String wrapperClassName, String configClassName, List
.replace("{accessors}\n", accessorMethods.finish());
}

private String makeGetAccessor(String fieldName, Option.Key fieldKey, TypeMirror fieldType) {
private String makeGetAccessor(String fieldName, Key fieldKey, TypeMirror fieldType) {
return GET_ACCESSOR_TEMPLATE
.replace("{option_instance}", constantNameOf(fieldKey))
.replace("{field_name}", fieldName)
.replace("{field_type}", fieldType.toString());
}

private String makeSetAccessor(String fieldName, Option.Key fieldKey, TypeMirror fieldType) {
private String makeSetAccessor(String fieldName, Key fieldKey, TypeMirror fieldType) {
return SET_ACCESSOR_TEMPLATE
.replace("{option_instance}", constantNameOf(fieldKey))
.replace("{field_name}", fieldName)
.replace("{field_type}", fieldType.toString());
}

private String makeSubscribe(String fieldName, Option.Key fieldKey, TypeMirror fieldType) {
private String makeSubscribe(String fieldName, Key fieldKey, TypeMirror fieldType) {
return SUBSCRIBE_TEMPLATE
.replace("{option_instance}", constantNameOf(fieldKey))
.replace("{field_name}", fieldName)
.replace("{field_type}", this.primitivesToWrappers.getOrDefault(fieldType, fieldType).toString());
}

private String constantNameOf(Option.Key key) {
private String constantNameOf(Key key) {
return key.asString().replace(".", "_");
}

Expand All @@ -240,11 +240,11 @@ private interface ConfigField {

private final class ValueField implements ConfigField {
private final String name;
private final Option.Key key;
private final Key key;
private final TypeMirror type;
private final boolean makeSubscribe;

private ValueField(String name, Option.Key key, TypeMirror type, boolean makeSubscribe) {
private ValueField(String name, Key key, TypeMirror type, boolean makeSubscribe) {
this.name = name;
this.key = key;
this.type = type;
Expand Down Expand Up @@ -357,4 +357,86 @@ public char charAt(int index) {
return this.builder.toString();
}
}

private record Key(String[] path) {

public static final Key ROOT = new Key(new String[0]);

public Key(List<String> path) {
this(path.toArray(String[]::new));
}

public Key(String key) {
this(key.split("\\."));
}

/**
* @return The immediate parent of this key,
* or {@link #ROOT} if the parent is the root key
*/
public Key parent() {
if (this.path.length <= 1) return ROOT;

var newPath = new String[this.path.length - 1];
System.arraycopy(this.path, 0, newPath, 0, this.path.length - 1);
return new Key(newPath);
}

/**
* Create the key for a child of this key
*
* @param childName The name of the child
*/
public Key child(String childName) {
var newPath = new String[this.path.length + 1];
System.arraycopy(this.path, 0, newPath, 0, this.path.length);
newPath[this.path.length] = childName;
return new Key(newPath);
}

/**
* @return The segments of this key joined with {@code .}
*/
public String asString() {
return String.join(".", this.path);
}

/**
* @return The name of the element this key describes,
* without any of its parents
*/
public String name() {
if (this.path.length < 1) return "";
return this.path[this.path.length - 1];
}

/**
* @return {@code true} if and only if this
* key is reference-equal to {@link #ROOT}
*/
public boolean isRoot() {
return this == ROOT;
}

// Records don't play nicely with arrays, thus need to manually
// declare all the record autogenerated stuff here

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
return Arrays.equals(path, key.path);
}

@Override
public int hashCode() {
return Arrays.hashCode(path);
}

@Override
public String toString() {
return "Key{" + "path=" + Arrays.toString(path) + '}';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.wispforest.owo.config.annotation;

import com.mojang.datafixers.types.templates.Hook;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pluginManagement {
}
}

include 'owo-sentinel'
include 'owo-sentinel'
include 'owo-config-ap'
14 changes: 14 additions & 0 deletions src/main/java/io/wispforest/owo/Owo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import io.wispforest.owo.client.screens.ScreenInternals;
import io.wispforest.owo.command.debug.OwoDebugCommands;
import io.wispforest.owo.impl.OwoConfigImpl;
import io.wispforest.owo.itemgroup.data.OwoItemGroupLoader;
import io.wispforest.owo.moddata.ModDataLoader;
import io.wispforest.owo.ops.LootOps;
import io.wispforest.owo.text.CustomTextRegistry;
import io.wispforest.owo.text.InsertingTextContent;
import io.wispforest.owo.util.OwoFreezer;
import io.wispforest.owo.util.Wisdom;
import io.wispforest.owo.util.pond.OwoItemGroupExtension;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemGroups;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -45,6 +51,8 @@ public class Owo implements ModInitializer {
DEBUG = debug;
}

public static final OwoConfigImpl CONFIG = OwoConfigImpl.createAndLoad();

@Override
@ApiStatus.Internal
public void onInitialize() {
Expand All @@ -57,6 +65,12 @@ public void onInitialize() {

Wisdom.spread();

OwoFreezer.registerFreezeCallback(() -> {
ModDataLoader.load(OwoItemGroupLoader.INSTANCE);

ItemGroups.getGroups().forEach(group -> ((OwoItemGroupExtension) group).attemptToBuildExtension());
});

if (!DEBUG) return;

OwoDebugCommands.register();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/wispforest/owo/client/OwoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import io.wispforest.owo.client.screens.ScreenInternals;
import io.wispforest.owo.command.debug.OwoDebugCommands;
import io.wispforest.owo.config.OwoConfigCommand;
import io.wispforest.owo.itemgroup.json.OwoItemGroupLoader;
import io.wispforest.owo.moddata.ModDataLoader;
import io.wispforest.owo.itemgroup.data.CondensedEntryLoader;
import io.wispforest.owo.ui.core.OwoUIPipelines;
import io.wispforest.owo.ui.parsing.UIModelLoader;
import io.wispforest.owo.ui.renderstate.OwoSpecialGuiElementRenderers;
Expand Down Expand Up @@ -45,10 +44,9 @@ public class OwoClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ModDataLoader.load(OwoItemGroupLoader.INSTANCE);

ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new UIModelLoader());
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new NinePatchTexture.MetadataLoader());
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(CondensedEntryLoader.INSTANCE);

OwoUIPipelines.register();

Expand Down
Loading