forked from minetest-mods/technic
Fix laser discharging
Commit a6dae893d6
introduced per-version
charge cost for firing mining lasers, but applies this in addition to
the old fixed cost which it was meant to replace. Fix by removing the
application of the fixed cost.
The same commit did successfully change the check for a laser having
sufficient charge to fire, so that's based purely on the variable cost.
As a consequence, firing a laser that has just enough charge to cover the
variable cost could cause its charge to go negative. (For example, by
fully charging a Mk1 laser and then firing it until it empties, resulting
in a charge of -400.) It turned out that set_RE_wear handled that badly,
producing an over-100% wear value that would wrap to a *low* wear value,
leading to the laser's wear bar looking as if it's fully charged.
To protect against silly wear values, make set_RE_wear clamp the wear
value to avoid wrapping. Handle specially the case of a fully-discharged
tool, where there was desirable wrapping to zero.
This commit is contained in:
parent
44dbc75b61
commit
db20250371
|
@ -44,7 +44,14 @@ end
|
|||
|
||||
-- Wear down a tool depending on the remaining charge.
|
||||
function technic.set_RE_wear(itemstack, item_load, max_load)
|
||||
local temp = 65536 - math.floor(item_load / max_load * 65535)
|
||||
local temp
|
||||
if item_load == 0 then
|
||||
temp = 0
|
||||
else
|
||||
temp = 65536 - math.floor(item_load / max_load * 65535)
|
||||
if temp > 65535 then temp = 65535 end
|
||||
if temp < 1 then temp = 1 end
|
||||
end
|
||||
itemstack:set_wear(temp)
|
||||
return itemstack
|
||||
end
|
||||
|
|
|
@ -178,7 +178,6 @@ for _, m in pairs(mining_lasers_list) do
|
|||
if meta.charge >= m[4] then
|
||||
meta.charge = meta.charge - m[4]
|
||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
||||
meta.charge = meta.charge - 400
|
||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user