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:
WayofTime 2020-10-27 10:40:39 -04:00
parent f9327d8f5a
commit f0d62b997a
12 changed files with 634 additions and 16 deletions

View file

@ -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"));
}
}

View file

@ -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);
}
}