Skip to content

Commit

Permalink
feat: datagen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed Aug 4, 2024
1 parent 8856425 commit 9ac39f6
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ eclipse
run
.architectury-transformer

backup
backup
.cache
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ subprojects {

loom {
silentMojangMappingsLicense()

mixin {
useLegacyMixinAp = false
}
}

jar {
Expand Down Expand Up @@ -58,6 +62,7 @@ allprojects {

repositories {
mavenCentral()
mavenLocal()

maven {
name = "Modrinth"
Expand Down
15 changes: 15 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ architectury {
common(rootProject.enabled_platforms.split(","))
}

sourceSets {
main {
resources {
srcDirs "src/generated/resources"
}
}
}

loom {
splitEnvironmentSourceSets()

mods {
utility_belt {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "item/generated",
"parent": "minecraft:item/generated",
"textures": {
"layer0": "utility_belt:item/utility_belt"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"replace": false,
"values": [
"utility_belt:utility_belt"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
{
"parent": "minecraft:story/smelt_iron",
"display": {
"icon": {
"id": "utility_belt:utility_belt"
},
"title": {
"translate": "advancements.utility_belt.utility_belt.title"
},
"description": {
"translate": "advancements.utility_belt.utility_belt.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"rewards": {
"experience": 25
},
"criteria": {
"utility_belt": {
"trigger": "minecraft:inventory_changed",
"obtain_belt": {
"conditions": {
"items": [
{
"items": [
"utility_belt:utility_belt"
]
"items": "utility_belt:utility_belt"
}
]
}
},
"trigger": "minecraft:inventory_changed"
}
},
"display": {
"description": {
"translate": "advancements.utility_belt.utility_belt.description"
},
"icon": {
"count": 1,
"id": "utility_belt:utility_belt"
},
"title": {
"translate": "advancements.utility_belt.utility_belt.title"
}
},
"requirements": [
[
"utility_belt"
"obtain_belt"
]
]
}
],
"rewards": {
"experience": 25
},
"sends_telemetry_event": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_diamond": {
"conditions": {
"items": [
{
"items": "minecraft:diamond"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_leather": {
"conditions": {
"items": [
{
"items": "minecraft:leather"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_string": {
"conditions": {
"items": [
{
"items": "minecraft:string"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "utility_belt:utility_belt"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_diamond",
"has_leather",
"has_string"
]
],
"rewards": {
"recipes": [
"utility_belt:utility_belt"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"SDS",
"L L",
"SLS"
],
"category": "equipment",
"key": {
"S": {
"item": "minecraft:string"
},
"D": {
"item": "minecraft:diamond"
},
"L": {
"item": "minecraft:leather"
},
"S": {
"item": "minecraft:string"
}
},
"pattern": [
"SDS",
"L L",
"SLS"
],
"result": {
"id": "utility_belt:utility_belt",
"count": 1
"count": 1,
"id": "utility_belt:utility_belt"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"replace": false,
"values": [
{
"id": "create:wrench",
"required": false
}
]
}
}
33 changes: 33 additions & 0 deletions datagen/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
}

architectury {
platformSetupLoomIde()
fabric()
}

fabricApi {
configureDataGeneration {
createSourceSet = false
addToResources = false
outputDirectory = project(":common").file("src/generated/resources")
}
}

configurations {
common
shadowCommon
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
}

dependencies {
modImplementation libs.fabric.loader
modImplementation libs.fabric.api
modImplementation libs.architectury.fabric
modImplementation libs.jamlib.fabric
modImplementation libs.accessories.fabric

common(project(path: ":common", configuration: "namedElements")) { transitive false }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.jamalam360.utility_belt.datagen;

import io.github.jamalam360.utility_belt.UtilityBelt;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricAdvancementProvider;
import net.minecraft.advancements.*;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.core.HolderLookup;
import net.minecraft.network.chat.Component;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

public class Advancements extends FabricAdvancementProvider {
protected Advancements(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registryLookup) {
super(output, registryLookup);
}

@Override
public void generateAdvancement(HolderLookup.Provider registryLookup, Consumer<AdvancementHolder> consumer) {
Advancement.Builder.advancement()
.display(UtilityBelt.UTILITY_BELT_ITEM.get(), Component.translatable("advancements.utility_belt.utility_belt.title"), Component.translatable("advancements.utility_belt.utility_belt.description"), null, AdvancementType.TASK, true, true, false)
.addCriterion("obtain_belt", InventoryChangeTrigger.TriggerInstance.hasItems(UtilityBelt.UTILITY_BELT_ITEM.get()))
.rewards(AdvancementRewards.Builder.experience(25))
.save(consumer, "utility_belt:obtain_utility_belt");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.jamalam360.utility_belt.datagen;

import io.github.jamalam360.utility_belt.UtilityBelt;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class Datagen implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator gen) {
UtilityBelt.LOGGER.info("Generating data and assets...");
FabricDataGenerator.Pack pack = gen.createPack();
pack.addProvider(Advancements::new);
pack.addProvider(Models::new);
pack.addProvider(Recipes::new);
pack.addProvider(Tags::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.jamalam360.utility_belt.datagen;

import io.github.jamalam360.utility_belt.UtilityBelt;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.data.models.BlockModelGenerators;
import net.minecraft.data.models.ItemModelGenerators;
import net.minecraft.data.models.model.ModelTemplates;

public class Models extends FabricModelProvider {
public Models(FabricDataOutput output) {
super(output);
}

@Override
public void generateBlockStateModels(BlockModelGenerators gen) {

}

@Override
public void generateItemModels(ItemModelGenerators gen) {
gen.generateFlatItem(UtilityBelt.UTILITY_BELT_ITEM.get(), ModelTemplates.FLAT_ITEM);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.jamalam360.utility_belt.datagen;

import io.github.jamalam360.utility_belt.UtilityBelt;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.world.item.Items;

import java.util.concurrent.CompletableFuture;

public class Recipes extends FabricRecipeProvider {
public Recipes(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
super(output, registriesFuture);
}

@Override
public void buildRecipes(RecipeOutput exporter) {
ShapedRecipeBuilder
.shaped(RecipeCategory.TOOLS, UtilityBelt.UTILITY_BELT_ITEM.get())
.pattern("SDS").pattern("L L").pattern("SLS")
.define('S', Items.STRING).define('D', Items.DIAMOND).define('L', Items.LEATHER)
.unlockedBy("has_diamond", has(Items.DIAMOND))
.unlockedBy("has_leather", has(Items.LEATHER))
.unlockedBy("has_string", has(Items.STRING))
.save(exporter);
}
}
Loading

0 comments on commit 9ac39f6

Please sign in to comment.