Skip to content

Commit

Permalink
Fix issue with imports for REI and use EDM endec for CountedIngredient
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Dec 28, 2023
1 parent 200565c commit 1af09ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
31 changes: 19 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation ("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

modCompileOnly ("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}") {
exclude(module: "cloth-config-fabric")
}
modCompileOnly ("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version")
modCompileOnly ("me.shedaniel:RoughlyEnoughItems-default-plugin:$rei_version")
modCompileOnly ("me.shedaniel.cloth:basic-math:0.6.1")
modCompileOnly ("dev.architectury:architectury-fabric:11.0.8")

modLocalRuntime ("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}") {
exclude(module: "cloth-config-fabric")
exclude(module: "architectury-fabric")
}
modLocalRuntime ("me.shedaniel.cloth:cloth-config-fabric:13.0.114") {
exclude(module: "fabric-api")
exclude(module: "architectury-fabric")
}
modLocalRuntime ("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}")

// modCompileOnly ("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}") {
// exclude(module: "cloth-config-fabric")
// }
// modCompileOnly ("me.shedaniel.cloth:basic-math:0.6.1")
// modCompileOnly ("dev.architectury:architectury-fabric:11.0.8")
//
// modLocalRuntime ("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}") {
// exclude(module: "cloth-config-fabric")
// exclude(module: "architectury-fabric")
// }
// modLocalRuntime ("me.shedaniel.cloth:cloth-config-fabric:13.0.114") {
// exclude(module: "fabric-api")
// exclude(module: "architectury-fabric")
// }

//modLocalRuntime ("dev.architectury:architectury-fabric:11.0.8") { exclude(module: "fabric-api") }

//modLocalRuntime "dev.architectury:architectury-fabric:${project.arch_version}"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ archives_base_name=alloy-forgery
# Dependencies
fabric_version=0.91.2+1.20.4
# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=14.0.687
rei_version=14.0.688
# https://www.curseforge.com/minecraft/mc-mods/modmenu/files
modmenu_version=9.0.0
# https://maven.wispforest.io/io/wispforest/owo-lib
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/wraith/alloyforgery/recipe/CountedIngredient.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package wraith.alloyforgery.recipe;

import io.wispforest.owo.serialization.Endec;
import io.wispforest.owo.serialization.format.json.JsonDeserializer;
import io.wispforest.owo.serialization.format.json.JsonEndec;
import io.wispforest.owo.serialization.format.json.JsonSerializer;
import io.wispforest.owo.serialization.format.edm.EdmDeserializer;
import io.wispforest.owo.serialization.format.edm.EdmElement;
import io.wispforest.owo.serialization.format.edm.EdmEndec;
import io.wispforest.owo.serialization.format.edm.EdmSerializer;
import net.minecraft.recipe.Ingredient;
import wraith.alloyforgery.utils.EndecUtils;

import java.util.Map;

public record CountedIngredient(Ingredient ingredient, int count) {
public static Endec<CountedIngredient> ENDEC = JsonEndec.INSTANCE.xmap(element -> {
var object = element.getAsJsonObject();
public static Endec<CountedIngredient> ENDEC = EdmEndec.INSTANCE.xmap(element -> {
var object = element.<Map<String, EdmElement<?>>>cast();

return new CountedIngredient(
EndecUtils.INGREDIENT.decode(new JsonDeserializer(element)),
object.keySet().contains("count") ? object.get("count").getAsInt() : 1
EndecUtils.INGREDIENT.decode(new EdmDeserializer(element)),
object.containsKey("count") ? object.get("count").<Number>cast().intValue() : 1
);
}, countedIngredient -> {
var element = EndecUtils.INGREDIENT.encodeFully(JsonSerializer::of, countedIngredient.ingredient());
var element = (EdmElement<Map<String, EdmElement<?>>>) EndecUtils.INGREDIENT.encodeFully(EdmSerializer::new, countedIngredient.ingredient());

var count = countedIngredient.count();

if (count > 1) element.getAsJsonObject().addProperty("count", count);
if (count > 1) element.value().put("count", EdmElement.wrapInt(count));

return element;
});
Expand Down

0 comments on commit 1af09ec

Please sign in to comment.