forked from minetest-mods/technic
Fix negative tool discharging and a few other tweaks...
Disable the flashlight by default. Use itemstack:{get,set}_{metadata,name,wear,...} rather than {to,from}_table. Improve the style of part of the code of mischelaneous tools
This commit is contained in:
parent
66e4b5ede4
commit
eac4844175
|
@ -8,7 +8,7 @@ local conf_table = technic.config:to_table()
|
|||
local defaults = {
|
||||
enable_mining_drill = "true",
|
||||
enable_mining_laser = "true",
|
||||
enable_flashlight = "true",
|
||||
enable_flashlight = "false",
|
||||
enable_rubber_tree_generation = "true",
|
||||
enable_marble_generation = "true",
|
||||
enable_granite_generation = "true",
|
||||
|
|
|
@ -137,80 +137,73 @@ function technic.register_battery_box(data)
|
|||
end -- End registration
|
||||
|
||||
|
||||
function technic.charge_tools(meta, charge, charge_step)
|
||||
--charge registered power tools
|
||||
function technic.charge_tools(meta, batt_charge, charge_step)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("src") then
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_item = srcstack:to_table()
|
||||
local src_meta = get_item_meta(src_item["metadata"])
|
||||
|
||||
local toolname = src_item["name"]
|
||||
if technic.power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta = get_item_meta(src_item["metadata"])
|
||||
src_meta = src_meta or {}
|
||||
if src_meta["charge"] == nil then
|
||||
src_meta["charge"] = 0
|
||||
end
|
||||
-- Do the charging
|
||||
local item_max_charge = technic.power_tools[toolname]
|
||||
local tool_charge = src_meta["charge"]
|
||||
if tool_charge < item_max_charge and charge > 0 then
|
||||
if charge - charge_step < 0 then
|
||||
charge_step = charge
|
||||
end
|
||||
if tool_charge + charge_step > item_max_charge then
|
||||
charge_step = item_max_charge - tool_charge
|
||||
end
|
||||
tool_charge = tool_charge + charge_step
|
||||
charge = charge - charge_step
|
||||
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
|
||||
src_meta["charge"] = tool_charge
|
||||
src_item["metadata"] = set_item_meta(src_meta)
|
||||
inv:set_stack("src", 1, src_item)
|
||||
end
|
||||
end
|
||||
if inv:is_empty("src") then
|
||||
return batt_charge
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_meta = get_item_meta(srcstack:get_metadata())
|
||||
|
||||
local toolname = srcstack:get_name()
|
||||
if not technic.power_tools[toolname] then
|
||||
return batt_charge
|
||||
end
|
||||
-- Set meta data for the tool if it didn't do it itself
|
||||
src_meta = get_item_meta(srcstack:get_metadata())
|
||||
src_meta = src_meta or {}
|
||||
if not src_meta.charge then
|
||||
src_meta.charge = 0
|
||||
end
|
||||
-- Do the charging
|
||||
local item_max_charge = technic.power_tools[toolname]
|
||||
local tool_charge = src_meta.charge
|
||||
if tool_charge >= item_max_charge or batt_charge <= 0 then
|
||||
return batt_charge
|
||||
end
|
||||
charge_step = math.min(charge_step, batt_charge)
|
||||
charge_step = math.min(charge_step, item_max_charge - tool_charge)
|
||||
tool_charge = tool_charge + charge_step
|
||||
batt_charge = batt_charge - charge_step
|
||||
technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
|
||||
src_meta.charge = tool_charge
|
||||
srcstack:set_metadata(set_item_meta(src_meta))
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
return batt_charge
|
||||
end
|
||||
|
||||
|
||||
function technic.discharge_tools(meta, charge, charge_step, max_charge)
|
||||
-- discharging registered power tools
|
||||
function technic.discharge_tools(meta, batt_charge, charge_step, max_charge)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("dst") then
|
||||
srcstack = inv:get_stack("dst", 1)
|
||||
src_item = srcstack:to_table()
|
||||
local src_meta = get_item_meta(src_item["metadata"])
|
||||
local toolname = src_item["name"]
|
||||
if technic.power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta = get_item_meta(src_item["metadata"])
|
||||
src_meta = src_meta or {}
|
||||
if src_meta["charge"] == nil then
|
||||
src_meta["charge"] = 0
|
||||
end
|
||||
|
||||
-- Do the discharging
|
||||
local item_max_charge = technic.power_tools[toolname]
|
||||
local tool_charge = src_meta["charge"]
|
||||
if tool_charge > 0 and charge < max_charge then
|
||||
if charge + charge_step > max_charge then
|
||||
charge_step = max_charge - charge
|
||||
end
|
||||
if tool_charge - charge_step < 0 then
|
||||
charge_step = charge
|
||||
end
|
||||
tool_charge = tool_charge - charge_step
|
||||
charge = charge + charge_step
|
||||
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
|
||||
src_meta["charge"] = tool_charge
|
||||
src_item["metadata"] = set_item_meta(src_meta)
|
||||
inv:set_stack("dst", 1, src_item)
|
||||
end
|
||||
end
|
||||
if inv:is_empty("dst") then
|
||||
return batt_charge
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
srcstack = inv:get_stack("dst", 1)
|
||||
local toolname = srcstack:get_name()
|
||||
if technic.power_tools[toolname] == nil then
|
||||
return batt_charge
|
||||
end
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
local src_meta = get_item_meta(srcstack:get_metadata())
|
||||
src_meta = src_meta or {}
|
||||
if not src_meta.charge then
|
||||
src_meta.charge = 0
|
||||
end
|
||||
|
||||
-- Do the discharging
|
||||
local item_max_charge = technic.power_tools[toolname]
|
||||
local tool_charge = src_meta.charge
|
||||
if tool_charge <= 0 or batt_charge >= max_charge then
|
||||
return batt_charge
|
||||
end
|
||||
charge_step = math.min(charge_step, max_charge - batt_charge)
|
||||
charge_step = math.min(charge_step, tool_charge)
|
||||
tool_charge = tool_charge - charge_step
|
||||
batt_charge = batt_charge + charge_step
|
||||
technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
|
||||
src_meta.charge = tool_charge
|
||||
srcstack:set_metadata(set_item_meta(src_meta))
|
||||
inv:set_stack("dst", 1, srcstack)
|
||||
return batt_charge
|
||||
end
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ function technic.set_RE_item_load(load1, max_load)
|
|||
end
|
||||
|
||||
-- Wear down a tool depending on the remaining charge.
|
||||
function technic.set_RE_wear(item_stack, item_load, max_load)
|
||||
function technic.set_RE_wear(itemstack, item_load, max_load)
|
||||
local temp = 65536 - math.floor(item_load / max_load * 65535)
|
||||
item_stack.wear = tostring(temp)
|
||||
return item_stack
|
||||
itemstack:set_wear(temp)
|
||||
return itemstack
|
||||
end
|
||||
|
|
|
@ -26,48 +26,46 @@ minetest.register_tool("technic:water_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"])
|
||||
return
|
||||
end
|
||||
|
||||
if n.name == "default:water_source" then
|
||||
if load+1<17 then
|
||||
minetest.env:add_node(pointed_thing.under, {name="air"})
|
||||
load=load+1;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,water_can_max_load)
|
||||
itemstack:replace(item)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
item=itemstack:to_table()
|
||||
if load==0 then return end
|
||||
|
||||
if n.name == "default:water_flowing" then
|
||||
minetest.env:add_node(pointed_thing.under, {name="default:water_source"})
|
||||
load=load-1;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,water_can_max_load)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
node = minetest.get_node(pointed_thing.under)
|
||||
|
||||
n = minetest.env:get_node(pointed_thing.above)
|
||||
if n.name == "air" then
|
||||
minetest.env:add_node(pointed_thing.above, {name="default:water_source"})
|
||||
load=load-1;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,water_can_max_load)
|
||||
itemstack:replace(item)
|
||||
local charge = nil
|
||||
if itemstack:get_metadata() == "" then
|
||||
charge = 0
|
||||
else
|
||||
charge = tonumber(itemstack:get_metadata())
|
||||
end
|
||||
if node.name == "default:water_source" then
|
||||
if charge + 1 < 17 then
|
||||
minetest.remove_node(pointed_thing.under)
|
||||
charge = charge + 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, water_can_max_load)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
if charge == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if node.name == "default:water_flowing" then
|
||||
minetest.set_node(pointed_thing.under, {name="default:water_source"})
|
||||
charge = charge - 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, water_can_max_load)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
node = minetest.get_node(pointed_thing.above)
|
||||
if node.name == "air" then
|
||||
minetest.set_node(pointed_thing.above, {name="default:water_source"})
|
||||
charge = charge - 1;
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, water_can_max_load)
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -77,44 +75,45 @@ 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"])
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
if n.name == "default:lava_source" then
|
||||
if load+1<17 then
|
||||
minetest.env:add_node(pointed_thing.under, {name="air"})
|
||||
load=load+1;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,lava_can_max_load)
|
||||
itemstack:replace(item)
|
||||
end
|
||||
return itemstack
|
||||
node = minetest.get_node(pointed_thing.under)
|
||||
local charge = 0
|
||||
if itemstack:get_metadata() == "" then
|
||||
charge = 0
|
||||
else
|
||||
charge = tonumber(itemstack:get_metadata())
|
||||
end
|
||||
item=itemstack:to_table()
|
||||
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;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,lava_can_max_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;
|
||||
item["metadata"]=tostring(load)
|
||||
technic.set_RE_wear(item,load,lava_can_max_load)
|
||||
itemstack:replace(item)
|
||||
if node.name == "default:lava_source" then
|
||||
if charge + 1 < 17 then
|
||||
minetest.remove_node(pointed_thing.under)
|
||||
charge = charge + 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, lava_can_max_load)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
if charge == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if node.name == "default:lava_flowing" then
|
||||
minetest.set_node(pointed_thing.under, {name="default:lava_source"})
|
||||
charge = charge - 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, lava_can_max_load)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
node = minetest.get_node(pointed_thing.above)
|
||||
if node.name == "air" then
|
||||
minetest.set_node(pointed_thing.above, {name="default:lava_source"})
|
||||
charge = charge - 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
technic.set_RE_wear(itemstack, charge, lava_can_max_load)
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -6,27 +6,28 @@ local chainsaw_leaves = true -- true - Cut down entire trees, leaves
|
|||
technic.register_power_tool("technic:chainsaw", chainsaw_max_charge)
|
||||
|
||||
minetest.register_tool("technic:chainsaw", {
|
||||
description = "Chainsaw",
|
||||
inventory_image = "technic_chainsaw.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 end --tool not charged
|
||||
if meta["charge"]==nil then return end
|
||||
-- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
|
||||
local charge=meta["charge"]
|
||||
if charge < chainsaw_charge_per_node then return end -- only cut if charged
|
||||
description = "Chainsaw",
|
||||
inventory_image = "technic_chainsaw.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
return itemstack
|
||||
end
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
-- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
|
||||
if mata.charge < chainsaw_charge_per_node then
|
||||
return
|
||||
end
|
||||
|
||||
charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge)
|
||||
technic.set_RE_wear(item,charge,chainsaw_max_charge)
|
||||
meta["charge"]=charge
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
meta.charge = chainsaw_dig_it(pos, user, mata.charge)
|
||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
|
@ -140,28 +140,26 @@ minetest.register_node("technic:light_off", {
|
|||
},
|
||||
})
|
||||
|
||||
function check_for_flashlight (player)
|
||||
if player==nil then return false end
|
||||
local inv = player:get_inventory()
|
||||
local hotbar=inv:get_list("main")
|
||||
for i=1,8,1 do
|
||||
|
||||
if hotbar[i]:get_name() == "technic:flashlight" then
|
||||
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;
|
||||
technic.set_RE_wear(item,charge,flashlight_max_charge)
|
||||
meta["charge"]=charge
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
hotbar[i]:replace(item)
|
||||
inv:set_stack("main",i,hotbar[i])
|
||||
return true
|
||||
function check_for_flashlight(player)
|
||||
if player == nil then
|
||||
return false
|
||||
end
|
||||
local inv = player:get_inventory()
|
||||
local hotbar = inv:get_list("main")
|
||||
for i = 1, 8 do
|
||||
if hotbar[i]:get_name() == "technic:flashlight" then
|
||||
local meta = get_item_meta(hotbar[i]:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return false
|
||||
end
|
||||
if meta.charge - 2 > 0 then
|
||||
meta.charge = meta.charge - 2;
|
||||
technic.set_RE_wear(hotbar[i], meta.charge, flashlight_max_charge)
|
||||
hotbar[i]:set_metadata(set_item_meta(meta))
|
||||
inv:set_stack("main", i, hotbar[i])
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
|
|
@ -8,28 +8,28 @@ local mining_drill_mk3_power_usage = 1800
|
|||
minetest.register_craft({
|
||||
output = 'technic:mining_drill',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', 'technic:diamond_drill_head', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
|
||||
{'', 'technic:red_energy_crystal', 'moreores:copper_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:diamond_drill_head', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
|
||||
{'', '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', ''},
|
||||
{'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', ''},
|
||||
{'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', ''},
|
||||
}
|
||||
})
|
||||
for i=1,4,1 do
|
||||
for i = 1, 4 do
|
||||
minetest.register_craft({
|
||||
output = 'technic:mining_drill_mk3',
|
||||
recipe = {
|
||||
|
@ -40,25 +40,23 @@ for i=1,4,1 do
|
|||
})
|
||||
end
|
||||
|
||||
function drill_dig_it (pos, player,drill_type,mode)
|
||||
|
||||
function drill_dig_it(pos, player, drill_type, mode)
|
||||
local charge
|
||||
|
||||
if mode==1 then
|
||||
drill_dig_it0 (pos,player)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
|
@ -226,22 +224,21 @@ minetest.register_tool("technic:mining_drill", {
|
|||
inventory_image = "technic_mining_drill.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type=="node" then
|
||||
local item=itemstack:to_table()
|
||||
local meta=get_item_meta(item["metadata"])
|
||||
if meta==nil then return end --tool not charghed
|
||||
if meta["charge"]==nil then return end
|
||||
local 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)
|
||||
technic.set_RE_wear(item,charge,mining_drill_max_charge)
|
||||
itemstack:replace(item)
|
||||
end
|
||||
return itemstack
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
charge_to_take = drill_dig_it(pos, user, 1, 1)
|
||||
meta.charge = meta.charge - mining_drill_power_usage
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -249,14 +246,14 @@ 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
|
||||
mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
technic.register_power_tool("technic:mining_drill_mk2", mining_drill_mk2_max_charge)
|
||||
|
||||
for i=1,4,1 do
|
||||
for i = 1, 4 do
|
||||
technic.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,
|
||||
|
@ -295,56 +292,54 @@ for i=1,5,1 do
|
|||
})
|
||||
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()
|
||||
local 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 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)
|
||||
technic.set_RE_wear(item,charge,mining_drill_mk2_max_charge)
|
||||
itemstack:replace(item)
|
||||
function mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk2_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 2, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk2_max_charge)
|
||||
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()
|
||||
local 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 end
|
||||
local 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,3,meta["mode"])
|
||||
charge=charge-charge_to_take;
|
||||
if charge<0 then charge=0 end
|
||||
meta["charge"]=charge
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
technic.set_RE_wear(item,charge,mining_drill_mk3_max_charge)
|
||||
itemstack:replace(item)
|
||||
function mining_drill_mk3_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk3_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 3, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk3_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
mining_drill_mode_text={
|
||||
{"Single node."},
|
||||
{"3 nodes deep."},
|
||||
{"3 modes wide."},
|
||||
{"3 modes tall."},
|
||||
{"3x3 nodes."},
|
||||
mining_drill_mode_text = {
|
||||
{"Single node."},
|
||||
{"3 nodes deep."},
|
||||
{"3 modes wide."},
|
||||
{"3 modes tall."},
|
||||
{"3x3 nodes."},
|
||||
}
|
||||
|
||||
function mining_drill_mk2_setmode(user,itemstack)
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
local laser_mk1_max_charge = 40000
|
||||
technic.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()
|
||||
local dir=player:get_look_dir()
|
||||
if pointed_thing.type=="node" then
|
||||
pos=minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if node.name~="ignore" then
|
||||
minetest.node_dig(pos,node,player)
|
||||
end
|
||||
laser_straight_mode=1
|
||||
end
|
||||
|
||||
direction_y=math.abs(math.floor(dir.y*100))
|
||||
if direction_y>50 then entity_name="technic:laser_beam_entityV"
|
||||
else entity_name="technic:laser_beam_entity" end
|
||||
|
||||
if laser_straight_mode==1 then
|
||||
pos1=minetest.get_pointed_thing_position(pointed_thing, under)
|
||||
pos1.x=math.floor(pos1.x)
|
||||
pos1.y=math.floor(pos1.y)
|
||||
pos1.z=math.floor(pos1.z)
|
||||
obj=minetest.env:add_entity(pos1,entity_name)
|
||||
else
|
||||
obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.6,z=playerpos.z},entity_name)
|
||||
end
|
||||
if obj:get_luaentity().player == nil then
|
||||
obj:get_luaentity().player = player
|
||||
end
|
||||
if laser_straight_mode==1 and direction_y<50 then
|
||||
obj:setvelocity({x=dir.x*8, y=0, z=dir.z*8})
|
||||
else if laser_straight_mode==1 and direction_y>50 then
|
||||
obj:setvelocity({x=0, y=dir.y*8, z=dir.z*8})
|
||||
end
|
||||
end
|
||||
if laser_straight_mode==0 then
|
||||
obj:setvelocity({x=dir.x*8, y=dir.y*8, z=dir.z*8})
|
||||
end
|
||||
obj:setacceleration({x=0, y=0, z=0})
|
||||
obj:setyaw(player:get_look_yaw()+math.pi)
|
||||
if obj:get_luaentity().player == nil then
|
||||
obj:get_luaentity().player = player
|
||||
end
|
||||
--obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
|
||||
minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
|
||||
return true
|
||||
local laser_shoot = function(player, pointed_thing)
|
||||
local laser_straight_mode=0
|
||||
local playerpos=player:getpos()
|
||||
local dir=player:get_look_dir()
|
||||
if pointed_thing.type=="node" then
|
||||
pos=minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if node.name~="ignore" then
|
||||
minetest.node_dig(pos,node,player)
|
||||
end
|
||||
laser_straight_mode=1
|
||||
end
|
||||
|
||||
direction_y=math.abs(math.floor(dir.y*100))
|
||||
if direction_y>50 then entity_name="technic:laser_beam_entityV"
|
||||
else entity_name="technic:laser_beam_entity" end
|
||||
|
||||
if laser_straight_mode==1 then
|
||||
pos1=minetest.get_pointed_thing_position(pointed_thing, under)
|
||||
pos1.x=math.floor(pos1.x)
|
||||
pos1.y=math.floor(pos1.y)
|
||||
pos1.z=math.floor(pos1.z)
|
||||
obj=minetest.env:add_entity(pos1,entity_name)
|
||||
else
|
||||
obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.6,z=playerpos.z},entity_name)
|
||||
end
|
||||
if obj:get_luaentity().player == nil then
|
||||
obj:get_luaentity().player = player
|
||||
end
|
||||
if laser_straight_mode==1 and direction_y<50 then
|
||||
obj:setvelocity({x=dir.x*8, y=0, z=dir.z*8})
|
||||
else if laser_straight_mode==1 and direction_y>50 then
|
||||
obj:setvelocity({x=0, y=dir.y*8, z=dir.z*8})
|
||||
end
|
||||
end
|
||||
if laser_straight_mode==0 then
|
||||
obj:setvelocity({x=dir.x*8, y=dir.y*8, z=dir.z*8})
|
||||
end
|
||||
obj:setacceleration({x=0, y=0, z=0})
|
||||
obj:setyaw(player:get_look_yaw()+math.pi)
|
||||
if obj:get_luaentity().player == nil then
|
||||
obj:get_luaentity().player = player
|
||||
end
|
||||
--obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
|
||||
minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
@ -55,18 +55,15 @@ minetest.register_tool("technic:laser_mk1", {
|
|||
inventory_image = "technic_mining_laser_mk1.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
item=itemstack:to_table()
|
||||
local meta=get_item_meta(item["metadata"])
|
||||
if meta==nil then return end --tool not charghed
|
||||
if meta["charge"]==nil then return end
|
||||
charge=meta["charge"]
|
||||
if charge-400>0 then
|
||||
laser_shoot(item, user, pointed_thing)
|
||||
charge = charge-400;
|
||||
technic.set_RE_wear(item,charge,laser_mk1_max_charge)
|
||||
meta["charge"]=charge
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
itemstack:replace(item)
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - 400 > 0 then
|
||||
laser_shoot(user, pointed_thing)
|
||||
meta.charge = meta.charge - 400
|
||||
technic.set_RE_wear(itemstack, meta.charge, laser_mk1_max_charge)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
|
|
@ -2,52 +2,57 @@ local sonic_screwdriver_max_charge = 15000
|
|||
technic.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 end --tool not charghed
|
||||
if meta1["charge"]==nil then return 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)
|
||||
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.get_node(pos)
|
||||
local node_name = node.name
|
||||
if minetest.registered_nodes[node_name].paramtype2 ~= "facedir" and
|
||||
minetest.registered_nodes[node_name].paramtype2 ~= "wallmounted" then
|
||||
return itemstack
|
||||
end
|
||||
if node.param2 == nil then
|
||||
return
|
||||
end
|
||||
local meta1 = get_item_meta(itemstack:get_metadata())
|
||||
if not meta1 or not meta1.charge then
|
||||
return
|
||||
end
|
||||
if meta1.charge - 100 > 0 then
|
||||
minetest.sound_play("technic_sonic_screwdriver",
|
||||
{pos = pos, gain = 0.3, max_hear_distance = 10})
|
||||
local p = node.param2
|
||||
if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
|
||||
p = p + 1
|
||||
if p == 4 then
|
||||
p = 0
|
||||
end
|
||||
else
|
||||
p = p + 1
|
||||
if p == 6 then
|
||||
p = 0
|
||||
end
|
||||
end
|
||||
-- hacky_swap_node, unforunatly.
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta0 = meta:to_table()
|
||||
node.param2 = p
|
||||
minetest.set_node(pos, node)
|
||||
meta = minetest.get_meta(pos)
|
||||
meta:from_table(meta0)
|
||||
|
||||
charge=charge-100;
|
||||
meta1["charge"]=charge
|
||||
item["metadata"]=set_item_meta(meta1)
|
||||
technic.set_RE_wear(item,charge,sonic_screwdriver_max_charge)
|
||||
itemstack:replace(item)
|
||||
end
|
||||
return itemstack
|
||||
else
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
|
||||
})
|
||||
meta1.charge = meta1.charge - 100
|
||||
itemstack:set_metadata(set_item_meta(meta1))
|
||||
technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "technic:sonic_screwdriver",
|
||||
|
|
Loading…
Reference in New Issue
Block a user