diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index d06adbc3..9bc7a5fb 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -20,7 +20,7 @@ org.eclipse.jdt.core.formatter.align_with_spaces=false org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=1 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=1 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=1 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=1 @@ -31,7 +31,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=0 org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=48 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 @@ -49,7 +49,7 @@ org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=1 org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0 org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=0 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 75896b7e..58e9535a 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -194,6 +194,8 @@ f38355165034ce314a9f0344ebc3a6cad22c76c8 data/bloodmagic/recipes/altar/reinforce 584d01dff4d64bb88bd3783751a29723700f1728 data/bloodmagic/recipes/altar/slate.json 926d4a0e165c87a15a609744d832d2f5f04a40d0 data/bloodmagic/recipes/altar/water_tool.json 7551501cf361667ec7454c307b9d2368536fbed6 data/bloodmagic/recipes/altar/weakbloodorb.json +4f511cfb93faf65aa50fabd7e753e0759ed95a1c data/bloodmagic/recipes/arc/test1.json +14e7bce6990a346e36171564c29f93a14e50df44 data/bloodmagic/recipes/arc/test2.json e1285ec51100f2336c1ea1a1a3057e74a0dd84d1 data/bloodmagic/recipes/array/airsigil.json d1ac23080f72f21adb5908befefe965ffb4efd4f data/bloodmagic/recipes/array/bloodlightsigil.json 1890706e5b93cd6df764b0419483c348e0d7f277 data/bloodmagic/recipes/array/divinationsigil.json @@ -231,3 +233,4 @@ c0e75e0e12290d191245c5b0b5b13bc739d2ff44 data/bloodmagic/recipes/soulforge/reage a222d09abf1ea61feb684f2ac23d011c2034f526 data/bloodmagic/recipes/soulforge/reagent_water.json 7e281841a2953c1284d332c2bbf75097f8128241 data/bloodmagic/recipes/soulforge/sentientsword.json d7d993bb729284a5201c164ea81fbe1d8e4e4750 data/bloodmagic/recipes/weak_activation_crystal.json +94ff722e094a3479433cad0e4a1386f68f170e7b data/bloodmagic/tags/items/arc_tool.json diff --git a/src/generated/resources/data/bloodmagic/recipes/arc/test1.json b/src/generated/resources/data/bloodmagic/recipes/arc/test1.json new file mode 100644 index 00000000..8e9d5d69 --- /dev/null +++ b/src/generated/resources/data/bloodmagic/recipes/arc/test1.json @@ -0,0 +1,20 @@ +{ + "type": "bloodmagic:arc", + "input": { + "tag": "forge:gems/diamond" + }, + "tool": { + "tag": "forge:bones" + }, + "addedoutput": [ + { + "chance": 0.5, + "type": { + "item": "minecraft:diamond" + } + } + ], + "output": { + "item": "bloodmagic:altar" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/bloodmagic/recipes/arc/test2.json b/src/generated/resources/data/bloodmagic/recipes/arc/test2.json new file mode 100644 index 00000000..8037c2b9 --- /dev/null +++ b/src/generated/resources/data/bloodmagic/recipes/arc/test2.json @@ -0,0 +1,12 @@ +{ + "type": "bloodmagic:arc", + "input": { + "tag": "forge:gems/diamond" + }, + "tool": { + "item": "minecraft:acacia_boat" + }, + "output": { + "item": "bloodmagic:altar" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/bloodmagic/tags/items/arc_tool.json b/src/generated/resources/data/bloodmagic/tags/items/arc_tool.json new file mode 100644 index 00000000..a0b7317d --- /dev/null +++ b/src/generated/resources/data/bloodmagic/tags/items/arc_tool.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "minecraft:diamond" + ] +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/BloodMagic.java b/src/main/java/WayofTime/bloodmagic/BloodMagic.java index 4b3aa5ce..491329e2 100644 --- a/src/main/java/WayofTime/bloodmagic/BloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/BloodMagic.java @@ -38,7 +38,9 @@ import wayoftime.bloodmagic.client.render.entity.SoulSnareRenderer; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; import wayoftime.bloodmagic.common.data.GeneratorBaseRecipes; import wayoftime.bloodmagic.common.data.GeneratorBlockStates; +import wayoftime.bloodmagic.common.data.GeneratorBlockTags; import wayoftime.bloodmagic.common.data.GeneratorItemModels; +import wayoftime.bloodmagic.common.data.GeneratorItemTags; import wayoftime.bloodmagic.common.data.GeneratorLanguage; import wayoftime.bloodmagic.common.data.GeneratorLootTable; import wayoftime.bloodmagic.common.data.recipe.BloodMagicRecipeProvider; @@ -117,7 +119,7 @@ public class BloodMagic private void registerRecipes(RegistryEvent.Register> event) { - System.out.println("Registering IngredientBloodOrb Serializer."); +// System.out.println("Registering IngredientBloodOrb Serializer."); CraftingHelper.register(IngredientBloodOrb.NAME, IngredientBloodOrb.Serializer.INSTANCE); // event.getRegistry().registerAll( @@ -171,6 +173,11 @@ public class BloodMagic gen.addProvider(new BloodMagicRecipeProvider(gen)); gen.addProvider(new GeneratorBaseRecipes(gen)); gen.addProvider(new GeneratorLootTable(gen)); + + GeneratorBlockTags bmBlockTags = new GeneratorBlockTags(gen, event.getExistingFileHelper()); + gen.addProvider(bmBlockTags); + gen.addProvider(new GeneratorItemTags(gen, bmBlockTags, event.getExistingFileHelper())); + } } diff --git a/src/main/java/WayofTime/bloodmagic/api/impl/recipe/RecipeBloodAltar.java b/src/main/java/WayofTime/bloodmagic/api/impl/recipe/RecipeBloodAltar.java index 8b8ab1c8..359c197b 100644 --- a/src/main/java/WayofTime/bloodmagic/api/impl/recipe/RecipeBloodAltar.java +++ b/src/main/java/WayofTime/bloodmagic/api/impl/recipe/RecipeBloodAltar.java @@ -14,7 +14,6 @@ import wayoftime.bloodmagic.altar.AltarTier; public abstract class RecipeBloodAltar extends BloodMagicRecipe { - @Nonnull private final Ingredient input; @Nonnull diff --git a/src/main/java/WayofTime/bloodmagic/core/recipe/IngredientBloodOrb.java b/src/main/java/WayofTime/bloodmagic/core/recipe/IngredientBloodOrb.java index 35962b33..ab607824 100644 --- a/src/main/java/WayofTime/bloodmagic/core/recipe/IngredientBloodOrb.java +++ b/src/main/java/WayofTime/bloodmagic/core/recipe/IngredientBloodOrb.java @@ -18,12 +18,6 @@ import wayoftime.bloodmagic.orb.BloodOrb; public class IngredientBloodOrb extends Ingredient { - -// private final BloodOrb orb; -// private NonNullList orbs; -// private IntList itemIds = null; -// private ItemStack[] items; - public static final ResourceLocation NAME = new ResourceLocation(BloodMagic.MODID, "bloodorb"); public final int orbTier; @@ -61,14 +55,8 @@ public class IngredientBloodOrb extends Ingredient @Override public Collection getStacks() { -// System.out.println("BING BONG"); List orbGet = OrbRegistry.getOrbsDownToTier(orbTier); -// List orbGet = new ArrayList(); -// orbGet.add(new ItemStack(Items.DIAMOND)); -// orbs = NonNullList.withSize(orbGet.size(), ItemStack.EMPTY); -// -// for (int i = 0; i < orbGet.size(); i++) -// orbs.set(i, orbGet.get(i)); + return orbGet; } @@ -89,24 +77,7 @@ public class IngredientBloodOrb extends Ingredient @Override public Ingredient parse(JsonObject json) { - System.out.println("Parsing Blood Orb"); return new IngredientBloodOrb(JSONUtils.getInt(json, "orb_tier")); } } - -// -// @Override -// public boolean test(@Nullable ItemStack input) -// { -// System.out.println("Testing"); -// if (input == null || input.isEmpty()) -// return false; -// -// if (!(input.getItem() instanceof IBloodOrb)) -// return false; -// -// BloodOrb orb = ((IBloodOrb) input.getItem()).getOrb(input); -// return orb != null && orb.getTier() >= this.orbTier; -// } - } diff --git a/src/main/java/WayofTime/bloodmagic/util/Constants.java b/src/main/java/WayofTime/bloodmagic/util/Constants.java index 7821f745..f682b1f1 100644 --- a/src/main/java/WayofTime/bloodmagic/util/Constants.java +++ b/src/main/java/WayofTime/bloodmagic/util/Constants.java @@ -133,8 +133,10 @@ public class Constants public static class JSON { public static final String INPUT = "input"; + public static final String TOOL = "tool"; public static final String BASEINPUT = "baseinput"; public static final String ADDEDINPUT = "addedinput"; + public static final String ADDEDOUTPUT = "addedoutput"; public static final String OUTPUT = "output"; public static final String ITEM = "item"; public static final String COUNT = "count"; @@ -142,6 +144,7 @@ public class Constants public static final String TYPE = "type"; public static final String TEXTURE = "texture"; public static final String CONDITIONS = "conditions"; + public static final String CHANCE = "chance"; public static final String ALTAR_TIER = Constants.NBT.ALTAR_TIER; public static final String ALTAR_SYPHON = "altarSyphon"; diff --git a/src/main/java/wayoftime/bloodmagic/api/impl/recipe/RecipeARC.java b/src/main/java/wayoftime/bloodmagic/api/impl/recipe/RecipeARC.java new file mode 100644 index 00000000..343cb038 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/api/impl/recipe/RecipeARC.java @@ -0,0 +1,110 @@ +package wayoftime.bloodmagic.api.impl.recipe; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import javax.annotation.Nonnull; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; + +public abstract class RecipeARC extends BloodMagicRecipe +{ + public static final int MAX_RANDOM_OUTPUTS = 3; + + @Nonnull + private final Ingredient input; + @Nonnull + private final Ingredient arc_tool; + @Nonnull + private final ItemStack output; + + private final List> addedItems; + + protected RecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, ItemStack output) + { + this(id, input, arc_tool, output, new ArrayList>()); + } + + protected RecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, ItemStack output, List> addedItems) + { + super(id); + this.input = input; + this.arc_tool = arc_tool; + this.output = output; + this.addedItems = addedItems; + } + + public RecipeARC addRandomOutput(ItemStack stack, double chance) + { + if (addedItems.size() >= MAX_RANDOM_OUTPUTS) + { + return this; + } + + addedItems.add(Pair.of(stack, chance)); + + return this; + } + + @Nonnull + public final Ingredient getInput() + { + return input; + } + + @Override + public final NonNullList getIngredients() + { + NonNullList list = NonNullList.create(); + list.add(getInput()); + return list; + } + + public List getAllListedOutputs() + { + List list = new ArrayList(); + + list.add(output.copy()); + for (Pair pair : addedItems) + { + list.add(pair.getLeft().copy()); + } + + return list; + } + + public List getAllOutputs(Random rand) + { + List list = new ArrayList(); + + list.add(output.copy()); + for (Pair pair : addedItems) + { + if (rand.nextDouble() < pair.getRight()) + list.add(pair.getLeft().copy()); + } + + return list; + } + + @Override + public void write(PacketBuffer buffer) + { + input.write(buffer); + arc_tool.write(buffer); + buffer.writeItemStack(output); + buffer.writeInt(addedItems.size()); + for (Pair pair : addedItems) + { + buffer.writeItemStack(pair.getLeft()); + buffer.writeDouble(pair.getValue()); + } + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockTags.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockTags.java new file mode 100644 index 00000000..f861928c --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockTags.java @@ -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"; + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemTags.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemTags.java new file mode 100644 index 00000000..7adb8e63 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemTags.java @@ -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"; + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/data/recipe/BloodMagicRecipeProvider.java b/src/main/java/wayoftime/bloodmagic/common/data/recipe/BloodMagicRecipeProvider.java index 9bbf2eed..5a46c06b 100644 --- a/src/main/java/wayoftime/bloodmagic/common/data/recipe/BloodMagicRecipeProvider.java +++ b/src/main/java/wayoftime/bloodmagic/common/data/recipe/BloodMagicRecipeProvider.java @@ -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 getSubRecipeProviders() { - return Arrays.asList(new BloodAltarRecipeProvider(), new AlchemyArrayRecipeProvider(), new TartaricForgeRecipeProvider()); + return Arrays.asList(new BloodAltarRecipeProvider(), new AlchemyArrayRecipeProvider(), new TartaricForgeRecipeProvider(), new ARCRecipeProvider()); } } diff --git a/src/main/java/wayoftime/bloodmagic/common/data/recipe/builder/ARCRecipeBuilder.java b/src/main/java/wayoftime/bloodmagic/common/data/recipe/builder/ARCRecipeBuilder.java new file mode 100644 index 00000000..fac5b7ee --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/data/recipe/builder/ARCRecipeBuilder.java @@ -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 +{ + private final Ingredient input; + private final Ingredient arcTool; + private final ItemStack output; + private final List> addedItems = new ArrayList>(); + + 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 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)); + } + } +} \ No newline at end of file diff --git a/src/main/java/wayoftime/bloodmagic/common/recipe/ARCRecipeProvider.java b/src/main/java/wayoftime/bloodmagic/common/recipe/ARCRecipeProvider.java new file mode 100644 index 00000000..89dc4a5d --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/recipe/ARCRecipeProvider.java @@ -0,0 +1,23 @@ +package wayoftime.bloodmagic.common.recipe; + +import java.util.function.Consumer; + +import net.minecraft.data.IFinishedRecipe; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.crafting.Ingredient; +import net.minecraftforge.common.Tags; +import wayoftime.bloodmagic.BloodMagic; +import wayoftime.bloodmagic.common.block.BloodMagicBlocks; +import wayoftime.bloodmagic.common.data.recipe.builder.ARCRecipeBuilder; + +public class ARCRecipeProvider implements ISubRecipeProvider +{ + @Override + public void addRecipes(Consumer 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")); + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/recipe/BloodMagicRecipeType.java b/src/main/java/wayoftime/bloodmagic/common/recipe/BloodMagicRecipeType.java index e8a99239..87a30fe4 100644 --- a/src/main/java/wayoftime/bloodmagic/common/recipe/BloodMagicRecipeType.java +++ b/src/main/java/wayoftime/bloodmagic/common/recipe/BloodMagicRecipeType.java @@ -1,6 +1,7 @@ package wayoftime.bloodmagic.common.recipe; import net.minecraft.item.crafting.IRecipeType; +import wayoftime.bloodmagic.api.impl.recipe.RecipeARC; import wayoftime.bloodmagic.api.impl.recipe.RecipeAlchemyArray; import wayoftime.bloodmagic.api.impl.recipe.RecipeBloodAltar; import wayoftime.bloodmagic.api.impl.recipe.RecipeTartaricForge; @@ -10,4 +11,5 @@ public class BloodMagicRecipeType public static final IRecipeType ALTAR = IRecipeType.register("altar"); public static final IRecipeType ARRAY = IRecipeType.register("array"); public static final IRecipeType TARTARICFORGE = IRecipeType.register("soulforge"); + public static final IRecipeType ARC = IRecipeType.register("arc"); } diff --git a/src/main/java/wayoftime/bloodmagic/common/recipe/serializer/ARCRecipeSerializer.java b/src/main/java/wayoftime/bloodmagic/common/recipe/serializer/ARCRecipeSerializer.java new file mode 100644 index 00000000..84481184 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/recipe/serializer/ARCRecipeSerializer.java @@ -0,0 +1,127 @@ +package wayoftime.bloodmagic.common.recipe.serializer; + +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.JsonElement; +import com.google.gson.JsonObject; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.JSONUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistryEntry; +import wayoftime.bloodmagic.api.SerializerHelper; +import wayoftime.bloodmagic.api.impl.recipe.RecipeARC; +import wayoftime.bloodmagic.util.Constants; + +public class ARCRecipeSerializer extends ForgeRegistryEntry> + implements IRecipeSerializer +{ + private final IFactory factory; + + public ARCRecipeSerializer(IFactory factory) + { + this.factory = factory; + } + + @Nonnull + @Override + public RECIPE read(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) + { + JsonElement input = JSONUtils.isJsonArray(json, Constants.JSON.INPUT) + ? JSONUtils.getJsonArray(json, Constants.JSON.INPUT) + : JSONUtils.getJsonObject(json, Constants.JSON.INPUT); + + JsonElement tool = JSONUtils.isJsonArray(json, Constants.JSON.TOOL) + ? JSONUtils.getJsonArray(json, Constants.JSON.TOOL) + : JSONUtils.getJsonObject(json, Constants.JSON.TOOL); + + Ingredient inputIng = Ingredient.deserialize(input); + Ingredient toolIng = Ingredient.deserialize(tool); + ItemStack output = SerializerHelper.getItemStack(json, Constants.JSON.OUTPUT); + + List> addedItems = new ArrayList>(); + if (json.has(Constants.JSON.ADDEDOUTPUT) && JSONUtils.isJsonArray(json, Constants.JSON.ADDEDOUTPUT)) + { + JsonArray mainArray = JSONUtils.getJsonArray(json, Constants.JSON.ADDEDOUTPUT); + + arrayLoop: for (JsonElement element : mainArray) + { + if (addedItems.size() >= RecipeARC.MAX_RANDOM_OUTPUTS) + { + break arrayLoop; + } + if (element.isJsonObject()) + { + JsonObject obj = element.getAsJsonObject(); + double chance = JSONUtils.getFloat(obj, Constants.JSON.CHANCE); + ItemStack extraDrop = SerializerHelper.getItemStack(obj, Constants.JSON.TYPE); + + addedItems.add(Pair.of(extraDrop, chance)); + } + } + } + + return this.factory.create(recipeId, inputIng, toolIng, output, addedItems); + } + + @Override + public RECIPE read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer) + { + try + { + List> addedItems = new ArrayList>(); + Ingredient inputIng = Ingredient.read(buffer); + Ingredient toolIng = Ingredient.read(buffer); + ItemStack output = buffer.readItemStack(); + + int addedItemSize = buffer.readInt(); + for (int i = 0; i < addedItemSize; i++) + { + ItemStack stack = buffer.readItemStack(); + double chance = buffer.readDouble(); + addedItems.add(Pair.of(stack, chance)); + } + + buffer.writeInt(addedItems.size()); + for (Pair pair : addedItems) + { + buffer.writeItemStack(pair.getLeft()); + buffer.writeDouble(pair.getValue()); + } + + return this.factory.create(recipeId, inputIng, toolIng, output, addedItems); + } catch (Exception e) + { +// Mekanism.logger.error("Error reading electrolysis recipe from packet.", e); + throw e; + } + } + + @Override + public void write(@Nonnull PacketBuffer buffer, @Nonnull RECIPE recipe) + { + try + { + recipe.write(buffer); + } catch (Exception e) + { +// Mekanism.logger.error("Error writing electrolysis recipe to packet.", e); + throw e; + } + } + + @FunctionalInterface + public interface IFactory + { + RECIPE create(ResourceLocation id, Ingredient input, Ingredient arcTool, ItemStack output, List> addedItems); + } +} \ No newline at end of file diff --git a/src/main/java/wayoftime/bloodmagic/common/registries/BloodMagicRecipeSerializers.java b/src/main/java/wayoftime/bloodmagic/common/registries/BloodMagicRecipeSerializers.java index 53f454d7..3aee8ab2 100644 --- a/src/main/java/wayoftime/bloodmagic/common/registries/BloodMagicRecipeSerializers.java +++ b/src/main/java/wayoftime/bloodmagic/common/registries/BloodMagicRecipeSerializers.java @@ -1,14 +1,17 @@ package wayoftime.bloodmagic.common.registries; import wayoftime.bloodmagic.BloodMagic; +import wayoftime.bloodmagic.api.impl.recipe.RecipeARC; import wayoftime.bloodmagic.api.impl.recipe.RecipeAlchemyArray; import wayoftime.bloodmagic.api.impl.recipe.RecipeBloodAltar; import wayoftime.bloodmagic.api.impl.recipe.RecipeTartaricForge; +import wayoftime.bloodmagic.common.recipe.serializer.ARCRecipeSerializer; import wayoftime.bloodmagic.common.recipe.serializer.AlchemyArrayRecipeSerializer; import wayoftime.bloodmagic.common.recipe.serializer.BloodAltarRecipeSerializer; import wayoftime.bloodmagic.common.recipe.serializer.TartaricForgeRecipeSerializer; import wayoftime.bloodmagic.common.registration.impl.IRecipeSerializerDeferredRegister; import wayoftime.bloodmagic.common.registration.impl.IRecipeSerializerRegistryObject; +import wayoftime.bloodmagic.recipe.IRecipeARC; import wayoftime.bloodmagic.recipe.IRecipeAlchemyArray; import wayoftime.bloodmagic.recipe.IRecipeBloodAltar; import wayoftime.bloodmagic.recipe.IRecipeTartaricForge; @@ -25,6 +28,7 @@ public class BloodMagicRecipeSerializers public static final IRecipeSerializerRegistryObject ALTAR = RECIPE_SERIALIZERS.register("altar", () -> new BloodAltarRecipeSerializer<>(IRecipeBloodAltar::new)); public static final IRecipeSerializerRegistryObject ARRAY = RECIPE_SERIALIZERS.register("array", () -> new AlchemyArrayRecipeSerializer<>(IRecipeAlchemyArray::new)); public static final IRecipeSerializerRegistryObject TARTARIC = RECIPE_SERIALIZERS.register("soulforge", () -> new TartaricForgeRecipeSerializer<>(IRecipeTartaricForge::new)); + public static final IRecipeSerializerRegistryObject ARC = RECIPE_SERIALIZERS.register("arc", () -> new ARCRecipeSerializer<>(IRecipeARC::new)); // public static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, BloodMagic.MODID); diff --git a/src/main/java/wayoftime/bloodmagic/common/tags/BloodMagicTags.java b/src/main/java/wayoftime/bloodmagic/common/tags/BloodMagicTags.java new file mode 100644 index 00000000..9953561f --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/tags/BloodMagicTags.java @@ -0,0 +1,12 @@ +package wayoftime.bloodmagic.common.tags; + +import net.minecraft.item.Item; +import net.minecraft.tags.ITag; +import net.minecraft.tags.ItemTags; + +public class BloodMagicTags +{ + public static final ITag.INamedTag ARC_TOOL = ItemTags.makeWrapperTag("bloodmagic:arc_tool"); + public static final ITag.INamedTag ARC_TOOL_FURNACE = ItemTags.makeWrapperTag("bloodmagic:arc_tool_furnace"); + public static final ITag.INamedTag ARC_TOOL_SIEVE = ItemTags.makeWrapperTag("bloodmagic:arc_tool_sieve"); +} diff --git a/src/main/java/wayoftime/bloodmagic/recipe/IRecipeARC.java b/src/main/java/wayoftime/bloodmagic/recipe/IRecipeARC.java new file mode 100644 index 00000000..6a388181 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/recipe/IRecipeARC.java @@ -0,0 +1,40 @@ +package wayoftime.bloodmagic.recipe; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.IRecipeType; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.util.ResourceLocation; +import wayoftime.bloodmagic.api.impl.recipe.RecipeARC; +import wayoftime.bloodmagic.common.recipe.BloodMagicRecipeType; +import wayoftime.bloodmagic.common.registries.BloodMagicRecipeSerializers; + +public class IRecipeARC extends RecipeARC +{ + public IRecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, ItemStack output) + { + super(id, input, arc_tool, output, new ArrayList>()); + } + + public IRecipeARC(ResourceLocation id, Ingredient input, Ingredient arc_tool, ItemStack output, List> addedItems) + { + super(id, input, arc_tool, output, addedItems); + } + + @Override + public IRecipeSerializer getSerializer() + { + return BloodMagicRecipeSerializers.ARC.getRecipeSerializer(); + } + + @Override + public IRecipeType getType() + { + return BloodMagicRecipeType.ARC; + } +} diff --git a/src/main/java/wayoftime/bloodmagic/tile/contailer/ContainerAlchemicalReactionChamber.java b/src/main/java/wayoftime/bloodmagic/tile/contailer/ContainerAlchemicalReactionChamber.java index 8b600788..01bd3506 100644 --- a/src/main/java/wayoftime/bloodmagic/tile/contailer/ContainerAlchemicalReactionChamber.java +++ b/src/main/java/wayoftime/bloodmagic/tile/contailer/ContainerAlchemicalReactionChamber.java @@ -14,7 +14,7 @@ import net.minecraft.network.PacketBuffer; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; -import wayoftime.bloodmagic.common.item.IARCTool; +import wayoftime.bloodmagic.common.tags.BloodMagicTags; import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber; public class ContainerAlchemicalReactionChamber extends Container @@ -88,7 +88,7 @@ public class ContainerAlchemicalReactionChamber extends Container slot.onSlotChange(itemstack1, itemstack); } else if (index > 9) // Attempting to transfer from main inventory { - if (itemstack1.getItem() instanceof IARCTool) // Try the tool slot first + if (itemstack1.getItem().isIn(BloodMagicTags.ARC_TOOL)) // Try the tool slot first { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { @@ -150,7 +150,7 @@ public class ContainerAlchemicalReactionChamber extends Container @Override public boolean isItemValid(ItemStack itemStack) { - return itemStack.getItem() instanceof IARCTool; + return itemStack.getItem().isIn(BloodMagicTags.ARC_TOOL); } }