Start moving advancements to datagen

This commit is contained in:
modmuss50 2023-05-13 23:02:34 +01:00 committed by modmuss
parent 53a299b12a
commit 628d949c60
9 changed files with 228 additions and 171 deletions

View file

@ -29,6 +29,7 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
import net.minecraft.registry.RegistryBuilder
import net.minecraft.registry.RegistryKeys
import techreborn.TechReborn
import techreborn.datagen.advancement.TRAdvancementProvider
import techreborn.datagen.loottables.BlockLootTableProvider
import techreborn.datagen.models.ModelProvider
import techreborn.datagen.recipes.crafting.CraftingRecipesProvider
@ -85,6 +86,7 @@ class TechRebornDataGen implements DataGeneratorEntrypoint {
add BlockLootTableProvider::new
add TRDynamicProvider::new
add TRAdvancementProvider::new
}
@Override

View file

@ -0,0 +1,99 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2023 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.datagen.advancement
import net.minecraft.advancement.Advancement
import net.minecraft.advancement.AdvancementFrame
import net.minecraft.advancement.criterion.CriterionConditions
import net.minecraft.item.ItemConvertible
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import net.minecraft.util.Identifier
class AdvancementFactory {
private String name
private ItemStack icon
private AdvancementFrame frame = AdvancementFrame.TASK
private List<CriterionConditions> conditionsList = []
private Advancement parent
private Identifier background
void name(String name) {
this.name = name
}
void icon(ItemStack icon) {
this.icon = icon
}
void icon(ItemConvertible item) {
icon new ItemStack(item)
}
void frame(AdvancementFrame frame) {
this.frame = frame
}
void condition(CriterionConditions condition) {
this.conditionsList << condition
}
void parent(Advancement advancement) {
this.parent = advancement
}
void background(Identifier identifier) {
this.background = identifier
}
Advancement build() {
Objects.requireNonNull(name, "No name set")
assert conditionsList.size() > 0
def builder = Advancement.Builder.createUntelemetered()
builder.display(
icon,
Text.translatable("advancements.techreborn.${name}"),
Text.translatable("advancements.techreborn.${name}.desc"),
background,
frame,
true,
true,
false
)
int i = 0
conditionsList.forEach {
builder.criterion("crit_${i++}", it)
}
if (parent != null) {
builder.parent(parent)
}
return builder.build(new Identifier("techreborn:${name}"))
}
}

View file

@ -0,0 +1,127 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2023 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.datagen.advancement
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput
import net.fabricmc.fabric.api.datagen.v1.provider.FabricAdvancementProvider
import net.minecraft.advancement.Advancement
import net.minecraft.advancement.AdvancementFrame
import net.minecraft.advancement.criterion.CriterionConditions
import net.minecraft.advancement.criterion.InventoryChangedCriterion
import net.minecraft.advancement.criterion.ItemCriterion
import net.minecraft.block.Block
import net.minecraft.item.Item
import net.minecraft.item.ItemConvertible
import net.minecraft.predicate.item.ItemPredicate
import net.minecraft.registry.RegistryWrapper
import net.minecraft.registry.tag.TagKey
import net.minecraft.util.Identifier
import techreborn.init.TRContent
import java.util.concurrent.CompletableFuture
import java.util.function.Consumer
class TRAdvancementProvider extends FabricAdvancementProvider {
private Consumer<Advancement> consumer
public TRAdvancementProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output)
}
@Override
void generateAdvancement(Consumer<Advancement> consumer) {
this.consumer = consumer
def root = create {
name "root"
icon TRContent.MANUAL
background new Identifier("techreborn:textures/block/storage/steel_storage_block.png")
condition inventoryChanged(TRContent.ItemTags.ORES)
condition inventoryChanged(TRContent.ItemTags.RAW_METALS)
condition inventoryChanged(TRContent.ItemTags.GEMS)
}
refinedIronTree(root)
}
private void refinedIronTree(Advancement root) {
def refinediron = create {
parent root
name "refinediron"
icon TRContent.Ingots.REFINED_IRON
condition inventoryChanged(TRContent.Ingots.REFINED_IRON)
}
def alarm = create {
parent refinediron
name "alarm"
icon TRContent.Machine.ALARM
condition inventoryChanged(TRContent.Machine.ALARM)
}
def machineBlock = create {
parent refinediron
name "machineblock"
icon TRContent.MachineBlocks.BASIC.frame
condition inventoryChanged(TRContent.MachineBlocks.BASIC.frame)
}
def generator = create {
parent machineBlock
name "generator"
icon TRContent.Machine.SOLID_FUEL_GENERATOR
condition placedBlock(TRContent.Machine.SOLID_FUEL_GENERATOR.block)
}
def windmill = create {
parent generator
name "windmill"
frame AdvancementFrame.GOAL
icon TRContent.Machine.WIND_MILL
condition placedBlock(TRContent.Machine.WIND_MILL.block)
}
}
private static CriterionConditions placedBlock(Block block) {
return ItemCriterion.Conditions.createPlacedBlock(block)
}
private static CriterionConditions inventoryChanged(ItemConvertible... items) {
return InventoryChangedCriterion.Conditions.items(items)
}
private static CriterionConditions inventoryChanged(TagKey<Item> tag) {
return InventoryChangedCriterion.Conditions.items(ItemPredicate.Builder.create().tag(tag).build())
}
private Advancement create(@DelegatesTo(value = AdvancementFactory.class) Closure closure) {
def factory = new AdvancementFactory()
closure.setDelegate(factory)
closure.call(factory)
def advancement = factory.build()
consumer.accept(advancement)
return advancement
}
}

