Reworked power tools, new drills

This commit is contained in:
RealBadAngel 2013-02-21 22:01:49 +01:00
parent 671ba32e5a
commit e23f87d20c
21 changed files with 648 additions and 302 deletions

View File

@ -18,19 +18,12 @@ power_tools[registered_power_tools_count].tool_name=string1
power_tools[registered_power_tools_count].max_charge=max_charge
end
register_power_tool ("technic:mining_drill",60000)
register_power_tool ("technic:chainsaw",30000)
register_power_tool ("technic:laser_mk1",40000)
register_power_tool ("technic:battery",10000)
register_power_tool ("technic:sonic_screwdriver",15000)
register_power_tool ("technic:flashlight",30000)
register_power_tool ("technic:red_energy_crystal",100000)
register_power_tool ("technic:green_energy_crystal",250000)
register_power_tool ("technic:blue_energy_crystal",500000)
minetest.register_alias("battery", "technic:battery")
minetest.register_alias("battery_box", "technic:battery_box")
minetest.register_craft({
output = 'technic:battery 1',
recipe = {
@ -143,7 +136,6 @@ minetest.register_node("technic:battery_box"..i, {
})
end
LV_nodes_visited = {}
function get_RE_item_load (load1,max_load)
@ -163,13 +155,12 @@ end
function set_RE_wear (item_stack,load1,max_load)
local temp=65536-math.floor(load1/max_load*65535)
item_stack["wear"]=tostring(temp)
return item_stack
return item_stack
end
minetest.register_abm({
nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
"technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"
},
"technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
@ -185,51 +176,73 @@ minetest.register_abm({
meta:set_float("last_side_shown",i)
end
--loading registered power tools
--loading registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
item_meta=srcstack:get_metadata()
if src_item["metadata"]=="" then src_item["metadata"]="0" end --create meta for not used before tool/item
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge = nil
local counter=registered_power_tools_count
for i=1, counter,1 do
if power_tools[i].tool_name==src_item["name"] then
item_max_charge=power_tools[i].max_charge
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
item_max_charge=power_tools[i].max_charge
end
end
end
if item_max_charge then
load1=tonumber((src_item["metadata"]))
load_step=1000
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_item["metadata"]=tostring(load1)
inv:set_stack("src", 1, src_item)
end
meta:set_int("battery_charge",charge)
end
if item_max_charge then
load1=src_meta["charge"]
load_step=1000
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
meta:set_int("battery_charge",charge)
end
end
-- dischargin registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local item_max_charge = nil
local counter=registered_power_tools_count-1
for i=1, counter,1 do
if power_tools[i].tool_name==src_item["name"] then
item_max_charge=power_tools[i].max_charge
end
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
item_max_charge=power_tools[i].max_charge
end
end
if item_max_charge then
if src_item["metadata"]=="" then src_item["metadata"]="0" end --create meta for not used before battery/crystal
local load1=tonumber((src_item["metadata"]))
local load1=src_meta["charge"]
load_step=1000
if load1>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
@ -237,7 +250,8 @@ minetest.register_abm({
load1=load1-load_step
charge=charge+load_step
set_RE_wear(src_item,load1,item_max_charge)
src_item["metadata"]=tostring(load1)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
@ -247,18 +261,10 @@ minetest.register_abm({
local load = math.floor(charge/60000 * 100)
meta:set_string("formspec",
"invsize[8,9;]"..
battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;Battery box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]")
(load)..":technic_power_meter_fg.png]")
local pos1={}
pos1.y=pos.y-1
@ -269,15 +275,15 @@ minetest.register_abm({
meta1 = minetest.env:get_meta(pos1)
if meta1:get_float("cablelike")~=1 then return end
local LV_nodes = {}
local PR_nodes = {}
local RE_nodes = {}
local LV_nodes = {}
local PR_nodes = {}
local RE_nodes = {}
LV_nodes[1]={}
LV_nodes[1].x=pos1.x
LV_nodes[1].y=pos1.y
LV_nodes[1].z=pos1.z
LV_nodes[1].visited=false
LV_nodes[1]={}
LV_nodes[1].x=pos1.x
LV_nodes[1].y=pos1.y
LV_nodes[1].z=pos1.z
LV_nodes[1].visited=false
table_index=1
@ -344,45 +350,45 @@ end
})
function add_new_cable_node (LV_nodes,pos1)
local i=1
local i=1
repeat
if LV_nodes[i]==nil then break end
if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end
i=i+1
until false
LV_nodes[i]={}
LV_nodes[i].x=pos1.x
LV_nodes[i].y=pos1.y
LV_nodes[i].z=pos1.z
LV_nodes[i].visited=false
return true
LV_nodes[i]={}
LV_nodes[i].x=pos1.x
LV_nodes[i].y=pos1.y
LV_nodes[i].z=pos1.z
LV_nodes[i].visited=false
return true
end
function check_LV_node (PR_nodes,RE_nodes,LV_nodes,i)
local pos1={}
pos1.x=LV_nodes[i].x
pos1.y=LV_nodes[i].y
pos1.z=LV_nodes[i].z
LV_nodes[i].visited=true
new_node_added=false
pos1.x=pos1.x+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.x=pos1.x-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.x=pos1.x+1
pos1.y=pos1.y+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.y=pos1.y-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.y=pos1.y+1
local pos1={}
pos1.x=LV_nodes[i].x
pos1.y=LV_nodes[i].y
pos1.z=LV_nodes[i].z
LV_nodes[i].visited=true
new_node_added=false
pos1.z=pos1.z+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.z=pos1.z-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.z=pos1.z+1
pos1.x=pos1.x+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.x=pos1.x-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.x=pos1.x+1
pos1.y=pos1.y+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.y=pos1.y-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.y=pos1.y+1
pos1.z=pos1.z+1
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.z=pos1.z-2
check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
pos1.z=pos1.z+1
return new_node_added
end

View File

@ -85,7 +85,7 @@ minetest.register_node("technic:mv_battery_box"..i, {
battery_charge = 0
max_charge = 300000
last_side_shown=0
end,
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
@ -122,51 +122,73 @@ minetest.register_abm({
meta:set_float("last_side_shown",i)
end
--loading registered power tools
--loading registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
item_meta=srcstack:get_metadata()
if src_item["metadata"]=="" then src_item["metadata"]="0" end --create meta for not used before tool/item
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge = nil
local counter=registered_power_tools_count
for i=1, counter,1 do
if power_tools[i].tool_name==src_item["name"] then
item_max_charge=power_tools[i].max_charge
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
item_max_charge=power_tools[i].max_charge
end
end
end
if item_max_charge then
load1=tonumber((src_item["metadata"]))
load_step=4000
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_item["metadata"]=tostring(load1)
inv:set_stack("src", 1, src_item)
end
meta:set_int("battery_charge",charge)
end
if item_max_charge then
load1=src_meta["charge"]
load_step=4000
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
meta:set_int("battery_charge",charge)
end
end
-- dischargin registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local item_max_charge = nil
local counter=registered_power_tools_count-1
for i=1, counter,1 do
if power_tools[i].tool_name==src_item["name"] then
item_max_charge=power_tools[i].max_charge
end
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
item_max_charge=power_tools[i].max_charge
end
end
if item_max_charge then
if src_item["metadata"]=="" then src_item["metadata"]="0" end --create meta for not used before battery/crystal
local load1=tonumber((src_item["metadata"]))
local load1=src_meta["charge"]
load_step=4000
if load1>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
@ -174,7 +196,8 @@ minetest.register_abm({
load1=load1-load_step
charge=charge+load_step
set_RE_wear(src_item,load1,item_max_charge)
src_item["metadata"]=tostring(load1)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
@ -182,19 +205,12 @@ minetest.register_abm({
meta:set_int("battery_charge",charge)
local load = math.floor(charge/300000 * 100)
local load = math.floor((charge/300000) * 100)
meta:set_string("formspec",
"invsize[8,9;]"..
mv_battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;MV Battery box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]")
(load)..":technic_power_meter_fg.png]"
)
local pos1={}

View File

@ -77,19 +77,20 @@ minetest.register_tool("technic:lava_can", {
stack_max = 1,
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then return end
n = minetest.env:get_node(pointed_thing.under)
item=itemstack:to_table()
local load=nil
if item["metadata"]=="" then load=0
else load=tonumber(item["metadata"])
end
if n.name == "default:water_source" then
if n.name == "default:lava_source" then
if load+1<17 then
minetest.env:add_node(pointed_thing.under, {name="air"})
load=load+1;
load=load+1;
item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load)
set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item)
end
return itemstack
@ -101,7 +102,7 @@ minetest.register_tool("technic:lava_can", {
minetest.env:add_node(pointed_thing.under, {name="default:lava_source"})
load=load-1;
item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load)
set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item)
return itemstack
end
@ -111,52 +112,9 @@ minetest.register_tool("technic:lava_can", {
minetest.env:add_node(pointed_thing.above, {name="default:lava_source"})
load=load-1;
item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load)
set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item)
return itemstack
end
if pointed_thing.type ~= "node" then
return end
n = minetest.env:get_node(pointed_thing.under)
if n.name == "default:lava_source" then
item=itemstack:to_table()
local load=tonumber((item["wear"]))
if load==0 then load =65535 end
load=get_RE_item_load(load,lava_can_max_load)
if load+1<9 then
minetest.env:add_node(pointed_thing.under, {name="air"})
load=load+1;
load=set_RE_item_load(load,lava_can_max_load)
item["wear"]=tostring(load)
itemstack:replace(item)
end
return itemstack
end
item=itemstack:to_table()
load=tonumber((item["wear"]))
if load==0 then load =65535 end
load=get_RE_item_load(load,lava_can_max_load)
if load==0 then return end
if n.name == "default:lava_flowing" then
minetest.env:add_node(pointed_thing.under, {name="default:lava_source"})
load=load-1;
load=set_RE_item_load(load,lava_can_max_load)
item["wear"]=tostring(load)
itemstack:replace(item)
return itemstack
end
n = minetest.env:get_node(pointed_thing.above)
if n.name == "air" then
minetest.env:add_node(pointed_thing.above, {name="default:lava_source"})
load=load-1;
load=set_RE_item_load(load,lava_can_max_load)
item["wear"]=tostring(load)
itemstack:replace(item)
return itemstack
end
end,
})

View File

@ -1,4 +1,5 @@
chainsaw_max_charge=30000
register_power_tool ("technic:chainsaw",chainsaw_max_charge)
minetest.register_tool("technic:chainsaw", {
description = "Chainsaw",
@ -7,14 +8,17 @@ minetest.register_tool("technic:chainsaw", {
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type=="node" then
item=itemstack:to_table()
if item["metadata"]=="" or item["metadata"]=="0" then return end --tool not charged
charge=tonumber(item["metadata"])
local meta=get_item_meta(item["metadata"])
if meta==nil then return false end --tool not charghed
if meta["charge"]==nil then return false end
charge=meta["charge"]
charge_to_take=600;
if charge-charge_to_take>0 then
charge_to_take=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge_to_take)
charge=charge-charge_to_take;
set_RE_wear(item,charge,chainsaw_max_charge)
item["metadata"]=tostring(charge)
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
itemstack:replace(item)
return itemstack
end
@ -56,4 +60,4 @@ function chainsaw_dig_it (pos, player,charge_to_take)
end
return charge_to_take
end
end

View File

@ -1,23 +1,25 @@
-- original code comes from walkin_light mod by Echo http://minetest.net/forum/viewtopic.php?id=2621
flashlight_max_charge=30000
register_power_tool ("technic:flashlight",flashlight_max_charge)
minetest.register_tool("technic:flashlight", {
description = "Flashlight",
inventory_image = "technic_flashlight.png",
minetest.register_tool("technic:flashlight", {
description = "Flashlight",
inventory_image = "technic_flashlight.png",
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
end,
})
minetest.register_craft({
output = "technic:flashlight",
recipe = {
{"technic:rubber","glass","technic:rubber"},
{"technic:stainless_steel_ingot","technic:battery","technic:stainless_steel_ingot"},
{"","technic:battery",""}
}
})
on_use = function(itemstack, user, pointed_thing)
end,
})
minetest.register_craft({
output = "technic:flashlight",
recipe = {
{"technic:rubber","glass","technic:rubber"},
{"technic:stainless_steel_ingot","technic:battery","technic:stainless_steel_ingot"},
{"","technic:battery",""}
}
})
local players = {}
local player_positions = {}
local last_wielded = {}
@ -152,13 +154,16 @@ local hotbar=inv:get_list("main")
for i=1,8,1 do
if hotbar[i]:get_name() == "technic:flashlight" then
item=hotbar[i]:to_table()
if item["metadata"]=="" or item["metadata"]=="0" then return false end --flashlight not charghed
charge=tonumber(item["metadata"])
local item=hotbar[i]:to_table()
local meta=get_item_meta(item["metadata"])
if meta==nil then return false end --flashlight not charghed
if meta["charge"]==nil then return false end
charge=meta["charge"]
if charge-2>0 then
charge =charge-2;
set_RE_wear(item,charge,flashlight_max_charge)
item["metadata"]=tostring(charge)
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
hotbar[i]:replace(item)
inv:set_stack("main",i,hotbar[i])
return true

10
technic/helpers.lua Normal file
View File

@ -0,0 +1,10 @@
function get_item_meta (string)
if string.find(string, "return {") then
return minetest.deserialize(string)
else return nil
end
end
function set_item_meta (table)
return minetest.serialize(table)
end

View File

@ -1,9 +1,11 @@
-- Minetest 0.4.4 : technic
-- Minetest 0.4.4d1 : technic
modpath=minetest.get_modpath("technic")
--Read technic config file
dofile(modpath.."/config.lua")
--helper functions
dofile(modpath.."/helpers.lua")
-- world gen
dofile(modpath.."/ores.lua")

View File

@ -1,25 +1,9 @@
mining_drill_max_charge=60000
minetest.register_tool("technic:mining_drill", {
description = "Mining Drill",
inventory_image = "technic_mining_drill.png",
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type=="node" then
item=itemstack:to_table()
if item["metadata"]=="" or item["metadata"]=="0" then return end --tool not charged
charge=tonumber(item["metadata"])
if charge-200>0 then
drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user)
charge =charge-200;
item["metadata"]=tostring(charge)
set_RE_wear(item,charge,mining_drill_max_charge)
itemstack:replace(item)
end
return itemstack
end
end,
})
mining_drill_mk2_max_charge=240000
mining_drill_mk3_max_charge=960000
mining_drill_power_usage=200
mining_drill_mk2_power_usage=600
mining_drill_mk3_power_usage=1800
minetest.register_craft({
output = 'technic:mining_drill',
@ -29,21 +13,373 @@ minetest.register_craft({
{'', 'technic:red_energy_crystal', 'moreores:copper_ingot'},
}
})
minetest.register_craft({
output = 'technic:mining_drill_mk2',
recipe = {
{'technic:diamond_drill_head', 'technic:diamond_drill_head', 'technic:diamond_drill_head'},
{'technic:stainless_steel_ingot', 'technic:mining_drill', 'technic:stainless_steel_ingot'},
{'', 'technic:green_energy_crystal', ''},
}
})
minetest.register_craft({
output = 'technic:mining_drill_mk3',
recipe = {
{'technic:diamond_drill_head', 'technic:diamond_drill_head', 'technic:diamond_drill_head'},
{'technic:stainless_steel_ingot', 'technic:mining_drill_mk2', 'technic:stainless_steel_ingot'},
{'', 'technic:blue_energy_crystal', ''},
}
})
function drill_dig_it (pos, player,drill_type,mode)
local charge
if mode==1 then
drill_dig_it0 (pos,player)
end
if mode==2 then -- 3 deep
dir=drill_dig_it1(player)
if dir==0 then -- x+
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
end
if dir==1 then -- x-
drill_dig_it0 (pos,player)
pos.x=pos.x-1
drill_dig_it0 (pos,player)
pos.x=pos.x-1
drill_dig_it0 (pos,player)
end
if dir==2 then -- z+
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
end
if dir==3 then -- z-
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
end
end
if mode==3 then -- 3 wide
dir=drill_dig_it1(player)
if dir==0 or dir==1 then -- x
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z-2
drill_dig_it0 (pos,player)
end
if dir==2 or dir==3 then -- z
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
end
end
if mode==4 then -- 3 tall, selected in the middle
drill_dig_it0 (pos,player)
pos.y=pos.y+1
drill_dig_it0 (pos,player)
pos.y=pos.y-2
drill_dig_it0 (pos,player)
end
if mode==5 then -- 3 x 3
local dir=player:get_look_dir()
if math.abs(dir.y)<0.5 then
dir=drill_dig_it1(player)
if dir==0 or dir==1 then -- x
drill_dig_it2(pos,player)
end
if dir==2 or dir==3 then -- z
drill_dig_it3(pos,player)
end
else
drill_dig_it4(pos,player)
end
end
if drill_type==1 then charge=mining_drill_power_usage end
if drill_type==2 then
if mode==1 then charge=mining_drill_mk2_power_usage end
if (mode==2 or mode==3 or mode==4) then charge=mining_drill_mk2_power_usage*3 end
end
if drill_type==3 then
if mode==1 then charge=mining_drill_power_usage end
if (mode==2 or mode==3 or mode==4) then charge=mining_drill_mk2_power_usage*6 end
if mode==5 then charge=mining_drill_mk2_power_usage*9 end
end
minetest.sound_play("mining_drill", {pos = pos, gain = 1.0, max_hear_distance = 10,})
return charge
end
function drill_dig_it (pos, player)
function drill_dig_it0 (pos,player)
local node=minetest.env:get_node(pos)
if node.name == "air" or node.name == "ignore" then return end
if node.name == "default:lava_source" then return end
if node.name == "default:lava_flowing" then return end
if node.name == "default:water_source" then minetest.env:remove_node(pos) return end
if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
minetest.sound_play("mining_drill", {pos = pos, gain = 1.0, max_hear_distance = 10,})
minetest.node_dig(pos,node,player)
end
end
function drill_dig_it1 (player)
local dir=player:get_look_dir()
if math.abs(dir.x)>math.abs(dir.z) then
if dir.x>0 then return 0 end
return 1
end
if dir.z>0 then return 2 end
return 3
end
function drill_dig_it2 (pos,player)
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z-2
drill_dig_it0 (pos,player)
pos.z=pos.z+1
pos.y=pos.y+1
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z-2
drill_dig_it0 (pos,player)
pos.z=pos.z+1
pos.y=pos.y-2
drill_dig_it0 (pos,player)
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.z=pos.z-2
drill_dig_it0 (pos,player)
end
function drill_dig_it3 (pos,player)
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
pos.y=pos.y+1
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
pos.y=pos.y-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
end
function drill_dig_it4 (pos,player)
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
pos.z=pos.z+1
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
pos.z=pos.z-2
drill_dig_it0 (pos,player)
pos.x=pos.x+1
drill_dig_it0 (pos,player)
pos.x=pos.x-2
drill_dig_it0 (pos,player)
end
register_power_tool ("technic:mining_drill",mining_drill_max_charge)
minetest.register_tool("technic:mining_drill", {
description = "Mining Drill Mk1",
inventory_image = "technic_mining_drill.png",
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type=="node" then
item=itemstack:to_table()
local meta=get_item_meta(item["metadata"])
if meta==nil then return false end --tool not charghed
if meta["charge"]==nil then return false end
charge=meta["charge"]
if charge-mining_drill_power_usage>0 then
charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,1,1)
charge =charge-mining_drill_power_usage;
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_max_charge)
itemstack:replace(item)
end
return itemstack
end
end,
})
minetest.register_tool("technic:mining_drill_mk2", {
description = "Mining Drill Mk2",
inventory_image = "technic_mining_drill_mk2.png",
on_use = function(itemstack, user, pointed_thing)
mining_drill_mk2_handler(itemstack,user,pointed_thing)
return itemstack
end,
})
register_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge)
for i=1,4,1 do
register_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge)
minetest.register_tool("technic:mining_drill_mk2_"..i, {
description = "Mining Drill Mk2 in Mode "..i,
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
wield_image = "technic_mining_drill_mk2.png",
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
mining_drill_mk2_handler(itemstack,user,pointed_thing)
return itemstack
end,
})
end
minetest.register_tool("technic:mining_drill_mk3", {
description = "Mining Drill Mk3",
inventory_image = "technic_mining_drill_mk3.png",
on_use = function(itemstack, user, pointed_thing)
mining_drill_mk3_handler(itemstack,user,pointed_thing)
return itemstack
end,
})
register_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge)
for i=1,5,1 do
register_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge)
minetest.register_tool("technic:mining_drill_mk3_"..i, {
description = "Mining Drill Mk3 in Mode "..i,
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
wield_image = "technic_mining_drill_mk3.png",
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
mining_drill_mk3_handler(itemstack,user,pointed_thing)
return itemstack
end,
})
end
function mining_drill_mk2_handler (itemstack,user,pointed_thing)
local keys=user:get_player_control()
local player_name=user:get_player_name()
local item=itemstack:to_table()
meta=get_item_meta(item["metadata"])
if meta==nil or keys["sneak"]==true then return mining_drill_mk2_setmode(user,itemstack) end
if meta["mode"]==nil then return mining_drill_mk2_setmode(user,itemstack) end
if pointed_thing.type~="node" then return end
if meta["charge"]==nil then return false end
charge=meta["charge"]
if charge-mining_drill_power_usage>0 then
local charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,2,meta["mode"])
charge=charge-charge_to_take;
if charge<0 then charge=0 end
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_mk2_max_charge)
itemstack:replace(item)
end
return itemstack
end
function mining_drill_mk3_handler (itemstack,user,pointed_thing)
local keys=user:get_player_control()
local player_name=user:get_player_name()
local item=itemstack:to_table()
meta=get_item_meta(item["metadata"])
if meta==nil or keys["sneak"]==true then return mining_drill_mk3_setmode(user,itemstack) end
if meta["mode"]==nil then return mining_drill_mk3_setmode(user,itemstack) end
if pointed_thing.type~="node" then return end
if meta["charge"]==nil then return false end
charge=meta["charge"]
if charge-mining_drill_power_usage>0 then
print(dump(meta))
local charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,3,meta["mode"])
charge=charge-charge_to_take;
if charge<0 then charge=0 end
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_mk3_max_charge)
itemstack:replace(item)
end
return itemstack
end
mining_drill_mode_text={
{"Single node."},
{"3 nodes deep."},
{"3 modes wide."},
{"3 modes tall."},
{"3x3 nodes."},
}
function mining_drill_mk2_setmode(user,itemstack)
local player_name=user:get_player_name()
local item=itemstack:to_table()
local meta=get_item_meta(item["metadata"])
if meta==nil then
meta={}
mode=0
end
if meta["mode"]==nil then
minetest.chat_send_player(player_name,"Hold shift and use to change Mining Drill Mk2 modes.")
meta["mode"]=0
mode=0
end
mode=(meta["mode"])
mode=mode+1
if mode>=5 then mode=1 end
minetest.chat_send_player(player_name, "Mining Drill Mk2 mode : "..mode.." - "..mining_drill_mode_text[mode][1] )
item["name"]="technic:mining_drill_mk2_"..mode
meta["mode"]=mode
item["metadata"]=set_item_meta(meta)
itemstack:replace(item)
return itemstack
end
function mining_drill_mk3_setmode(user,itemstack)
local player_name=user:get_player_name()
local item=itemstack:to_table()
local meta=get_item_meta(item["metadata"])
if meta==nil then
meta={}
mode=0
end
if meta["mode"]==nil then
minetest.chat_send_player(player_name,"Hold shift and use to change Mining Drill Mk3 modes.")
meta["mode"]=0
mode=0
end
mode=(meta["mode"])
mode=mode+1
if mode>=6 then mode=1 end
minetest.chat_send_player(player_name, "Mining Drill Mk3 mode : "..mode.." - "..mining_drill_mode_text[mode][1] )
item["name"]="technic:mining_drill_mk3_"..mode
meta["mode"]=mode
item["metadata"]=set_item_meta(meta)
itemstack:replace(item)
return itemstack
end

View File

@ -1,4 +1,6 @@
laser_mk1_max_charge=40000
register_power_tool ("technic:laser_mk1",laser_mk1_max_charge)
local laser_shoot = function(itemstack, player, pointed_thing)
local laser_straight_mode=0
local playerpos=player:getpos()
@ -10,7 +12,7 @@ local laser_shoot = function(itemstack, player, pointed_thing)
minetest.node_dig(pos,node,player)
end
laser_straight_mode=1
end
end
direction_y=math.abs(math.floor(dir.y*100))
if direction_y>50 then entity_name="technic:laser_beam_entityV"
@ -54,13 +56,16 @@ minetest.register_tool("technic:laser_mk1", {
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
item=itemstack:to_table()
if item["metadata"]=="" or item["metadata"]=="0" then return end
local charge=tonumber((item["metadata"]))
local meta=get_item_meta(item["metadata"])
if meta==nil then return false end --tool not charghed
if meta["charge"]==nil then return false end
charge=meta["charge"]
if charge-400>0 then
laser_shoot(item, user, pointed_thing)
charge =charge-400;
item["metadata"]=tostring(charge)
charge=set_RE_wear(item,charge,laser_mk1_max_charge)
charge =charge-400;
set_RE_wear(item,charge,laser_mk1_max_charge)
meta["charge"]=charge
item["metadata"]=set_item_meta(meta)
itemstack:replace(item)
end
return itemstack
@ -171,4 +176,4 @@ function lazer_it (pos, player)
if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
if player then minetest.node_dig(pos,node,player) end
end
end

View File

@ -1,55 +1,59 @@
sonic_screwdriver_max_charge=15000
minetest.register_tool("technic:sonic_screwdriver", {
description = "Sonic Screwdriver",
inventory_image = "technic_sonic_screwdriver.png",
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to facedir applicable node
if pointed_thing.type~="node" then return end
local pos=minetest.get_pointed_thing_position(pointed_thing,above)
local node=minetest.env:get_node(pos)
local node_name=node.name
if minetest.registered_nodes[node_name].paramtype2 == "facedir" or minetest.registered_nodes[node_name].paramtype2 == "wallmounted" then
if node.param2==nil then return end
item=itemstack:to_table()
if item["metadata"]=="" or item["metadata"]=="0" then return end
local charge=tonumber((item["metadata"]))
if charge-100>0 then
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10,})
local n = node.param2
if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
n = n+1
if n == 4 then n = 0 end
else
n = n+1
if n == 6 then n = 0 end
end
-- hacky_swap_node, unforunatly.
local meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table()
node.param2 = n
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
charge =charge-100;
item["metadata"]=tostring(charge)
set_RE_wear(item,charge,sonic_screwdriver_max_charge)
itemstack:replace(item)
end
return itemstack
else
return itemstack
end
end,
})
minetest.register_craft({
output = "technic:sonic_screwdriver",
recipe = {
{"technic:diamond"},
{"technic:battery"},
{"technic:stainless_steel_ingot"}
}
})
register_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge)
minetest.register_tool("technic:sonic_screwdriver", {
description = "Sonic Screwdriver",
inventory_image = "technic_sonic_screwdriver.png",
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to facedir applicable node
if pointed_thing.type~="node" then return end
local pos=minetest.get_pointed_thing_position(pointed_thing,above)
local node=minetest.env:get_node(pos)
local node_name=node.name
if minetest.registered_nodes[node_name].paramtype2 == "facedir" or minetest.registered_nodes[node_name].paramtype2 == "wallmounted" then
if node.param2==nil then return end
item=itemstack:to_table()
local meta1=get_item_meta(item["metadata"])
if meta1==nil then return false end --tool not charghed
if meta1["charge"]==nil then return false end
charge=meta1["charge"]
if charge-100>0 then
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10,})
local n = node.param2
if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
n = n+1
if n == 4 then n = 0 end
else
n = n+1
if n == 6 then n = 0 end
end
-- hacky_swap_node, unforunatly.
local meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table()
node.param2 = n
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
charge=charge-100;
meta1["charge"]=charge
item["metadata"]=set_item_meta(meta1)
set_RE_wear(item,charge,sonic_screwdriver_max_charge)
itemstack:replace(item)
end
return itemstack
else
return itemstack
end
end,
})
minetest.register_craft({
output = "technic:sonic_screwdriver",
recipe = {
{"technic:diamond"},
{"technic:battery"},
{"technic:stainless_steel_ingot"}
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B