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