cake/init.lua

148 lines
3.5 KiB
Lua
Raw Normal View History

2015-11-06 19:24:55 -08:00
local throwable_cake = false
-- CAKE --
local S = minetest.get_translator("cake")
2015-11-02 19:03:49 -08:00
local sizes = {-0.4375, -0.3125, -0.1875, -0.0625, 0.0625, 0.1875, 0.3125}
for i, size in ipairs(sizes) do
local slice = i - 1
local name
local description
local drop
local tiles
2015-11-02 19:03:49 -08:00
if slice == 0 then
name = "cake:cake"
description = S("Cake")
2015-11-02 19:03:49 -08:00
drop = nil
tiles = {"cake_top.png", "cake_bottom.png", "cake_side.png"}
else
name = "cake:cake_"..slice
drop = ''
tiles = {"cake_top.png", "cake_bottom.png", "cake_side.png", "cake_inner.png", "cake_side.png", "cake_side.png"}
end
2015-11-02 19:03:49 -08:00
minetest.register_node(name, {
description = description,
drop = drop,
drawtype = "nodebox",
tiles = tiles,
2016-02-20 14:31:52 -08:00
inventory_image = "cake.png",
wield_image = "cake.png",
2015-11-02 19:03:49 -08:00
paramtype = "light",
is_ground_content = false,
2015-11-10 21:32:44 -08:00
groups = {crumbly=3},
2015-11-02 19:03:49 -08:00
--sounds = sounds,
node_box = {
type = "fixed",
fixed = {
{size, -0.5, -0.4375, 0.4375, 0, 0.4375},
}
},
on_rightclick = function(pos, node, clicker)
clicker:set_hp(clicker:get_hp() + 1)
2015-11-02 19:03:49 -08:00
if i < #sizes then
minetest.swap_node(pos, {name="cake:cake_"..i})
else
minetest.remove_node(pos)
end
end,
})
end
2016-06-01 11:12:23 -07:00
if not minetest.get_modpath("food") then
2015-11-06 19:24:30 -08:00
minetest.register_craftitem("cake:sugar", {
description = S("Sugar"),
2015-11-06 19:24:30 -08:00
inventory_image = "cake_sugar.png",
groups = {food_sugar=1}
})
2015-11-06 19:24:30 -08:00
minetest.register_craft({
type = "shapeless",
output = "cake:sugar",
recipe = {"default:papyrus"}
})
else
minetest.register_alias("cake:sugar", "food:sugar")
end
2015-11-02 19:03:49 -08:00
minetest.register_craft({
type = "shapeless",
output = "cake:cake",
recipe = {"farming:flour", "group:water_bucket", "group:food_sugar", "group:food_sugar"},
replacements = {
2015-11-15 08:14:10 -08:00
{"group:water_bucket", "bucket:bucket_empty"},
2015-11-15 14:48:11 -08:00
-- Not needed >0.4.13
2016-02-20 12:12:28 -08:00
{"bucket:bucket_water", "bucket:bucket_empty"},
{"bucket:bucket_river_water", "bucket:bucket_empty"}
}
2015-11-02 19:03:49 -08:00
})
2015-11-06 19:24:55 -08:00
-- THROWABLE CAKE --
minetest.register_entity("cake:cake_entity", {
physical = false,
timer = 0,
2016-02-20 14:31:52 -08:00
textures = {"cake.png"},
2015-11-06 19:24:55 -08:00
lastpos = {},
collisionbox = {0,0,0,0,0,0},
on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
2016-02-27 09:51:52 +09:00
local node = minetest.get_node(pos)
2015-11-06 19:24:55 -08:00
if self.timer>0.2 then
2016-02-27 09:51:52 +09:00
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
2015-11-06 19:24:55 -08:00
for k, obj in pairs(objs) do
if obj:get_luaentity() == nil or obj:get_luaentity().name ~= "cake:cake_entity" and obj:get_luaentity().name ~= "__builtin:item" then
obj:set_hp(obj:get_hp() + 7)
self.object:remove()
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" then
2016-02-27 09:51:52 +09:00
minetest.add_item(self.lastpos, 'cake:cake')
2015-11-06 19:24:55 -08:00
self.object:remove()
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end,
})
if throwable_cake then
minetest.override_item("cake:cake", {
on_use = function(itemstack, player, pointed_thing)
if not minetest.settings:get_bool("creative_mode") then
2015-11-06 19:24:55 -08:00
itemstack:take_item()
end
local playerpos = player:getpos()
2016-02-27 09:51:52 +09:00
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "cake:cake_entity")
2015-11-06 19:24:55 -08:00
local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3})
obj:setyaw(player:get_look_yaw()+math.pi)
return itemstack
end,
})
end
2016-06-01 11:13:13 -07:00
-- CAKE AWARD --
if minetest.get_modpath("awards") then
awards.register_achievement("award_the_lie", {
title = S("The Lie"),
description = S("Craft a cake"),
icon = "cake.png",
trigger = {
type = "craft",
item = "cake:cake",
target = 1
}
})
end