Going wireless! Implementing powered teleports
This commit is contained in:
parent
cd9a802c1b
commit
aea77184e0
@ -79,6 +79,12 @@ minetest.register_craftitem("elepower_dynamics:zinc_lump", {
|
||||
groups = {zinc = 1, lump = 1}
|
||||
})
|
||||
|
||||
minetest.register_craftitem("elepower_dynamics:xycrone_lump", {
|
||||
description = "Xycrone\nUsed for Quantum Superpositioning\nUnstable",
|
||||
inventory_image = "elepower_xycrone.png",
|
||||
groups = {xycrone = 1, lump = 1}
|
||||
})
|
||||
|
||||
-- Special
|
||||
|
||||
minetest.register_craftitem("elepower_dynamics:carbon_fiber", {
|
||||
@ -105,8 +111,8 @@ minetest.register_craftitem("elepower_dynamics:silicon_wafer", {
|
||||
groups = {wafer = 1}
|
||||
})
|
||||
|
||||
minetest.register_craftitem("elepower_dynamics:silicon_wafer_solar", {
|
||||
description = "Silicon Wafer\nFor Solar Panel Crafting",
|
||||
minetest.register_craftitem("elepower_dynamics:silicon_wafer_doped", {
|
||||
description = "Doped Silicon Wafer\nFor Solar Panel Crafting",
|
||||
inventory_image = "elepower_silicon_wafer_solar.png",
|
||||
groups = {wafer = 2}
|
||||
})
|
||||
@ -118,7 +124,7 @@ minetest.register_craftitem("elepower_dynamics:tree_tap", {
|
||||
})
|
||||
|
||||
minetest.register_craftitem("elepower_dynamics:pcb_blank", {
|
||||
description = "Printed Circuit Board (PCB) Blank",
|
||||
description = "Printed Circuit Board (PCB) Blank\nUse Etching Acid to etch",
|
||||
inventory_image = "elepower_blank_pcb.png",
|
||||
liquids_pointable = true,
|
||||
groups = {blank_board = 1, static_component = 1}
|
||||
|
BIN
elepower_dynamics/textures/elepower_xycrone.png
Normal file
BIN
elepower_dynamics/textures/elepower_xycrone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 459 B |
@ -98,13 +98,6 @@ elepm.register_craft({
|
||||
time = 8,
|
||||
})
|
||||
|
||||
elepm.register_craft({
|
||||
type = "grind",
|
||||
recipe = { "elepower_dynamics:silicon_wafer" },
|
||||
output = "elepower_dynamics:silicon_wafer_solar",
|
||||
time = 18,
|
||||
})
|
||||
|
||||
-----------------
|
||||
-- Compressing --
|
||||
-----------------
|
||||
@ -122,6 +115,40 @@ for mat, ingot in pairs(ingot_map) do
|
||||
end
|
||||
end
|
||||
|
||||
-- Detect sands
|
||||
for name in pairs(minetest.registered_nodes) do
|
||||
if name:match("sand") and not name:match("sandstone") then
|
||||
local sand = name
|
||||
local sandstone = name .. "stone"
|
||||
if minetest.registered_nodes[sandstone] then
|
||||
elepm.register_craft({
|
||||
type = "compress",
|
||||
recipe = { sand .. " 4" },
|
||||
output = sandstone,
|
||||
time = 1,
|
||||
})
|
||||
|
||||
-- Find block as well
|
||||
local ssblock = sandstone .. "_block"
|
||||
if minetest.registered_nodes[ssblock] then
|
||||
elepm.register_craft({
|
||||
type = "compress",
|
||||
recipe = { sandstone .. " 4" },
|
||||
output = ssblock,
|
||||
time = 1,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elepm.register_craft({
|
||||
type = "compress",
|
||||
recipe = { "elepower_dynamics:viridisium_block 9" },
|
||||
output = "elepower_dynamics:xycrone_lump",
|
||||
time = 20,
|
||||
})
|
||||
|
||||
-------------
|
||||
-- Sawmill --
|
||||
-------------
|
||||
|
@ -153,8 +153,9 @@ function ele.register_base_device(nodename, nodedef)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("storage", 0)
|
||||
end
|
||||
|
||||
|
||||
ele.clear_networks(pos)
|
||||
|
||||
if original_on_construct then
|
||||
original_on_construct(pos)
|
||||
end
|
||||
@ -170,8 +171,23 @@ function ele.register_base_device(nodename, nodedef)
|
||||
end
|
||||
|
||||
-- Save storage amount when picked up
|
||||
nodedef.preserve_metadata = preserve_metadata
|
||||
nodedef.after_place_node = retrieve_metadata
|
||||
local original_preserve_metadata = nodedef.preserve_metadata
|
||||
nodedef.preserve_metadata = function (pos, oldnode, oldmeta, drops)
|
||||
drops = preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||
if original_preserve_metadata then
|
||||
drops = original_preserve_metadata(pos, oldnode, oldmeta, drops)
|
||||
end
|
||||
return drops
|
||||
end
|
||||
|
||||
local original_after_place_node = nodedef.after_place_node
|
||||
nodedef.after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local ret = retrieve_metadata(pos, placer, itemstack, pointed_thing)
|
||||
if original_after_place_node then
|
||||
ret = original_after_place_node(pos, placer, itemstack, pointed_thing)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
-- Prevent digging when there's items inside
|
||||
if not nodedef.can_dig then
|
||||
|
@ -23,7 +23,6 @@ function ele.tools.groupcaps(itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
local itemdef = minetest.registered_items[itemstack:get_name()]
|
||||
|
||||
local toolcaps = itemdef.tool_capabilities
|
||||
if wear == 65535 then
|
||||
meta:set_tool_capabilities({})
|
||||
else
|
||||
|
0
elepower_wireless/crafting.lua
Normal file
0
elepower_wireless/crafting.lua
Normal file
75
elepower_wireless/craftitems.lua
Normal file
75
elepower_wireless/craftitems.lua
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
ele.register_tool("elepower_wireless:wireless_porter", {
|
||||
description = "Wireless Porter",
|
||||
inventory_image = "elewireless_wireless_porter.png",
|
||||
on_use = function (itemstack, player, pointed_thing)
|
||||
local meta = itemstack:get_meta()
|
||||
local storage = ele.tools.get_tool_property(itemstack, "storage")
|
||||
local pos = minetest.string_to_pos(meta:get_string("receiver"))
|
||||
|
||||
if not pos or pos == "" then return itemstack end
|
||||
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
|
||||
local plname = player:get_player_name()
|
||||
if not node or not ele.helpers.get_item_group(node.name, "matter_receiver") then
|
||||
minetest.chat_send_player(plname, "Destination Receiver is missing or unloaded!")
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local nmeta = minetest.get_meta(pos)
|
||||
local nstorage = ele.helpers.get_node_property(nmeta, pos, "storage")
|
||||
local nusage = ele.helpers.get_node_property(nmeta, pos, "usage")
|
||||
local top = vector.add(pos, {x = 0, y = 1, z = 0})
|
||||
local topnode = minetest.get_node_or_nil(top)
|
||||
|
||||
if topnode and topnode.name ~= "air" then
|
||||
minetest.chat_send_player(plname, "Destination is obstructed!")
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if not (nstorage >= nusage and storage >= nusage) then
|
||||
minetest.chat_send_player(plname, "Not enough power to commit teleport!")
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Teleport player
|
||||
player:set_pos(top)
|
||||
nmeta:set_int("storage", nstorage - nusage)
|
||||
|
||||
-- Add wear
|
||||
meta:set_int("storage", storage - nusage)
|
||||
itemstack = ele.tools.update_tool_wear(itemstack)
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer or placer:get_player_name() == "" then return itemstack end
|
||||
local player = placer:get_player_name()
|
||||
|
||||
if minetest.is_protected(pos, player) then
|
||||
minetest.chat_send_player(player, "You are not allowed to teleport here!")
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local meta = itemstack:get_meta()
|
||||
local pos = pointed_thing.under
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
|
||||
if not node or not ele.helpers.get_item_group(node.name, "matter_receiver") then return itemstack end
|
||||
|
||||
local strpos = minetest.pos_to_string(pos)
|
||||
local curpos = minetest.string_to_pos(meta:get_string("receiver"))
|
||||
|
||||
if (curpos and curpos ~= "") and curpos == strpos then
|
||||
minetest.chat_send_player(player, "Wireless Porter is already bound to this location!")
|
||||
return itemstack
|
||||
end
|
||||
|
||||
meta:set_string("receiver", strpos)
|
||||
minetest.chat_send_player(player, ("Wireless Porter bound to %s!"):format(strpos))
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
ele_capacity = 1000,
|
||||
})
|
2
elepower_wireless/depends.txt
Normal file
2
elepower_wireless/depends.txt
Normal file
@ -0,0 +1,2 @@
|
||||
elepower_dynamics
|
||||
elepower_machines
|
17
elepower_wireless/init.lua
Normal file
17
elepower_wireless/init.lua
Normal file
@ -0,0 +1,17 @@
|
||||
-- Elepower Mod
|
||||
-- Copyright 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
elewi = rawget(_G, "elewi") or {}
|
||||
elewi.modpath = modpath
|
||||
|
||||
-- Items
|
||||
dofile(modpath .. "/craftitems.lua")
|
||||
dofile(modpath .. "/nodes.lua")
|
||||
|
||||
-- Machines
|
||||
dofile(modpath .. "/machines/init.lua")
|
||||
|
||||
-- Crafting
|
||||
dofile(modpath .. "/crafting.lua")
|
4
elepower_wireless/machines/init.lua
Normal file
4
elepower_wireless/machines/init.lua
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
local mp = elewi.modpath .. "/machines/"
|
||||
|
||||
dofile(mp .. "matter_receiver.lua")
|
88
elepower_wireless/machines/matter_receiver.lua
Normal file
88
elepower_wireless/machines/matter_receiver.lua
Normal file
@ -0,0 +1,88 @@
|
||||
|
||||
local function get_formspec(power, name, player)
|
||||
return "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
ele.formspec.power_meter(power)..
|
||||
"field[1.5,0.5;5,1;name;Receiver Name;".. name .."]"..
|
||||
"field_close_on_enter[name;false]"..
|
||||
"label[0,3.75;Owned by " .. player .. "]"..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
"listring[current_player;main]"..
|
||||
default.get_hotbar_bg(0, 4.25)
|
||||
end
|
||||
|
||||
local function matter_receiver_timer(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local name = meta:get_string("name")
|
||||
local player = meta:get_string("player")
|
||||
|
||||
if name == "" then
|
||||
name = "Matter Receiver"
|
||||
end
|
||||
|
||||
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
|
||||
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
||||
local usage = ele.helpers.get_node_property(meta, pos, "usage")
|
||||
|
||||
local pow_percent = math.floor((storage / capacity) * 100)
|
||||
|
||||
if storage >= usage then
|
||||
ele.helpers.swap_node(pos, "elepower_wireless:matter_receiver_active")
|
||||
else
|
||||
ele.helpers.swap_node(pos, "elepower_wireless:matter_receiver")
|
||||
end
|
||||
|
||||
meta:set_string("formspec", get_formspec(pow_percent, name, player))
|
||||
meta:set_string("infotext", "Matter Receiver\n" .. ele.capacity_text(capacity, storage))
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
ele.register_machine("elepower_wireless:matter_receiver", {
|
||||
description = "Matter Receiver",
|
||||
tiles = {
|
||||
"elewireless_receiver_top_inactive.png", "elewireless_device_side.png^elepower_power_port.png", "elewireless_device_side.png",
|
||||
"elewireless_device_side.png", "elewireless_device_side.png", "elewireless_device_side.png"
|
||||
},
|
||||
ele_active_node = true,
|
||||
ele_active_nodedef = {
|
||||
tiles = {
|
||||
{
|
||||
name = "elewireless_receiver_top_animated.png",
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
speed = 5,
|
||||
},
|
||||
},
|
||||
"elewireless_device_side.png^elepower_power_port.png", "elewireless_device_side.png",
|
||||
"elewireless_device_side.png", "elewireless_device_side.png", "elewireless_device_side.png"
|
||||
},
|
||||
},
|
||||
groups = {cracky = 1, ele_user = 1, matter_receiver = 1},
|
||||
ele_capacity = 8000,
|
||||
ele_usage = 120,
|
||||
ele_no_automatic_ports = true,
|
||||
on_timer = matter_receiver_timer,
|
||||
after_place_node = function (pos, placer, itemstack, pointed_thing)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not placer or placer:get_player_name() == "" then return false end
|
||||
|
||||
meta:set_string("player", placer:get_player_name())
|
||||
end,
|
||||
on_receive_fields = function (pos, formname, fields, sender)
|
||||
if sender and sender ~= "" and minetest.is_protected(pos, sender:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Set Name
|
||||
local meta = minetest.get_meta(pos)
|
||||
if fields["name"] and fields["key_enter"] == "true" then
|
||||
meta:set_string("name", fields["name"])
|
||||
end
|
||||
end
|
||||
})
|
3
elepower_wireless/mod.conf
Normal file
3
elepower_wireless/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = elepower_wireless
|
||||
description = Going wireless!
|
||||
depends = elepower_dynamics,elepower_machines
|
0
elepower_wireless/nodes.lua
Normal file
0
elepower_wireless/nodes.lua
Normal file
BIN
elepower_wireless/textures/elewireless_device_side.png
Normal file
BIN
elepower_wireless/textures/elewireless_device_side.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 403 B |
BIN
elepower_wireless/textures/elewireless_receiver_top.png
Normal file
BIN
elepower_wireless/textures/elewireless_receiver_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 617 B |
BIN
elepower_wireless/textures/elewireless_receiver_top_animated.png
Normal file
BIN
elepower_wireless/textures/elewireless_receiver_top_animated.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
elepower_wireless/textures/elewireless_receiver_top_inactive.png
Normal file
BIN
elepower_wireless/textures/elewireless_receiver_top_inactive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
BIN
elepower_wireless/textures/elewireless_wireless_porter.png
Normal file
BIN
elepower_wireless/textures/elewireless_wireless_porter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 720 B |
Loading…
Reference in New Issue
Block a user