autoeat: merge fleckmagic
parent
c8ee822901
commit
3cdd9284d9
|
@ -1,46 +1,74 @@
|
||||||
autoeat = {}
|
autoeat = {}
|
||||||
autoeat.last = 0
|
autoeat.lock = false
|
||||||
local last_step_eating = false
|
|
||||||
autoeat.interval = 1
|
local autodupe = rawget(_G, "autodupe")
|
||||||
|
local hud_id = nil
|
||||||
|
|
||||||
|
local function get_float(name, default)
|
||||||
|
return tonumber(minetest.settings:get("autoeat_" .. name) or "") or default
|
||||||
|
end
|
||||||
|
|
||||||
|
local etime = 0
|
||||||
|
|
||||||
function autoeat.eat()
|
function autoeat.eat()
|
||||||
local player = minetest.localplayer
|
local food_index
|
||||||
local owx=player:get_wield_index()
|
local food_count = 0
|
||||||
autoeat.eating = true
|
for index, stack in pairs(minetest.get_inventory("current_player").main) do
|
||||||
player:set_wield_index(9)
|
local stackname = stack:get_name()
|
||||||
minetest.place_node(player:get_pos())
|
if stackname ~= "" then
|
||||||
minetest.after("0.2",function()
|
local def = minetest.get_item_def(stackname)
|
||||||
player:set_wield_index(owx)
|
if def and def.groups.food then
|
||||||
end)
|
food_count = food_count + 1
|
||||||
|
if food_index then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
food_index = index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if food_index then
|
||||||
|
if food_count == 1 and autodupe then
|
||||||
|
autodupe.needed(food_index)
|
||||||
|
autoeat.lock = true
|
||||||
|
else
|
||||||
|
local player = minetest.localplayer
|
||||||
|
local old_index = player:get_wield_index()
|
||||||
|
player:set_wield_index(food_index)
|
||||||
|
minetest.interact("activate", {type = "nothing"})
|
||||||
|
player:set_wield_index(old_index)
|
||||||
|
autoeat.lock = false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function autoeat.conditional()
|
function autoeat.get_hunger()
|
||||||
if os.time() < autoeat.last + ( autoeat.interval * 60 ) then return end
|
if hud_id then
|
||||||
autoeat.last = os.time()
|
return minetest.localplayer:hud_get(hud_id).number
|
||||||
|
else
|
||||||
|
return 20
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
if not minetest.localplayer then return end
|
||||||
|
etime = etime + dtime
|
||||||
|
if autoeat.lock or minetest.settings:get_bool("autoeat") and etime >= get_float("cooldown", 0.5) and autoeat.get_hunger() < get_float("hunger", 9) then
|
||||||
|
etime = 0
|
||||||
autoeat.eat()
|
autoeat.eat()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_damage_taken(function()
|
|
||||||
if not minetest.settings:get_bool("autoeat") then return end
|
|
||||||
autoeat.eat()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
minetest.after(3, function()
|
||||||
if last_step_eating then
|
local player = minetest.localplayer
|
||||||
autoeat.eating, last_step_eating = false, false
|
local def
|
||||||
elseif autoeat.eating then
|
local i = -1
|
||||||
last_step_eating = true
|
repeat
|
||||||
|
i = i + 1
|
||||||
|
def = player:hud_get(i)
|
||||||
|
until not def or def.text == "hbhunger_icon.png"
|
||||||
|
if def then
|
||||||
|
hud_id = i
|
||||||
end
|
end
|
||||||
|
|
||||||
if not minetest.settings:get_bool("autoeat_timed") then return end
|
|
||||||
if ( autofly.speed ~= 0 and minetest.settings:get_bool("autosprint") )
|
|
||||||
or (minetest.settings:get_bool("autofsprint") and minetest.settings:get_bool("continuous_forward") )
|
|
||||||
or (minetest.settings:get_bool("killaura")) then
|
|
||||||
autoeat.conditional()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_cheat("AutoEat", "Player", "autoeat")
|
minetest.register_cheat("AutoEat", "Player", "autoeat")
|
||||||
minetest.register_cheat("AutoEatTimed", "Player", "autoeat_timed")
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
name = autoeat
|
name = autoeat
|
||||||
description = Automatically eat when damage was taken, assuming that there is food in the first hotbar slot. This is only useful when used in combination with an afk bot, like schematicas.
|
|
||||||
author = Fleckenstein
|
author = Fleckenstein
|
||||||
|
description = Automatically eat when a certain hunger is reached (MineClone2).
|
||||||
|
optional_depends = autodupe
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
autoeat (Automatically eat when damage was taken) bool false
|
autoeat (AutoEat) bool false
|
||||||
|
autoeat_cooldown (AutoEat cooldown) float 0.5
|
||||||
|
autoeat_hunger (AutoEat hunger) float 9.0
|
||||||
|
|
Loading…
Reference in New Issue