mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2025-01-02 02:57:29 +01:00
item drop
This commit is contained in:
parent
686055a682
commit
2ceaa9857e
43
cannon.lua
43
cannon.lua
@ -1,4 +1,3 @@
|
|||||||
local has_technic_mod = minetest.get_modpath("technic")
|
|
||||||
|
|
||||||
local register_spacecannon = function(def)
|
local register_spacecannon = function(def)
|
||||||
|
|
||||||
@ -42,17 +41,25 @@ local register_spacecannon = function(def)
|
|||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
if node.name == "air" then
|
if node.name == "air" or node.name == "vacuum:vacuum" then
|
||||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 3)
|
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 3)
|
||||||
|
local collided = false
|
||||||
for k, obj in pairs(objs) do
|
for k, obj in pairs(objs) do
|
||||||
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, {
|
collided = true
|
||||||
full_punch_interval=1.0,
|
obj:punch(self.object, 1.0, {
|
||||||
damage_groups={fleshy=def.range*2},
|
full_punch_interval=1.0,
|
||||||
}, nil)
|
damage_groups={fleshy=def.range*2},
|
||||||
|
}, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif node.name ~= "air" then
|
|
||||||
|
if collided then
|
||||||
|
spacecannon.destroy(pos, def.range)
|
||||||
|
self.object:remove()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then
|
||||||
-- collision
|
-- collision
|
||||||
spacecannon.destroy(pos, def.range)
|
spacecannon.destroy(pos, def.range)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
@ -109,24 +116,12 @@ local register_spacecannon = function(def)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int("powerstorage", 0)
|
meta:set_int("powerstorage", 0)
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
meta:set_int("HV_EU_input", 0)
|
||||||
inv:set_size("main", 8)
|
meta:set_int("HV_EU_demand", 0)
|
||||||
|
|
||||||
if has_technic_mod then
|
|
||||||
meta:set_int("HV_EU_input", 0)
|
|
||||||
meta:set_int("HV_EU_demand", 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
spacecannon.update_formspec(meta)
|
spacecannon.update_formspec(meta)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("main")
|
|
||||||
end,
|
|
||||||
|
|
||||||
|
|
||||||
technic_run = function(pos, node)
|
technic_run = function(pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local eu_input = meta:get_int("HV_EU_input")
|
local eu_input = meta:get_int("HV_EU_input")
|
||||||
@ -156,9 +151,7 @@ local register_spacecannon = function(def)
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if has_technic_mod then
|
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
|
||||||
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'spacecannon:cannon_' .. def.color,
|
output = 'spacecannon:cannon_' .. def.color,
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
default
|
default
|
||||||
technic?
|
technic
|
||||||
mesecons?
|
mesecons?
|
||||||
|
7
init.lua
7
init.lua
@ -5,12 +5,7 @@ spacecannon = {
|
|||||||
powerstorage = 10000,
|
powerstorage = 10000,
|
||||||
|
|
||||||
-- charge value in EU
|
-- charge value in EU
|
||||||
powerrequirement = 2500,
|
powerrequirement = 2500
|
||||||
|
|
||||||
-- fuel item and count
|
|
||||||
power_item = "default:mese_crystal",
|
|
||||||
power_item_count = 1
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
util.lua
41
util.lua
@ -1,12 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
spacecannon.update_formspec = function(meta)
|
spacecannon.update_formspec = function(meta)
|
||||||
meta:set_string("formspec", "size[8,10;]" ..
|
meta:set_string("formspec", "size[8,2;]" ..
|
||||||
"button_exit[0,2;8,1;fire;Fire]" ..
|
"button_exit[0,2;8,1;fire;Fire]")
|
||||||
|
|
||||||
"list[context;main;0,3;8,1;]" ..
|
|
||||||
|
|
||||||
"list[current_player;main;0,5;8,4;]")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
spacecannon.fire = function(pos, color, speed, range)
|
spacecannon.fire = function(pos, color, speed, range)
|
||||||
@ -15,19 +11,9 @@ spacecannon.fire = function(pos, color, speed, range)
|
|||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
|
|
||||||
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
||||||
|
-- not enough power
|
||||||
|
return
|
||||||
|
|
||||||
-- check inventory
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
local power_item = spacecannon.config.power_item
|
|
||||||
local power_item_count = spacecannon.config.power_item_count * range
|
|
||||||
|
|
||||||
if not inv:contains_item("main", {name=power_item, count=power_item_count}) then
|
|
||||||
minetest.chat_send_player(owner, "Not enough fuel to fire cannon, expected " .. power_item_count .. " " .. power_item)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- use up items
|
|
||||||
inv:remove_item("main", {name=power_item, count=power_item_count})
|
|
||||||
else
|
else
|
||||||
-- use power
|
-- use power
|
||||||
meta:set_int("powerstorage", 0)
|
meta:set_int("powerstorage", 0)
|
||||||
@ -53,10 +39,17 @@ spacecannon.destroy = function(pos,range)
|
|||||||
return -- fail fast
|
return -- fail fast
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO: replace env* stuff
|
local n = minetest.get_node_or_nil(np)
|
||||||
local n = minetest.env:get_node(np)
|
|
||||||
if n.name ~= "air" then
|
if n and n.name ~= "air" then
|
||||||
minetest.env:remove_node(np)
|
minetest.set_node(np, {name="air"})
|
||||||
|
local itemstacks = minetest.get_node_drops(n.name)
|
||||||
|
for _, itemname in ipairs(itemstacks) do
|
||||||
|
if math.random(5) == 5 then
|
||||||
|
-- chance drop
|
||||||
|
minetest.add_item(np, itemname)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -97,4 +90,6 @@ spacecannon.facedir_to_down_dir = function(facing)
|
|||||||
{x=-1, y=0, z=0},
|
{x=-1, y=0, z=0},
|
||||||
{x=1, y=0, z=0},
|
{x=1, y=0, z=0},
|
||||||
{x=0, y=1, z=0}})[math.floor(facing/4)]
|
{x=0, y=1, z=0}})[math.floor(facing/4)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user