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

默认情况下,此模组为大多数基础材料提供了基础价值。
此外,你可以使用以下方法添加或修改物品的基础价值:
OEVEvents.addItemValue(event => {
// 添加基础价值。
event.addBaseItemValue('minecraft:iron_nugget', 10);
// 通过匹配 NBT 添加额外价值,例如 Tacz 的枪械。
event.addExtraItemValue('{GunId:"tacz:m700"}', 500000);
});
如果某个物品没有显示价值,其价值为 0。上述方法会增加 +10 的价值(例如,0 变为 10)。这些方法支持负数。
物品价值向下取整(例如,0.5 变为 0)。
如果你需要与其他模组交互并随时读取价值,可以使用 Value Manager:
// 当玩家右键点击物品时输出该物品的价值。
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 => {
// 为加工价值添加自定义配方处理器,遍历所有配方。
event.addCustomRecipeHandler($RecipeType.CRAFTING, recipe => {
let value = 0;
// 遍历配方中的每种原料。
for (let ingredient of recipe.getIngredients()) {
// 获取单个原料的最小价值。例如,对于匹配煤(价值 128)或木炭(价值 32)等标签的原料,在制作火把时取值为 32。
let ingredientMinValue = event.getMinIngredientValue(ingredient);
// 处理原料为空或没有对应价值的情况。直接照抄即可。
if (ingredientMinValue === event.getMaxInteger()) continue;
else if (ingredientMinValue === -1) return true;
value += ingredientMinValue;
}
value *= 10;
// 设置单个配方的最终价值。
return event.defaultSetRecipeValue(recipe, value);
});
// 辅助方法,输出包含所有已注册配方类型的数组。
console.log(event.getAllRecipeType());
});
未来计划
One Enough Value
This mod provides an item value system similar to ProjectE, offering a convenient and highly extensible reference for item values.
Requires KubeJS as a prerequisite.
Base Value

By default, this mod provides base values for most basic materials.
Additionally, you can add or modify base values for items using the following methods:
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);
});
If an item does not show a value, its value is 0. The methods above add a value of +10 (e.g., 0 becomes 10). These methods support negative numbers.
Item values are rounded down (e.g., 0.5 becomes 0).
If you need to interact with other mods and read values at any time, you can use the Value Manager:
// Output the item's value when the player right-clicks the item.
ItemEvents.rightClicked(event => {
event.player.tell(OEV$ItemValueManager.getValue(event.item));
});
Processing Value
If an item has no base value, but there is a recipe that produces it, the item's value will default to the minimum sum of the ingredient values from the recipes.
For example, red dye can be crafted from a red tulip (value 16) or a beetroot (value 64), so the default value will be 16.
For recipes that produce more than one item, the value is automatically divided by the quantity. For instance, a gold ingot (default value 648) can craft 9 gold nuggets, each with a value of 72.
Vanilla recipes are set by default to use a simple summation method.
For new recipe types registered by other mods, you can set up a simple summation method using the following approach:
let $RecipeType = Java.loadClass("net.minecraft.world.item.crafting.RecipeType");
OEVEvents.addRecipeHandler(event => {
event.addSimpleRecipeHandler($RecipeType.BLASTING);
});
Custom Processing
Here is a simple template to make the value of a crafted item ten times the sum of the ingredient values:
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());
});
Future Plans
评论 0
登录后参与评分
还没有评论,来抢沙发吧