register with definition

This commit is contained in:
Thomas Rudin 2018-11-15 14:15:10 +01:00
parent 538c2cf718
commit 686055a682
2 changed files with 58 additions and 23 deletions

@ -1,10 +1,10 @@
local has_technic_mod = minetest.get_modpath("technic") local has_technic_mod = minetest.get_modpath("technic")
local register_spacecannon = function(color, range, timeout, speed) local register_spacecannon = function(def)
local entity_texture = "energycube_" .. color .. ".png" local entity_texture = "energycube_" .. def.color .. ".png"
minetest.register_entity("spacecannon:energycube_" .. color, { minetest.register_entity("spacecannon:energycube_" .. def.color, {
initial_properties = { initial_properties = {
visual = "cube", visual = "cube",
visual_size = {x=0.25, y=0.25}, visual_size = {x=0.25, y=0.25},
@ -13,6 +13,7 @@ local register_spacecannon = function(color, range, timeout, speed)
physical = false physical = false
}, },
timer = 0, timer = 0,
static_save = false,
on_step = function(self, dtime) on_step = function(self, dtime)
self.timer = self.timer + dtime self.timer = self.timer + dtime
@ -47,20 +48,20 @@ local register_spacecannon = function(color, range, timeout, speed)
if obj:get_luaentity() ~= nil and obj:get_luaentity().name ~= self.name then if obj:get_luaentity() ~= nil and obj:get_luaentity().name ~= self.name then
obj:punch(self.object, 1.0, { obj:punch(self.object, 1.0, {
full_punch_interval=1.0, full_punch_interval=1.0,
damage_groups={fleshy=range*2}, damage_groups={fleshy=def.range*2},
}, nil) }, nil)
end end
end end
elseif node.name ~= "air" then elseif node.name ~= "air" then
-- collision -- collision
spacecannon.destroy(pos, range) spacecannon.destroy(pos, def.range)
self.object:remove() self.object:remove()
end end
end, end,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
minetest.after(timeout, minetest.after(def.timeout,
function(self) function(self)
self.object:remove() self.object:remove()
end, end,
@ -71,18 +72,28 @@ local register_spacecannon = function(color, range, timeout, speed)
minetest.register_node("spacecannon:cannon_" .. color, { minetest.register_node("spacecannon:cannon_" .. def.color, {
description = "Spacecannon (" .. color .. ")", description = "Spacecannon (" .. def.desc .. ")",
-- top, bottom -- top, bottom
tiles = {"cannon_blank.png","cannon_front_" .. color .. ".png","cannon_blank.png","cannon_blank.png","cannon_blank.png","cannon_blank.png"}, tiles = {
"cannon_blank.png",
"cannon_front_" .. def.color .. ".png",
"cannon_blank.png",
"cannon_blank.png",
"cannon_blank.png",
"cannon_blank.png"
},
inventory_image = minetest.inventorycube("cannon_front_" .. def.color .. ".png", "cannon_blank.png", "cannon_blank.png"),
groups = {cracky=3,oddly_breakable_by_hand=3,technic_machine = 1, technic_hv = 1}, groups = {cracky=3,oddly_breakable_by_hand=3,technic_machine = 1, technic_hv = 1},
drop = "spacecannon:cannon_" .. color, drop = "spacecannon:cannon_" .. def.color,
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
paramtype2 = "facedir", paramtype2 = "facedir",
legacy_facedir_simple = true,
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
spacecannon.fire(pos, color, speed, range) spacecannon.fire(pos, def.color, def.speed, def.range)
end end
}}, }},
@ -124,7 +135,7 @@ local register_spacecannon = function(color, range, timeout, speed)
meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store) meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store)
if store < spacecannon.config.powerstorage * range then if store < spacecannon.config.powerstorage * def.range then
-- charge -- charge
meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement) meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement)
store = store + eu_input store = store + eu_input
@ -139,34 +150,56 @@ local register_spacecannon = function(color, range, timeout, speed)
local meta = minetest.get_meta(pos); local meta = minetest.get_meta(pos);
if fields.fire then if fields.fire then
spacecannon.fire(pos, color, speed, range) spacecannon.fire(pos, def.color, def.speed, def.range)
end end
end end
}) })
if has_technic_mod then if has_technic_mod then
technic.register_machine("HV", "spacecannon:cannon_" .. color, technic.receiver) technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
end end
--[[
minetest.register_craft({ minetest.register_craft({
output = 'spacecannon:cannon_' .. color, output = 'spacecannon:cannon_' .. def.color,
recipe = { recipe = {
{'', 'default:tnt', ''}, {'', 'default:steelblock', ''},
{'default:diamond', 'default:mese_block', 'default:diamond'}, { def.ingredient, def.ingredient, def.ingredient},
{'', 'default:tnt', ''} {'', 'default:steelblock', ''}
} }
}) })
--]]
end end
register_spacecannon("green", 1, 8, 10) register_spacecannon({
register_spacecannon("yellow", 3, 8, 5) color = "green",
register_spacecannon("red", 5, 15, 3) range = 1,
timeout = 8,
speed = 10,
desc = "fast,low damage",
ingredient = "default:mese_block"
})
register_spacecannon({
color = "yellow",
range = 3,
timeout = 8,
speed = 5,
desc = "medium speed, medium damage",
ingredient = "spacecannon:cannon_green"
})
register_spacecannon({
color = "red",
range = 5,
timeout = 15,
speed = 3,
desc = "slow, heavy damage",
ingredient = "spacecannon:cannon_yellow"
})

@ -41,6 +41,7 @@ spacecannon.fire = function(pos, color, speed, range)
end end
-- destroy stuff in range -- destroy stuff in range
-- TODO: resilient material list
spacecannon.destroy = function(pos,range) spacecannon.destroy = function(pos,range)
for x=-range,range do for x=-range,range do
for y=-range,range do for y=-range,range do
@ -52,6 +53,7 @@ spacecannon.destroy = function(pos,range)
return -- fail fast return -- fail fast
end end
--TODO: replace env* stuff
local n = minetest.env:get_node(np) local n = minetest.env:get_node(np)
if n.name ~= "air" then if n.name ~= "air" then
minetest.env:remove_node(np) minetest.env:remove_node(np)