Skip to content

Commit

Permalink
refactor(recipes): update NBT handling and recipe conditions for comp…
Browse files Browse the repository at this point in the history
…atibility

- Modify ModShapedRecipeBuilder to use CompoundTag instead of String for NBT data.
- Refactor the way NBT tags are constructed, especially for creative Energy Cube and Slot recipes.
- Change recipe conditions to include 'mekanismgenerators' mod for creative bin recipe.- Rename recipe files to include 'botania' prefix for clarity and consistency.- Update build.gradle with the latest Mekanism version.
- Correct the indentation in the tc3_creative_slot JSON files for proper formatting.

BREAKING CHANGE: The use of CompoundTag instead of String for NBT data requires updates to
any custom recipes that rely on the previous String format.
  • Loading branch information
cnlimiter committed Jul 27, 2024
1 parent f17ec03 commit f61fcfa
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 35 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ dependencies {

implementation fg.deobf("curse.maven:charm-of-undying-316873:${cou_version}")
implementation fg.deobf("curse.maven:projecte-226410:${projecte_version}")
runtimeOnly fg.deobf("curse.maven:mekanism-268560:${mek_version}")

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixin_extras_version}"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.3.6")) {
Expand Down Expand Up @@ -189,7 +190,7 @@ publishing {
if (System.getenv('MAVEN_USERNAME') != null && System.getenv('MAVEN_PASSWORD') != null) {
maven {
name 'S3'
url = 'https://maven.nova-committee.cn/s'
url = 'https://maven.nova-committee.cn/s3'

credentials {
username System.getenv('MAVEN_USERNAME')
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rhino_version=2001.2.2-build.6
curios_version=5.4.7+1.20.1
cou_version=5159193
projecte_version=4901949
mek_version=5395221
mixin_extras_version=0.3.6

## Mod Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
{
"type": "forge:mod_loaded",
"modid": "mekanism"
},
{
"type": "forge:mod_loaded",
"modid": "mekanismgenerators"
}
],
"recipe": {
"type": "avaritia:shaped_extreme_craft",
"category": "equipment",
"key": {
"A": {
"item": "mekanism:fusion_reactor_frame"
"item": "mekanismgenerators:fusion_reactor_frame"
},
"B": {
"item": "mekanism:ultimate_energy_cube"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"item": "mekanism:induction_port"
},
"D": {
"item": "mekanism:induction_cell"
"item": "mekanism:ultimate_induction_cell"
},
"E": {
"item": "mekanism:induction_provider"
"item": "mekanism:ultimate_induction_provider"
},
"I": {
"item": "avaritia:infinity_ingot"
Expand All @@ -46,7 +46,8 @@
"BBBCECBBB"
],
"result": {
"item": "mekanism:creative_energy_cube"
"item": "mekanism:creative_energy_cube",
"nbt": "{mekData:{EnergyContainers:[{Container:0b,stored:\"18446744073709551615.9999\"}]}}"
},
"show_notification": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"item": "mekanism:dynamic_tank"
},
"C": {
"item": "mekanism:dynamic_glass"
"item": "mekanism:structural_glass"
},
"D": {
"item": "mekanism:dynamic_valve"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"result": {
"item": "tconstruct:creative_slot",
"nbt": "{slot:abilities}"
"nbt": "{slot:\"abilities\"}"
},
"show_notification": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"result": {
"item": "tconstruct:creative_slot",
"nbt": "{slot:defense}"
"nbt": "{slot:\"defense\"}"
},
"show_notification": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"result": {
"item": "tconstruct:creative_slot",
"nbt": "{slot:souls}"
"nbt": "{slot:\"souls\"}"
},
"show_notification": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"result": {
"item": "tconstruct:creative_slot",
"nbt": "{slot:upgrades}"
"nbt": "{slot:\"upgrades\"}"
},
"show_notification": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.*;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -480,7 +483,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {

.unlockedBy("has_item", has(ModItems.neutron_ingot.get())).save(consumer);

ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.infinity_totem.get(), "")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.infinity_totem.get())
.pattern(" NNN ")
.pattern(" NIIIN ")
.pattern(" NYIYN ")
Expand All @@ -497,7 +500,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {

.unlockedBy("has_item", has(Items.TOTEM_OF_UNDYING)).save(consumer);

ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.infinity_bucket.get(), "")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.infinity_bucket.get())
.pattern("NN NN")
.pattern("NNX XNN")
.pattern("NBBX XBBN")
Expand Down Expand Up @@ -532,8 +535,12 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("ae2", "dense_energy_cell")))::save
).build(consumer, Static.rl( "ae2_creative_energy_cell"));

var mana_tablet_tag = new CompoundTag();
mana_tablet_tag.putInt("mana", 500000);
mana_tablet_tag.putBoolean("creative", true);

ConditionalRecipe.builder().addCondition(modLoaded("botania")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("botania", "mana_tablet"), "{creative:1b,mana:500000}")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("botania", "mana_tablet"), mana_tablet_tag)
.pattern("BAAACAAAD")
.pattern("ATTJKLTTA")
.pattern("ATUUMUUTA")
Expand Down Expand Up @@ -566,7 +573,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.define('T', Static.getIngredient("botania", "fabulous_pool"))
.define('U', Static.getIngredient("botania", "terrasteel_block"))
.unlockedBy("has_item", has(Static.getItem("botania", "terrasteel_block")))::save
).build(consumer, Static.rl( "bot_mana_tablet"));
).build(consumer, Static.rl( "botania_mana_tablet"));

