Skip to content

Commit

Permalink
feat(AvaritiaClient): add rainbow color effect to Eternal Singularity…
Browse files Browse the repository at this point in the history
… 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
cnlimiter committed Jun 13, 2024
1 parent 02929d6 commit e50cb3f
Show file tree
Hide file tree
Showing 23 changed files with 617 additions and 37 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: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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "avaritia:infinity_catalyst_craft",
"category": "misc",
"group": "default",
"ingredients": [
{
"item": "minecraft:emerald_block"
Expand Down
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"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"category": "misc",
"key": {
"c": {
"tag": "forge:ores/coal"
"tag": "forge:storage_blocks/coal"
},
"x": {
"item": "avaritia:infinity_catalyst"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"values": [
"avaritia:singularity"
"avaritia:singularity",
"avaritia:eternal_singularity"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModMenus;
import committee.nova.mods.avaritia.init.registry.ModTileEntities;
import committee.nova.mods.avaritia.util.client.ColorUtils;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.RenderLayerParent;
Expand Down Expand Up @@ -49,6 +50,10 @@ public static void registerEntityLayerDefinitions(EntityRenderersEvent.RegisterL
@SubscribeEvent
public static void onItemColors(RegisterColorHandlersEvent.Item event) {
event.register(new IColored.ItemColors(), ModItems.singularity.get());
event.register(
(stack, index) -> getCurrentRainbowColor(),
ModItems.eternal_singularity.get()
);
}

@SubscribeEvent
Expand All @@ -72,4 +77,9 @@ private static void addLayer(final EntityRenderersEvent.AddLayers e, final Strin
final LivingEntityRenderer entityRenderer = e.getSkin(s);
entityRenderer.addLayer(new InfinityArmorModel.PlayerRender((RenderLayerParent<Player, PlayerModel<Player>>)entityRenderer));
}

public static int getCurrentRainbowColor() {
var hue = (System.currentTimeMillis() % 18000) / 18000F;
return ColorUtils.HSBToRGB(hue, 1, 1);
}
}
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);
}
}
}
}
Loading

0 comments on commit e50cb3f

Please sign in to comment.