This commit is contained in:
2022-07-11 13:06:47 +02:00
parent bad55d19a0
commit f580dcd720
10 changed files with 84 additions and 129 deletions

127
init.lua
View File

@@ -337,7 +337,7 @@ on_activate= function(self, staticdata)
end,
on_step=portalgun_on_step,
})
minetest.register_craftitem("portalgun:gun", {
minetest.register_craftitem(":", {
description = "Portalgun",
range = 100,
inventory_image = "portalgun_gun0_rndr.png",
@@ -352,118 +352,33 @@ minetest.register_craftitem("portalgun:gun", {
damage_groups = {fleshy=1},
},
on_place=function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 2)
portalgun_onuse(itemstack, user, pointed_thing)
local node = minetest.get_node(pointed_thing.under)
if node.name=="portalgun:button"then
--use the item normally
minetest.item_place(itemstack, user, pointed_thing)
else
portalgun_onuse(itemstack, user, pointed_thing, 2)
end
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 1)
portalgun_onuse(itemstack, user, pointed_thing)
--if pointing at turret then start breaking it
if pointed_thing.type=="node" then
local node=minetest.get_node(pointed_thing.under)
if node.name=="portalgun:turretgun" or node.name=="portalgun:turretgun2" then
minetest.remove_node(pointed_thing.under)
end
end
portalgun_onuse(itemstack, user, pointed_thing, 1)
return itemstack
end
})
minetest.register_craftitem("portalgun:gun1", {
description = "Portalgun (blue)",
range = 100,
groups = {not_in_creative_inventory=1},
inventory_image = "portalgun_gun1_rndr.png",
wield_image = "portalgun_gun1_rndr.png",
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 3,
groupcaps = {
fleshy = {times={[2]=0.80, [3]=0.40}, uses=100, maxlevel=3},
oddly_breakable_by_hand = {times={[1]=1}, uses=100, maxlevel=1},
},
damage_groups = {fleshy=1},
},
on_place=function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 2)
portalgun_onuse(itemstack, user, pointed_thing)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 1)
portalgun_onuse(itemstack, user, pointed_thing)
return itemstack
end
})
minetest.register_craftitem("portalgun:gun2", {
description = "Portalgun (orange)",
range = 100,
inventory_image = "portalgun_gun2_rndr.png",
wield_image = "portalgun_gun2_rndr.png",
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 3,
groupcaps = {
fleshy = {times={[2]=0.80, [3]=0.40}, uses=100, maxlevel=3},
oddly_breakable_by_hand = {times={[1]=1}, uses=100, maxlevel=1},
},
damage_groups = {fleshy=1},
},
groups = {not_in_creative_inventory=1},
on_place=function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 2)
portalgun_onuse(itemstack, user, pointed_thing)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
portalgun_setmode(itemstack, user, pointed_thing, 1)
portalgun_onuse(itemstack, user, pointed_thing)
return itemstack
end
})
function portalgun_mode(itemstack, user, pointed_thing) -- change modes
local item=itemstack:to_table()
local meta=minetest.deserialize(item["metadata"])
local mode=0
if meta==nil then
meta={}
mode=1
minetest.chat_send_player(user:get_player_name(), "<Portalgun> PLACE to change portal mode (or LEFT+RIGHTCLICK to use the other)")
minetest.chat_send_player(user:get_player_name(), "<Portalgun> LEFTCLICK on an object to carry it, CLICK AGAIN to release")
minetest.chat_send_player(user:get_player_name(), "<Portalgun> SHIFT+LEFTCLICK to close both portals (or wait 40sec until it removes it self)")
end
if meta.mode==nil then meta.mode=2 end
mode=(meta.mode)
if mode==1 then
mode=2
else
mode=1
end
meta.mode=mode
item.name="portalgun:gun"..mode
item.metadata=minetest.serialize(meta)
itemstack:replace(item)
minetest.sound_play("portalgun_mode", {pos=user:get_pos(),max_hear_distance = 5, gain = 1})
end
function portalgun_setmode(itemstack, user, pointed_thing, mode) -- change modes
local item=itemstack:to_table()
local meta=minetest.deserialize(item["metadata"])
if meta==nil then
meta={}
mode=1
minetest.chat_send_player(user:get_player_name(), "<Portalgun> PLACE to change portal mode (or LEFT+RIGHTCLICK to use the other)")
minetest.chat_send_player(user:get_player_name(), "<Portalgun> LEFTCLICK on an object to carry it, CLICK AGAIN to release")
minetest.chat_send_player(user:get_player_name(), "<Portalgun> SHIFT+LEFTCLICK to close both portals (or wait 40sec until it removes it self)")
end
if meta.mode==nil then meta.mode=2 end
meta.mode=mode
item.name="portalgun:gun"..mode
item.metadata=minetest.serialize(meta)
itemstack:replace(item)
minetest.sound_play("portalgun_mode", {pos=user:get_pos(),max_hear_distance = 5, gain = 1})
end
local function rnd(r)
return math.floor(r+ 0.5)
end
function portalgun_onuse(itemstack, user, pointed_thing) -- using the gun
function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
if pointed_thing.type=="object" then
portalgun_gravity(itemstack, user, pointed_thing)
@@ -477,14 +392,6 @@ function portalgun_onuse(itemstack, user, pointed_thing) -- using the gun
local exist=0
local item=itemstack:to_table()
local mode=minetest.deserialize(item["metadata"])
if mode==nil then
portalgun_mode(itemstack, user, pointed_thing)
return itemstack
else
mode=mode.mode
end
local ob={}
ob.project=1
ob.lifelime=portalgun_lifelime