Part 2 of ARC Recipe Implementation
Added the ability for FluidStacks to be used as inputs and outputs, with a bit of cribbing off of how Mekanism handled their FluidStackIngredient.
This commit is contained in:
parent
f9327d8f5a
commit
f0d62b997a
12 changed files with 634 additions and 16 deletions
|
@ -13,7 +13,9 @@ import com.google.gson.JsonObject;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import wayoftime.bloodmagic.api.SerializerHelper;
|
||||
import wayoftime.bloodmagic.api.event.recipes.FluidStackIngredient;
|
||||
import wayoftime.bloodmagic.api.impl.recipe.RecipeARC;
|
||||
import wayoftime.bloodmagic.common.data.recipe.BloodMagicRecipeBuilder;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
@ -22,20 +24,24 @@ public class ARCRecipeBuilder extends BloodMagicRecipeBuilder<ARCRecipeBuilder>
|
|||
{
|
||||
private final Ingredient input;
|
||||
private final Ingredient arcTool;
|
||||
private final FluidStackIngredient inputFluid;
|
||||
private final ItemStack output;
|
||||
private final FluidStack outputFluid;
|
||||
private final List<Pair<ItemStack, Double>> addedItems = new ArrayList<Pair<ItemStack, Double>>();
|
||||
|
||||
protected ARCRecipeBuilder(Ingredient input, Ingredient arcTool, ItemStack output)
|
||||
protected ARCRecipeBuilder(Ingredient input, Ingredient arcTool, FluidStackIngredient inputFluid, ItemStack output, FluidStack outputFluid)
|
||||
{
|
||||
super(bmSerializer("arc"));
|
||||
this.input = input;
|
||||
this.arcTool = arcTool;
|
||||
this.inputFluid = inputFluid;
|
||||
this.output = output;
|
||||
this.outputFluid = outputFluid;
|
||||
}
|
||||
|
||||
public static ARCRecipeBuilder arc(Ingredient input, Ingredient arcTool, ItemStack output)
|
||||
public static ARCRecipeBuilder arc(Ingredient input, Ingredient arcTool, FluidStackIngredient inputFluid, ItemStack output, FluidStack outputFluid)
|
||||
{
|
||||
return new ARCRecipeBuilder(input, arcTool, output);
|
||||
return new ARCRecipeBuilder(input, arcTool, inputFluid, output, outputFluid);
|
||||
}
|
||||
|
||||
public ARCRecipeBuilder addRandomOutput(ItemStack stack, double chance)
|
||||
|
@ -69,6 +75,9 @@ public class ARCRecipeBuilder extends BloodMagicRecipeBuilder<ARCRecipeBuilder>
|
|||
json.add(Constants.JSON.INPUT, input.serialize());
|
||||
json.add(Constants.JSON.TOOL, arcTool.serialize());
|
||||
|
||||
if (inputFluid != null)
|
||||
json.add(Constants.JSON.INPUT_FLUID, inputFluid.serialize());
|
||||
|
||||
if (addedItems.size() > 0)
|
||||
{
|
||||
JsonArray mainArray = new JsonArray();
|
||||
|
@ -83,6 +92,9 @@ public class ARCRecipeBuilder extends BloodMagicRecipeBuilder<ARCRecipeBuilder>
|
|||
json.add(Constants.JSON.ADDEDOUTPUT, mainArray);
|
||||
}
|
||||
|
||||
if (outputFluid != null)
|
||||
json.add(Constants.JSON.OUTPUT_FLUID, SerializerHelper.serializeFluidStack(outputFluid));
|
||||
|
||||
json.add(Constants.JSON.OUTPUT, SerializerHelper.serializeItemStack(output));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ package wayoftime.bloodmagic.common.recipe;
|
|||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.api.event.recipes.FluidStackIngredient;
|
||||
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
|
||||
import wayoftime.bloodmagic.common.data.recipe.builder.ARCRecipeBuilder;
|
||||
|
||||
|
@ -17,7 +20,7 @@ public class ARCRecipeProvider implements ISubRecipeProvider
|
|||
public void addRecipes(Consumer<IFinishedRecipe> consumer)
|
||||
{
|
||||
String basePath = "arc/";
|
||||
ARCRecipeBuilder.arc(Ingredient.fromTag(Tags.Items.GEMS_DIAMOND), Ingredient.fromTag(Tags.Items.BONES), new ItemStack(BloodMagicBlocks.BLOOD_ALTAR.get())).addRandomOutput(new ItemStack(Items.DIAMOND), 0.5).build(consumer, BloodMagic.rl(basePath + "test1"));
|
||||
ARCRecipeBuilder.arc(Ingredient.fromTag(Tags.Items.GEMS_DIAMOND), Ingredient.fromItems(Items.ACACIA_BOAT), new ItemStack(BloodMagicBlocks.BLOOD_ALTAR.get())).build(consumer, BloodMagic.rl(basePath + "test2"));
|
||||
ARCRecipeBuilder.arc(Ingredient.fromTag(Tags.Items.GEMS_DIAMOND), Ingredient.fromTag(Tags.Items.BONES), null, new ItemStack(BloodMagicBlocks.BLOOD_ALTAR.get()), null).addRandomOutput(new ItemStack(Items.DIAMOND), 0.5).build(consumer, BloodMagic.rl(basePath + "test1"));
|
||||
ARCRecipeBuilder.arc(Ingredient.fromTag(Tags.Items.GEMS_DIAMOND), Ingredient.fromItems(Items.ACACIA_BOAT), FluidStackIngredient.from(Fluids.LAVA, 1000), new ItemStack(BloodMagicBlocks.BLOOD_ALTAR.get()), new FluidStack(Fluids.WATER, 100)).build(consumer, BloodMagic.rl(basePath + "test2"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,10 @@ import net.minecraft.item.crafting.Ingredient;
|
|||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import wayoftime.bloodmagic.api.SerializerHelper;
|
||||
import wayoftime.bloodmagic.api.event.recipes.FluidStackIngredient;
|
||||
import wayoftime.bloodmagic.api.impl.recipe.RecipeARC;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
||||
|
@ -70,7 +72,24 @@ public class ARCRecipeSerializer<RECIPE extends RecipeARC> extends ForgeRegistry
|
|||
}
|
||||
}
|
||||
|
||||
return this.factory.create(recipeId, inputIng, toolIng, output, addedItems);
|
||||
FluidStackIngredient inputFluidIng = null;
|
||||
|
||||
if (json.has(Constants.JSON.INPUT_FLUID))
|
||||
{
|
||||
JsonElement inputFluid = JSONUtils.isJsonArray(json, Constants.JSON.INPUT_FLUID)
|
||||
? JSONUtils.getJsonArray(json, Constants.JSON.INPUT_FLUID)
|
||||
: JSONUtils.getJsonObject(json, Constants.JSON.INPUT_FLUID);
|
||||
inputFluidIng = FluidStackIngredient.deserialize(inputFluid);
|
||||
}
|
||||
|
||||
FluidStack outputFluid = null;
|
||||
|
||||
if (json.has(Constants.JSON.OUTPUT_FLUID))
|
||||
{
|
||||
outputFluid = SerializerHelper.deserializeFluid(json);
|
||||
}
|
||||
|
||||
return this.factory.create(recipeId, inputIng, toolIng, inputFluidIng, output, addedItems, outputFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,7 +117,20 @@ public class ARCRecipeSerializer<RECIPE extends RecipeARC> extends ForgeRegistry
|
|||
buffer.writeDouble(pair.getValue());
|
||||
}
|
||||
|
||||
return this.factory.create(recipeId, inputIng, toolIng, output, addedItems);
|
||||
FluidStackIngredient inputFluid = null;
|
||||
FluidStack outputFluid = null;
|
||||
|
||||
if (buffer.readBoolean())
|
||||
{
|
||||
inputFluid = FluidStackIngredient.read(buffer);
|
||||
}
|
||||
|
||||
if (buffer.readBoolean())
|
||||
{
|
||||
outputFluid = FluidStack.readFromPacket(buffer);
|
||||
}
|
||||
|
||||
return this.factory.create(recipeId, inputIng, toolIng, inputFluid, output, addedItems, outputFluid);
|
||||
} catch (Exception e)
|
||||
{
|
||||
// Mekanism.logger.error("Error reading electrolysis recipe from packet.", e);
|
||||
|
@ -122,6 +154,6 @@ public class ARCRecipeSerializer<RECIPE extends RecipeARC> extends ForgeRegistry
|
|||
@FunctionalInterface
|
||||
public interface IFactory<RECIPE extends RecipeARC>
|
||||
{
|
||||
RECIPE create(ResourceLocation id, Ingredient input, Ingredient arcTool, ItemStack output, List<Pair<ItemStack, Double>> addedItems);
|
||||
RECIPE create(ResourceLocation id, Ingredient input, Ingredient arcTool, FluidStackIngredient inputFluid, ItemStack output, List<Pair<ItemStack, Double>> addedItems, FluidStack outputFluid);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue