forked from VoxeLibre/VoxeLibre
Efficiency & Unbreaking
This commit is contained in:
parent
e09ecb5431
commit
04d8d999e2
|
@ -18,7 +18,7 @@ digging times in seconds. These digging times can be then added verbatim into th
|
||||||
Example:
|
Example:
|
||||||
mcl_autogroup.digtimes.pickaxey_dig_diamond[1] = 0.2
|
mcl_autogroup.digtimes.pickaxey_dig_diamond[1] = 0.2
|
||||||
|
|
||||||
→ This menas that when a node has been assigned the group “pickaxey_dig_diamond=1”, it can be dug by the
|
→ This means that when a node has been assigned the group “pickaxey_dig_diamond=1”, it can be dug by the
|
||||||
diamond pickaxe in 0.2 seconds.
|
diamond pickaxe in 0.2 seconds.
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ local divisors = {
|
||||||
["shearsy_wool"] = 5,
|
["shearsy_wool"] = 5,
|
||||||
["swordy_cobweb"] = 15,
|
["swordy_cobweb"] = 15,
|
||||||
}
|
}
|
||||||
|
local max_efficiency_level = 5
|
||||||
|
|
||||||
mcl_autogroup = {}
|
mcl_autogroup = {}
|
||||||
mcl_autogroup.digtimes = {}
|
mcl_autogroup.digtimes = {}
|
||||||
|
@ -53,11 +54,19 @@ for m=1, #materials do
|
||||||
for g=1, #basegroups do
|
for g=1, #basegroups do
|
||||||
mcl_autogroup.digtimes[basegroups[g].."_dig_"..materials[m]] = {}
|
mcl_autogroup.digtimes[basegroups[g].."_dig_"..materials[m]] = {}
|
||||||
mcl_autogroup.creativetimes[basegroups[g].."_dig_"..materials[m]] = {}
|
mcl_autogroup.creativetimes[basegroups[g].."_dig_"..materials[m]] = {}
|
||||||
|
for e=1, max_efficiency_level do
|
||||||
|
mcl_autogroup.digtimes[basegroups[g].."_dig_"..materials[m].."_efficiency_"..e] = {}
|
||||||
|
mcl_autogroup.creativetimes[basegroups[g].."_dig_"..materials[m].."_efficiency_"..e] = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for g=1, #minigroups do
|
for g=1, #minigroups do
|
||||||
mcl_autogroup.digtimes[minigroups[g].."_dig"] = {}
|
mcl_autogroup.digtimes[minigroups[g].."_dig"] = {}
|
||||||
mcl_autogroup.creativetimes[minigroups[g].."_dig"] = {}
|
mcl_autogroup.creativetimes[minigroups[g].."_dig"] = {}
|
||||||
|
for e=1, max_efficiency_level do
|
||||||
|
mcl_autogroup.digtimes[minigroups[g].."_dig_efficiency_"..e] = {}
|
||||||
|
mcl_autogroup.creativetimes[minigroups[g].."_dig_efficiency_"..e] = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local overwrite = function()
|
local overwrite = function()
|
||||||
|
@ -80,7 +89,7 @@ local overwrite = function()
|
||||||
groups_changed = true
|
groups_changed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calculate_group(hardness, material, diggroup, newgroups, actual_rating, expected_rating)
|
local function calculate_group(hardness, material, diggroup, newgroups, actual_rating, expected_rating, efficiency)
|
||||||
local time, validity_factor
|
local time, validity_factor
|
||||||
if actual_rating >= expected_rating then
|
if actual_rating >= expected_rating then
|
||||||
-- Valid tool
|
-- Valid tool
|
||||||
|
@ -89,7 +98,11 @@ local overwrite = function()
|
||||||
-- Wrong tool (higher digging time)
|
-- Wrong tool (higher digging time)
|
||||||
validity_factor = 5
|
validity_factor = 5
|
||||||
end
|
end
|
||||||
time = (hardness * validity_factor) / divisors[material]
|
local speed_multiplier = divisors[material]
|
||||||
|
if efficiency then
|
||||||
|
speed_multiplier = speed_multiplier + efficiency * efficiency + 1
|
||||||
|
end
|
||||||
|
time = (hardness * validity_factor) / speed_multiplier
|
||||||
if time <= 0.05 then
|
if time <= 0.05 then
|
||||||
time = 0
|
time = 0
|
||||||
else
|
else
|
||||||
|
@ -113,6 +126,9 @@ local overwrite = function()
|
||||||
for g=1,#materials do
|
for g=1,#materials do
|
||||||
local diggroup = basegroup.."_dig_"..materials[g]
|
local diggroup = basegroup.."_dig_"..materials[g]
|
||||||
newgroups = calculate_group(hardness, materials[g], diggroup, newgroups, g, ndef.groups[basegroup])
|
newgroups = calculate_group(hardness, materials[g], diggroup, newgroups, g, ndef.groups[basegroup])
|
||||||
|
for e=1,max_efficiency_level do
|
||||||
|
newgroups = calculate_group(hardness, materials[g], diggroup .. "_efficiency_" .. e, newgroups, g, ndef.groups[basegroup], e)
|
||||||
|
end
|
||||||
groups_changed = true
|
groups_changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -134,6 +150,9 @@ local overwrite = function()
|
||||||
or
|
or
|
||||||
(ndef.groups[minigroup] and minigroup ~= "swordy_cobweb" and minigroup ~= "shearsy_wool") then
|
(ndef.groups[minigroup] and minigroup ~= "swordy_cobweb" and minigroup ~= "shearsy_wool") then
|
||||||
newgroups = calculate_group(hardness, minigroup, diggroup, newgroups, ar, 1)
|
newgroups = calculate_group(hardness, minigroup, diggroup, newgroups, ar, 1)
|
||||||
|
for e=1,max_efficiency_level do
|
||||||
|
newgroups = calculate_group(hardness, minigroup, diggroup .. "_efficiency_" .. e, newgroups, ar, 1, e)
|
||||||
|
end
|
||||||
groups_changed = true
|
groups_changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,7 +90,7 @@ mcl_enchanting.enchantments.depth_strider = {
|
||||||
requires_tool = false,
|
requires_tool = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- unimplemented
|
-- implemented via on_enchant
|
||||||
mcl_enchanting.enchantments.efficiency = {
|
mcl_enchanting.enchantments.efficiency = {
|
||||||
name = "Efficiency",
|
name = "Efficiency",
|
||||||
max_level = 5,
|
max_level = 5,
|
||||||
|
@ -101,7 +101,17 @@ mcl_enchanting.enchantments.efficiency = {
|
||||||
weight = 10,
|
weight = 10,
|
||||||
description = "Increases mining speed.",
|
description = "Increases mining speed.",
|
||||||
curse = false,
|
curse = false,
|
||||||
on_enchant = function() end,
|
on_enchant = function(itemstack, level, itemdef)
|
||||||
|
local tool_capabilities = itemstack:get_tool_capabilities()
|
||||||
|
local groupcaps = {}
|
||||||
|
for group, capability in pairs(tool_capabilities.groupcaps) do
|
||||||
|
local groupname = group .. "_efficiency_" .. level
|
||||||
|
capability.times = mcl_autogroup.digtimes[groupname]
|
||||||
|
groupcaps[groupname] = capability
|
||||||
|
end
|
||||||
|
tool_capabilities.groupcaps = groupcaps
|
||||||
|
itemstack:get_meta():set_tool_capabilities(tool_capabilities)
|
||||||
|
end,
|
||||||
requires_tool = false,
|
requires_tool = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +460,7 @@ mcl_enchanting.enchantments.thorns = {
|
||||||
requires_tool = false,
|
requires_tool = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- unimplemented
|
-- implemented via on_enchant; Unimplemented for Bows, Armor and Fishing Rods
|
||||||
mcl_enchanting.enchantments.unbreaking = {
|
mcl_enchanting.enchantments.unbreaking = {
|
||||||
name = "Unbreaking",
|
name = "Unbreaking",
|
||||||
max_level = 3,
|
max_level = 3,
|
||||||
|
@ -461,12 +471,17 @@ mcl_enchanting.enchantments.unbreaking = {
|
||||||
weight = 5,
|
weight = 5,
|
||||||
description = "Increases item durability.",
|
description = "Increases item durability.",
|
||||||
curse = false,
|
curse = false,
|
||||||
on_enchant = function() end,
|
on_enchant = function(itemstack, level, itemdef)
|
||||||
|
local new_capabilities = itemstack:get_tool_capabilities()
|
||||||
|
for group, capability in pairs(new_capabilities.groupcaps) do
|
||||||
|
capability.uses = capability.uses * (1 + level)
|
||||||
|
end
|
||||||
|
new_capabilities.punch_attack_uses = new_capabilities.punch_attack_uses * (1 + level)
|
||||||
|
itemstack:get_meta():set_tool_capabilities(new_capabilities)
|
||||||
|
end,
|
||||||
requires_tool = true,
|
requires_tool = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
||||||
local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
|
||||||
|
@ -544,48 +559,3 @@ minetest.register_on_mods_loaded(function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
|
||||||
--[[
|
|
||||||
sharpness = {
|
|
||||||
name = "Sharpness",
|
|
||||||
max_level = 5,
|
|
||||||
create_itemdef = function(def, level)
|
|
||||||
def.tool_capabilities.damage_groups.fleshy = def.tool_capabilities.damage_groups.fleshy + (level + 1) / 2
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
efficiency = {
|
|
||||||
name = "Efficiency",
|
|
||||||
max_level = 5,
|
|
||||||
create_itemdef = function(def, level)
|
|
||||||
local groupcaps = def.tool_capabilities.groupcaps
|
|
||||||
for _, groupcap in pairs(groupcaps) do
|
|
||||||
for i, t in pairs(groupcap.times) do
|
|
||||||
local m = 1 / t
|
|
||||||
m = m + math.pow(level, 2) + 1
|
|
||||||
groupcap.times[i] = 1 / m
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
unbreaking = {
|
|
||||||
name = "Unbreaking",
|
|
||||||
max_level = 3,
|
|
||||||
create_itemdef = function(def, level)
|
|
||||||
local toolcaps = def.tool_capabilities
|
|
||||||
local armor_uses = def.groups.mcl_armor_uses
|
|
||||||
local factor = 0.5
|
|
||||||
if toolcaps then
|
|
||||||
local groupcaps = toolcaps.groupcaps
|
|
||||||
for _, groupcap in pairs(groupcaps) do
|
|
||||||
groupcap.uses = math.floor(groupcap.uses * (1 + level))
|
|
||||||
end
|
|
||||||
def.tool_capabilities.punch_attack_uses = math.floor(def.tool_capabilities.punch_attack_uses * (1 + level))
|
|
||||||
elseif armor_uses then
|
|
||||||
def.groups.mcl_armor_uses = math.floor(armor_uses / (0.6 + (0.4 / (level + 1))))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
},
|
|
||||||
},--]]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ function mcl_enchanting.set_enchantments(itemstack, enchantments)
|
||||||
itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
|
itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
|
||||||
local itemdef = itemstack:get_definition()
|
local itemdef = itemstack:get_definition()
|
||||||
if itemstack:get_name() ~= "mcl_enchanting:book_enchanted" then
|
if itemstack:get_name() ~= "mcl_enchanting:book_enchanted" then
|
||||||
|
if itemdef.tool_capabilities then
|
||||||
|
itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities)
|
||||||
|
end
|
||||||
for enchantment, level in pairs(enchantments) do
|
for enchantment, level in pairs(enchantments) do
|
||||||
local enchantment_def = mcl_enchanting.enchantments[enchantment]
|
local enchantment_def = mcl_enchanting.enchantments[enchantment]
|
||||||
if enchantment_def.on_enchant then
|
if enchantment_def.on_enchant then
|
|
@ -8,7 +8,7 @@ mcl_enchanting = {
|
||||||
debug = true,
|
debug = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
dofile(modpath .. "/api.lua")
|
dofile(modpath .. "/engine.lua")
|
||||||
dofile(modpath .. "/enchantments.lua")
|
dofile(modpath .. "/enchantments.lua")
|
||||||
dofile(modpath .. "/command.lua")
|
dofile(modpath .. "/command.lua")
|
||||||
dofile(modpath .. "/tt.lua")
|
dofile(modpath .. "/tt.lua")
|
||||||
|
|
|
@ -23,7 +23,7 @@ minetest.register_on_dieplayer(function(player)
|
||||||
local z = math.random(0, 9)/3
|
local z = math.random(0, 9)/3
|
||||||
pos.x = pos.x + x
|
pos.x = pos.x + x
|
||||||
pos.z = pos.z + z
|
pos.z = pos.z + z
|
||||||
if not void_deadly and drop and mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then
|
if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then
|
||||||
local def = minetest.registered_items[stack:get_name()]
|
local def = minetest.registered_items[stack:get_name()]
|
||||||
if def and def.on_drop then
|
if def and def.on_drop then
|
||||||
stack = def.on_drop(stack, player, pos)
|
stack = def.on_drop(stack, player, pos)
|
||||||
|
|
Loading…
Reference in New Issue