mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-11-19 21:53:50 +01:00
Mesechest: limit API functions overwriting
This commit is contained in:
parent
6291b4c001
commit
fd21b16c02
@ -11,54 +11,22 @@ end
|
||||
|
||||
local open_chests = {}
|
||||
|
||||
|
||||
--[[
|
||||
default.register_chest prefixes chest names with "default:"
|
||||
and registers an LBM. Hack: override functions used by
|
||||
default.register_chest
|
||||
]]
|
||||
local old_register_lbm = minetest.register_lbm
|
||||
minetest.register_lbm = function() end
|
||||
|
||||
local old_register_node = minetest.register_node
|
||||
-- Override minetest.register_node so it adds a prefix ":"
|
||||
local old_minetest_register_node = minetest.register_node
|
||||
minetest.register_node = function(name, def)
|
||||
name = string.gsub(name, "default:", "")
|
||||
old_minetest_register_node(":"..name, def)
|
||||
|
||||
def.drop = def.drop and string.gsub(def.drop, "default:", "")
|
||||
local old_on_metadata_inventory_put = def.on_metadata_inventory_put
|
||||
local old_on_metadata_inventory_take = def.on_metadata_inventory_take
|
||||
local old_on_rightclick = def.on_rightclick
|
||||
|
||||
local old_on_blast = def.on_blast
|
||||
def.on_blast = function(pos)
|
||||
local drops = old_on_blast(pos)
|
||||
drops[#drops] = name
|
||||
return drops
|
||||
end
|
||||
|
||||
local old_on_construct = def.on_construct
|
||||
def.on_construct = function(pos)
|
||||
old_on_construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", string.gsub(meta:get_string("infotext"), "Chest", "Mese Chest"))
|
||||
end
|
||||
if def.after_place_node then
|
||||
local old_after_place_node = def.after_place_node
|
||||
def.after_place_node = function(pos, placer)
|
||||
old_after_place_node(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", string.gsub(meta:get_string("infotext"), "Chest", "Mese Chest"))
|
||||
end
|
||||
end
|
||||
|
||||
-- Mesecons functions
|
||||
local old_on_metadata_inventory_move = def.on_metadata_inventory_put
|
||||
def.on_metadata_inventory_put = function(pos, ...)
|
||||
old_on_metadata_inventory_move(pos, ...)
|
||||
old_on_metadata_inventory_put(pos, ...)
|
||||
mesecon.receptor_on(pos, {mesechest_get_output_rules(minetest.get_node(pos))[2]})
|
||||
minetest.after(1, function(pos)
|
||||
mesecon.receptor_off(pos, {mesechest_get_output_rules(minetest.get_node(pos))[2]})
|
||||
end, pos)
|
||||
end
|
||||
|
||||
local old_on_metadata_inventory_take = def.on_metadata_inventory_take
|
||||
def.on_metadata_inventory_take = function(pos, ...)
|
||||
old_on_metadata_inventory_take(pos, ...)
|
||||
mesecon.receptor_on(pos, {mesechest_get_output_rules(minetest.get_node(pos))[3]})
|
||||
@ -66,17 +34,15 @@ minetest.register_node = function(name, def)
|
||||
mesecon.receptor_off(pos, {mesechest_get_output_rules(minetest.get_node(pos))[3]})
|
||||
end, pos)
|
||||
end
|
||||
|
||||
local old_on_rightclick = def.on_rightclick
|
||||
def.on_rightclick = function(pos, node, clicker, ...)
|
||||
if old_on_rightclick(pos, node, clicker, ...) == nil then
|
||||
mesecon.receptor_on(pos, {mesechest_get_output_rules(node)[1]})
|
||||
open_chests[clicker:get_player_name()] = pos
|
||||
end
|
||||
end
|
||||
|
||||
old_register_node(name, def)
|
||||
end
|
||||
local old_minetest_register_lbm = minetest.register_lbm
|
||||
minetest.register_lbm = function() end
|
||||
|
||||
-- Get the on_player_receive_fields function. That's a huge hack
|
||||
for i, f in ipairs(minetest.registered_on_player_receive_fields) do
|
||||
@ -85,30 +51,17 @@ for i, f in ipairs(minetest.registered_on_player_receive_fields) do
|
||||
minetest.registered_on_player_receive_fields[i] = function(player, formname, fields)
|
||||
if f(player, formname, fields) == true then
|
||||
local pn = player:get_player_name()
|
||||
if open_chests[pn] then
|
||||
mesecon.receptor_off(open_chests[pn], {mesechest_get_output_rules(minetest.get_node(open_chests[pn]))[1]})
|
||||
open_chests[pn] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- This function is permanently overwritten
|
||||
local old_swap_node = minetest.swap_node
|
||||
minetest.swap_node = function(pos, node)
|
||||
if node.name == "default:moremesecons_mesechest:mesechest" then
|
||||
node.name = "moremesecons_mesechest:mesechest"
|
||||
elseif node.name == "default:moremesecons_mesechest:mesechest_open" then
|
||||
node.name = "moremesecons_mesechest:mesechest_open"
|
||||
elseif node.name == "default:moremesecons_mesechest:mesechest_locked" then
|
||||
node.name = "moremesecons_mesechest:mesechest_locked"
|
||||
elseif node.name == "default:moremesecons_mesechest:mesechest_locked_open" then
|
||||
node.name = "moremesecons_mesechest:mesechest_locked_open"
|
||||
end
|
||||
old_swap_node(pos, node)
|
||||
end
|
||||
|
||||
default.register_chest("moremesecons_mesechest:mesechest", {
|
||||
default.register_chest("mesechest", {
|
||||
description = "Mese Chest",
|
||||
tiles = { "default_chest_wood.png" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
@ -122,7 +75,7 @@ default.register_chest("moremesecons_mesechest:mesechest", {
|
||||
}
|
||||
})
|
||||
|
||||
default.register_chest("moremesecons_mesechest:mesechest_locked", {
|
||||
default.register_chest("mesechest_locked", {
|
||||
description = "Locked Mese Chest",
|
||||
tiles = { "default_chest_wood_locked.png" },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
@ -137,5 +90,5 @@ default.register_chest("moremesecons_mesechest:mesechest_locked", {
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_lbm = old_register_lbm
|
||||
minetest.register_node = old_register_node
|
||||
minetest.register_node = old_minetest_register_node
|
||||
minetest.register_lbm = old_minetest_register_lbm
|
||||
|
Loading…
Reference in New Issue
Block a user