Skip to content

Commit 9e85abb

Browse files
try fixing issue with maven local
1 parent 8b36278 commit 9e85abb

File tree

17 files changed

+303677
-32
lines changed

17 files changed

+303677
-32
lines changed

build.gradle

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ tasks.test {
217217
//debug = true;
218218
}
219219
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing:
220-
// tasks.named('publish').configure {
221-
// dependsOn 'reobfJar'
222-
// }
220+
221+
tasks.named('publish').configure {
222+
dependsOn 'reobfJar'
223+
}
223224

224225
// Example configuration to allow publishing using the maven-publish plugin
225226

@@ -232,7 +233,45 @@ publishing {
232233
publications {
233234
mavenJava(MavenPublication) {
234235
from components.java
235-
//artifactId = "FormicAPI" // ✅ no spaces or invalid chars
236+
artifactId = "FormicAPI" // ✅ no spaces or invalid chars
237+
}
238+
}
239+
}
240+
tasks.register("fixModuleMetadata") {
241+
dependsOn("publishMavenJavaPublicationToMavenLocal")
242+
doLast {
243+
def moduleFile = file("$buildDir/publications/mavenJava/module.json")
244+
if (moduleFile.exists()) {
245+
def text = moduleFile.text
246+
def cleaned = text.replaceAll(/_mapped_official_\d+\.\d+\.\d+/, '')
247+
if (text != cleaned) {
248+
println "Fixing module metadata versions in ${moduleFile}"
249+
moduleFile.text = cleaned
250+
}
251+
} else {
252+
println "Module metadata file not found: ${moduleFile}"
253+
}
254+
}
255+
}
256+
afterEvaluate {
257+
publishing {
258+
publications {
259+
mavenJava(MavenPublication) {
260+
pom.withXml {
261+
asNode().dependencies?.dependency?.each { dep ->
262+
def versionNodes = dep.version
263+
if (versionNodes != null && versionNodes.size() > 0) {
264+
def versionNode = versionNodes[0] // get first Node from NodeList
265+
def versionText = versionNode.text()
266+
def cleaned = versionText.replaceAll(/_mapped_official_\d+\.\d+\.\d+/, '')
267+
if (versionText != cleaned) {
268+
println "Cleaning version: ${versionText} -> ${cleaned}"
269+
versionNode.setValue(cleaned)
270+
}
271+
}
272+
}
273+
}
274+
}
236275
}
237276
}
238277
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod_id=formicapi
2020
mod_name=Formic API
2121
mod_license=MIT
2222

23-
mod_version=1.3.3
23+
mod_version=1.4.2
2424

2525
create_version = 6.0.2-50
2626
flywheel_version = 1.0.1
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,98 @@
11
package com.rae.formicapi;
22

33
import com.rae.formicapi.config.FormicAPIConfigs;
4+
import com.rae.formicapi.data.managers.FloatMapDataLoader;
5+
import com.rae.formicapi.data.managers.TwoDTabulatedFunctionLoader;
6+
import com.rae.formicapi.data.providers.TwoDTabulatedFunctionProvider;
7+
import com.rae.formicapi.math.data.StepMode;
8+
import com.rae.formicapi.thermal_utilities.EOSLibrary;
9+
import com.rae.formicapi.thermal_utilities.eos.CubicEOS;
10+
import com.rae.formicapi.thermal_utilities.helper.WaterCubicEOS;
11+
import com.rae.formicapi.thermal_utilities.helper.WaterTableBased;
12+
import net.minecraft.data.DataGenerator;
13+
import net.minecraft.data.PackOutput;
14+
import net.minecraft.resources.ResourceLocation;
15+
import net.minecraft.world.level.block.Block;
416
import net.minecraftforge.common.MinecraftForge;
17+
import net.minecraftforge.data.event.GatherDataEvent;
18+
import net.minecraftforge.event.AddReloadListenerEvent;
19+
import net.minecraftforge.eventbus.api.EventPriority;
520
import net.minecraftforge.eventbus.api.IEventBus;
621
import net.minecraftforge.fml.ModLoadingContext;
722
import net.minecraftforge.fml.common.Mod;
823
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
24+
import net.minecraftforge.registries.ForgeRegistries;
925
import org.apache.logging.log4j.LogManager;
1026
import org.apache.logging.log4j.Logger;
1127

1228
@Mod(FormicAPI.MODID)
1329
public class FormicAPI {
1430
public static final String MODID = "formicapi";
1531
public static final Logger LOGGER = LogManager.getLogger(MODID);
32+
public static final TwoDTabulatedFunctionLoader WATER_PH_T = new TwoDTabulatedFunctionLoader(MODID,"water/pressure_enthalpy_to_temperature");
33+
public static final TwoDTabulatedFunctionLoader WATER_PS_T = new TwoDTabulatedFunctionLoader(MODID,"water/pressure_entropy_to_temperature");
34+
1635
public FormicAPI() {
1736
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
1837
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
1938
ModLoadingContext modLoadingContext = ModLoadingContext.get();
2039
FormicAPIConfigs.registerConfigs(modLoadingContext);
40+
modEventBus.addListener(EventPriority.NORMAL,this::gatherData);
41+
forgeEventBus.addListener(FormicAPI::onAddReloadListeners);
42+
2143

2244
}
45+
public static void onAddReloadListeners(AddReloadListenerEvent event)
46+
{
47+
event.addListener(FormicAPI.WATER_PH_T);
48+
event.addListener(FormicAPI.WATER_PS_T);
49+
}
50+
51+
public void gatherData(GatherDataEvent event) {
52+
DataGenerator generator = event.getGenerator();
53+
PackOutput output = generator.getPackOutput();
54+
55+
/*generator.addProvider(event.includeServer(), new TwoDTabulatedFunctionProvider(
56+
output, resource("water/pressure_enthalpy_to_temperature"),
57+
WaterCubicEOS::get_T
58+
,1e2f,0, 3e7f, 2e7f,300,1000,StepMode.LOGARITHMIC, StepMode.LINEAR, true
59+
));*/
60+
61+
/*generator.addProvider(
62+
true, new TwoDTabulatedFunctionProvider(
63+
output, resource("water/pressure_enthalpy_to_entropy"),
64+
(P, H) -> {
65+
//get H from the
66+
float T = WaterCubicEOS.get_T(P,H);
67+
CubicEOS EOS = EOSLibrary.getPRWaterEOS();
68+
return (float) EOS.getEntropy(T, P, WaterCubicEOS.get_x(H,T,P));
69+
}
70+
,1e2f,0, 3e7f, 2e7f,30,100,StepMode.LOGARITHMIC, StepMode.LINEAR, true
71+
72+
)
73+
);*/
74+
generator.addProvider(
75+
event.includeServer(), new TwoDTabulatedFunctionProvider(
76+
output, resource("water/pressure_entropy_to_temperature"),
77+
(P, S) -> {
78+
//get H from the
79+
float initialH = 0;
80+
float initialT = WaterCubicEOS.get_T(P, initialH);
81+
float x = WaterCubicEOS.get_x(P, initialH, initialT);
82+
return WaterCubicEOS.getT(initialT, x, P, S);
83+
}
84+
,1e2f,1e-3f, 2e7f, 10e3f,30,100,StepMode.LOGARITHMIC, StepMode.LINEAR, true
85+
86+
)
87+
);
88+
/*generator.addProvider(event.includeServer(), new TwoDTabulatedFunctionProvider(
89+
output, new ResourceLocation(MODID, "water/pressure_entropy_to_temperature"),
90+
(h, p)-> WaterCubicEOS.get_T(p, h)
91+
,1e2f,0, 1e7f, 5e7f,1000,1000,StepMode.LOGARITHMIC, StepMode.LINEAR, true
92+
));*/
93+
}
94+
public static ResourceLocation resource(String name) {
95+
return new ResourceLocation(MODID,name);
96+
}
97+
2398
}

src/main/java/com/rae/formicapi/data/Event.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public static <T> Registry<T> getSideAwareRegistry(ResourceKey<Registry<T>> regi
3232
.orElseThrow();
3333
}
3434
}
35+
3536
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.rae.formicapi.data.managers;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
6+
import com.mojang.logging.LogUtils;
7+
import com.mojang.serialization.JsonOps;
8+
import com.rae.formicapi.math.data.TwoDTabulatedFunction;
9+
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.server.packs.resources.ResourceManager;
11+
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
12+
import net.minecraft.util.GsonHelper;
13+
import net.minecraft.util.profiling.ProfilerFiller;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.slf4j.Logger;
16+
17+
import java.util.Map;
18+
19+
public class TwoDTabulatedFunctionLoader extends SimpleJsonResourceReloadListener {
20+
private static final Gson GSON = new Gson();
21+
private static final String FOLDER = "tabulated_functions";
22+
23+
private final ResourceLocation FILE_NAME;
24+
private TwoDTabulatedFunction FUNCTION;
25+
public static final Logger LOGGER = LogUtils.getLogger();
26+
public TwoDTabulatedFunctionLoader(String modId, String fileName) {
27+
super(GSON, FOLDER);
28+
FILE_NAME = new ResourceLocation(modId, fileName);
29+
}
30+
31+
@Override
32+
protected void apply(Map<ResourceLocation, JsonElement> map, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller profiler) {
33+
LOGGER.info("Reloading TwoDTabulatedFunctionLoader for: {}", FILE_NAME);
34+
35+
for (Map.Entry<ResourceLocation, JsonElement> entry : map.entrySet()) {
36+
if (!entry.getKey().equals(FILE_NAME)) continue;
37+
try {
38+
JsonObject json = GsonHelper.convertToJsonObject(entry.getValue(), "tabulated function");
39+
FUNCTION = TwoDTabulatedFunction.CODEC.decode(JsonOps.INSTANCE, json).getOrThrow(false, s -> {}).getFirst();
40+
} catch (Exception e) {
41+
LOGGER.error("Failed to load float data from {}", entry.getKey(), e);
42+
}
43+
}
44+
}
45+
46+
public float getValue(float x,float y) {
47+
return FUNCTION.evaluate(x, y);
48+
}
49+
50+
51+
52+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.rae.formicapi.data.providers;
2+
3+
import com.google.gson.JsonElement;
4+
import com.mojang.serialization.JsonOps;
5+
import com.rae.formicapi.math.data.StepMode;
6+
import com.rae.formicapi.math.data.TwoDTabulatedFunction;
7+
import net.minecraft.data.CachedOutput;
8+
import net.minecraft.data.DataProvider;
9+
import net.minecraft.data.PackOutput;
10+
import net.minecraft.resources.ResourceLocation;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.nio.file.Path;
14+
import java.util.concurrent.CompletableFuture;
15+
import java.util.function.BiFunction;
16+
17+
public class TwoDTabulatedFunctionProvider implements DataProvider {
18+
19+
private final PackOutput output;
20+
private final ResourceLocation location;
21+
private final BiFunction<Float, Float, Float> f;
22+
private final float xStart;
23+
private final float yStart;
24+
private final float xEnd;
25+
private final float yEnd;
26+
private final int xNbr;
27+
private final int yNbr;
28+
private final StepMode xMode;
29+
private final StepMode yMode;
30+
private final boolean clamp;
31+
32+
public TwoDTabulatedFunctionProvider(PackOutput output, ResourceLocation location, BiFunction<Float, Float, Float> f,
33+
float xStart, float yStart,
34+
float xEnd, float yEnd,
35+
int xNbr, int yNbr,
36+
StepMode xMode, StepMode yMode,
37+
boolean clamp
38+
) {
39+
this.output = output;
40+
this.location = location;
41+
this.f = f;
42+
this.xStart = xStart;
43+
this.yStart = yStart;
44+
this.xEnd = xEnd;
45+
this.yEnd = yEnd;
46+
this.xNbr = xNbr;
47+
this.yNbr = yNbr;
48+
this.xMode = xMode;
49+
this.yMode = yMode;
50+
this.clamp = clamp;
51+
}
52+
53+
@Override
54+
public @NotNull CompletableFuture<?> run(@NotNull CachedOutput cache) {
55+
// Example path: data/yourmod/tabulated_functions/my_function.json
56+
TwoDTabulatedFunction function = TwoDTabulatedFunction.populate(
57+
f, // your function here
58+
xStart, yStart, xEnd, yEnd, xNbr, yNbr,
59+
xMode, yMode,
60+
clamp
61+
);
62+
63+
JsonElement json = TwoDTabulatedFunction.CODEC.encodeStart(JsonOps.INSTANCE, function)
64+
.getOrThrow(false, s -> {
65+
});
66+
Path path = output.getOutputFolder()
67+
.resolve("data/" + location.getNamespace() + "/tabulated_functions/" + location.getPath() + ".json");
68+
69+
return DataProvider.saveStable(cache, json, path);
70+
}
71+
72+
@Override
73+
public @NotNull String getName() {
74+
return "2D Functions for " + location.toString();
75+
}
76+
}

src/main/java/com/rae/formicapi/math/data/OneDTabulatedFunction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ private float evaluate(double input, TreeMap<Float, Float> table) {
3131
int lowerIndex = (int) Math.floor(index);
3232
float frac = index - lowerIndex;
3333

34-
float T1 = (float) mode.inverse.applyAsDouble(lowerIndex * step);
35-
float T2 = (float) mode.inverse.applyAsDouble((lowerIndex + 1) * step);
34+
float X1 = (float) mode.inverse.applyAsDouble(lowerIndex * step);
35+
float X2 = (float) mode.inverse.applyAsDouble((lowerIndex + 1) * step);
3636

3737
// Safeguard in case floating-point precision causes a missing key
38-
if (!table.containsKey(T1) || !table.containsKey(T2)) {
38+
if (!table.containsKey(X1) || !table.containsKey(X2)) {
3939
Map.Entry<Float, Float> lower = table.floorEntry((float) input);
4040
Map.Entry<Float, Float> upper = table.ceilingEntry((float) input);
4141

@@ -53,8 +53,8 @@ private float evaluate(double input, TreeMap<Float, Float> table) {
5353
return lower.getValue() * (1 - fracAlt) + upper.getValue() * fracAlt;
5454
}
5555

56-
float P1 = table.get(T1);
57-
float P2 = table.get(T2);
56+
float P1 = table.get(X1);
57+
float P2 = table.get(X2);
5858

5959
return P1 * (1 - frac) + P2 * frac;
6060
}

src/main/java/com/rae/formicapi/math/data/StepMode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.rae.formicapi.math.data;
22

3+
import com.mojang.serialization.Codec;
4+
35
import java.util.function.DoubleUnaryOperator;
46

57
public enum StepMode {
@@ -19,4 +21,9 @@ public enum StepMode {
1921
this.forward = forward;
2022
this.inverse = inverse;
2123
}
24+
public static final Codec<StepMode> CODEC = Codec.STRING.xmap(
25+
StepMode::valueOf,
26+
StepMode::name
27+
);
28+
2229
}

0 commit comments

Comments
 (0)