-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AvaritiaClient): add rainbow color effect to Eternal Singularity…
… item- Implement a new getCurrentRainbowColor method in AvaritiaClient to generate a rainbow color effect for the Eternal Singularity item. - Register the Eternal Singularity item with a unique color in the item color handler event. - Refactor the DynamicRecipeHandler to load ingredients for the Eternal Singularity Craft Recipe dynamically. - Add a new EternalSingularityCraftRecipe class, corresponding item model, and recipe JSON files for the new recipe.- Update the ExtremeCraftingTableCategory and ExtremeTableCrafting scripts to include the Eternal Singularity recipe.- Modify the InfinityCatalystCraftRecipe to support a recipe group and ingredients loading.
- Loading branch information
Showing
23 changed files
with
617 additions
and
37 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...enerated/resources/data/avaritia/advancements/recipes/misc/infinity_catalyst_eternal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:eternal_singularity" | ||
] | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:inventory_changed" | ||
}, | ||
"has_the_recipe": { | ||
"conditions": { | ||
"recipe": "avaritia:infinity_catalyst_eternal" | ||
}, | ||
"trigger": "minecraft:recipe_unlocked" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_item", | ||
"has_the_recipe" | ||
] | ||
], | ||
"rewards": { | ||
"recipes": [ | ||
"avaritia:infinity_catalyst_eternal" | ||
] | ||
}, | ||
"sends_telemetry_event": true | ||
} |
1 change: 1 addition & 0 deletions
1
src/generated/resources/data/avaritia/recipes/infinity_catalyst.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/generated/resources/data/avaritia/recipes/infinity_catalyst_eternal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"type": "avaritia:infinity_catalyst_craft", | ||
"category": "misc", | ||
"group": "eternal_singularity", | ||
"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" | ||
}, | ||
{ | ||
"item": "avaritia:eternal_singularity" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/generated/resources/data/avaritia/tags/items/singularity.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"values": [ | ||
"avaritia:singularity" | ||
"avaritia:singularity", | ||
"avaritia:eternal_singularity" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
...va/committee/nova/mods/avaritia/common/crafting/recipe/EternalSingularityCraftRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package committee.nova.mods.avaritia.common.crafting.recipe; | ||
|
||
import com.google.gson.JsonObject; | ||
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe; | ||
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.init.registry.ModRecipeTypes; | ||
import committee.nova.mods.avaritia.util.SingularityUtils; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.Container; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraft.world.item.crafting.RecipeType; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.common.util.RecipeMatcher; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.wrapper.InvWrapper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* Name: Avaritia-forge / InfinityCatalystRecipe | ||
* Author: cnlimiter | ||
* CreateTime: 2023/9/16 17:19 | ||
* Description: | ||
*/ | ||
|
||
public class EternalSingularityCraftRecipe implements ISpecialRecipe{ | ||
private static boolean ingredientsLoaded = false; | ||
private final ResourceLocation recipeId; | ||
private final String group; | ||
public NonNullList<Ingredient> inputs; | ||
private BiFunction<Integer, ItemStack, ItemStack> transformers; | ||
|
||
public EternalSingularityCraftRecipe(ResourceLocation recipeId, String pGroup, NonNullList<Ingredient> inputs) { | ||
this.recipeId = recipeId; | ||
this.group = pGroup; | ||
this.inputs = inputs; | ||
} | ||
|
||
@Override | ||
public @NotNull String getGroup() { | ||
return this.group; | ||
} | ||
|
||
@Override | ||
public boolean canCraftInDimensions(int width, int height) { | ||
return width * height >= this.inputs.size(); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack getResultItem(@NotNull RegistryAccess pRegistryAccess) { | ||
return new ItemStack(ModItems.eternal_singularity.get()); | ||
} | ||
|
||
@Override | ||
public @NotNull NonNullList<Ingredient> getIngredients() { | ||
if (!ingredientsLoaded) { | ||
inputs.clear(); | ||
|
||
SingularityRegistryHandler.getInstance().getSingularities() | ||
.stream() | ||
.filter(singularity -> singularity.getIngredient() != Ingredient.EMPTY) | ||
.limit(81) | ||
.map(SingularityUtils::getItemForSingularity) | ||
.map(Ingredient::of) | ||
.forEach(inputs::add); | ||
|
||
ingredientsLoaded = true; | ||
} | ||
return this.inputs; | ||
} | ||
|
||
@Override | ||
public @NotNull ResourceLocation getId() { | ||
return this.recipeId; | ||
} | ||
|
||
@Override | ||
public @NotNull RecipeSerializer<?> getSerializer() { | ||
return ModRecipeSerializers.ETERNAL_SINGULARITY_CRAFT_SERIALIZER.get(); | ||
} | ||
|
||
@Override | ||
public @NotNull RecipeType<?> getType() { | ||
return ModRecipeTypes.EXTREME_CRAFT_RECIPE.get(); | ||
} | ||
|
||
@Override | ||
public ItemStack assemble(IItemHandler var1) { | ||
return new ItemStack(ModItems.eternal_singularity.get()); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack assemble(@NotNull Container inv, @NotNull RegistryAccess p_267052_) { | ||
return new ItemStack(ModItems.eternal_singularity.get()); | ||
} | ||
@Override | ||
public boolean matches(IItemHandler inventory) { | ||
List<ItemStack> inputs = new ArrayList<>(); | ||
int matched = 0; | ||
|
||
for (int i = 0; i < inventory.getSlots(); i++) { | ||
var stack = inventory.getStackInSlot(i); | ||
|
||
if (!stack.isEmpty()) { | ||
inputs.add(stack); | ||
|
||
matched++; | ||
} | ||
} | ||
|
||
return matched == this.inputs.size() && RecipeMatcher.findMatches(inputs, this.inputs) != null; | ||
} | ||
|
||
@Override | ||
public boolean matches(@NotNull Container inv, @NotNull Level level) { | ||
return this.matches(new InvWrapper(inv)); | ||
} | ||
|
||
@Override | ||
public @NotNull NonNullList<ItemStack> getRemainingItems(@NotNull IItemHandler inv) { | ||
var remaining = ISpecialRecipe.super.getRemainingItems(inv); | ||
|
||
if (this.transformers != null) { | ||
var used = new boolean[remaining.size()]; | ||
|
||
for (int i = 0; i < remaining.size(); i++) { | ||
var stack = inv.getStackInSlot(i); | ||
|
||
for (int j = 0; j < this.inputs.size(); j++) { | ||
var input = this.inputs.get(j); | ||
|
||
if (!used[j] && input.test(stack)) { | ||
var ingredient = this.transformers.apply(j, stack); | ||
|
||
used[j] = true; | ||
remaining.set(i, ingredient); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return remaining; | ||
} | ||
|
||
public void setTransformers(BiFunction<Integer, ItemStack, ItemStack> transformers) { | ||
this.transformers = transformers; | ||
} | ||
|
||
public static class Serializer implements RecipeSerializer<EternalSingularityCraftRecipe> { | ||
@Override | ||
public @NotNull EternalSingularityCraftRecipe fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject json) { | ||
String s = GsonHelper.getAsString(json, "group", ""); | ||
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 EternalSingularityCraftRecipe(recipeId, s, inputs); | ||
} | ||
|
||
@Override | ||
public EternalSingularityCraftRecipe fromNetwork(@NotNull ResourceLocation recipeId, @NotNull FriendlyByteBuf buffer) { | ||
String s = buffer.readUtf(); | ||
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 EternalSingularityCraftRecipe(recipeId, s, inputs); | ||
} | ||
|
||
@Override | ||
public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull EternalSingularityCraftRecipe recipe) { | ||
buffer.writeUtf(recipe.group); | ||
buffer.writeVarInt(recipe.inputs.size()); | ||
for (var ingredient : recipe.inputs) { | ||
ingredient.toNetwork(buffer); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.