uwu functions file

master
Nathaniel Freeman 2021-08-08 03:37:42 +02:00
parent 14786de887
commit 33d37a1047
2 changed files with 142 additions and 1 deletions

140
functions.lua Normal file
View File

@ -0,0 +1,140 @@
-- Copyright (C) 2020 2021 PsycoJaker
-- This file is part of UwU Mod Minetest Mod.
-- UwU Mod is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
-- UwU Mod is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with UwU Mod. If not, see <https://www.gnu.org/licenses/>.
local S = core.get_translator(core.get_current_modname())
uwu = {}
uwu.timer = math.random(30, 50)
uwu.growhappiness = 50
function uwu.newpos(pos)
-- return nearest air node pos or nil
local up = {x=pos.x, y=pos.y+1, z=pos.z}
local down = {x=pos.x, y=pos.y-1, z=pos.z}
local side1 = {x=pos.x+1, y=pos.y, z=pos.z}
local side2 = {x=pos.x-1, y=pos.y, z=pos.z}
local side3 = {x=pos.x, y=pos.y, z=pos.z+1}
local side4 = {x=pos.x, y=pos.y, z=pos.z-1}
local r = math.random(1, 6)
if r == 1 and core.get_node(side1).name == "air" then
return side1
elseif r == 2 and core.get_node(side2).name == "air" then
return side2
elseif r == 3 and core.get_node(side3).name == "air" then
return side3
elseif r == 4 and core.get_node(side4).name == "air" then
return side4
elseif r == 5 and core.get_node(up).name == "air" then
return up
elseif r == 6 and core.get_node(down).name == "air" then
return down
else
return nil
end
end
function uwu.walk(pos)
local oldnode = core.get_node(pos)
local oldnodemeta = core.get_meta(pos):to_table()
local newpos = uwu.newpos(pos)
if newpos then
core.set_node(newpos, oldnode)
core.get_meta(newpos):from_table(oldnodemeta)
core.get_node_timer(newpos):start(uwu.timer)
core.set_node(pos, {name = "air"})
end
end
function uwu.add_happiness(pos, num, prob)
-- if prob take happiness 1/prob times
local meta = core.get_meta(pos)
local happiness = meta:get_int("happiness")
local rprob = prob or 1
local r = math.random(1, rprob)
if r == 1 and happiness+num >= 0 then
meta:set_int("happiness", happiness+num)
if happiness+num <= 0 then
meta:set_string("infotext", S("UnU happiness: @1", happiness+num) )
else
meta:set_string("infotext", S("UwU happiness: @1", happiness+num) )
end
end
end
function uwu.burp (pos, prob)
local rprob = prob or 1
local r = math.random(1, rprob)
if r == 1 then
core.sound_play("burp", {
pos = pos,
gain = 22,
max_hear_distance = 20,
pitch = math.random(70,110)/100
})
else
core.sound_play("mcl_hunger_bite", {pos = pos, gain = 0.2})
end
end
function uwu.say_uwu(pos, prob)
local rprob = prob or 1
local r = math.random(1, rprob)
local nodename = core.get_node(pos).name
local pitch = 1
if r == 1 then
if nodename == "uwu:little" then pitch = 2 end
core.sound_play("uwu", {
pos = pos,
gain = 5,
pitch = pitch
})
end
end
function uwu.on_rightclick(pos, node, clicker, itemstack)
local itemname = itemstack:get_name()
local isfood = core.get_item_group(itemname, "food") -- int num
local energy = core.get_item_group(itemname, "eatable") or 1
if isfood >= 1 then
itemstack:take_item()
uwu.add_happiness(pos, energy)
uwu.burp(pos, 5)
end
end
function uwu.grow(pos)
local nodename = core.get_node(pos).name
local newpos = uwu.newpos(pos)
if nodename == "uwu:block" then
if newpos then
core.set_node(newpos, {name = "uwu:little"} )
uwu.add_happiness(pos, 1-uwu.growhappiness)
uwu.add_happiness(newpos, 1-uwu.growhappiness)
core.get_node_timer(newpos):start(uwu.timer)
uwu.say_uwu(pos)
end
end
if nodename == "uwu:little" then
core.set_node(pos, {name = "uwu:block"} )
uwu.add_happiness(pos, 1-uwu.growhappiness)
uwu.say_uwu(pos)
end
end

View File

@ -23,9 +23,10 @@
local modpath = core.get_modpath(core.get_current_modname())
dofile(modpath .. "/nodes.lua")
dofile(modpath .. "/tools.lua")
dofile(modpath .. "/crafts.lua")
dofile(modpath .. "/functions.lua")
dofile(modpath .. "/nodes.lua")
-- UwU Gen