
One Enough Value
一个类似于ProjectE的物品价值系统,为物品价值提供便捷且高度可扩展的参考。
One Enough Value
此模组提供了一个类似于 ProjectE 的物品价值系统,为物品价值提供了便捷且高度可扩展的参考。
需要 KubeJS 作为前置。
基础价值

默认情况下,此模组为大多数基础材料提供了基础价值。
此外,你可以使用以下方法为物品添加或修改基础价值:
OEVEvents.addItemValue(event => {
// Add base value.
event.addBaseItemValue('minecraft:iron_nugget', 10);
// Add extra value by matching NBT, such as Tacz's firearms.
event.addExtraItemValue('{GunId:"tacz:m700"}', 500000);
});
如果物品不显示价值,则其价值为 0。上述方法会添加 +10 的价值(例如,0 变为 10)。这些方法支持负数。
物品价值会向下取整(例如,0.5 变为 0)。
如果你需要与其他模组交互并随时读取价值,可以使用价值管理器:
// Output the item's value when the player right-clicks the item.
ItemEvents.rightClicked(event => {
event.player.tell(OEV$ItemValueManager.getValue(event.item));
});
加工价值
如果物品没有基础价值,但存在生产它的配方,则该物品的价值默认为配方中原料价值总和的最小值。
例如,红色染料可以由红色郁金香(价值 16)或甜菜根(价值 64)合成,因此默认价值将为 16。
对于产出多个物品的配方,价值会自动除以数量。例如,一个金锭(默认价值 648)可以合成 9 个金粒,每个价值为 72。
原版配方默认设置为使用简单的求和方法。
对于其他模组注册的新配方类型,你可以使用以下方法设置简单的求和方法:
let $RecipeType = Java.loadClass("net.minecraft.world.item.crafting.RecipeType");
OEVEvents.addRecipeHandler(event => {
event.addSimpleRecipeHandler($RecipeType.BLASTING);
});
自定义加工
以下是一个简单的模板,用于将合成物品的价值设为原料价值总和的十倍:
let $RecipeType = Java.loadClass("net.minecraft.world.item.crafting.RecipeType");
OEVEvents.addRecipeHandler(event => {
// Add a custom recipe handler for processing value, iterating through all recipes.
event.addCustomRecipeHandler($RecipeType.CRAFTING, recipe => {
let value = 0;
// Iterate through each ingredient in the recipe.
for (let ingredient of recipe.getIngredients()) {
// Get the minimum value of a single ingredient. For example, for an ingredient matching a tag like coal (value 128) or charcoal (value 32), it takes 32 when crafting a torch.
let ingredientMinValue = event.getMinIngredientValue(ingredient);
// Handle cases where the ingredient is empty or has no corresponding value. Just copy this as is.
if (ingredientMinValue === event.getMaxInteger()) continue;
else if (ingredientMinValue === -1) return true;
value += ingredientMinValue;
}
value *= 10;
// Set the final value for a single recipe.
return event.defaultSetRecipeValue(recipe, value);
});
// Helper method to output an array containing all registered recipe types.
console.log(event.getAllRecipeType());
});
未来计划
- 移植到其他版本。
正在加载版本记录…
正在加载评论…
评论在新手盒子客户端中发表,这里同步展示。