ConditionalRecipe.builder().addCondition(modLoaded("botania")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("botania", "creative_pool"))
Expand All @@ -587,7 +594,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.define('E', Static.getIngredient("botania", "dragonstone_block"))
.define('F', Static.getIngredient("botania", "mana_tablet"))
.unlockedBy("has_item", has(Static.getItem("botania", "mana_tablet")))::save
).build(consumer, Static.rl( "bot_creative_pool"));
).build(consumer, Static.rl( "botania_creative_pool"));

ConditionalRecipe.builder().addCondition(modLoaded("draconicevolution")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("draconicevolution", "creative_capacitor"))
Expand Down Expand Up @@ -713,8 +720,11 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("refinedstorage", "wireless_grid")))::save
).build(consumer, Static.rl( "rs_creative_wireless_grid"));

var creative_slot_abilities = new CompoundTag();
creative_slot_abilities.putString("slot", "abilities");

ConditionalRecipe.builder().addCondition(modLoaded("tconstruct")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), "{slot:abilities}")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), creative_slot_abilities)
.pattern("GGBHHHBGG")
.pattern("GCCCCCCCG")
.pattern("BCBFFFBCB")
Expand All @@ -735,8 +745,11 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("tconstruct", "ichor_slime_crystal")))::save
).build(consumer, Static.rl( "tc3_creative_slot_ability"));

var creative_slot_defense = new CompoundTag();
creative_slot_defense.putString("slot", "defense");

ConditionalRecipe.builder().addCondition(modLoaded("tconstruct")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), "{slot:defense}")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), creative_slot_defense)
.pattern("GGBHHHBGG")
.pattern("GCCCCCCCG")
.pattern("BCBFFFBCB")
Expand All @@ -757,8 +770,12 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("tconstruct", "earth_slime_crystal")))::save
).build(consumer, Static.rl("tc3_creative_slot_defense"));


var creative_slot_souls = new CompoundTag();
creative_slot_souls.putString("slot", "souls");

ConditionalRecipe.builder().addCondition(modLoaded("tconstruct")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), "{slot:souls}")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), creative_slot_souls)
.pattern("GGBHHHBGG")
.pattern("GCCCCCCCG")
.pattern("BCBFFFBCB")
Expand All @@ -779,8 +796,11 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("tconstruct", "sky_slime_crystal")))::save
).build(consumer, Static.rl("tc3_creative_slot_souls"));

