initial commit

master
Arturas Norkus 2016-05-07 15:32:59 +03:00
parent d34508f013
commit c7d9879d37
10 changed files with 184 additions and 1 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ luac.out
*.x86_64
*.hex
.settings/*
.project
.buildpath

View File

@ -1,2 +1,12 @@
# fort_spikes
# Fort Spikes
Mod for Minetest game
Improve your base defense with wood and iron spikes around.
License of source code:
-----------------------
MIT
Media
-----------------------
Texture files are created by xeranas and lisensed under CC-0

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default

1
description.txt Normal file
View File

@ -0,0 +1 @@
Improve your base defense with wood and iron spikes around.

168
init.lua Normal file
View File

@ -0,0 +1,168 @@
fort_spikes = {
wood_durability_index = 0.4,
iron_durability_index = 0.9
}
-- add damage to any object.
fort_spikes.do_damage = function(obj, durability_index)
if obj ~= nil and obj:get_entity_name() ~= "__builtin:item" then
obj:punch(obj, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy=5}}, nil)
if durability_index ~= nil and fort_spikes.is_broken(durability_index) then
return 1
end
end
return 0
end
-- check nodes below/above to forbid construct spikes in two vertical rows.
fort_spikes.is_allowed_position = function(pos)
local node = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
if minetest.get_node_group(node.name, "spikes") > 0 then
return false
end
node = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z})
if minetest.get_node_group(node.name, "spikes") > 0 then
return false
end
return true
end
-- ramdomly decide if spike is broken.
fort_spikes.is_broken = function(durability_index)
if (durability_index < math.random()) then
return true
end
return false
end
minetest.register_node("fort_spikes:wood_spikes", {
description = "Wood spikes",
drawtype = "plantlike",
visual_scale = 1,
tile_images = {"fort_spikes_wood_spikes.png"},
inventory_image = ("fort_spikes_wood_spikes.png"),
paramtype = "light",
walkable = false,
drop = "default:stick 3",
sunlight_propagates = true,
groups = {spikes=1, flammable=2, choppy = 2, oddly_breakable_by_hand = 1},
on_punch = function(pos, node, puncher, pointed_thing)
fort_spikes.do_damage(puncher, nil)
end,
on_construct = function(pos)
if fort_spikes.is_allowed_position(pos) == false then
minetest.dig_node(pos)
end
end,
})
minetest.register_node("fort_spikes:broken_wood_spikes", {
description = "Broken wood spikes",
drawtype = "plantlike",
visual_scale = 1,
tile_images = {"fort_spikes_broken_wood_spikes.png"},
inventory_image = ("fort_spikes_broken_wood_spikes.png"),
paramtype = "light",
walkable = false,
sunlight_propagates = true,
drop = "default:stick 3",
groups = {spikes=1, flammable=2, choppy = 2, oddly_breakable_by_hand = 1},
})
minetest.register_craft({
output = 'fort_spikes:wood_spikes 3',
recipe = {
{'default:stick', '', 'default:stick'},
{'', 'default:stick', ''},
{'default:stick', '', 'default:stick'},
},
on_place = function(itemstack, placer, pointed_thing, param2)
if (fort_spikes.is_spikes_below(pointed_thing)) then
return
end
end,
})
minetest.register_node("fort_spikes:iron_spikes", {
description = "Iron spikes",
drawtype = "plantlike",
visual_scale = 1,
tile_images = {"fort_spikes_iron_spikes.png"},
inventory_image = ("fort_spikes_iron_spikes.png"),
paramtype = "light",
walkable = false,
sunlight_propagates = true,
drop = "default:steel_ingot 2",
groups = {cracky=2, spikes=1},
on_punch = function(pos, node, puncher, pointed_thing)
fort_spikes.do_damage(puncher, nil)
end,
on_construct = function(pos)
if fort_spikes.is_allowed_position(pos) == false then
minetest.dig_node(pos)
end
end,
})
minetest.register_node("fort_spikes:broken_iron_spikes", {
description = "Broken spikes",
drawtype = "plantlike",
visual_scale = 1,
tile_images = {"fort_spikes_broken_iron_spikes.png"},
inventory_image = ("fort_spikes_broken_iron_spikes.png"),
paramtype = "light",
walkable = false,
sunlight_propagates = true,
drop = "default:steel_ingot 2",
groups = {cracky=2, spikes=1},
})
minetest.register_craft({
output = 'fort_spikes:iron_spikes 3',
recipe = {
{'default:steel_ingot', '', 'default:steel_ingot'},
{'', 'default:steel_ingot', ''},
{'default:steel_ingot', '', 'default:steel_ingot'},
},
on_place = function(itemstack, placer, pointed_thing, param2)
if (fort_spikes.is_spikes_below(pointed_thing)) then
return
end
end,
})
minetest.register_abm(
{nodenames = {"fort_spikes:wood_spikes"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local times_broken = 0
local objs = minetest.get_objects_inside_radius(pos, 1)
for k, obj in pairs(objs) do
times_broken = times_broken + fort_spikes.do_damage(obj, fort_spikes.wood_durability_index)
end
if times_broken > 0 then
minetest.remove_node(pos)
minetest.place_node(pos, {name="fort_spikes:broken_wood_spikes"})
end
end,
}
)
minetest.register_abm(
{nodenames = {"fort_spikes:iron_spikes"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local times_broken = 0
local objs = minetest.get_objects_inside_radius(pos, 1)
for k, obj in pairs(objs) do
times_broken = times_broken + fort_spikes.do_damage(obj, fort_spikes.iron_durability_index)
end
if times_broken > 0 then
minetest.remove_node(pos)
minetest.place_node(pos, {name="fort_spikes:broken_iron_spikes"})
end
end,
}
)

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 B