Add floor bombs.

This commit is contained in:
Duane 2016-07-06 17:58:20 -05:00
parent 2e978e540c
commit d820a49197
5 changed files with 127 additions and 9 deletions

View file

@ -87,6 +87,7 @@ local chest_formspec =
local newnode = fun_caves.clone_node("default:chest")
newnode.description = "Treasure Chest"
newnode.on_construct = nil
newnode.drop = 'default:chest'
newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local ready = meta:get_string('formspec')

View file

@ -32,6 +32,7 @@ local newnode = fun_caves.clone_node("default:chest")
newnode.description = "Treasure Casket"
newnode.light_source = 1
newnode.on_construct = nil
newnode.drop = 'default:chest'
newnode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local ready = meta:get_string('formspec')

View file

@ -1,16 +1,78 @@
local function disintigrate(pos, radius, node_name, user)
local p1 = vector.subtract(pos, radius)
local p2 = vector.add(pos, radius)
local nodes = minetest.find_nodes_in_area(p1, p2, node_name)
for _, node in pairs(nodes) do
if not minetest.is_protected(node, user) then
minetest.remove_node(node)
local function disintigrate(pos, radius, node_name, user, dropped)
local node_id = minetest.get_content_id(node_name)
local air = minetest.get_content_id('air')
local minp = vector.subtract(pos, radius)
local maxp = vector.add(pos, radius)
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(minp, maxp)
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
local count = 0
local drops = {}
local p = {}
for z = minp.z, maxp.z do
p.z = z
for y = minp.y, maxp.y do
p.y = y
local ivm = area:index(minp.x, y, z)
for x = minp.x, maxp.x do
p.x = x
if data[ivm] == node_id and not minetest.is_protected(p, user) then
data[ivm] = air
count = count + 1
if count % 50 == 0 then
drops[#drops+1] = table.copy(p)
end
end
ivm = ivm + 1
end
end
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
count = math.floor(count / 3)
for _, p in pairs(drops) do
if count < 1 then
return
end
local dropitem = ItemStack(dropped or node_name)
local take = math.min(count, dropitem:get_stack_max())
dropitem:set_count(take)
local obj = minetest.add_item(p, dropitem)
if obj then
count = count - take
end
end
end
local nodes = {{'fun_caves:pyramid_1', 'default:sandstone_block'},}
local function floor(pos, blocks, node_name, user)
local p = {y = pos.y}
local count = 0
for r = 1, blocks do
for z = -r, r do
p.z = pos.z + z
for x = -r, r do
p.x = pos.x + x
local node = minetest.get_node_or_nil(p)
if node and node.name == 'air' and not minetest.is_protected(p, user) then
minetest.set_node(p, {name = node_name})
count = count + 1
if count > blocks then
return
end
end
end
end
end
end
local nodes = {{'fun_caves:pyramid_1', 'default:sandstone'},}
for _, node in pairs(nodes) do
local node_name = node[1]
local comp = node[2] or node_name
@ -25,7 +87,7 @@ for _, node in pairs(nodes) do
newnode.inventory_image = '[inventorycube{tnt_top.png{'..node_texture..'{tnt_side.png'
newnode.on_punch = function(pos, node, puncher, pointed_thing)
minetest.after(5, function()
disintigrate(pos, 5, node_name, puncher)
disintigrate(pos, 5, node_name, puncher, comp)
minetest.remove_node(pos)
end)
end
@ -40,3 +102,49 @@ for _, node in pairs(nodes) do
}
})
end
local nodes = {{'default:sandstone', 'default:sandstone'},}
for _, node in pairs(nodes) do
local node_name = node[1]
local comp = node[2] or node_name
local node_texture = minetest.registered_items[node_name].tiles
if type(node_texture) == 'table' then
node_texture = node_texture[1]
end
local _, d_name = node_name:match('(.*:)(.*)')
local d_name_u = d_name:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)
for i = 1, 5 do
local newnode = fun_caves.clone_node(node_name)
newnode.description = d_name_u.." Floor Bomb Mk "..i
newnode.inventory_image = '[inventorycube{'..node_texture..'{'..node_texture..'{'..node_texture..'^fun_caves_expand.png'
newnode.on_punch = function(pos, node, puncher, pointed_thing)
minetest.after(5, function()
floor(pos, 20 * i, node_name, puncher)
minetest.set_node(pos, {name = node_name})
end)
end
minetest.register_node("fun_caves:"..d_name..'_floor_bomb_'..i, newnode)
if i > 1 then
minetest.register_craft({
output = "fun_caves:"..d_name..'_floor_bomb_'..i,
recipe = {
{comp, comp, comp},
{comp, "fun_caves:"..d_name..'_floor_bomb_'..(i-1), comp},
{comp, comp, comp}
}
})
end
end
minetest.register_craft({
output = "fun_caves:"..d_name..'_floor_bomb_1',
recipe = {
{comp, comp, comp},
{comp, "tnt:gunpowder", comp},
{comp, comp, comp}
}
})
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

View file

@ -239,6 +239,14 @@ minetest.register_craft({
}
})
if minetest.get_modpath('tnt') then
minetest.register_craft({
output = "tnt:gunpowder",
type = "shapeless",
recipe = {"fun_caves:charcoal", "default:gravel"}
})
end
minetest.register_craft({
output = 'fun_caves:syrup',
type = "shapeless",