View file

@ -1,22 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:alarm"
},
"title": {
"translate": "advancements.techreborn.alarm"
},
"description": {
"translate": "advancements.techreborn.alarm.desc"
}
},
"parent": "techreborn:refined_iron",
"criteria": {
"crit1": {
"trigger": "minecraft:placed_block",
"conditions": {
"block": "techreborn:alarm"
}
}
}
}

View file

@ -1,22 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:solid_fuel_generator"
},
"title": {
"translate": "advancements.techreborn.generator"
},
"description": {
"translate": "advancements.techreborn.generator.desc"
}
},
"parent": "techreborn:machineblock",
"criteria": {
"crit1": {
"trigger": "minecraft:placed_block",
"conditions": {
"block": "techreborn:solid_fuel_generator"
}
}
}
}

View file

@ -1,26 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:basic_machine_frame"
},
"title": {
"translate": "advancements.techreborn.machineblock"
},
"description": {
"translate": "advancements.techreborn.machineblock.desc"
}
},
"parent": "techreborn:refined_iron",
"criteria": {
"crit1": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:basic_machine_frame"]
}
]
}
}
}
}

View file

@ -1,27 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:refined_iron_ingot"
},
"title": {
"translate": "advancements.techreborn.refinediron"
},
"description": {
"translate": "advancements.techreborn.refinediron.desc"
}
},
"parent": "techreborn:root",
"criteria": {
"crit1": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:refined_iron_ingot"]
}
]
}
}
}
}

View file

@ -1,51 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:manual"
},
"title": {
"translate": "advancements.techreborn.root"
},
"description": {
"translate": "advancements.techreborn.root.desc"
},
"background": "techreborn:textures/block/storage/steel_storage_block.png",
"show_toast": true,
"announce_to_chat": true
},
"criteria": {
"ore_in_inventory": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"tag": "techreborn:ores"
}
]
}
},
"raw_metal_in_inventory": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"tag": "techreborn:raw_metals"
}
]
}
},
"gem_in_inventory": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"tag": "techreborn:gems"
}
]
}
}
},
"requirements": [
["ore_in_inventory", "raw_metal_in_inventory","gem_in_inventory"]
]
}

View file

@ -1,23 +0,0 @@
{
"display": {
"icon": {
"item": "techreborn:wind_mill"
},
"title": {
"translate": "advancements.techreborn.windmill"
},
"description": {
"translate": "advancements.techreborn.windmill.desc"
},
"frame": "goal"
},
"parent": "techreborn:generator",
"criteria": {
"crit1": {
"trigger": "minecraft:placed_block",
"conditions": {
"block": "techreborn:wind_mill"
}
}
}
}