ARC Recipe Framework Part 1

Added the serializers, deserializers, builders, etc, for the Alchemical Reaction Chamber recipe, ARCRecipe. The block does not currently have the functionality to use it yet.

And only when I am currently writing this do I realize I forgot to add FluidStack functionality to the recipes. Welp.
This commit is contained in:
WayofTime 2020-10-26 21:48:53 -04:00
parent 152525bbe3
commit f9327d8f5a
21 changed files with 556 additions and 39 deletions

View file

@ -0,0 +1,40 @@
package wayoftime.bloodmagic.common.data;
import java.nio.file.Path;
import net.minecraft.data.BlockTagsProvider;
import net.minecraft.data.DataGenerator;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.data.ExistingFileHelper;
import wayoftime.bloodmagic.BloodMagic;
public class GeneratorBlockTags extends BlockTagsProvider
{
public GeneratorBlockTags(DataGenerator generatorIn, ExistingFileHelper exFileHelper)
{
super(generatorIn, BloodMagic.MODID, exFileHelper);
}
@Override
public void registerTags()
{
}
/**
* Resolves a Path for the location to save the given tag.
*/
@Override
protected Path makePath(ResourceLocation id)
{
return this.generator.getOutputFolder().resolve("data/" + id.getNamespace() + "/tags/blocks/" + id.getPath() + ".json");
}
/**
* Gets a name for this provider, to use in logging.
*/
@Override
public String getName()
{
return "Block Tags";
}
}

View file

@ -0,0 +1,48 @@
package wayoftime.bloodmagic.common.data;
import java.nio.file.Path;
import net.minecraft.data.BlockTagsProvider;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.ItemTagsProvider;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.data.ExistingFileHelper;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.common.tags.BloodMagicTags;
public class GeneratorItemTags extends ItemTagsProvider
{
public GeneratorItemTags(DataGenerator dataGenerator, BlockTagsProvider blockTagProvider, ExistingFileHelper existingFileHelper)
{
super(dataGenerator, blockTagProvider, BloodMagic.MODID, existingFileHelper);
}
@Override
public void registerTags()
{
this.getOrCreateBuilder(BloodMagicTags.ARC_TOOL).add(Items.DIAMOND);
// this.getOrCreateBuilder(GOORESISTANT).addTag(BlockTags.DOORS);
// this.getOrCreateBuilder(GOORESISTANT).addTag(BlockTags.BEDS);
// this.getOrCreateBuilder(GOORESISTANT).add(Blocks.PISTON, Blocks.PISTON_HEAD, Blocks.STICKY_PISTON, Blocks.MOVING_PISTON);
}
/**
* Resolves a Path for the location to save the given tag.
*/
@Override
protected Path makePath(ResourceLocation id)
{
return this.generator.getOutputFolder().resolve("data/" + id.getNamespace() + "/tags/items/" + id.getPath() + ".json");
}
/**
* Gets a name for this provider, to use in logging.
*/
@Override
public String getName()
{
return "Item Tags";
}
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import net.minecraft.data.DataGenerator;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.common.recipe.ARCRecipeProvider;
import wayoftime.bloodmagic.common.recipe.AlchemyArrayRecipeProvider;
import wayoftime.bloodmagic.common.recipe.BloodAltarRecipeProvider;
import wayoftime.bloodmagic.common.recipe.ISubRecipeProvider;
@ -20,6 +21,6 @@ public class BloodMagicRecipeProvider extends BaseRecipeProvider
@Override
protected List<ISubRecipeProvider> getSubRecipeProviders()
{
return Arrays.asList(new BloodAltarRecipeProvider(), new AlchemyArrayRecipeProvider(), new TartaricForgeRecipeProvider());
return Arrays.asList(new BloodAltarRecipeProvider(), new AlchemyArrayRecipeProvider(), new TartaricForgeRecipeProvider(), new ARCRecipeProvider());
}
}

View file

@ -0,0 +1,89 @@
package wayoftime.bloodmagic.common.data.recipe.builder;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.tuple.Pair;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import wayoftime.bloodmagic.api.SerializerHelper;
import wayoftime.bloodmagic.api.impl.recipe.RecipeARC;
import wayoftime.bloodmagic.common.data.recipe.BloodMagicRecipeBuilder;
import wayoftime.bloodmagic.util.Constants;
public class ARCRecipeBuilder extends BloodMagicRecipeBuilder<ARCRecipeBuilder>
{
private final Ingredient input;
private final Ingredient arcTool;
private final ItemStack output;
private final List<Pair<ItemStack, Double>> addedItems = new ArrayList<Pair<ItemStack, Double>>();
protected ARCRecipeBuilder(Ingredient input, Ingredient arcTool, ItemStack output)
{
super(bmSerializer("arc"));
this.input = input;
this.arcTool = arcTool;
this.output = output;
}
public static ARCRecipeBuilder arc(Ingredient input, Ingredient arcTool, ItemStack output)
{
return new ARCRecipeBuilder(input, arcTool, output);
}
public ARCRecipeBuilder addRandomOutput(ItemStack stack, double chance)
{
if (addedItems.size() >= RecipeARC.MAX_RANDOM_OUTPUTS)
{
return this;
}
addedItems.add(Pair.of(stack, chance));
return this;
}
@Override
protected ARCRecipeResult getResult(ResourceLocation id)
{
return new ARCRecipeResult(id);
}
public class ARCRecipeResult extends RecipeResult
{
protected ARCRecipeResult(ResourceLocation id)
{
super(id);
}
@Override
public void serialize(@Nonnull JsonObject json)
{
json.add(Constants.JSON.INPUT, input.serialize());
json.add(Constants.JSON.TOOL, arcTool.serialize());
if (addedItems.size() > 0)
{
JsonArray mainArray = new JsonArray();
for (Pair<ItemStack, Double> pair : addedItems)
{
JsonObject jsonObj = new JsonObject();
jsonObj.addProperty(Constants.JSON.CHANCE, pair.getValue().floatValue());
jsonObj.add(Constants.JSON.TYPE, SerializerHelper.serializeItemStack(pair.getKey()));
mainArray.add(jsonObj);
}
json.add(Constants.JSON.ADDEDOUTPUT, mainArray);
}
json.add(Constants.JSON.OUTPUT, SerializerHelper.serializeItemStack(output));
}
}
}