Add Vaccuum Chest
This commit is contained in:
parent
ea20145c49
commit
eb2d072cdb
@ -3,7 +3,6 @@ Missing Features:
|
||||
|
||||
High Priority:
|
||||
- Vaccuum Supply Chest
|
||||
- Trash Can
|
||||
- Togglable Cable
|
||||
- Autocrafter
|
||||
|
||||
|
@ -11,3 +11,4 @@ dofile(path.."/access_point.lua")
|
||||
dofile(path.."/lava_furnace.lua")
|
||||
dofile(path.."/lava_furnace_recipe.lua")
|
||||
dofile(path.."/trashcan.lua")
|
||||
dofile(path.."/vaccuum_chest.lua")
|
||||
|
155
api/vaccuum_chest.lua
Normal file
155
api/vaccuum_chest.lua
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
local FORMSPEC_NAME = "logistica_vaccuum_chest"
|
||||
local ON_OFF_BUTTON = "on_off_btn"
|
||||
|
||||
local forms = {}
|
||||
|
||||
local function get_vaccuum_formspec(pos)
|
||||
local posForm = "nodemeta:"..pos.x..","..pos.y..","..pos.z
|
||||
local isOn = logistica.is_machine_on(pos)
|
||||
|
||||
return "formspec_version[4]" ..
|
||||
"size[10.5,10]" ..
|
||||
logistica.ui.background..
|
||||
logistica.ui.on_off_btn(isOn, 7.0, 0.5, ON_OFF_BUTTON, "Vaccuum items:")..
|
||||
"label[0.6,1.0;Supplies collected items to the network.]"..
|
||||
"list["..posForm..";main;0.4,1.4;8,2;0]"..
|
||||
"list[current_player;main;0.4,4.5;8,4;0]"..
|
||||
"listring[]"
|
||||
end
|
||||
|
||||
local function show_vaccuum_formspec(playerName, pos)
|
||||
forms[playerName] = {position = pos}
|
||||
minetest.show_formspec(playerName, FORMSPEC_NAME, get_vaccuum_formspec(pos))
|
||||
end
|
||||
|
||||
local function on_player_receive_fields(player, formname, fields)
|
||||
if not player or not player:is_player() then return false end
|
||||
if formname ~= FORMSPEC_NAME then return false end
|
||||
local playerName = player:get_player_name()
|
||||
if not forms[playerName] then return false end
|
||||
local pos = forms[playerName].position
|
||||
if minetest.is_protected(pos, playerName) then return true end
|
||||
|
||||
if fields.quit then
|
||||
forms[playerName] = nil
|
||||
elseif fields[ON_OFF_BUTTON] then
|
||||
logistica.toggle_machine_on_off(pos)
|
||||
show_vaccuum_formspec(player:get_player_name(), pos)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_vaccuum_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||
if not clicker or not clicker:is_player() then return end
|
||||
if minetest.is_protected(pos, clicker:get_player_name()) then return end
|
||||
show_vaccuum_formspec(clicker:get_player_name(), pos)
|
||||
end
|
||||
|
||||
local function after_place_vaccuum(pos, placer, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", logistica.get_supplier_inv_size(pos))
|
||||
logistica.set_node_tooltip_from_state(pos)
|
||||
logistica.on_supplier_change(pos)
|
||||
end
|
||||
|
||||
local function allow_vaccuum_storage_inv_put(pos, _, _, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then return 0 end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function allow_vaccuum_inv_take(pos, _, _, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then return 0 end
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
local function allow_vaccuum_inv_move(pos, _, _, _, _, count, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then return 0 end
|
||||
return count
|
||||
end
|
||||
|
||||
local function on_vaccuum_inventory_put(pos, _, _, _, _)
|
||||
logistica.update_cache_at_pos(pos, LOG_CACHE_SUPPLIER)
|
||||
end
|
||||
|
||||
local function on_vaccuum_inventory_take(pos, _, _, _, _)
|
||||
logistica.update_cache_at_pos(pos, LOG_CACHE_SUPPLIER)
|
||||
end
|
||||
|
||||
local function can_dig_vaccuum(pos, _)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end
|
||||
|
||||
local function on_vaccuum_power(pos, power)
|
||||
logistica.vaccuum_chest_on_power(pos, power)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------
|
||||
-- Minetest registration
|
||||
----------------------------------------------------------------
|
||||
|
||||
minetest.register_on_player_receive_fields(on_player_receive_fields)
|
||||
|
||||
minetest.register_on_leaveplayer(function(objRef, timed_out)
|
||||
if objRef:is_player() then
|
||||
forms[objRef:get_player_name()] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------
|
||||
-- Public Registration API
|
||||
----------------------------------------------------------------
|
||||
-- `simpleName` is used for the description and for the name (can contain spaces)
|
||||
-- `inventorySize` should be 16 at max
|
||||
function logistica.register_vaccuum_chest(desc, name, inventorySize, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local vaccuum_name = "logistica:"..lname
|
||||
logistica.vaccuum_suppliers[vaccuum_name] = true
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
description = desc,
|
||||
drawtype = "normal",
|
||||
tiles = tiles,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = grps,
|
||||
drop = vaccuum_name,
|
||||
sounds = logistica.node_sound_metallic(),
|
||||
after_place_node = after_place_vaccuum,
|
||||
after_destruct = logistica.on_supplier_change,
|
||||
on_rightclick = on_vaccuum_rightclick,
|
||||
allow_metadata_inventory_put = allow_vaccuum_storage_inv_put,
|
||||
allow_metadata_inventory_take = allow_vaccuum_inv_take,
|
||||
allow_metadata_inventory_move = allow_vaccuum_inv_move,
|
||||
on_metadata_inventory_put = on_vaccuum_inventory_put,
|
||||
on_metadata_inventory_take = on_vaccuum_inventory_take,
|
||||
on_timer = logistica.vaccuum_chest_on_timer,
|
||||
can_dig = can_dig_vaccuum,
|
||||
logistica = {
|
||||
inventory_size = inventorySize,
|
||||
on_power = on_vaccuum_power,
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(vaccuum_name, def)
|
||||
|
||||
local def_disabled = table.copy(def)
|
||||
local tiles_disabled = {}
|
||||
for k, v in pairs(def.tiles) do tiles_disabled[k] = v.."^logistica_disabled.png" end
|
||||
|
||||
def_disabled.tiles = tiles_disabled
|
||||
def_disabled.groups = { oddly_breakable_by_hand = 3, cracky = 3, choppy = 3, not_in_creative_inventory = 1 }
|
||||
def_disabled.on_construct = nil
|
||||
def_disabled.after_destruct = nil
|
||||
def_disabled.on_punch = nil
|
||||
def_disabled.on_rightclick = nil
|
||||
def_disabled.on_timer = nil
|
||||
def_disabled.logistica = nil
|
||||
|
||||
minetest.register_node(vaccuum_name.."_disabled", def_disabled)
|
||||
|
||||
end
|
@ -7,6 +7,7 @@ logistica.mass_storage = {}
|
||||
logistica.item_storage = {}
|
||||
logistica.misc_machines = {}
|
||||
logistica.trashcans = {}
|
||||
logistica.vaccuum_suppliers = {}
|
||||
logistica.tiers = {}
|
||||
logistica.TIER_ALL = "logistica_all_tiers"
|
||||
logistica.GROUP_ALL = "group:" .. logistica.TIER_ALL
|
||||
@ -62,6 +63,10 @@ function logistica.is_trashcan(name)
|
||||
return logistica.trashcans[name] ~= nil
|
||||
end
|
||||
|
||||
function logistica.is_vaccuum_supplier(name)
|
||||
return logistica.vaccuum_suppliers[name] ~= nil
|
||||
end
|
||||
|
||||
function logistica.get_item_tiers(name)
|
||||
local tiers = {}
|
||||
for tier,_ in pairs(logistica.tiers) do
|
||||
|
@ -15,3 +15,4 @@ dofile(path.."/access_point.lua")
|
||||
dofile(path.."/access_point_formspec.lua")
|
||||
dofile(path.."/lava_furnace_guide_formspec.lua")
|
||||
dofile(path.."/trashcan.lua")
|
||||
dofile(path.."/vaccuum_chest.lua")
|
||||
|
@ -147,6 +147,9 @@ local function recursive_scan_for_nodes_for_controller(network, positionHashes,
|
||||
elseif logistica.is_supplier(otherName) then
|
||||
network.suppliers[otherHash] = true
|
||||
valid = true
|
||||
elseif logistica.is_vaccuum_supplier(otherName) then
|
||||
network.suppliers[otherHash] = true
|
||||
valid = true
|
||||
elseif logistica.is_mass_storage(otherName) then
|
||||
network.mass_storage[otherHash] = true
|
||||
valid = true
|
||||
|
@ -23,6 +23,8 @@ end
|
||||
|
||||
-- tries to put the given item in this supplier, returns what's leftover
|
||||
function logistica.put_item_in_supplier(pos, stack)
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
if not logistica.is_supplier(nodeName) then return stack end
|
||||
-- only insert if its enabled
|
||||
if not logistica.is_machine_on(pos) then return stack end
|
||||
local origCount = stack:get_count()
|
||||
|
89
logic/vaccuum_chest.lua
Normal file
89
logic/vaccuum_chest.lua
Normal file
@ -0,0 +1,89 @@
|
||||
|
||||
local TIMER_INTERVAL = 0.8
|
||||
local TIMER_INTERVAL_LONG = 2.0
|
||||
local DEF_RADIUS = 3
|
||||
local INV_MAIN = "main"
|
||||
local ITEM_TAKE_PER_CYCLE_LIMIT = 10
|
||||
local NUM_PARTICLES_PER_COLLECT = 3
|
||||
|
||||
local function random_offset()
|
||||
return vector.new((math.random() - 0.5)/4, (math.random() - 0.5)/4, (math.random() - 0.5)/4)
|
||||
end
|
||||
|
||||
local function add_particle_effect_for_item_taken(itemPos, vaccuumPos)
|
||||
for _ = 1, NUM_PARTICLES_PER_COLLECT do
|
||||
local startPos = vector.add(itemPos, random_offset())
|
||||
local endPos = vector.add(vaccuumPos, vector.new(0, -0.45, 0))
|
||||
local vel = vector.normalize(vector.subtract(endPos, startPos)) * 2
|
||||
minetest.add_particle({
|
||||
pos = startPos,
|
||||
velocity = vel,
|
||||
expirationtime = 2,
|
||||
size = 1,
|
||||
collisiondetection = true,
|
||||
collision_removal = true,
|
||||
object_collision = false,
|
||||
texture = "logistica_vaccuum_particle.png",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- returns how many were inserted
|
||||
local function collect_items_into(pos, distance)
|
||||
local inserted = 0
|
||||
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
if not logistica.is_vaccuum_supplier(nodeName) then return inserted end
|
||||
local nodeDef = minetest.registered_nodes[nodeName]
|
||||
if not nodeDef or not nodeDef.logistica or not nodeDef.on_metadata_inventory_put then
|
||||
return inserted
|
||||
end
|
||||
|
||||
distance = distance + 0.5
|
||||
local minPos = vector.subtract(pos, distance)
|
||||
local maxPos = vector.add(pos, distance)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
for _, obj in pairs(minetest.get_objects_in_area(minPos, maxPos)) do
|
||||
local entity = obj:get_luaentity()
|
||||
if entity
|
||||
and entity.name == "__builtin:item"
|
||||
and entity.itemstring ~= "" then
|
||||
local itemStack = ItemStack(entity.itemstring)
|
||||
if inv:room_for_item(INV_MAIN, itemStack) then
|
||||
add_particle_effect_for_item_taken(obj:get_pos(), pos)
|
||||
inv:add_item(INV_MAIN, itemStack)
|
||||
-- this look unsafe, but we only target our supplier nodes
|
||||
entity.itemstring = ""
|
||||
inserted = inserted + 1
|
||||
obj:remove()
|
||||
if ITEM_TAKE_PER_CYCLE_LIMIT > 0
|
||||
and inserted >= ITEM_TAKE_PER_CYCLE_LIMIT then
|
||||
nodeDef.on_metadata_inventory_put(pos, nil, nil, nil, nil)
|
||||
return inserted
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if inserted > 0 then
|
||||
nodeDef.on_metadata_inventory_put(pos, nil, nil, nil, nil)
|
||||
end
|
||||
return inserted
|
||||
end
|
||||
|
||||
-- global functions
|
||||
|
||||
function logistica.vaccuum_chest_on_timer(pos, elapsed)
|
||||
if not logistica.is_machine_on(pos) then return false end
|
||||
local inserted = collect_items_into(pos, DEF_RADIUS)
|
||||
if inserted then
|
||||
logistica.start_node_timer(pos, TIMER_INTERVAL)
|
||||
else
|
||||
logistica.start_node_timer(pos, TIMER_INTERVAL_LONG)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function logistica.vaccuum_chest_on_power(pos, power)
|
||||
logistica.set_node_tooltip_from_state(pos, nil, power)
|
||||
logistica.start_node_timer(pos, TIMER_INTERVAL)
|
||||
end
|
@ -172,3 +172,12 @@ logistica.register_trashcan("Trashcan", "trashcan", {
|
||||
"logistica_trashcan_side.png",
|
||||
"logistica_trashcan_side.png",
|
||||
})
|
||||
|
||||
logistica.register_vaccuum_chest("Vaccuum Supplier Chest", "vaccuum_chest", 16, {
|
||||
"logistica_vaccuum_top.png",
|
||||
"logistica_vaccuum_bottom.png",
|
||||
"logistica_vaccuum_side.png",
|
||||
"logistica_vaccuum_side.png",
|
||||
"logistica_vaccuum_side.png",
|
||||
"logistica_vaccuum_front.png",
|
||||
})
|
||||
|
BIN
textures/logistica_vaccuum_bottom.png
Normal file
BIN
textures/logistica_vaccuum_bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/logistica_vaccuum_front.png
Normal file
BIN
textures/logistica_vaccuum_front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/logistica_vaccuum_particle.png
Normal file
BIN
textures/logistica_vaccuum_particle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
textures/logistica_vaccuum_side.png
Normal file
BIN
textures/logistica_vaccuum_side.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/logistica_vaccuum_top.png
Normal file
BIN
textures/logistica_vaccuum_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
x
Reference in New Issue
Block a user