var creative_slot_upgrades = new CompoundTag();
creative_slot_upgrades.putString("slot", "upgrades");

ConditionalRecipe.builder().addCondition(modLoaded("tconstruct")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), "{slot:upgrades}")
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("tconstruct", "creative_slot"), creative_slot_upgrades)
.pattern("GGBHHHBGG")
.pattern("GCCCCCCCG")
.pattern("BCBFFFBCB")
Expand Down Expand Up @@ -820,8 +840,20 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("storagedrawers", "upgrade_storage")))::save
).build(consumer, Static.rl("sd_upgrade_creative"));

var creative_energy_cube_main = new CompoundTag();
var energyContainers = new ListTag();
var stored = new CompoundTag();
var mekData = new CompoundTag();
stored.putString("stored", "18446744073709551615.9999");
stored.putBoolean("Container", false);
energyContainers.add(stored);
mekData.put("EnergyContainers", energyContainers);
creative_energy_cube_main.put("mekData", mekData);

ConditionalRecipe.builder().addCondition(modLoaded("mekanism")).addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("mekanism", "creative_energy_cube"))
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("mekanism", "creative_energy_cube"),
creative_energy_cube_main
)
.pattern("BBBCECBBB")
.pattern("BDDDADDDB")
.pattern("BDSDADSDB")
Expand All @@ -837,8 +869,8 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.define('A', Static.getIngredient("mekanism", "ultimate_energy_cube"))
.define('B', Static.getIngredient("mekanism", "induction_casing"))
.define('C', Static.getIngredient("mekanism", "induction_port"))
.define('D', Static.getIngredient("mekanism", "induction_cell"))
.define('E', Static.getIngredient("mekanism", "induction_provider"))
.define('D', Static.getIngredient("mekanism", "ultimate_induction_cell"))
.define('E', Static.getIngredient("mekanism", "ultimate_induction_provider"))
.unlockedBy("has_item", has(Static.getItem("mekanism", "creative_energy_cube")))::save
).build(consumer, Static.rl("mek_creative_energy_cube"));

Expand All @@ -858,7 +890,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.define('S', ModItems.infinity_catalyst.get())
.define('A', Static.getIngredient("mekanism", "ultimate_fluid_tank"))
.define('B', Static.getIngredient("mekanism", "dynamic_tank"))
.define('C', Static.getIngredient("mekanism", "dynamic_glass"))
.define('C', Static.getIngredient("mekanism", "structural_glass"))
.define('D', Static.getIngredient("mekanism", "dynamic_valve"))
.unlockedBy("has_item", has(Static.getItem("mekanism", "creative_fluid_tank")))::save
).build(consumer, Static.rl("mek_creative_fluid_tank"));
Expand All @@ -884,7 +916,10 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_item", has(Static.getItem("mekanism", "creative_chemical_tank")))::save
).build(consumer, Static.rl("mek_creative_chemical_tank"));

ConditionalRecipe.builder().addCondition(modLoaded("mekanism")).addRecipe(
ConditionalRecipe.builder()
.addCondition(modLoaded("mekanism"))
.addCondition(modLoaded("mekanismgenerators"))
.addRecipe(
ModShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ResourceLocation.tryBuild("mekanism", "creative_bin"))
.pattern("AAAAAAAAA")
.pattern("AEIIIIIEA")
Expand All @@ -898,7 +933,7 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {

.define('I', ModItems.infinity_ingot.get())
.define('S', ModItems.infinity_catalyst.get())
.define('A', Static.getIngredient("mekanism", "fusion_reactor_frame"))
.define('A', Static.getIngredient("mekanismgenerators", "fusion_reactor_frame"))
.define('B', Static.getIngredient("mekanism", "ultimate_energy_cube"))
.define('C', Static.getIngredient("mekanism", "ultimate_fluid_tank"))
.define('D', Static.getIngredient("mekanism", "ultimate_chemical_tank"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -48,15 +50,15 @@ public class ModShapedRecipeBuilder extends CraftingRecipeBuilder implements Rec
private final ItemLike result;
private final ResourceLocation result2;
private final int count;
private final String nbt;
private final CompoundTag nbt;
private final List<String> rows = Lists.newArrayList();
private final Map<Character, Ingredient> key = Maps.newLinkedHashMap();
private final Advancement.Builder advancement = Advancement.Builder.advancement();
@Nullable
private String group;
private boolean showNotification = true;

public ModShapedRecipeBuilder(RecipeCategory category, ItemLike itemLike, ResourceLocation itemLocation, int count, String nbt) {
public ModShapedRecipeBuilder(RecipeCategory category, ItemLike itemLike, ResourceLocation itemLocation, int count, CompoundTag nbt) {
this.category = category;
this.result = itemLike;
this.result2 = itemLocation;
Expand All @@ -65,27 +67,27 @@ public ModShapedRecipeBuilder(RecipeCategory category, ItemLike itemLike, Resour
}

@Contract("_, _, _ -> new")
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ResourceLocation itemLocation, String nbt) {
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ResourceLocation itemLocation, CompoundTag nbt) {
return shaped(category, null, itemLocation, 1, nbt);
}

@Contract("_, _ -> new")
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ResourceLocation itemLocation) {
return shaped(category, null, itemLocation, 1, "");
return shaped(category, null, itemLocation, 1, new CompoundTag());
}

@Contract("_, _, _ -> new")
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ItemLike itemLike, String nbt) {
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ItemLike itemLike, CompoundTag nbt) {
return shaped(category, itemLike, null, 1, nbt);
}

@Contract("_, _ -> new")
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ItemLike itemLike) {
return shaped(category, itemLike, null, 1, "");
return shaped(category, itemLike, null, 1, new CompoundTag());
}

@Contract("_, _, _, _, _ -> new")
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ItemLike itemLike, ResourceLocation itemLocation, int count, String nbt) {
public static @NotNull ModShapedRecipeBuilder shaped(RecipeCategory category, ItemLike itemLike, ResourceLocation itemLocation, int count, CompoundTag nbt) {
return new ModShapedRecipeBuilder(category, itemLike, itemLocation, count, nbt);
}

Expand Down Expand Up @@ -190,15 +192,15 @@ public static class Result extends CraftingRecipeBuilder.CraftingResult {
private final ItemLike result;
private final ResourceLocation result2;
private final int count;
private final String nbt;
private final CompoundTag nbt;
private final String group;
private final List<String> pattern;
private final Map<Character, Ingredient> key;
private final Advancement.Builder advancement;
private final ResourceLocation advancementId;
private final boolean showNotification;

public Result(ResourceLocation resourceLocation, ItemLike item, ResourceLocation result2, int count, String nbt, String group, CraftingBookCategory p_273500_, List<String> p_273744_, Map<Character, Ingredient> p_272991_, Advancement.Builder p_273260_, ResourceLocation p_273106_, boolean p_272862_) {
public Result(ResourceLocation resourceLocation, ItemLike item, ResourceLocation result2, int count, CompoundTag nbt, String group, CraftingBookCategory p_273500_, List<String> p_273744_, Map<Character, Ingredient> p_272991_, Advancement.Builder p_273260_, ResourceLocation p_273106_, boolean p_272862_) {
super(p_273500_);
this.id = resourceLocation;
this.result = item;
Expand Down Expand Up @@ -243,7 +245,7 @@ public void serializeRecipeData(@NotNull JsonObject pJson) {
}

if (!this.nbt.isEmpty()){
jsonobject1.addProperty("nbt", this.nbt);
jsonobject1.addProperty("nbt", this.nbt.toString());
}

pJson.add("result", jsonobject1);
Expand Down

0 comments on commit f61fcfa

Please sign in to comment.