Skip to content

Commit

Permalink
refactor(工艺): 重构无穷催化剂和永恒奇点的配方系统
Browse files Browse the repository at this point in the history
- 新增 CraftTweaker 兼容类 CraftingOthers,用于处理特殊配方
- 修改 CraftingTable 类,使其仅处理基础工作台配方
- 更新 EternalSingularityCraftRecipe 和 InfinityCatalystCraftRecipe 的配方类型为 CRAFTING_OTHERS_RECIPE
- 在 KubeJSAvaritiaPlugin 中注册永恒奇点合成的配方序列化器
- 新增 ModRecipeTypes.CRAFTING_OTHERS_RECIPE 配方类型
  • Loading branch information
cnlimiter committed Dec 14, 2024
1 parent 4ab705a commit 4aa7a3c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean canCraftInDimensions(int width, int height) {

@Override
public @NotNull RecipeType<?> getType() {
return ModRecipeTypes.CRAFTING_TABLE_RECIPE.get();
return ModRecipeTypes.CRAFTING_OTHERS_RECIPE.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean canCraftInDimensions(int width, int height) {

@Override
public @NotNull RecipeType<?> getType() {
return ModRecipeTypes.CRAFTING_TABLE_RECIPE.get();
return ModRecipeTypes.CRAFTING_OTHERS_RECIPE.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package committee.nova.mods.avaritia.init.compat.crafttweaker;

import com.blamejared.crafttweaker.api.CraftTweakerAPI;
import com.blamejared.crafttweaker.api.CraftTweakerConstants;
import com.blamejared.crafttweaker.api.action.recipe.ActionAddRecipe;
import com.blamejared.crafttweaker.api.action.recipe.ActionRemoveRecipe;
import com.blamejared.crafttweaker.api.annotation.ZenRegister;
import com.blamejared.crafttweaker.api.ingredient.IIngredient;
import com.blamejared.crafttweaker.api.item.IItemStack;
import com.blamejared.crafttweaker.api.item.MCItemStack;
import com.blamejared.crafttweaker.api.recipe.manager.base.IRecipeManager;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.InfinityCatalystCraftRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import org.openzen.zencode.java.ZenCodeType;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
* Description:
* Author: cnlimiter
* Date: 2022/5/17 8:39
* Version: 1.0
*/
@ZenCodeType.Name("mods.avaritia.CraftingOthers")
@ZenRegister
public class CraftingOthers implements IRecipeManager<ISpecialRecipe> {
private static final CraftingOthers INSTANCE = new CraftingOthers();

@ZenCodeType.Method
public static void addCatalyst(String name, IIngredient[] inputs) {
var id = CraftTweakerConstants.rl(INSTANCE.fixRecipeName(name));
var recipe = new InfinityCatalystCraftRecipe(id, "default", toIngredientsList(inputs));

recipe.setTransformers((slot, stack) -> inputs[slot].getRemainingItem(new MCItemStack(stack)).getInternal());

CraftTweakerAPI.apply(new ActionAddRecipe<>(INSTANCE, (ISpecialRecipe)recipe));
}

@ZenCodeType.Method
public static void remove(IItemStack stack) {
CraftTweakerAPI.apply(new ActionRemoveRecipe<>(INSTANCE, recipe -> recipe.getResultItem(RegistryAccess.EMPTY).is(stack.getInternal().getItem())));
}

private static NonNullList<Ingredient> toIngredientsList(IIngredient... ingredients) {
return Arrays.stream(ingredients)
.map(IIngredient::asVanillaIngredient)
.collect(Collectors.toCollection(NonNullList::create));
}

@Override
public RecipeType<ISpecialRecipe> getRecipeType() {
return ModRecipeTypes.CRAFTING_OTHERS_RECIPE.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.blamejared.crafttweaker.api.recipe.manager.base.IRecipeManager;
import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.BaseTableCraftingRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.InfinityCatalystCraftRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapedTableCraftingRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapelessTableCraftingRecipe;
Expand All @@ -32,7 +33,7 @@
*/
@ZenCodeType.Name("mods.avaritia.CraftingTable")
@ZenRegister
public class CraftingTable implements IRecipeManager<ISpecialRecipe> {
public class CraftingTable implements IRecipeManager<BaseTableCraftingRecipe> {
private static final CraftingTable INSTANCE = new CraftingTable();

@ZenCodeType.Method
Expand Down Expand Up @@ -86,16 +87,6 @@ public static void addShapeless(String name, int tier, IItemStack output, IIngre
CraftTweakerAPI.apply(new ActionAddRecipe<>(INSTANCE, recipe));
}

@ZenCodeType.Method
public static void addCatalyst(String name, IIngredient[] inputs) {
var id = CraftTweakerConstants.rl(INSTANCE.fixRecipeName(name));
var recipe = new InfinityCatalystCraftRecipe(id, "default", toIngredientsList(inputs));

recipe.setTransformers((slot, stack) -> inputs[slot].getRemainingItem(new MCItemStack(stack)).getInternal());

CraftTweakerAPI.apply(new ActionAddRecipe<>(INSTANCE, recipe));
}

@ZenCodeType.Method
public static void remove(IItemStack stack) {
CraftTweakerAPI.apply(new ActionRemoveRecipe<>(INSTANCE, recipe -> recipe.getResultItem(RegistryAccess.EMPTY).is(stack.getInternal().getItem())));
Expand All @@ -108,7 +99,7 @@ private static NonNullList<Ingredient> toIngredientsList(IIngredient... ingredie
}

@Override
public RecipeType<ISpecialRecipe> getRecipeType() {
public RecipeType<BaseTableCraftingRecipe> getRecipeType() {
return ModRecipeTypes.CRAFTING_TABLE_RECIPE.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public void registerRecipeSchemas(RegisterRecipeSchemasEvent event) {
event.register(ModRecipeSerializers.SHAPELESS_CRAFT_SERIALIZER.getId(), ShapelessTableRecipeSchema.SCHEMA);
event.register(ModRecipeSerializers.COMPRESSOR_SERIALIZER.getId(), CompressRecipeSchema.SCHEMA);
event.register(ModRecipeSerializers.INFINITY_CATALYST_CRAFT_SERIALIZER.getId(), InfinityCatalystRecipeSchema.SCHEMA);
event.register(ModRecipeSerializers.ETERNAL_SINGULARITY_CRAFT_SERIALIZER.getId(), InfinityCatalystRecipeSchema.SCHEMA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ModRecipeTypes {
public static final DeferredRegister<RecipeType<?>> RECIPES = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, Static.MOD_ID);

public static final @NotNull RegistryObject<RecipeType<BaseTableCraftingRecipe>> CRAFTING_TABLE_RECIPE = recipe("crafting_table_recipe", () -> RecipeType.simple(new ResourceLocation(Static.MOD_ID, "crafting_table_recipe")));
public static final @NotNull RegistryObject<RecipeType<ISpecialRecipe>> CRAFTING_OTHERS_RECIPE = recipe("crafting_others_recipe", () -> RecipeType.simple(new ResourceLocation(Static.MOD_ID, "crafting_others_recipe")));
public static final @NotNull RegistryObject<RecipeType<ICompressorRecipe>> COMPRESSOR_RECIPE = recipe("compressor_recipe", () -> RecipeType.simple(new ResourceLocation(Static.MOD_ID, "compressor_recipe")));


Expand Down

0 comments on commit 4aa7a3c

Please sign in to comment.