First look at data generated machine recipes.
Doesn't support all the features but should be a good start.
This commit is contained in:
parent
9e6b4385f6
commit
32368f8388
14 changed files with 380 additions and 150 deletions
|
@ -26,6 +26,7 @@ package techreborn.datagen
|
|||
|
||||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
|
||||
import techreborn.datagen.recipes.machine.grinder.GrinderRecipesProvider
|
||||
import techreborn.datagen.recipes.smelting.SmeltingRecipesProvider
|
||||
import techreborn.datagen.recipes.crafting.CraftingRecipesProvider
|
||||
import techreborn.datagen.tags.TRItemTagProvider
|
||||
|
@ -40,5 +41,7 @@ class TechRebornDataGen implements DataGeneratorEntrypoint {
|
|||
// tags before all else, very important!!
|
||||
fabricDataGenerator.addProvider(SmeltingRecipesProvider.&new)
|
||||
fabricDataGenerator.addProvider(CraftingRecipesProvider.&new)
|
||||
|
||||
fabricDataGenerator.addProvider(GrinderRecipesProvider.&new)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ import net.minecraft.item.ItemConvertible
|
|||
import net.minecraft.recipe.Ingredient
|
||||
import net.minecraft.tag.Tag
|
||||
import net.minecraft.util.Identifier
|
||||
import techreborn.datagen.recipes.machine.MachineRecipeJsonFactory
|
||||
|
||||
import techreborn.init.ModRecipes
|
||||
|
||||
import java.util.function.Consumer
|
||||
|
||||
|
@ -120,6 +123,10 @@ abstract class TechRebornRecipesProvider extends FabricRecipesProvider {
|
|||
throw new IllegalArgumentException()
|
||||
}
|
||||
|
||||
def offerGrinderRecipe(@DelegatesTo(value = MachineRecipeJsonFactory.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
|
||||
MachineRecipeJsonFactory.create(ModRecipes.GRINDER, closure).offerTo(exporter)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Identifier getRecipeIdentifier(Identifier identifier) {
|
||||
return new Identifier("techreborn", super.getRecipeIdentifier(identifier).path)
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020 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.recipes.machine
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemConvertible
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.tag.Tag
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient
|
||||
import reborncore.common.crafting.ingredient.StackIngredient
|
||||
import reborncore.common.crafting.ingredient.TagIngredient
|
||||
|
||||
class IngredientBuilder {
|
||||
private Tag.Identified<Item> tag
|
||||
private List<ItemStack> stacks = new ArrayList<>()
|
||||
|
||||
private IngredientBuilder() {
|
||||
}
|
||||
|
||||
static IngredientBuilder create() {
|
||||
return new IngredientBuilder()
|
||||
}
|
||||
|
||||
RebornIngredient build() {
|
||||
if (tag != null) {
|
||||
if (!stacks.isEmpty()) {
|
||||
throw new IllegalStateException("Cannot have ingredient with tag and stack inputs")
|
||||
}
|
||||
|
||||
return new TagIngredient(tag, getCount())
|
||||
}
|
||||
|
||||
if (!stacks.isEmpty()) {
|
||||
return new StackIngredient(stacks, getCount(), Optional.empty(), false)
|
||||
}
|
||||
|
||||
throw new IllegalStateException()
|
||||
}
|
||||
|
||||
def tag(Tag.Identified<Item> tag) {
|
||||
this.tag = tag
|
||||
return this
|
||||
}
|
||||
|
||||
def item(ItemConvertible itemConvertible) {
|
||||
return stack(new ItemStack(itemConvertible.asItem()))
|
||||
}
|
||||
|
||||
def stack(ItemStack itemStack) {
|
||||
stacks.add(itemStack)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
private Optional<Integer> getCount() {
|
||||
return Optional.empty()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020 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.recipes.machine
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import net.minecraft.data.server.recipe.RecipeJsonProvider
|
||||
import net.minecraft.item.ItemConvertible
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.recipe.RecipeSerializer
|
||||
import net.minecraft.tag.Tag
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.registry.Registry
|
||||
import reborncore.common.crafting.RebornRecipe
|
||||
import reborncore.common.crafting.RebornRecipeType
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient
|
||||
|
||||
import java.util.function.Consumer
|
||||
|
||||
class MachineRecipeJsonFactory<R extends RebornRecipe> {
|
||||
private final RebornRecipeType<R> type
|
||||
|
||||
private final List<RebornIngredient> ingredients = new ArrayList<>()
|
||||
private final List<ItemStack> outputs = new ArrayList<>()
|
||||
private int power = -1
|
||||
private int time = -1
|
||||
private Identifier customId = null
|
||||
|
||||
protected MachineRecipeJsonFactory(RebornRecipeType<R> type) {
|
||||
this.type = type
|
||||
}
|
||||
|
||||
static <R extends RebornRecipe> MachineRecipeJsonFactory<R> create(RebornRecipeType<R> type) {
|
||||
return new MachineRecipeJsonFactory<R>(type)
|
||||
}
|
||||
|
||||
static <R extends RebornRecipe> MachineRecipeJsonFactory<R> create(RebornRecipeType<R> type, @DelegatesTo(value = MachineRecipeJsonFactory.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
|
||||
def factory = new MachineRecipeJsonFactory<R>(type)
|
||||
closure.setDelegate(factory)
|
||||
closure.call(factory)
|
||||
return factory
|
||||
}
|
||||
|
||||
def ingredients(Object... objects) {
|
||||
for (object in objects) {
|
||||
if (object instanceof ItemConvertible) {
|
||||
ingredient {
|
||||
item object
|
||||
}
|
||||
} else if (object instanceof Tag.Identified) {
|
||||
ingredient {
|
||||
tag object
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
def ingredient(@DelegatesTo(value = IngredientBuilder.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
|
||||
def builder = IngredientBuilder.create()
|
||||
closure.setDelegate(builder)
|
||||
closure.call(builder)
|
||||
ingredients.add(builder.build())
|
||||
return this
|
||||
}
|
||||
|
||||
def outputs(Object... objects) {
|
||||
for (object in objects) {
|
||||
if (object instanceof ItemStack) {
|
||||
output(object)
|
||||
} else if (object instanceof ItemConvertible) {
|
||||
output(new ItemStack(object.asItem()))
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
def output(ItemStack stack) {
|
||||
outputs.add(stack)
|
||||
return this
|
||||
}
|
||||
|
||||
def power(int power) {
|
||||
this.power = power
|
||||
return this
|
||||
}
|
||||
|
||||
def time(int time) {
|
||||
this.time = time
|
||||
return this
|
||||
}
|
||||
|
||||
def id(Identifier identifier) {
|
||||
this.customId = identifier
|
||||
return this
|
||||
}
|
||||
|
||||
MachineRecipeJsonFactory id(String path) {
|
||||
return id(new Identifier("techreborn", path))
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to support custom recipe types.
|
||||
*/
|
||||
protected R createRecipe(Identifier identifier) {
|
||||
return new RebornRecipe(type, identifier, ingredients, outputs, power, time) as R
|
||||
}
|
||||
|
||||
protected void validate() {
|
||||
if (ingredients.isEmpty()) {
|
||||
throw new IllegalStateException("recipe has no ingrendients")
|
||||
}
|
||||
|
||||
if (outputs.isEmpty()) {
|
||||
throw new IllegalStateException("recipe has no outputs")
|
||||
}
|
||||
|
||||
if (power < 0) {
|
||||
throw new IllegalStateException("recipe has no power value")
|
||||
}
|
||||
|
||||
if (time < 0) {
|
||||
throw new IllegalStateException("recipe has no time value")
|
||||
}
|
||||
}
|
||||
|
||||
void offerTo(Consumer<RecipeJsonProvider> exporter) {
|
||||
validate()
|
||||
exporter.accept(new MachineRecipeJsonProvider<R>(type, createRecipe(getIdentifier())))
|
||||
}
|
||||
|
||||
def getIdentifier() {
|
||||
if (customId) {
|
||||
return customId
|
||||
}
|
||||
|
||||
if (outputs.size() < 1) {
|
||||
throw new IllegalStateException("Recipe has no outputs")
|
||||
}
|
||||
|
||||
if (outputs.size() > 1) {
|
||||
throw new IllegalStateException("Cannot compute default identifier for a recipe with more than one output. TODO might want to improve this?")
|
||||
}
|
||||
|
||||
def outputId = Registry.ITEM.getId(outputs[0].item)
|
||||
return new Identifier("techreborn", "${type.name().path}/${outputId.path}")
|
||||
}
|
||||
|
||||
static class MachineRecipeJsonProvider<R extends RebornRecipe> implements RecipeJsonProvider {
|
||||
private final RebornRecipeType<R> type
|
||||
private final R recipe
|
||||
|
||||
MachineRecipeJsonProvider(RebornRecipeType<R> type, R recipe) {
|
||||
this.type = type
|
||||
this.recipe = recipe
|
||||
}
|
||||
|
||||
@Override
|
||||
JsonObject toJson() {
|
||||
return type.toJson(recipe, false)
|
||||
}
|
||||
|
||||
@Override
|
||||
Identifier getRecipeId() {
|
||||
return recipe.id
|
||||
}
|
||||
|
||||
@Override
|
||||
void serialize(JsonObject json) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
RecipeSerializer<?> getSerializer() {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
JsonObject toAdvancementJson() {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
Identifier getAdvancementId() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020 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.recipes.machine.grinder
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
|
||||
import net.minecraft.item.Items
|
||||
import techreborn.datagen.recipes.TechRebornRecipesProvider
|
||||
import techreborn.init.TRContent
|
||||
|
||||
class GrinderRecipesProvider extends TechRebornRecipesProvider {
|
||||
GrinderRecipesProvider(FabricDataGenerator dataGenerator) {
|
||||
super(dataGenerator)
|
||||
}
|
||||
|
||||
@Override
|
||||
void generateRecipes() {
|
||||
// offerGrinderRecipe {
|
||||
// ingredients TRContent.ORES_TAG, Items.ACACIA_BOAT
|
||||
// outputs Items.DIAMOND
|
||||
// power 5
|
||||
// time 200
|
||||
// }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue