Harvester node
This commit is contained in:
parent
caf62e2b9c
commit
9d32873abb
@ -23,3 +23,17 @@ function elefarm.formspec.planter_formspec(timer, power)
|
|||||||
default.get_hotbar_bg(0, 5.75)
|
default.get_hotbar_bg(0, 5.75)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function elefarm.formspec.harvester_formspec(timer, power)
|
||||||
|
return "size[8,8.5]"..
|
||||||
|
default.gui_bg..
|
||||||
|
default.gui_bg_img..
|
||||||
|
default.gui_slots..
|
||||||
|
ele.formspec.power_meter(power)..
|
||||||
|
bar(1, 0, 100-timer)..
|
||||||
|
"list[context;dst;1.5,0.25;6,2;]"..
|
||||||
|
"list[current_player;main;0,4.25;8,1;]"..
|
||||||
|
"list[current_player;main;0,5.5;8,3;8]"..
|
||||||
|
"listring[context;dst]"..
|
||||||
|
"listring[current_player;main]"..
|
||||||
|
default.get_hotbar_bg(0, 4.25)
|
||||||
|
end
|
||||||
|
238
elepower_farming/nodes/fluids.lua
Normal file
238
elepower_farming/nodes/fluids.lua
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
|
||||||
|
-- Tree Sap
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:tree_sap_source", {
|
||||||
|
description = "Tree Sap Source",
|
||||||
|
drawtype = "liquid",
|
||||||
|
tiles = {"elefarming_tree_sap.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "source",
|
||||||
|
liquid_alternative_source = "elepower_farming:tree_sap_source",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:tree_sap_flowing",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 84, g = 34, b = 0},
|
||||||
|
groups = {tree_sap = 3, liquid = 3},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:tree_sap_flowing", {
|
||||||
|
description = "Flowing Tree Sap",
|
||||||
|
drawtype = "flowingliquid",
|
||||||
|
tiles = {"elefarming_tree_sap.png"},
|
||||||
|
special_tiles = {"elefarming_tree_sap.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "flowingliquid",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "flowing",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:tree_sap_flowing",
|
||||||
|
liquid_alternative_source = "elepower_farming:tree_sap_source",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 84, g = 34, b = 0},
|
||||||
|
groups = {tree_sap = 3, liquid = 3, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Biomass
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biomass_source", {
|
||||||
|
description = "Biomass Source",
|
||||||
|
drawtype = "liquid",
|
||||||
|
tiles = {"elefarming_biomass.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "source",
|
||||||
|
liquid_alternative_source = "elepower_farming:biomass_source",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biomass_flowing",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 0, g = 42, b = 0},
|
||||||
|
groups = {biomass = 3, liquid = 3},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biomass_flowing", {
|
||||||
|
description = "Flowing Biomass",
|
||||||
|
drawtype = "flowingliquid",
|
||||||
|
tiles = {"elefarming_biomass.png"},
|
||||||
|
special_tiles = {"elefarming_biomass.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "flowingliquid",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "flowing",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biomass_flowing",
|
||||||
|
liquid_alternative_source = "elepower_farming:biomass_source",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 0, g = 42, b = 0},
|
||||||
|
groups = {biomass = 3, liquid = 3, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Biofuel
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biofuel_source", {
|
||||||
|
description = "Biomass Source",
|
||||||
|
drawtype = "liquid",
|
||||||
|
tiles = {"elefarming_biofuel.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "source",
|
||||||
|
liquid_alternative_source = "elepower_farming:biofuel_source",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biofuel_flowing",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 255, g = 163, b = 0},
|
||||||
|
groups = {biofuel = 3, liquid = 3},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biofuel_flowing", {
|
||||||
|
description = "Flowing Biomass",
|
||||||
|
drawtype = "flowingliquid",
|
||||||
|
tiles = {"elefarming_biofuel.png"},
|
||||||
|
special_tiles = {"elefarming_biofuel.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "flowingliquid",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "flowing",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biofuel_flowing",
|
||||||
|
liquid_alternative_source = "elepower_farming:biofuel_source",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 255, g = 163, b = 0},
|
||||||
|
groups = {biofuel = 3, liquid = 3, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Biofuel
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biofuel_source", {
|
||||||
|
description = "Biofuel Source",
|
||||||
|
drawtype = "liquid",
|
||||||
|
tiles = {"elefarming_biofuel.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "source",
|
||||||
|
liquid_alternative_source = "elepower_farming:biofuel_source",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biofuel_flowing",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 255, g = 163, b = 0},
|
||||||
|
groups = {biofuel = 3, liquid = 3},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:biofuel_flowing", {
|
||||||
|
description = "Flowing Biofuel",
|
||||||
|
drawtype = "flowingliquid",
|
||||||
|
tiles = {"elefarming_biofuel.png"},
|
||||||
|
special_tiles = {"elefarming_biofuel.png"},
|
||||||
|
alpha = 200,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "flowingliquid",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "flowing",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:biofuel_flowing",
|
||||||
|
liquid_alternative_source = "elepower_farming:biofuel_source",
|
||||||
|
liquid_viscosity = 7,
|
||||||
|
post_effect_color = {a = 103, r = 255, g = 163, b = 0},
|
||||||
|
groups = {biofuel = 3, liquid = 3, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Sludge
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:sludge_source", {
|
||||||
|
description = "Sludge Source",
|
||||||
|
drawtype = "liquid",
|
||||||
|
tiles = {"elefarming_tar.png"},
|
||||||
|
paramtype = "light",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "source",
|
||||||
|
liquid_alternative_source = "elepower_farming:sludge_source",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:sludge_flowing",
|
||||||
|
liquid_viscosity = 8,
|
||||||
|
post_effect_color = {a = 50, r = 0, g = 0, b = 0},
|
||||||
|
groups = {sludge = 3, liquid = 3},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("elepower_farming:sludge_flowing", {
|
||||||
|
description = "Flowing Sludge",
|
||||||
|
drawtype = "flowingliquid",
|
||||||
|
tiles = {"elefarming_tar.png"},
|
||||||
|
special_tiles = {"elefarming_tar.png"},
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "flowingliquid",
|
||||||
|
walkable = false,
|
||||||
|
pointable = false,
|
||||||
|
diggable = false,
|
||||||
|
buildable_to = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "",
|
||||||
|
drowning = 1,
|
||||||
|
liquidtype = "flowing",
|
||||||
|
liquid_alternative_flowing = "elepower_farming:sludge_flowing",
|
||||||
|
liquid_alternative_source = "elepower_farming:sludge_source",
|
||||||
|
liquid_viscosity = 8,
|
||||||
|
post_effect_color = {a = 50, r = 0, g = 0, b = 0},
|
||||||
|
groups = {sludge = 3, liquid = 3, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_water_defaults(),
|
||||||
|
})
|
155
elepower_farming/nodes/harvester.lua
Normal file
155
elepower_farming/nodes/harvester.lua
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
|
||||||
|
local HARVESTER_TICK = 10
|
||||||
|
|
||||||
|
local function can_dig(pos, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:is_empty("dst")
|
||||||
|
end
|
||||||
|
|
||||||
|
local fdir_areas = {
|
||||||
|
{ -- NEG Z (0)
|
||||||
|
{x = -4, z = -8, y = 0},
|
||||||
|
{x = 4, z = 0, y = 0},
|
||||||
|
},
|
||||||
|
{ -- NEG X (1)
|
||||||
|
{x = -8, z = -4, y = 0},
|
||||||
|
{x = 0, z = 4, y = 0},
|
||||||
|
},
|
||||||
|
{ -- POS Z (2)
|
||||||
|
{x = -4, z = 0, y = 0},
|
||||||
|
{x = 4, z = 8, y = 0},
|
||||||
|
},
|
||||||
|
{ -- POS X (3)
|
||||||
|
{x = 0, z = -4, y = 0},
|
||||||
|
{x = 8, z = 4, y = 0},
|
||||||
|
},
|
||||||
|
nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
local function harvest(pos, harvested, fdir)
|
||||||
|
local front = ele.helpers.face_front(pos, fdir)
|
||||||
|
local ranges = fdir_areas[fdir + 1]
|
||||||
|
local range_st = vector.add(front, ranges[1])
|
||||||
|
local range_end = vector.add(front, ranges[2])
|
||||||
|
|
||||||
|
local shots = 9
|
||||||
|
|
||||||
|
for x = range_st.x, range_end.x do
|
||||||
|
for z = range_st.z, range_end.z do
|
||||||
|
if shots == 0 then break end
|
||||||
|
local check_pos = {x = x, y = range_st.y, z = z}
|
||||||
|
local check_node = minetest.get_node_or_nil(check_pos)
|
||||||
|
if check_node and ele.helpers.get_item_group(check_node.name, "plant") then
|
||||||
|
local nodedef = minetest.registered_nodes[check_node.name]
|
||||||
|
if not nodedef['next_plant'] or not minetest.registered_nodes[nodedef.next_plant] then
|
||||||
|
-- Can harvest
|
||||||
|
local drop = minetest.get_node_drops(check_node.name)
|
||||||
|
if drop then
|
||||||
|
for _,item in ipairs(drop) do
|
||||||
|
harvested[#harvested + 1] = item
|
||||||
|
end
|
||||||
|
minetest.remove_node(check_pos)
|
||||||
|
shots = shots - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return harvested
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_timer(pos, elapsed)
|
||||||
|
local refresh = false
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
|
||||||
|
local usage = ele.helpers.get_node_property(meta, pos, "usage")
|
||||||
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||||
|
|
||||||
|
local work = meta:get_int("src_time")
|
||||||
|
|
||||||
|
if storage > usage then
|
||||||
|
if work == HARVESTER_TICK then
|
||||||
|
local harvested = {}
|
||||||
|
|
||||||
|
harvest(pos, harvested, node.param2)
|
||||||
|
|
||||||
|
work = 0
|
||||||
|
if #harvested > 0 then
|
||||||
|
storage = storage - usage
|
||||||
|
for _,itm in ipairs(harvested) do
|
||||||
|
local stack = ItemStack(itm)
|
||||||
|
if inv:room_for_item("dst", stack) then
|
||||||
|
inv:add_item("dst", stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
work = work + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
refresh = true
|
||||||
|
ele.helpers.swap_node(pos, "elepower_farming:harvester_active")
|
||||||
|
else
|
||||||
|
ele.helpers.swap_node(pos, "elepower_farming:harvester")
|
||||||
|
end
|
||||||
|
|
||||||
|
local power_percent = math.floor((storage / capacity)*100)
|
||||||
|
local work_percent = math.floor((work / HARVESTER_TICK)*100)
|
||||||
|
|
||||||
|
meta:set_string("formspec", elefarm.formspec.harvester_formspec(work_percent, power_percent))
|
||||||
|
meta:set_int("storage", storage)
|
||||||
|
meta:set_int("src_time", work)
|
||||||
|
|
||||||
|
return refresh
|
||||||
|
end
|
||||||
|
|
||||||
|
ele.register_machine("elepower_farming:harvester", {
|
||||||
|
description = "Automatic Harvester",
|
||||||
|
ele_capacity = 12000,
|
||||||
|
ele_inrush = 288,
|
||||||
|
ele_usage = 128,
|
||||||
|
tiles = {
|
||||||
|
"elefarming_machine_base.png", "elefarming_machine_base.png", "elefarming_machine_side.png",
|
||||||
|
"elefarming_machine_side.png", "elefarming_machine_side.png", "elefarming_machine_harvester.png",
|
||||||
|
},
|
||||||
|
groups = {
|
||||||
|
oddly_breakable_by_hand = 1,
|
||||||
|
ele_machine = 1,
|
||||||
|
ele_user = 1,
|
||||||
|
cracky = 1,
|
||||||
|
},
|
||||||
|
on_construct = function (pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("layout", 9)
|
||||||
|
inv:set_size("dst", 12)
|
||||||
|
|
||||||
|
meta:set_int("src_time", 0)
|
||||||
|
|
||||||
|
meta:set_string("formspec", elefarm.formspec.harvester_formspec(0,0))
|
||||||
|
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
end,
|
||||||
|
ele_active_node = true,
|
||||||
|
ele_active_nodedef = {
|
||||||
|
tiles = {
|
||||||
|
"elefarming_machine_base.png", "elefarming_machine_base.png", "elefarming_machine_side.png",
|
||||||
|
"elefarming_machine_side.png", "elefarming_machine_side.png", {
|
||||||
|
name = "elefarming_machine_harvester_animated.png",
|
||||||
|
animation = {
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
type = "vertical_frames",
|
||||||
|
length = 0.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
can_dig = can_dig,
|
||||||
|
on_timer = on_timer,
|
||||||
|
})
|
@ -1,2 +1,4 @@
|
|||||||
|
|
||||||
dofile(elefarm.modpath.."/nodes/planter.lua")
|
dofile(elefarm.modpath.."/nodes/planter.lua")
|
||||||
|
dofile(elefarm.modpath.."/nodes/harvester.lua")
|
||||||
|
dofile(elefarm.modpath.."/nodes/fluids.lua")
|
||||||
|
BIN
elepower_farming/textures/elefarming_biofuel.png
Normal file
BIN
elepower_farming/textures/elefarming_biofuel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 898 B |
BIN
elepower_farming/textures/elefarming_biomass.png
Normal file
BIN
elepower_farming/textures/elefarming_biomass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 894 B |
BIN
elepower_farming/textures/elefarming_machine_harvester.png
Normal file
BIN
elepower_farming/textures/elefarming_machine_harvester.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
elepower_farming/textures/elefarming_tar.png
Normal file
BIN
elepower_farming/textures/elefarming_tar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 891 B |
BIN
elepower_farming/textures/elefarming_tree_sap.png
Normal file
BIN
elepower_farming/textures/elefarming_tree_sap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 B |
Loading…
Reference in New Issue
Block a user