Skip to content

Commit

Permalink
+ fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Sep 16, 2023
1 parent 6cdd294 commit e98a44c
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_item": {
"conditions": {
"items": [
{
"items": [
"avaritia:neutron_ingot"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "avaritia:infinity_catalyst"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_item",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"avaritia:infinity_catalyst"
]
},
"sends_telemetry_event": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "misc",
"key": {
"x": {
"item": "avaritia:crystal_matrix_ingot"
"item": "avaritia:crystal_matrix"
},
"y": {
"item": "avaritia:double_compressed_crafting_table"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "avaritia:infinity_catalyst_craft",
"category": "misc",
"ingredients": [
{
"item": "minecraft:emerald_block"
},
{
"item": "avaritia:crystal_matrix_ingot"
},
{
"item": "avaritia:neutron_ingot"
},
{
"item": "avaritia:cosmic_meatballs"
},
{
"item": "avaritia:ultimate_stew"
},
{
"item": "avaritia:endest_pearl"
},
{
"item": "avaritia:record_fragment"
}
],
"result": {
"item": "avaritia:infinity_catalyst"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package committee.nova.mods.avaritia.common.crafting.recipe;
package committee.nova.mods.avaritia.api.common.crafting;

import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package committee.nova.mods.avaritia.common.crafting.recipe;
package committee.nova.mods.avaritia.api.common.crafting;

import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package committee.nova.mods.avaritia.common.crafting.recipe;
package committee.nova.mods.avaritia.api.common.crafting;

import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package committee.nova.mods.avaritia.common.crafting.recipe;

import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.api.common.crafting.ICompressorRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
import net.minecraft.core.NonNullList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package committee.nova.mods.avaritia.common.crafting.recipe;

import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.init.handler.SingularityRegistryHandler;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.util.SingularityUtils;
import net.minecraft.core.NonNullList;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;

/**
* Name: Avaritia-forge / InfinityCatalystRecipe
* Author: cnlimiter
* CreateTime: 2023/9/16 17:19
* Description:
*/

public class InfinityCatalystCraftRecipe extends ShapelessExtremeCraftingRecipe{
private boolean ingredientsLoaded = false;
public InfinityCatalystCraftRecipe(ResourceLocation recipeId, NonNullList<Ingredient> inputs) {
super(recipeId, inputs, new ItemStack(ModItems.infinity_catalyst.get()));
}

@Override
public @NotNull NonNullList<Ingredient> getIngredients() {
if (!this.ingredientsLoaded) {
SingularityRegistryHandler.getInstance().getSingularities()
.stream()
.filter(singularity -> singularity.getIngredient() != Ingredient.EMPTY)
.limit(74)
.map(SingularityUtils::getItemForSingularity)
.map(Ingredient::of)
.forEach(super.getIngredients()::add);

this.ingredientsLoaded = true;
}
return super.getIngredients();
}

@Override
public boolean matches(IItemHandler inventory) {
var ingredients = this.getIngredients();
return !ingredients.isEmpty() && super.matches(inventory);
}

@Override
public @NotNull RecipeSerializer<?> getSerializer() {
return ModRecipeSerializers.INFINITY_SERIALIZER.get();
}

public static class Serializer implements RecipeSerializer<InfinityCatalystCraftRecipe> {
@Override
public @NotNull InfinityCatalystCraftRecipe fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject json) {
NonNullList<Ingredient> inputs = NonNullList.create();
var ingredients = GsonHelper.getAsJsonArray(json, "ingredients");

for (int i = 0; i < ingredients.size(); i++) {
inputs.add(Ingredient.fromJson(ingredients.get(i)));
}
return new InfinityCatalystCraftRecipe(recipeId, inputs);
}

@Override
public InfinityCatalystCraftRecipe fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) {
int size = buffer.readVarInt();
var inputs = NonNullList.withSize(size, Ingredient.EMPTY);

for (int i = 0; i < size; ++i) {
inputs.set(i, Ingredient.fromNetwork(buffer));
}
return new InfinityCatalystCraftRecipe(recipeId, inputs);
}

@Override
public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull InfinityCatalystCraftRecipe recipe) {
buffer.writeVarInt(recipe.inputs.size());

for (var ingredient : recipe.inputs) {
ingredient.toNetwork(buffer);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
import net.minecraft.core.NonNullList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package committee.nova.mods.avaritia.common.crafting.recipe;

import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
import net.minecraft.core.NonNullList;
Expand Down Expand Up @@ -33,7 +35,7 @@
*/
public class ShapelessExtremeCraftingRecipe implements ISpecialRecipe, ICraftRecipe {
private final ResourceLocation recipeId;
private final NonNullList<Ingredient> inputs;
public final NonNullList<Ingredient> inputs;
private final ItemStack output;
private Map<Integer, Function<ItemStack, ItemStack>> transformers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package committee.nova.mods.avaritia.init.compat.jei.category;

import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.common.crafting.recipe.ICompressorRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ICompressorRecipe;
import committee.nova.mods.avaritia.init.registry.ModBlocks;
import committee.nova.mods.avaritia.init.registry.ModTooltips;
import committee.nova.mods.avaritia.util.lang.Localizable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package committee.nova.mods.avaritia.init.compat.jei.category;

import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.common.crafting.recipe.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapedExtremeCraftingRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapelessExtremeCraftingRecipe;
import committee.nova.mods.avaritia.init.compat.jei.JeiCompat;
Expand Down
Loading

0 comments on commit e98a44c

Please sign in to comment.