Add mods: technic, moreores, paintings, Nyancat (Pbj_pup). Small fix: sandwiches
This commit is contained in:
parent
15e8e696a2
commit
fb09deddc1
1404 changed files with 156555 additions and 211 deletions
87
mods/technic_plus_beta/technic/machines/compat/api.lua
Normal file
87
mods/technic_plus_beta/technic/machines/compat/api.lua
Normal file
|
@ -0,0 +1,87 @@
|
|||
local S = technic.getter
|
||||
|
||||
-- Registration compatibility shim to transform Technic 1.x arguments to 2.x
|
||||
-- This could be made stricter for new style API by utilizing `assert`
|
||||
|
||||
local function shallow_copy(t)
|
||||
local result = {}
|
||||
for k, v in pairs(t) do
|
||||
result[k] = v
|
||||
end
|
||||
return setmetatable(result, getmetatable(t))
|
||||
end
|
||||
|
||||
function technic.register_compat_v1_to_v2(name, data, default_name)
|
||||
local modname = minetest.get_current_modname()
|
||||
local colon, def
|
||||
if type(name) == "table" then
|
||||
-- Log old API usage, swap name to def and set name from def table
|
||||
local msg = "Deprecated Technic registration API call: %s (%s)"
|
||||
def = shallow_copy(name)
|
||||
name = def.machine_name or default_name
|
||||
def.machine_name = nil
|
||||
def.description = def.machine_desc
|
||||
def.machine_desc = nil
|
||||
minetest.log("warning", msg:format(tostring(name), tostring(modname)))
|
||||
else
|
||||
def = shallow_copy(data)
|
||||
end
|
||||
-- Input name can be "modname:nodename", ":modname:nodename" or "nodename".
|
||||
-- If name is presented as "nodename" then check for old def.modname field.
|
||||
if name:find(":") then
|
||||
colon, modname, name = name:match("(:?)(.+):(.+)")
|
||||
-- Make sure that all fields are set, can be empty but pattern matcher must succeed.
|
||||
assert(colon and modname and name)
|
||||
elseif def.modname then
|
||||
minetest.log("warning", ("Definition contains modname for %s"):format(name))
|
||||
colon = ":"
|
||||
modname = def.modname
|
||||
end
|
||||
return (colon or ""), modname, name, def
|
||||
end
|
||||
|
||||
-- Registration functions in Technic 1.x version
|
||||
|
||||
function technic.register_alloy_furnace(def)
|
||||
def.typename = "alloy"
|
||||
def.description = S("@1 Alloy Furnace", S(def.tier))
|
||||
def.insert_object = technic.insert_object_unique_stack
|
||||
def.can_insert = technic.can_insert_unique_stack
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_centrifuge(def)
|
||||
def.typename = "separating"
|
||||
def.description = S("@1 Centrifuge", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_compressor(def)
|
||||
def.typename = "compressing"
|
||||
def.description = S("@1 Compressor", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_extractor(def)
|
||||
def.typename = "extracting"
|
||||
def.description = S("@1 Extractor", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_freezer(def)
|
||||
def.typename = "freezing"
|
||||
def.description = S("@1 Freezer", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_grinder(def)
|
||||
def.typename = "grinding"
|
||||
def.description = S("@1 Grinder", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
||||
|
||||
function technic.register_electric_furnace(def)
|
||||
def.typename = "cooking"
|
||||
def.description = S("@1 Furnace", S(def.tier))
|
||||
technic.register_base_machine(def)
|
||||
end
|
109
mods/technic_plus_beta/technic/machines/compat/digtron.lua
Normal file
109
mods/technic_plus_beta/technic/machines/compat/digtron.lua
Normal file
|
@ -0,0 +1,109 @@
|
|||
--
|
||||
-- Compatibility hacks for digtron to work well with new Technic Plus network and power tools
|
||||
--
|
||||
-- More information:
|
||||
-- https://github.com/mt-mods/technic/issues/100
|
||||
-- https://github.com/mt-mods/technic/issues/233
|
||||
--
|
||||
-- Disable some luacheck warnings to allow having original formatting here
|
||||
-- luacheck: no max line length
|
||||
-- luacheck: globals digtron
|
||||
|
||||
-- Only relevant sections modified, you can directly compare this with upstream function defined in util.lua
|
||||
local node_inventory_table = {type="node"}
|
||||
local function tap_batteries(battery_positions, target, test)
|
||||
if (battery_positions == nil) then
|
||||
return 0
|
||||
end
|
||||
|
||||
local current_burned = 0
|
||||
-- 1 coal block is 370 PU
|
||||
-- 1 coal lump is 40 PU
|
||||
-- An RE battery holds 10000 EU of charge
|
||||
-- local power_ratio = 100 -- How much charge equals 1 unit of PU from coal
|
||||
-- setting Moved to digtron.config.power_ratio
|
||||
|
||||
for k, location in pairs(battery_positions) do
|
||||
if current_burned > target then
|
||||
break
|
||||
end
|
||||
node_inventory_table.pos = location.pos
|
||||
local inv = minetest.get_inventory(node_inventory_table)
|
||||
local invlist = inv:get_list("batteries")
|
||||
|
||||
if (invlist == nil) then -- This check shouldn't be needed, it's yet another guard against https://github.com/minetest/minetest/issues/8067
|
||||
break
|
||||
end
|
||||
|
||||
for i, itemstack in pairs(invlist) do
|
||||
local charge = technic.get_charge(itemstack)
|
||||
local power_available = math.floor(charge / digtron.config.power_ratio)
|
||||
if power_available ~= 0 then
|
||||
local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable
|
||||
-- don't bother recording the items if we're just testing, nothing is actually being removed.
|
||||
if test ~= true then
|
||||
-- since we are taking everything, the wear and charge can both be set to 0
|
||||
technic.set_charge(itemstack, 0)
|
||||
end
|
||||
current_burned = current_burned + actual_burned
|
||||
end
|
||||
|
||||
if current_burned > target then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if test ~= true then
|
||||
-- only update the list if we're doing this for real.
|
||||
inv:set_list("batteries", invlist)
|
||||
end
|
||||
end
|
||||
return current_burned
|
||||
end
|
||||
|
||||
local function power_connector_compat()
|
||||
local digtron_technic_run = minetest.registered_nodes["digtron:power_connector"].technic_run
|
||||
minetest.override_item("digtron:power_connector",{
|
||||
technic_run = function(pos, node)
|
||||
local network_id = technic.pos2network(pos)
|
||||
local sw_pos = network_id and technic.network2sw_pos(network_id)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("HV_network", sw_pos and minetest.pos_to_string(sw_pos) or "")
|
||||
return digtron_technic_run(pos, node)
|
||||
end,
|
||||
technic_on_disable = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("HV_network", "")
|
||||
meta:set_string("HV_EU_input", "")
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function battery_holder_compat()
|
||||
-- Override battery holder
|
||||
local tube = minetest.registered_nodes["digtron:battery_holder"].tube
|
||||
tube.can_insert = function(pos, node, stack, direction)
|
||||
if technic.get_charge(stack) > 0 then
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:room_for_item("batteries", stack)
|
||||
end
|
||||
return false
|
||||
end
|
||||
minetest.override_item("digtron:battery_holder",{
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return (listname == "batteries" and technic.get_charge(stack) > 0) and stack:get_count() or 0
|
||||
end,
|
||||
tube = tube,
|
||||
})
|
||||
-- Override digtron.tap_batteries
|
||||
digtron.tap_batteries = tap_batteries
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
if minetest.registered_nodes["digtron:power_connector"] then
|
||||
power_connector_compat()
|
||||
end
|
||||
if minetest.registered_nodes["digtron:battery_holder"] then
|
||||
battery_holder_compat()
|
||||
end
|
||||
end)
|
139
mods/technic_plus_beta/technic/machines/compat/tools.lua
Normal file
139
mods/technic_plus_beta/technic/machines/compat/tools.lua
Normal file
|
@ -0,0 +1,139 @@
|
|||
--
|
||||
-- This allows using old style technic.register_power_tool tool registration function.
|
||||
--
|
||||
-- To make tool fully compatible replace `minetest.register_tool` with `technic.register_power_tool`
|
||||
-- and add `technic_max_charge` field for tool definition.
|
||||
-- Fields `wear_represents` and `on_refill` can be removed if using defaults.
|
||||
--
|
||||
-- Does not offer compatibility for charger mods: mods that charge or discharge registered power tools.
|
||||
-- Compatibility for those can be achieved by using `<tooldef>.technic_get_charge` / `<tooldef>.technic_set_charge`.
|
||||
--
|
||||
|
||||
local function compat_set_RE_wear(stack, charge)
|
||||
local def = stack:get_definition()
|
||||
if def.technic_wear_factor then
|
||||
local wear = math.floor(charge * def.technic_wear_factor + 0.5)
|
||||
stack:set_wear(wear > 0 and 65536 - wear or 0)
|
||||
end
|
||||
end
|
||||
|
||||
local function compat_technic_get_charge(stack)
|
||||
local def = stack:get_definition()
|
||||
if def.technic_max_charge then
|
||||
local legacy_fields = minetest.deserialize(stack:get_meta():get_string("")) or {}
|
||||
return legacy_fields.charge or 0, def.technic_max_charge
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
local function compat_technic_set_charge(stack, charge)
|
||||
compat_set_RE_wear(stack, charge)
|
||||
local meta = stack:get_meta()
|
||||
local legacy_fields = minetest.deserialize(meta:get_string("")) or {}
|
||||
legacy_fields.charge = charge
|
||||
meta:set_string("", minetest.serialize(legacy_fields))
|
||||
end
|
||||
|
||||
-- This attempts to find out if mod is aware of technic.plus version property and marks mod as `plus_aware` if
|
||||
-- it tries to read `technic.plus` value. Marked tools wont receive automatic metadata compatibility functions.
|
||||
local plus_aware = {}
|
||||
do
|
||||
local original_mt = getmetatable(technic)
|
||||
local mt = original_mt and table.copy(original_mt) or {}
|
||||
local mt_index = mt.__index or rawget
|
||||
local plus = technic.plus
|
||||
rawset(technic, "plus", nil)
|
||||
|
||||
-- Extend `__index` lookup function for `technic` to collect mod names that are reading `technic.plus` property
|
||||
function mt:__index(key)
|
||||
if key == "plus" then
|
||||
local modname = minetest.get_current_modname()
|
||||
if modname then
|
||||
plus_aware[modname] = true
|
||||
end
|
||||
return plus
|
||||
end
|
||||
return mt_index(self, key)
|
||||
end
|
||||
setmetatable(technic, mt)
|
||||
|
||||
-- Restore version and metatable, this must happen after handling register_on_mods_loaded callbacks
|
||||
minetest.after(0, function()
|
||||
rawset(technic, "plus", plus)
|
||||
setmetatable(technic, original_mt)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Override `technic.register_power_tool` to handle old style registration that was only setting max charge value.
|
||||
local register_power_tool = technic.register_power_tool
|
||||
function technic.register_power_tool(itemname, def_or_max_charge)
|
||||
if type(def_or_max_charge) == "number" then
|
||||
minetest.log("warning", "Deprecated technic.register_power_tool use. Setting max_charge for "..itemname)
|
||||
technic.power_tools[itemname] = def_or_max_charge
|
||||
minetest.register_on_mods_loaded(function()
|
||||
minetest.log("warning", "Deprecated technic.register_power_tool use. Ensuring fields for "..itemname)
|
||||
local redef = minetest.registered_items[itemname]
|
||||
if redef and redef.wear_represents == "technic_RE_charge" then
|
||||
-- Override power tools that called register_power_tool but do not have on_refill function defined
|
||||
local overrides = {
|
||||
technic_max_charge = def_or_max_charge,
|
||||
technic_wear_factor = 65535 / def_or_max_charge,
|
||||
on_refill = function(stack)
|
||||
local tooldef = stack:get_definition()
|
||||
tooldef.technic_set_charge(stack, def_or_max_charge)
|
||||
return stack
|
||||
end,
|
||||
}
|
||||
-- Add legacy meta handlers if mod did not attempt to read technic.plus value
|
||||
local modname = itemname:match(":?(.+):")
|
||||
if plus_aware[modname] then
|
||||
overrides.technic_get_charge = redef.technic_get_charge or technic.get_charge
|
||||
overrides.technic_set_charge = redef.technic_set_charge or technic.set_charge
|
||||
minetest.log("warning", "Mod "..modname.." seems to be aware of technic.plus but "..
|
||||
itemname.." is still using deprecated registration, skipping meta charge compatibility.")
|
||||
elseif not redef.technic_get_charge and not redef.technic_set_charge then
|
||||
overrides.technic_get_charge = compat_technic_get_charge
|
||||
overrides.technic_set_charge = compat_technic_set_charge
|
||||
minetest.log("warning", "Using metadata charge values for "..itemname)
|
||||
end
|
||||
-- Override tool definition with added / new values
|
||||
minetest.override_item(itemname, overrides)
|
||||
minetest.log("warning", "Updated legacy Technic power tool definition for "..itemname)
|
||||
else
|
||||
minetest.log("error", "Technic compatibility overrides skipped for "..itemname..", charging might "..
|
||||
'cause crash. Upgrading to technic.register_power_tool("'..itemname..'", {itemdef}) recommended.')
|
||||
end
|
||||
end)
|
||||
else
|
||||
return register_power_tool(itemname, def_or_max_charge)
|
||||
end
|
||||
end
|
||||
|
||||
technic.set_RE_charge = assert(technic.set_charge)
|
||||
technic.get_RE_charge = assert(technic.get_charge)
|
||||
technic.use_RE_charge = assert(technic.use_charge)
|
||||
|
||||
-- Same as `technic.set_charge` but without calling through `itemdef.technic_set_charge`.
|
||||
function technic.set_RE_wear(stack, charge)
|
||||
minetest.log("warning", "Use of deprecated function technic.set_RE_wear with stack: "..stack:get_name())
|
||||
compat_set_RE_wear(stack, charge)
|
||||
end
|
||||
|
||||
-- Old utility function to recharge tools
|
||||
local function charge_tools(meta, batt_charge, charge_step)
|
||||
local src_stack = meta:get_inventory():get_stack("src", 1)
|
||||
local def = src_stack:get_definition()
|
||||
if not def or not def.technic_max_charge or src_stack:is_empty() then
|
||||
return batt_charge, false
|
||||
end
|
||||
local new_charge = math.min(def.technic_max_charge, def.technic_get_charge(src_stack) + charge_step)
|
||||
def.technic_set_charge(src_stack, new_charge)
|
||||
meta:get_inventory():set_stack("src", 1, src_stack)
|
||||
return batt_charge, (def.technic_max_charge == new_charge)
|
||||
end
|
||||
|
||||
function technic.charge_tools(...)
|
||||
minetest.log("warning", "Use of deprecated function technic.charge_tools")
|
||||
technic.charge_tools = charge_tools
|
||||
return charge_tools(...)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue