generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66ceddc
commit aaa5f07
Showing
4 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
src/main/java/com/portingdeadmods/moreplates/datagen/compat/MIDynamicDataPack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package com.portingdeadmods.moreplates.datagen.compat; | ||
import aztech.modern_industrialization.machines.init.MIMachineRecipeTypes; | ||
import aztech.modern_industrialization.machines.recipe.MachineRecipeBuilder; | ||
import aztech.modern_industrialization.machines.recipe.MachineRecipeType; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.portingdeadmods.moreplates.MorePlatesMod; | ||
import com.portingdeadmods.moreplates.config.MPConfig; | ||
import com.portingdeadmods.moreplates.datagen.DynamicDataPack; | ||
import com.portingdeadmods.moreplates.registries.MPItems; | ||
import net.mehvahdjukaar.moonlight.api.platform.PlatHelper; | ||
import net.mehvahdjukaar.moonlight.api.resources.SimpleTagBuilder; | ||
import net.mehvahdjukaar.moonlight.api.resources.pack.DynServerResourcesGenerator; | ||
import net.minecraft.advancements.Advancement; | ||
import net.minecraft.advancements.AdvancementHolder; | ||
import net.minecraft.advancements.critereon.InventoryChangeTrigger; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.data.recipes.RecipeCategory; | ||
import net.minecraft.data.recipes.RecipeOutput; | ||
import net.minecraft.data.recipes.ShapedRecipeBuilder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.repository.Pack; | ||
import net.minecraft.server.packs.resources.ResourceManager; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.crafting.Recipe; | ||
import net.minecraft.world.level.ItemLike; | ||
import net.neoforged.neoforge.common.conditions.ICondition; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MIDynamicDataPack extends DynServerResourcesGenerator { | ||
|
||
public static final MIDynamicDataPack INSTANCE = new MIDynamicDataPack(); | ||
|
||
public MIDynamicDataPack() { | ||
super(new net.mehvahdjukaar.moonlight.api.resources.pack.DynamicDataPack(ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID,"mi_generated_pack"), Pack.Position.TOP, false, false)); | ||
this.dynamicPack.setGenerateDebugResources(PlatHelper.isDev()); | ||
} | ||
|
||
@Override | ||
public Logger getLogger() { | ||
return MorePlatesMod.LOGGER; | ||
} | ||
|
||
@Override | ||
public boolean dependsOnLoadedPacks() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void regenerateDynamicAssets(ResourceManager manager) { | ||
BuiltInRegistries.ITEM.forEach((item) -> { | ||
ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(item); | ||
|
||
// Plates | ||
if (MorePlatesMod.MODID.equals(itemId.getNamespace()) && itemId.getPath().contains("plate")) { | ||
String rawName = itemId.getPath(); | ||
ResourceLocation inputIngot = MPConfig.getIngotFromPlate(itemId); | ||
if (inputIngot == null) return; | ||
|
||
Item inputItem = BuiltInRegistries.ITEM.get(inputIngot); | ||
|
||
MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.COMPRESSOR, 16, 100) | ||
.addItemInput((ItemLike) inputItem,1) | ||
.addItemOutput(item, 1); | ||
|
||
recipeBuilder.offerTo(new RecipeOutput() { | ||
@Override | ||
public Advancement.@NotNull Builder advancement() { | ||
return Advancement.Builder.advancement(); | ||
} | ||
|
||
@Override | ||
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) { | ||
dynamicPack.addRecipe(recipe, resourceLocation); | ||
} | ||
},"compressor/moreplates/"+itemId.getPath()); | ||
} | ||
|
||
// Gears | ||
if (MorePlatesMod.MODID.equals(itemId.getNamespace()) && itemId.getPath().contains("gear")) { | ||
String rawName = itemId.getPath(); | ||
ResourceLocation inputIngot = MPConfig.getIngotFromGear(itemId); | ||
if (inputIngot == null) return; | ||
|
||
Item inputItem = BuiltInRegistries.ITEM.get(inputIngot); | ||
|
||
MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.ASSEMBLER, 16, 100) | ||
.addItemInput((ItemLike) inputItem,4) | ||
.addItemOutput(item, 1); | ||
|
||
recipeBuilder.offerTo(new RecipeOutput() { | ||
@Override | ||
public Advancement.@NotNull Builder advancement() { | ||
return Advancement.Builder.advancement(); | ||
} | ||
|
||
@Override | ||
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) { | ||
dynamicPack.addRecipe(recipe, resourceLocation); | ||
} | ||
},"assembler/moreplates/"+itemId.getPath()); | ||
} | ||
|
||
// Rods | ||
if (MorePlatesMod.MODID.equals(itemId.getNamespace()) && itemId.getPath().contains("rod")) { | ||
String rawName = itemId.getPath(); | ||
ResourceLocation inputIngot = MPConfig.getIngotFromRod(itemId); | ||
if (inputIngot == null) return; | ||
|
||
Item inputItem = BuiltInRegistries.ITEM.get(inputIngot); | ||
|
||
|
||
ShapedRecipeBuilder recipeBuilder = ShapedRecipeBuilder.shaped(RecipeCategory.MISC, item, 2) | ||
.pattern("H") | ||
.pattern("I") | ||
.pattern("I") | ||
.define('H', MPItems.HAMMER) | ||
.define('I', inputItem) | ||
.unlockedBy("has_item", InventoryChangeTrigger.TriggerInstance.hasItems(inputItem)); | ||
|
||
recipeBuilder.save(new RecipeOutput() { | ||
@Override | ||
public Advancement.@NotNull Builder advancement() { | ||
return Advancement.Builder.advancement(); | ||
} | ||
|
||
@Override | ||
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) { | ||
dynamicPack.addRecipe(recipe, resourceLocation); | ||
} | ||
}); | ||
} | ||
|
||
}); | ||
|
||
} | ||
|
||
private static void removeNullEntries(JsonObject jsonObject) { | ||
jsonObject.entrySet().removeIf(entry -> entry.getValue().isJsonNull()); | ||
|
||
jsonObject.entrySet().forEach(entry -> { | ||
JsonElement element = entry.getValue(); | ||
if (element.isJsonObject()) { | ||
removeNullEntries(element.getAsJsonObject()); | ||
} else if (element.isJsonArray()) { | ||
removeNullEntries(element.getAsJsonArray()); | ||
} | ||
}); | ||
} | ||
|
||
private static void removeNullEntries(JsonArray jsonArray) { | ||
JsonArray newArray = new JsonArray(); | ||
jsonArray.forEach(element -> { | ||
if (!element.isJsonNull()) { | ||
if (element.isJsonObject()) { | ||
removeNullEntries(element.getAsJsonObject().getAsJsonArray()); | ||
} else if (element.isJsonArray()) { | ||
removeNullEntries(element.getAsJsonArray()); | ||
} | ||
newArray.add(element); | ||
} | ||
}); | ||
for (int i = 0; i < jsonArray.size(); i++) jsonArray.remove(i); | ||
jsonArray.addAll(newArray); | ||
} | ||
} | ||
|