Imported from trollstream "ContentDB"
|
@ -0,0 +1,25 @@
|
|||
# Technic Addons
|
||||
This mod was originally made for the https://playminetest.com server on the request of a player to add MK2 and MK3 chainsaws. However I took it a step up and added a few more additions as well to turn it into a full fledge addon mod! Below are the additions made to the mod...
|
||||
|
||||
# Chainsaws
|
||||
![Mk2 and Mk3 Chainsaws](chainsaws/chainsaws.png)
|
||||
Below are the specs of the additional chainsaws!
|
||||
- Chainsaw MK2: Holds 375,000 EU and uses 11 EU/node
|
||||
- Chainsaw MK3: Holds 1,000,000 EU and uses 10 EU/node
|
||||
|
||||
# Vacuums
|
||||
![Mk2 and Mk3 Vacuums](vacuums/vacuums.png)
|
||||
Below are the specs of the additional vacuums!
|
||||
- Vacuum MK2: 16 Nodes Area and Holds 25,000 EU and uses 90 EU/node
|
||||
- Vacuum MK3: 25 Nodes Area and Holds 100,000 EU and uses 75 EU/node
|
||||
|
||||
# Cans
|
||||
![Medium and Large Cans (Water and Lava)](cans/cans.png)
|
||||
Below are the specs of the additional cans!
|
||||
- Medium: Holds 32 to 64 liters depending on can type
|
||||
- Large: Holds 128 to 256 liters depending on can type
|
||||
|
||||
All textures and coding was based off of Technic which it's repository is https://github.com/mt-mods/technic and therefore the unmodified portions of the coding and textures still belongs to the original Technic mod creator(s).
|
||||
|
||||
# How to contribute to this mod
|
||||
In order to contribute ideas or requests for changes, please create a [New Issue](https://notabug.org/PlayMinetest/TechnicAddons/issues/new) in the [issue tracker](https://notabug.org/PlayMinetest/TechnicAddons/issues). If you can make changes directly, please feel free to fork this repo, commit your improvements with comments, and submit a detailed Pull Request **that was ALREADY tested on a local multiplayer server**. For the additions or changes you would like to propose to us. This is ensure we are able to push your changes as quickly as possible.
|
After Width: | Height: | Size: 88 KiB |
|
@ -0,0 +1,135 @@
|
|||
local S = technic.getter
|
||||
|
||||
local function set_can_wear(itemstack, level, max_level)
|
||||
local temp
|
||||
if level == 0 then
|
||||
temp = 0
|
||||
else
|
||||
temp = 65536 - math.floor(level / max_level * 65535)
|
||||
if temp > 65535 then temp = 65535 end
|
||||
if temp < 1 then temp = 1 end
|
||||
end
|
||||
itemstack:set_wear(temp)
|
||||
end
|
||||
|
||||
local function get_can_level(itemstack)
|
||||
if itemstack:get_metadata() == "" then
|
||||
return 0
|
||||
else
|
||||
return tonumber(itemstack:get_metadata())
|
||||
end
|
||||
end
|
||||
|
||||
function technic.register_can(d)
|
||||
local data = {}
|
||||
for k, v in pairs(d) do data[k] = v end
|
||||
minetest.register_tool(data.can_name, {
|
||||
description = data.can_description,
|
||||
inventory_image = data.can_inventory_image,
|
||||
stack_max = 1,
|
||||
wear_represents = "content_level",
|
||||
liquids_pointable = true,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if node.name ~= data.liquid_source_name then return end
|
||||
local charge = get_can_level(itemstack)
|
||||
if charge == data.can_capacity then return end
|
||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
minetest.log("action", user:get_player_name().." tried to take "..node.name.." at protected position "..minetest.pos_to_string(pointed_thing.under).." with a "..data.can_name)
|
||||
return
|
||||
end
|
||||
minetest.remove_node(pointed_thing.under)
|
||||
charge = charge + 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
set_can_wear(itemstack, charge, data.can_capacity)
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
local pos = pointed_thing.under
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local def = minetest.registered_nodes[node_name] or {}
|
||||
if def.on_rightclick and user and not user:get_player_control().sneak then
|
||||
return def.on_rightclick(pos, minetest.get_node(pos), user, itemstack, pointed_thing)
|
||||
end
|
||||
if not def.buildable_to or node_name == data.liquid_source_name then
|
||||
pos = pointed_thing.above
|
||||
node_name = minetest.get_node(pos).name
|
||||
def = minetest.registered_nodes[node_name] or {}
|
||||
-- Try to place node above the pointed source, or abort.
|
||||
if not def.buildable_to or node_name == data.liquid_source_name then return end
|
||||
end
|
||||
local charge = get_can_level(itemstack)
|
||||
if charge == 0 then return end
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.log("action", user:get_player_name().." tried to place "..data.liquid_source_name.." at protected position "..minetest.pos_to_string(pos).." with a "..data.can_name)
|
||||
return
|
||||
end
|
||||
minetest.set_node(pos, {name=data.liquid_source_name})
|
||||
charge = charge - 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
set_can_wear(itemstack, charge, data.can_capacity)
|
||||
return itemstack
|
||||
end,
|
||||
on_refill = function(stack)
|
||||
stack:set_metadata(tostring(data.can_capacity))
|
||||
set_can_wear(stack, data.can_capacity, data.can_capacity)
|
||||
return stack
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:water_largecan",
|
||||
can_description = S("Large Water Can"),
|
||||
can_inventory_image = "large_water_can.png",
|
||||
can_capacity = 256,
|
||||
liquid_source_name = "default:water_source",
|
||||
liquid_flowing_name = "default:water_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:water_largecan 1',
|
||||
recipe = {
|
||||
{'default:diamond', '','default:diamond'},
|
||||
{'technic:composite_plate', 'technic_addons:water_mediumcan', 'technic:composite_plate'},
|
||||
{'default:diamond', 'technic:composite_plate', 'default:diamond'},
|
||||
}
|
||||
})
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:lava_largecan",
|
||||
can_description = S("Large Lava Can"),
|
||||
can_inventory_image = "large_lava_can.png",
|
||||
can_capacity = 128,
|
||||
liquid_source_name = "default:lava_source",
|
||||
liquid_flowing_name = "default:lava_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:lava_largecan 1',
|
||||
recipe = {
|
||||
{'technic:cast_iron_ingot', 'technic:carbon_plate','technic:cast_iron_ingot'},
|
||||
{'technic:carbon_plate', 'technic_addons:lava_mediumcan', 'technic:carbon_plate'},
|
||||
{'technic:cast_iron_ingot', 'technic:carbon_plate', 'technic:cast_iron_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:river_water_largecan",
|
||||
can_description = S("Large River Water Can"),
|
||||
can_inventory_image = "large_river_water_can.png",
|
||||
can_capacity = 256,
|
||||
liquid_source_name = "default:river_water_source",
|
||||
liquid_flowing_name = "default:river_water_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:river_water_largecan 1',
|
||||
recipe = {
|
||||
{'default:diamond', '','default:diamond'},
|
||||
{'technic:composite_plate', 'technic_addons:river_water_mediumcan', 'technic:composite_plate'},
|
||||
{'default:diamond', 'technic:composite_plate', 'default:diamond'},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,135 @@
|
|||
local S = technic.getter
|
||||
|
||||
local function set_can_wear(itemstack, level, max_level)
|
||||
local temp
|
||||
if level == 0 then
|
||||
temp = 0
|
||||
else
|
||||
temp = 65536 - math.floor(level / max_level * 65535)
|
||||
if temp > 65535 then temp = 65535 end
|
||||
if temp < 1 then temp = 1 end
|
||||
end
|
||||
itemstack:set_wear(temp)
|
||||
end
|
||||
|
||||
local function get_can_level(itemstack)
|
||||
if itemstack:get_metadata() == "" then
|
||||
return 0
|
||||
else
|
||||
return tonumber(itemstack:get_metadata())
|
||||
end
|
||||
end
|
||||
|
||||
function technic.register_can(d)
|
||||
local data = {}
|
||||
for k, v in pairs(d) do data[k] = v end
|
||||
minetest.register_tool(data.can_name, {
|
||||
description = data.can_description,
|
||||
inventory_image = data.can_inventory_image,
|
||||
stack_max = 1,
|
||||
wear_represents = "content_level",
|
||||
liquids_pointable = true,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if node.name ~= data.liquid_source_name then return end
|
||||
local charge = get_can_level(itemstack)
|
||||
if charge == data.can_capacity then return end
|
||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
minetest.log("action", user:get_player_name().." tried to take "..node.name.." at protected position "..minetest.pos_to_string(pointed_thing.under).." with a "..data.can_name)
|
||||
return
|
||||
end
|
||||
minetest.remove_node(pointed_thing.under)
|
||||
charge = charge + 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
set_can_wear(itemstack, charge, data.can_capacity)
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
local pos = pointed_thing.under
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local def = minetest.registered_nodes[node_name] or {}
|
||||
if def.on_rightclick and user and not user:get_player_control().sneak then
|
||||
return def.on_rightclick(pos, minetest.get_node(pos), user, itemstack, pointed_thing)
|
||||
end
|
||||
if not def.buildable_to or node_name == data.liquid_source_name then
|
||||
pos = pointed_thing.above
|
||||
node_name = minetest.get_node(pos).name
|
||||
def = minetest.registered_nodes[node_name] or {}
|
||||
-- Try to place node above the pointed source, or abort.
|
||||
if not def.buildable_to or node_name == data.liquid_source_name then return end
|
||||
end
|
||||
local charge = get_can_level(itemstack)
|
||||
if charge == 0 then return end
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.log("action", user:get_player_name().." tried to place "..data.liquid_source_name.." at protected position "..minetest.pos_to_string(pos).." with a "..data.can_name)
|
||||
return
|
||||
end
|
||||
minetest.set_node(pos, {name=data.liquid_source_name})
|
||||
charge = charge - 1
|
||||
itemstack:set_metadata(tostring(charge))
|
||||
set_can_wear(itemstack, charge, data.can_capacity)
|
||||
return itemstack
|
||||
end,
|
||||
on_refill = function(stack)
|
||||
stack:set_metadata(tostring(data.can_capacity))
|
||||
set_can_wear(stack, data.can_capacity, data.can_capacity)
|
||||
return stack
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:water_mediumcan",
|
||||
can_description = S("Medium Water Can"),
|
||||
can_inventory_image = "medium_water_can.png",
|
||||
can_capacity = 64,
|
||||
liquid_source_name = "default:water_source",
|
||||
liquid_flowing_name = "default:water_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:water_mediumcan 1',
|
||||
recipe = {
|
||||
{'default:gold_ingot', '','default:gold_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:water_can', 'technic:stainless_steel_ingot'},
|
||||
{'default:gold_ingot', 'technic:stainless_steel_ingot', 'default:gold_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:lava_mediumcan",
|
||||
can_description = S("Medium Lava Can"),
|
||||
can_inventory_image = "medium_lava_can.png",
|
||||
can_capacity = 32,
|
||||
liquid_source_name = "default:lava_source",
|
||||
liquid_flowing_name = "default:lava_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:lava_mediumcan 1',
|
||||
recipe = {
|
||||
{'default:diamond', 'moreores:mithril_ingot','default:diamond'},
|
||||
{'moreores:mithril_ingot', 'technic:lava_can', 'moreores:mithril_ingot'},
|
||||
{'default:diamond', 'moreores:mithril_ingot', 'default:diamond'},
|
||||
}
|
||||
})
|
||||
|
||||
technic.register_can({
|
||||
can_name = "technic_addons:river_water_mediumcan",
|
||||
can_description = S("Medium River Water Can"),
|
||||
can_inventory_image = "medium_river_water_can.png",
|
||||
can_capacity = 64,
|
||||
liquid_source_name = "default:river_water_source",
|
||||
liquid_flowing_name = "default:river_water_flowing",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:river_water_mediumcan 1',
|
||||
recipe = {
|
||||
{'default:gold_ingot', '','default:gold_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:river_water_can', 'technic:stainless_steel_ingot'},
|
||||
{'default:gold_ingot', 'technic:stainless_steel_ingot', 'default:gold_ingot'},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,231 @@
|
|||
-- Configuration
|
||||
|
||||
local chainsaw_max_charge = 375000 -- Maximum charge of the saw
|
||||
-- Gives 2500 nodes on a single charge (about 50 complete normal trees)
|
||||
local chainsaw_charge_per_node = 11
|
||||
|
||||
local chainsaw_leaves = true -- Cut down tree leaves.
|
||||
-- Leaf decay may cause slowness on large trees if this is disabled.
|
||||
|
||||
local chainsaw_vines = true -- Cut down vines
|
||||
|
||||
local timber_nodenames = {} -- Cuttable nodes
|
||||
|
||||
local max_saw_radius = 12 -- max x/z distance away from starting position to allow cutting
|
||||
-- Prevents forest destruction, increase for extra wide trees
|
||||
|
||||
|
||||
-- Support for nodes not in any supported node groups (tree, leaves, leafdecay, leafdecay_drop)
|
||||
|
||||
timber_nodenames["default:papyrus"] = true
|
||||
timber_nodenames["default:cactus"] = true
|
||||
timber_nodenames["default:bush_stem"] = true
|
||||
timber_nodenames["default:acacia_bush_stem"] = true
|
||||
timber_nodenames["default:pine_bush_stem"] = true
|
||||
|
||||
if minetest.get_modpath("growing_trees") then
|
||||
timber_nodenames["growing_trees:branch_sprout"] = true
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["growing_trees:leaves"] = true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("snow") then
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["snow:needles"] = true
|
||||
timber_nodenames["snow:needles_decorated"] = true
|
||||
timber_nodenames["snow:star"] = true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("trunks") then
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["trunks:moss"] = true
|
||||
timber_nodenames["trunks:moss_fungus"] = true
|
||||
timber_nodenames["trunks:treeroot"] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic_addons:chainsawmk2", chainsaw_max_charge)
|
||||
|
||||
-- Table for saving what was sawed down
|
||||
local produced = {}
|
||||
|
||||
-- Save the items sawed down so that we can drop them in a nice single stack
|
||||
local function handle_drops(drops)
|
||||
for _, item in ipairs(drops) do
|
||||
local stack = ItemStack(item)
|
||||
local name = stack:get_name()
|
||||
local p = produced[name]
|
||||
if not p then
|
||||
produced[name] = stack
|
||||
else
|
||||
p:set_count(p:get_count() + stack:get_count())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This function does all the hard work. Recursively we dig the node at hand
|
||||
-- if it is in the table and then search the surroundings for more stuff to dig.
|
||||
local function recursive_dig(pos, origin, remaining_charge)
|
||||
if remaining_charge < chainsaw_charge_per_node then
|
||||
return remaining_charge
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if not timber_nodenames[node.name] then
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Wood found - cut it
|
||||
handle_drops(minetest.get_node_drops(node.name, ""))
|
||||
minetest.remove_node(pos)
|
||||
remaining_charge = remaining_charge - chainsaw_charge_per_node
|
||||
|
||||
-- Check for snow on pine trees, sand/gravel on leaves, etc
|
||||
minetest.check_for_falling(pos)
|
||||
|
||||
-- Check surroundings and run recursively if any charge left
|
||||
for y=-1, 1 do
|
||||
if (pos.y + y) >= origin.y then
|
||||
for x=-1, 1 do
|
||||
if (pos.x + x) <= (origin.x + max_saw_radius) and (pos.x + x) >= (origin.x - max_saw_radius) then
|
||||
for z=-1, 1 do
|
||||
if (pos.z + z) <= (origin.z + max_saw_radius) and (pos.z + z) >= (origin.z - max_saw_radius) then
|
||||
local npos = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
if remaining_charge < chainsaw_charge_per_node then
|
||||
return remaining_charge
|
||||
end
|
||||
if timber_nodenames[minetest.get_node(npos).name] then
|
||||
remaining_charge = recursive_dig(npos, origin, remaining_charge)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Function to randomize positions for new node drops
|
||||
local function get_drop_pos(pos)
|
||||
local drop_pos = {}
|
||||
|
||||
for i = 0, 8 do
|
||||
-- Randomize position for a new drop
|
||||
drop_pos.x = pos.x + math.random(-3, 3)
|
||||
drop_pos.y = pos.y - 1
|
||||
drop_pos.z = pos.z + math.random(-3, 3)
|
||||
|
||||
-- Move the randomized position upwards until
|
||||
-- the node is air or unloaded.
|
||||
for y = drop_pos.y, drop_pos.y + 5 do
|
||||
drop_pos.y = y
|
||||
local node = minetest.get_node_or_nil(drop_pos)
|
||||
|
||||
if not node then
|
||||
-- If the node is not loaded yet simply drop
|
||||
-- the item at the original digging position.
|
||||
return pos
|
||||
elseif node.name == "air" then
|
||||
-- Add variation to the entity drop position,
|
||||
-- but don't let drops get too close to the edge
|
||||
drop_pos.x = drop_pos.x + (math.random() * 0.8) - 0.5
|
||||
drop_pos.z = drop_pos.z + (math.random() * 0.8) - 0.5
|
||||
return drop_pos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Return the original position if this takes too long
|
||||
return pos
|
||||
end
|
||||
|
||||
-- Chainsaw entry point
|
||||
local function chainsaw_dig(pos, current_charge)
|
||||
-- Start sawing things down
|
||||
local remaining_charge = recursive_dig(pos, pos, current_charge)
|
||||
minetest.sound_play("chainsaw", {pos = pos, gain = 1.0,
|
||||
max_hear_distance = 10})
|
||||
|
||||
-- Now drop items for the player
|
||||
for name, stack in pairs(produced) do
|
||||
-- Drop stacks of stack max or less
|
||||
local count, max = stack:get_count(), stack:get_stack_max()
|
||||
stack:set_count(max)
|
||||
while count > max do
|
||||
minetest.add_item(get_drop_pos(pos), stack)
|
||||
count = count - max
|
||||
end
|
||||
stack:set_count(count)
|
||||
minetest.add_item(get_drop_pos(pos), stack)
|
||||
end
|
||||
|
||||
-- Clean up
|
||||
produced = {}
|
||||
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
|
||||
minetest.register_tool("technic_addons:chainsawmk2", {
|
||||
description = S("Chainsaw Mk2"),
|
||||
inventory_image = "technicaddons_chainsawmk2.png",
|
||||
stack_max = 1,
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge or
|
||||
meta.charge < chainsaw_charge_per_node then
|
||||
return
|
||||
end
|
||||
|
||||
local name = user:get_player_name()
|
||||
if minetest.is_protected(pointed_thing.under, name) then
|
||||
minetest.record_protection_violation(pointed_thing.under, name)
|
||||
return
|
||||
end
|
||||
|
||||
-- Send current charge to digging function so that the
|
||||
-- chainsaw will stop after digging a number of nodes
|
||||
meta.charge = chainsaw_dig(pointed_thing.under, meta.charge)
|
||||
if not technic.creative_mode then
|
||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
local mesecons_button = minetest.get_modpath("mesecons_button")
|
||||
local trigger = mesecons_button and "mesecons_button:button_off" or "default:mese_crystal_fragment"
|
||||
|
||||
minetest.register_craft({
|
||||
output = "technic_addons:chainsawmk2",
|
||||
recipe = {
|
||||
{"", "technic:stainless_steel_ingot", "technic:diamond_drill_head"},
|
||||
{"technic:stainless_steel_ingot", "technic:chainsaw", "technic:stainless_steel_ingot"},
|
||||
{"technic:green_energy_crystal", "technic:stainless_steel_ingot", ""},
|
||||
}})
|
||||
|
||||
-- Add cuttable nodes after all mods loaded
|
||||
minetest.after(0, function ()
|
||||
for k, v in pairs(minetest.registered_nodes) do
|
||||
if v.groups.tree then
|
||||
timber_nodenames[k] = true
|
||||
elseif chainsaw_leaves and (v.groups.leaves or v.groups.leafdecay or v.groups.leafdecay_drop) then
|
||||
timber_nodenames[k] = true
|
||||
elseif chainsaw_vines and v.groups.vines then
|
||||
timber_nodenames[k] = true
|
||||
end
|
||||
end
|
||||
end)
|
|
@ -0,0 +1,231 @@
|
|||
-- Configuration
|
||||
|
||||
local chainsaw_max_charge = 1000000 -- Maximum charge of the saw
|
||||
-- Gives 2500 nodes on a single charge (about 50 complete normal trees)
|
||||
local chainsaw_charge_per_node = 10
|
||||
|
||||
local chainsaw_leaves = true -- Cut down tree leaves.
|
||||
-- Leaf decay may cause slowness on large trees if this is disabled.
|
||||
|
||||
local chainsaw_vines = true -- Cut down vines
|
||||
|
||||
local timber_nodenames = {} -- Cuttable nodes
|
||||
|
||||
local max_saw_radius = 12 -- max x/z distance away from starting position to allow cutting
|
||||
-- Prevents forest destruction, increase for extra wide trees
|
||||
|
||||
|
||||
-- Support for nodes not in any supported node groups (tree, leaves, leafdecay, leafdecay_drop)
|
||||
|
||||
timber_nodenames["default:papyrus"] = true
|
||||
timber_nodenames["default:cactus"] = true
|
||||
timber_nodenames["default:bush_stem"] = true
|
||||
timber_nodenames["default:acacia_bush_stem"] = true
|
||||
timber_nodenames["default:pine_bush_stem"] = true
|
||||
|
||||
if minetest.get_modpath("growing_trees") then
|
||||
timber_nodenames["growing_trees:branch_sprout"] = true
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["growing_trees:leaves"] = true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("snow") then
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["snow:needles"] = true
|
||||
timber_nodenames["snow:needles_decorated"] = true
|
||||
timber_nodenames["snow:star"] = true
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("trunks") then
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["trunks:moss"] = true
|
||||
timber_nodenames["trunks:moss_fungus"] = true
|
||||
timber_nodenames["trunks:treeroot"] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic_addons:chainsawmk3", chainsaw_max_charge)
|
||||
|
||||
-- Table for saving what was sawed down
|
||||
local produced = {}
|
||||
|
||||
-- Save the items sawed down so that we can drop them in a nice single stack
|
||||
local function handle_drops(drops)
|
||||
for _, item in ipairs(drops) do
|
||||
local stack = ItemStack(item)
|
||||
local name = stack:get_name()
|
||||
local p = produced[name]
|
||||
if not p then
|
||||
produced[name] = stack
|
||||
else
|
||||
p:set_count(p:get_count() + stack:get_count())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This function does all the hard work. Recursively we dig the node at hand
|
||||
-- if it is in the table and then search the surroundings for more stuff to dig.
|
||||
local function recursive_dig(pos, origin, remaining_charge)
|
||||
if remaining_charge < chainsaw_charge_per_node then
|
||||
return remaining_charge
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if not timber_nodenames[node.name] then
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Wood found - cut it
|
||||
handle_drops(minetest.get_node_drops(node.name, ""))
|
||||
minetest.remove_node(pos)
|
||||
remaining_charge = remaining_charge - chainsaw_charge_per_node
|
||||
|
||||
-- Check for snow on pine trees, sand/gravel on leaves, etc
|
||||
minetest.check_for_falling(pos)
|
||||
|
||||
-- Check surroundings and run recursively if any charge left
|
||||
for y=-1, 1 do
|
||||
if (pos.y + y) >= origin.y then
|
||||
for x=-1, 1 do
|
||||
if (pos.x + x) <= (origin.x + max_saw_radius) and (pos.x + x) >= (origin.x - max_saw_radius) then
|
||||
for z=-1, 1 do
|
||||
if (pos.z + z) <= (origin.z + max_saw_radius) and (pos.z + z) >= (origin.z - max_saw_radius) then
|
||||
local npos = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
if remaining_charge < chainsaw_charge_per_node then
|
||||
return remaining_charge
|
||||
end
|
||||
if timber_nodenames[minetest.get_node(npos).name] then
|
||||
remaining_charge = recursive_dig(npos, origin, remaining_charge)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Function to randomize positions for new node drops
|
||||
local function get_drop_pos(pos)
|
||||
local drop_pos = {}
|
||||
|
||||
for i = 0, 8 do
|
||||
-- Randomize position for a new drop
|
||||
drop_pos.x = pos.x + math.random(-3, 3)
|
||||
drop_pos.y = pos.y - 1
|
||||
drop_pos.z = pos.z + math.random(-3, 3)
|
||||
|
||||
-- Move the randomized position upwards until
|
||||
-- the node is air or unloaded.
|
||||
for y = drop_pos.y, drop_pos.y + 5 do
|
||||
drop_pos.y = y
|
||||
local node = minetest.get_node_or_nil(drop_pos)
|
||||
|
||||
if not node then
|
||||
-- If the node is not loaded yet simply drop
|
||||
-- the item at the original digging position.
|
||||
return pos
|
||||
elseif node.name == "air" then
|
||||
-- Add variation to the entity drop position,
|
||||
-- but don't let drops get too close to the edge
|
||||
drop_pos.x = drop_pos.x + (math.random() * 0.8) - 0.5
|
||||
drop_pos.z = drop_pos.z + (math.random() * 0.8) - 0.5
|
||||
return drop_pos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Return the original position if this takes too long
|
||||
return pos
|
||||
end
|
||||
|
||||
-- Chainsaw entry point
|
||||
local function chainsaw_dig(pos, current_charge)
|
||||
-- Start sawing things down
|
||||
local remaining_charge = recursive_dig(pos, pos, current_charge)
|
||||
minetest.sound_play("chainsaw", {pos = pos, gain = 1.0,
|
||||
max_hear_distance = 10})
|
||||
|
||||
-- Now drop items for the player
|
||||
for name, stack in pairs(produced) do
|
||||
-- Drop stacks of stack max or less
|
||||
local count, max = stack:get_count(), stack:get_stack_max()
|
||||
stack:set_count(max)
|
||||
while count > max do
|
||||
minetest.add_item(get_drop_pos(pos), stack)
|
||||
count = count - max
|
||||
end
|
||||
stack:set_count(count)
|
||||
minetest.add_item(get_drop_pos(pos), stack)
|
||||
end
|
||||
|
||||
-- Clean up
|
||||
produced = {}
|
||||
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
|
||||
minetest.register_tool("technic_addons:chainsawmk3", {
|
||||
description = S("Chainsaw MK3"),
|
||||
inventory_image = "technicaddons_chainsawmk3.png",
|
||||
stack_max = 1,
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge or
|
||||
meta.charge < chainsaw_charge_per_node then
|
||||
return
|
||||
end
|
||||
|
||||
local name = user:get_player_name()
|
||||
if minetest.is_protected(pointed_thing.under, name) then
|
||||
minetest.record_protection_violation(pointed_thing.under, name)
|
||||
return
|
||||
end
|
||||
|
||||
-- Send current charge to digging function so that the
|
||||
-- chainsaw will stop after digging a number of nodes
|
||||
meta.charge = chainsaw_dig(pointed_thing.under, meta.charge)
|
||||
if not technic.creative_mode then
|
||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
local mesecons_button = minetest.get_modpath("mesecons_button")
|
||||
local trigger = mesecons_button and "mesecons_button:button_off" or "default:mese_crystal_fragment"
|
||||
|
||||
minetest.register_craft({
|
||||
output = "technic_addons:chainsawmk3",
|
||||
recipe = {
|
||||
{"", "technic:diamond_drill_head", "technic:diamond_drill_head"},
|
||||
{"technic:carbon_plate", "technic_addons:chainsawmk2", "technic:diamond_drill_head"},
|
||||
{"technic:blue_energy_crystal", "technic:composite_plate", ""},
|
||||
}})
|
||||
|
||||
-- Add cuttable nodes after all mods loaded
|
||||
minetest.after(0, function ()
|
||||
for k, v in pairs(minetest.registered_nodes) do
|
||||
if v.groups.tree then
|
||||
timber_nodenames[k] = true
|
||||
elseif chainsaw_leaves and (v.groups.leaves or v.groups.leafdecay or v.groups.leafdecay_drop) then
|
||||
timber_nodenames[k] = true
|
||||
elseif chainsaw_vines and v.groups.vines then
|
||||
timber_nodenames[k] = true
|
||||
end
|
||||
end
|
||||
end)
|
After Width: | Height: | Size: 119 KiB |
|
@ -0,0 +1,8 @@
|
|||
local modpath = minetest.get_modpath("technic_addons")
|
||||
technic.modpath = modpath
|
||||
dofile(modpath.."/chainsaws/chainsawmk2.lua")
|
||||
dofile(modpath.."/chainsaws/chainsawmk3.lua")
|
||||
dofile(modpath.."/cans/mediumcans.lua")
|
||||
dofile(modpath.."/cans/largecans.lua")
|
||||
dofile(modpath.."/vacuums/vacuummk2.lua")
|
||||
dofile(modpath.."/vacuums/vacuummk3.lua")
|
|
@ -0,0 +1,4 @@
|
|||
name = technic_addons
|
||||
description = Adds additional content to Technic. Currently adds mk2 and mk3 chainsaws and vacuums. As well as medium and large cans.
|
||||
depends = default, pipeworks, technic_worldgen, basic_materials, technic
|
||||
min_minetest_version = 5.3.0
|
After Width: | Height: | Size: 448 B |
After Width: | Height: | Size: 436 B |
After Width: | Height: | Size: 443 B |
After Width: | Height: | Size: 447 B |
After Width: | Height: | Size: 434 B |
After Width: | Height: | Size: 441 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 6.2 KiB |
|
@ -0,0 +1,61 @@
|
|||
-- Configuration
|
||||
local vacuum_max_charge = 25000 -- 10000 - Maximum charge of the vacuum cleaner
|
||||
local vacuum_charge_per_object = 90 -- 100 - Capable of picking up 50 objects
|
||||
local vacuum_range = 16 -- 8 - Area in which to pick up objects
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic_addons:vacuummk2", vacuum_max_charge)
|
||||
|
||||
minetest.register_tool("technic_addons:vacuummk2", {
|
||||
description = S("Vacuum Cleaner Mk2"),
|
||||
inventory_image = "technicaddons_vacuummk2.png",
|
||||
stack_max = 1,
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge > vacuum_charge_per_object then
|
||||
minetest.sound_play("vacuumcleaner", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
end
|
||||
local pos = user:get_pos()
|
||||
local inv = user:get_inventory()
|
||||
for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
|
||||
local luaentity = object:get_luaentity()
|
||||
if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
|
||||
if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
|
||||
meta.charge = meta.charge - vacuum_charge_per_object
|
||||
if meta.charge < vacuum_charge_per_object then
|
||||
return
|
||||
end
|
||||
inv:add_item("main", ItemStack(luaentity.itemstring))
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
luaentity.itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
technic.set_RE_wear(itemstack, meta.charge, vacuum_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:vacuummk2',
|
||||
recipe = {
|
||||
{'basic_materials:plastic_sheet', '', 'basic_materials:plastic_sheet'},
|
||||
{'basic_materials:plastic_sheet', 'technic:vacuum', 'basic_materials:plastic_sheet'},
|
||||
{'basic_materials:plastic_sheet', 'technic:green_energy_crystal', 'basic_materials:plastic_sheet'},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,61 @@
|
|||
-- Configuration
|
||||
local vacuum_max_charge = 100000 -- 10000 - Maximum charge of the vacuum cleaner
|
||||
local vacuum_charge_per_object = 75 -- 100 - Capable of picking up 50 objects
|
||||
local vacuum_range = 25 -- 8 - Area in which to pick up objects
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic_addons:vacuummk3", vacuum_max_charge)
|
||||
|
||||
minetest.register_tool("technic_addons:vacuummk3", {
|
||||
description = S("Vacuum Cleaner Mk3"),
|
||||
inventory_image = "technicaddons_vacuummk3.png",
|
||||
stack_max = 1,
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge > vacuum_charge_per_object then
|
||||
minetest.sound_play("vacuumcleaner", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
end
|
||||
local pos = user:get_pos()
|
||||
local inv = user:get_inventory()
|
||||
for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
|
||||
local luaentity = object:get_luaentity()
|
||||
if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
|
||||
if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
|
||||
meta.charge = meta.charge - vacuum_charge_per_object
|
||||
if meta.charge < vacuum_charge_per_object then
|
||||
return
|
||||
end
|
||||
inv:add_item("main", ItemStack(luaentity.itemstring))
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
luaentity.itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
technic.set_RE_wear(itemstack, meta.charge, vacuum_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic_addons:vacuummk3',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic_addons:vacuummk2', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:blue_energy_crystal', 'technic:stainless_steel_ingot'},
|
||||
}
|
||||
})
|
After Width: | Height: | Size: 90 KiB |