Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改配方优先级, 烹饪、熔炼配方适配调整 #868

Merged
merged 5 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.dubhe.anvilcraft.api.recipe;

import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe;
import dev.dubhe.anvilcraft.init.ModRecipeTypes;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;

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

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

/**
* 更新配方
*
* @param server 服务器实例
*/
public static void updateRecipes(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;
}
}
210 changes: 32 additions & 178 deletions common/src/main/java/dev/dubhe/anvilcraft/data/RecipeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,214 +14,68 @@ public class RecipeItem {
private final int count;
private final boolean isSelectOne;

/**
* 配方物品
*
* @param item 配方物品
* @param chance 概率
* @param count 数量
* @param isSelectOne 是否属于多选一
*/
public RecipeItem(double chance, ItemLike item, int count, boolean isSelectOne) {
private RecipeItem(ItemLike item, TagKey<Item> itemTagKey, int count, double chance, boolean isSelectOne) {
this.item = item;
this.itemTagKey = null;
this.chance = chance;
this.itemTagKey = itemTagKey;
this.count = count;
this.chance = chance;
this.isSelectOne = isSelectOne;
}

/**
* 配方物品
*
* @param chance 概率
* @param item 配方物品
* @param count 数量
*/
public RecipeItem(double chance, ItemLike item, int count) {
this.item = item;
this.itemTagKey = null;
this.chance = chance;
this.count = count;
this.isSelectOne = false;
public static RecipeItem of(ItemLike item, int count, double chance, boolean isSelectOne) {
return new RecipeItem(item, null, count, chance, isSelectOne);
}

/**
* 配方物品
*
* @param item 配方物品
*/
public RecipeItem(ItemLike item) {
this.item = item;
this.itemTagKey = null;
this.chance = 1;
this.count = 1;
this.isSelectOne = false;
public static RecipeItem of(ItemLike item, int count, double chance) {
return new RecipeItem(item, null, count, chance, false);
}

/**
* 配方物品
*
* @param item 配方物品
* @param count 数量
*/
public RecipeItem(ItemLike item, int count) {
this.item = item;
this.itemTagKey = null;
this.chance = 1;
this.count = count;
this.isSelectOne = false;
public static RecipeItem of(ItemLike item, int count) {
return new RecipeItem(item, null, count, 1d, false);
}

/**
* 配方物品
*
* @param chance 概率
* @param item 配方物品
*/
public RecipeItem(double chance, ItemLike item) {
this.item = item;
this.itemTagKey = null;
this.chance = chance;
this.count = 1;
this.isSelectOne = false;
public static RecipeItem of(ItemLike item, double chance) {
return new RecipeItem(item, null, 1, chance, false);
}

/**
* 配方物品
*
* @param item 配方物品
*/
public RecipeItem(ItemLike item, boolean isSelectOne) {
this.item = item;
this.itemTagKey = null;
this.chance = 1;
this.count = 1;
this.isSelectOne = isSelectOne;
public static RecipeItem of(ItemLike item, int count, boolean isSelectOne) {
return new RecipeItem(item, null, count, 1d, isSelectOne);
}

/**
* 配方物品
*
* @param item 配方物品
* @param count 数量
*/
public RecipeItem(ItemLike item, int count, boolean isSelectOne) {
this.item = item;
this.itemTagKey = null;
this.chance = 1;
this.count = count;
this.isSelectOne = isSelectOne;
public static RecipeItem of(ItemLike item, double chance, boolean isSelectOne) {
return new RecipeItem(item, null, 1, chance, isSelectOne);
}

/**
* 配方物品
*
* @param chance 概率
* @param item 配方物品
*/
public RecipeItem(double chance, ItemLike item, boolean isSelectOne) {
this.item = item;
this.itemTagKey = null;
this.chance = chance;
this.count = 1;
this.isSelectOne = isSelectOne;
public static RecipeItem of(TagKey<Item> itemTagKey, int count, double chance, boolean isSelectOne) {
return new RecipeItem(null, itemTagKey, count, chance, isSelectOne);
}

/**
* 配方物品
*
* @param chance 概率
* @param itemTagKey 配方物品标签
* @param count 数量
*/
public RecipeItem(double chance, TagKey<Item> itemTagKey, int count) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = chance;
this.count = count;
this.isSelectOne = false;
public static RecipeItem of(TagKey<Item> itemTagKey, int count, double chance) {
return new RecipeItem(null, itemTagKey, count, chance, false);
}

/**
* 配方物品
*
* @param itemTagKey 配方物品标签
*/
public RecipeItem(TagKey<Item> itemTagKey) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = 1;
this.count = 1;
this.isSelectOne = false;
public static RecipeItem of(TagKey<Item> itemTagKey, int count) {
return new RecipeItem(null, itemTagKey, count, 1d, false);
}

/**
* 配方物品
*
* @param itemTagKey 配方物品标签
* @param count 数量
*/
public RecipeItem(TagKey<Item> itemTagKey, int count) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = 1;
this.count = count;
this.isSelectOne = false;
public static RecipeItem of(TagKey<Item> itemTagKey, double chance) {
return new RecipeItem(null, itemTagKey, 1, chance, false);
}

/**
* 配方物品
*
* @param chance 概率
* @param itemTagKey 配方物品标签
*/
public RecipeItem(double chance, TagKey<Item> itemTagKey) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = chance;
this.count = 1;
this.isSelectOne = false;
public static RecipeItem of(TagKey<Item> itemTagKey, int count, boolean isSelectOne) {
return new RecipeItem(null, itemTagKey, count, 1d, isSelectOne);
}

/**
* 配方物品
*
* @param itemTagKey 配方物品标签
*/
public RecipeItem(TagKey<Item> itemTagKey, boolean isSelectOne) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = 1;
this.count = 1;
this.isSelectOne = isSelectOne;
public static RecipeItem of(TagKey<Item> itemTagKey, double chance, boolean isSelectOne) {
return new RecipeItem(null, itemTagKey, 1, chance, isSelectOne);
}

/**
* 配方物品
*
* @param itemTagKey 配方物品标签
* @param count 数量
*/
public RecipeItem(TagKey<Item> itemTagKey, int count, boolean isSelectOne) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = 1;
this.count = count;
this.isSelectOne = isSelectOne;
public static RecipeItem of(ItemLike item) {
return new RecipeItem(item, null, 1, 1d, false);
}

/**
* 配方物品
*
* @param chance 概率
* @param itemTagKey 配方物品标签
*/
public RecipeItem(double chance, TagKey<Item> itemTagKey, boolean isSelectOne) {
this.item = null;
this.itemTagKey = itemTagKey;
this.chance = chance;
this.count = 1;
this.isSelectOne = isSelectOne;
public static RecipeItem of(TagKey<Item> itemTagKey) {
return new RecipeItem(null, itemTagKey, 1, 1d, false);
}

/**
Expand All @@ -233,7 +87,7 @@ public String getKey() {
return this.item == null
? this.itemTagKey == null
? ""
: itemTagKey.location().getPath()
: itemTagKey.location().getNamespace() + "_" + itemTagKey.location().getPath()
: BuiltInRegistries.ITEM
.getKey(this.item.asItem()).getPath();
}
Expand Down
Loading
Loading