Skip to content

Commit

Permalink
Merge pull request #871 from dmzz-yyhyy/emi
Browse files Browse the repository at this point in the history
添加emi支持
  • Loading branch information
Gu-ZT authored Jun 10, 2024
2 parents aeb2ac9 + f9607dc commit 7472e01
Show file tree
Hide file tree
Showing 600 changed files with 2,172 additions and 874 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,62 @@

import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.init.ModRecipeTypes;
import lombok.Getter;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraft.world.item.crafting.SmokingRecipe;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class AnvilRecipeManager {
private static List<AnvilRecipe> ANVIL_RECIPE_SET = List.of();
@Getter
private static List<AnvilRecipe> anvilRecipeList = List.of();

/**
* 更新配方
*
* @param server 服务器实例
*/
public static void updateRecipes(MinecraftServer server) {
public static void updateRecipes(@NotNull MinecraftServer server) {
RecipeManager manager = server.getRecipeManager();
ArrayList<AnvilRecipe> anvilRecipes = new ArrayList<>(manager.getAllRecipesFor(ModRecipeTypes.ANVIL_RECIPE));
ArrayList<AnvilRecipe> smokingRecipes = new ArrayList<>();
ArrayList<AnvilRecipe> smeltingRecipes = new ArrayList<>();
manager.getAllRecipesFor(RecipeType.SMOKING).forEach(
smokingRecipe -> smokingRecipes.addAll(AnvilRecipe.of(smokingRecipe, server.registryAccess())));
manager.getAllRecipesFor(RecipeType.CAMPFIRE_COOKING).forEach(
campfireCookingRecipe ->
anvilRecipes.addAll(AnvilRecipe.of(campfireCookingRecipe, server.registryAccess())));
manager.getAllRecipesFor(RecipeType.BLASTING).forEach(
blastingRecipe ->
anvilRecipes.addAll(AnvilRecipe.of(blastingRecipe, server.registryAccess())));
manager.getAllRecipesFor(RecipeType.SMELTING).forEach(
smeltingRecipe -> {
List<AnvilRecipe> anvilRecipe =
AnvilRecipe.of(smeltingRecipe, server.registryAccess());
if (!anvilRecipe.isEmpty()
&& smokingRecipes.stream().noneMatch((smokingRecipe) ->
anvilRecipe.get(0).getResultItem(server.registryAccess())
.is(smokingRecipe.getResultItem(server.registryAccess()).getItem())))
smeltingRecipes.addAll(anvilRecipe);
});
manager.getAllRecipesFor(RecipeType.CRAFTING).forEach(
craftingRecipe ->
anvilRecipes.addAll(AnvilRecipe.of(craftingRecipe, server.registryAccess())));
anvilRecipes.addAll(smokingRecipes);
anvilRecipes.addAll(smeltingRecipes);

ANVIL_RECIPE_SET = anvilRecipes
.stream()
.sorted(Comparator.comparing(AnvilRecipe::getWeightCoefficient).reversed())
.toList();
}

public static List<AnvilRecipe> getAnvilRecipeList() {
return ANVIL_RECIPE_SET;
List<ItemStack> needFilter = new ArrayList<>();
for (CampfireCookingRecipe recipe : manager.getAllRecipesFor(RecipeType.CAMPFIRE_COOKING)) {
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (SmokingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMOKING)) {
needFilter.add(recipe.getResultItem(server.registryAccess()));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (BlastingRecipe recipe : manager.getAllRecipesFor(RecipeType.BLASTING)) {
needFilter.add(recipe.getResultItem(server.registryAccess()));
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (SmeltingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMELTING)) {
ItemStack item = recipe.getResultItem(server.registryAccess());
if (needFilter.stream().anyMatch(stack -> item.is(stack.getItem()))) continue;
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
for (CraftingRecipe recipe : manager.getAllRecipesFor(RecipeType.CRAFTING)) {
AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess());
if (anvilRecipe != null) anvilRecipes.add(anvilRecipe);
}
anvilRecipeList = Collections.synchronizedList(
anvilRecipes.stream().sorted(Comparator.comparing(AnvilRecipe::getWeightCoefficient).reversed()).toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.dubhe.anvilcraft.data.generator.lang;

import com.tterrag.registrate.providers.RegistrateLangProvider;

public class EmiLang {
/**
* @param provider 提供器
*/
public static void init(RegistrateLangProvider provider) {
provider.add("emi.category.anvilcraft.stamping", "Stamping");
provider.add("emi.category.anvilcraft.sieving", "Sieving");
provider.add("emi.category.anvilcraft.bulging", "Bulging");
provider.add("emi.category.anvilcraft.bulging_like", "Bulging Like");
provider.add("emi.category.anvilcraft.fluid_handling", "Fluid Handling");
provider.add("emi.category.anvilcraft.crystallize", "Crystallize");
provider.add("emi.category.anvilcraft.compaction", "Compaction");
provider.add("emi.category.anvilcraft.compress", "Compress");
provider.add("emi.category.anvilcraft.cooking", "Cooking");
provider.add("emi.category.anvilcraft.boil", "Boil");
provider.add("emi.category.anvilcraft.item_inject", "Item Inject");
provider.add("emi.category.anvilcraft.block_smash", "Block Smash");
provider.add("emi.category.anvilcraft.item_smash", "Item Smash");
provider.add("emi.category.anvilcraft.squeeze", "Squeeze");
provider.add("emi.category.anvilcraft.super_heating", "Super Heating");
provider.add("emi.category.anvilcraft.timewarp", "Timewarp");
provider.add("emi.category.anvilcraft.generic", "Anvil Progress");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public static void init(RegistrateLangProvider provider) {
OtherLang.init(provider);
PatchouliLang.init(provider);
ScreenLang.init(provider);
EmiLang.init(provider);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.data.generator.AnvilCraftDatagen;
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipeType;
import dev.dubhe.anvilcraft.init.ModBlocks;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;

public class SmashBlockRecipesLoader {
public class BlockSmashRecipesLoader {
/**
* 初始化粉碎方块配方
*
Expand Down Expand Up @@ -45,6 +46,7 @@ public static void init(RegistrateRecipeProvider provider) {
*/
public static void smash(Block block, @NotNull Block block1, RegistrateRecipeProvider provider) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.type(AnvilRecipeType.BLOCK_SMASH)
.hasBlock(block)
.setBlock(block1)
.unlockedBy(AnvilCraftDatagen.hasItem(block.asItem()), AnvilCraftDatagen.has(block.asItem()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,77 @@
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.data.generator.AnvilCraftDatagen;
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipeType;
import dev.dubhe.anvilcraft.init.ModItems;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.Vec3;

public class BulgingAndCrystallizeRecipesLoader {
private static RegistrateRecipeProvider provider = null;

/**
* 初始化膨发和晶化配方
*
* @param provider 提供器
*/
public static void init(RegistrateRecipeProvider provider) {
bulging(Items.DIRT, Items.CLAY, provider);
bulging(Items.CRIMSON_FUNGUS, Items.NETHER_WART_BLOCK, provider);
bulging(Items.WARPED_FUNGUS, Items.WARPED_WART_BLOCK, provider);
bulging(Items.SPIDER_EYE, Items.FERMENTED_SPIDER_EYE, provider);
bulging(Items.BRAIN_CORAL, Items.BRAIN_CORAL_BLOCK, provider);
bulging(Items.BUBBLE_CORAL, Items.BUBBLE_CORAL_BLOCK, provider);
bulging(Items.FIRE_CORAL, Items.FIRE_CORAL_BLOCK, provider);
bulging(Items.HORN_CORAL, Items.HORN_CORAL_BLOCK, provider);
bulging(Items.TUBE_CORAL, Items.TUBE_CORAL_BLOCK, provider);
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.icon(Items.WET_SPONGE)
.hasFluidCauldron(new Vec3(0.0, -1.0, 0.0), Blocks.WATER_CAULDRON, 1)
.hasItemIngredient(new Vec3(0.0, -1.0, 0.0), ModItems.SPONGE_GEMMULE.get())
.spawnItem(new Vec3(0.0, -1.0, 0.0), Items.WET_SPONGE)
.unlockedBy(
AnvilCraftDatagen.hasItem(ModItems.SPONGE_GEMMULE.get()),
AnvilCraftDatagen.has(ModItems.SPONGE_GEMMULE.get())
)
.save(provider, AnvilCraft.of("bulging/" + BuiltInRegistries.ITEM.getKey(Items.WET_SPONGE).getPath()));
crystallize(ModItems.SEA_HEART_SHELL_SHARD.get(), ModItems.PRISMARINE_CLUSTER.get(), provider);
BulgingAndCrystallizeRecipesLoader.provider = provider;
bulging(Items.DIRT, Items.CLAY);
bulging(Items.CRIMSON_FUNGUS, Items.NETHER_WART_BLOCK);
bulging(Items.WARPED_FUNGUS, Items.WARPED_WART_BLOCK);
bulging(Items.SPIDER_EYE, Items.FERMENTED_SPIDER_EYE);
bulging(Items.BRAIN_CORAL, Items.BRAIN_CORAL_BLOCK);
bulging(Items.BUBBLE_CORAL, Items.BUBBLE_CORAL_BLOCK);
bulging(Items.FIRE_CORAL, Items.FIRE_CORAL_BLOCK);
bulging(Items.HORN_CORAL, Items.HORN_CORAL_BLOCK);
bulging(Items.TUBE_CORAL, Items.TUBE_CORAL_BLOCK);
bulging(Items.WET_SPONGE, Items.WET_SPONGE, 1);
bulging(ModItems.FLOUR, ModItems.DOUGH);
crystallize(ModItems.SEA_HEART_SHELL_SHARD, ModItems.PRISMARINE_CLUSTER, 1);
}

/**
* 膨发配方
* 物品膨发
*
* @param item 原料
* @param item1 产物
* @param provider 提供器
* @param item 输入物品
* @param item1 输出物品
* @param deplete 消耗液体层数
*/
public static void bulging(Item item, Item item1, RegistrateRecipeProvider provider) {
public static void bulging(ItemLike item, ItemLike item1, int deplete) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.icon(item1)
.hasFluidCauldron(new Vec3(0.0, -1.0, 0.0), Blocks.WATER_CAULDRON)
.hasItemIngredient(new Vec3(0.0, -1.0, 0.0), item)
.spawnItem(new Vec3(0.0, -1.0, 0.0), item1)
.unlockedBy(AnvilCraftDatagen.hasItem(item), AnvilCraftDatagen.has(item))
.save(provider, AnvilCraft.of("bulging/" + BuiltInRegistries.ITEM.getKey(item1).getPath()));
.icon(item1)
.type(AnvilRecipeType.BULGING)
.hasFluidCauldron(new Vec3(0.0, -1.0, 0.0), Blocks.WATER_CAULDRON, deplete)
.hasItemIngredient(new Vec3(0.0, -1.0, 0.0), item)
.spawnItem(new Vec3(0.0, -1.0, 0.0), item1)
.unlockedBy(AnvilCraftDatagen.hasItem(item), AnvilCraftDatagen.has(item))
.save(provider, AnvilCraft.of("bulging/" + BuiltInRegistries.ITEM.getKey(item1.asItem()).getPath()));
}

public static void bulging(ItemLike item, ItemLike item1) {
bulging(item, item1, 0);
}

private static void crystallize(Item item, Item item1, RegistrateRecipeProvider provider) {
/**
* 物品晶化
*
* @param item 输入物品
* @param item1 输入物品
* @param deplete 输入液体层数
*/
public static void crystallize(ItemLike item, ItemLike item1, int deplete) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.icon(item1)
.hasFluidCauldron(new Vec3(0.0, -1.0, 0.0), Blocks.POWDER_SNOW_CAULDRON, 1)
.hasItemIngredient(new Vec3(0.0, -1.0, 0.0), item)
.spawnItem(new Vec3(0.0, -1.0, 0.0), item1)
.unlockedBy(AnvilCraftDatagen.hasItem(item), AnvilCraftDatagen.has(item))
.save(provider, AnvilCraft.of("bulging/" + BuiltInRegistries.ITEM.getKey(item1).getPath()));
.icon(item1)
.type(AnvilRecipeType.CRYSTALLIZE)
.hasFluidCauldron(new Vec3(0.0, -1.0, 0.0), Blocks.POWDER_SNOW_CAULDRON, deplete)
.hasItemIngredient(new Vec3(0.0, -1.0, 0.0), item)
.spawnItem(new Vec3(0.0, -1.0, 0.0), item1)
.unlockedBy(AnvilCraftDatagen.hasItem(item), AnvilCraftDatagen.has(item))
.save(provider, AnvilCraft.of("crystallize/"
+ BuiltInRegistries.ITEM.getKey(item1.asItem()).getPath()));
}
}
Loading

0 comments on commit 7472e01

Please sign in to comment.