factions/nodes.lua

273 lines
9.6 KiB
Lua
Raw Normal View History

2019-01-26 07:21:05 +01:00
function factions.can_use_node(pos, player, permission)
2016-08-24 15:32:08 +02:00
if not player then
return false
end
local parcel_faction = factions.get_faction_at(pos)
2018-10-31 22:15:08 +01:00
if not parcel_faction then
2016-08-24 15:32:08 +02:00
return true
end
2019-01-26 07:21:05 +01:00
local player_faction, facname = factions.get_player_faction(player)
if player_faction and (parcel_faction.name == facname or parcel_faction.allies[facname]) and factions.has_permission(facname, player, permission) then
2018-10-31 22:15:08 +01:00
return true
end
2016-08-24 15:32:08 +02:00
end
2019-01-26 07:21:05 +01:00
2018-10-31 22:15:08 +01:00
-- Make default chest the faction chest.
if minetest.registered_nodes["default:chest"] then
minetest.register_lbm({
label = "Replace faction chest with default one.",
name = "factions:replace_factions_chest",
nodenames = {"factions:chest"},
action = function(pos, node)
2019-01-22 23:13:48 +01:00
minetest.swap_node(pos, {name = "default:chest"})
2018-10-31 22:15:08 +01:00
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
2019-01-22 23:13:48 +01:00
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Chest (owned by faction " ..
2019-01-22 23:13:48 +01:00
name .. ")")
end
2018-10-31 22:15:08 +01:00
end
})
2018-10-31 22:15:08 +01:00
local dc = minetest.registered_nodes["default:chest"]
local def_on_rightclick = dc.on_rightclick
2019-01-22 23:13:48 +01:00
local after_place_node = function(pos, placer)
2018-10-31 22:15:08 +01:00
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
2019-01-22 23:13:48 +01:00
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Container (owned by faction " ..
2019-01-22 23:13:48 +01:00
name .. ")")
2018-10-31 22:15:08 +01:00
end
end
2019-01-26 07:21:05 +01:00
local can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
2018-10-31 22:15:08 +01:00
local inv = meta:get_inventory()
return inv:is_empty("main") and
2019-01-26 07:21:05 +01:00
factions.can_use_node(pos, player:get_player_name(), "container")
2018-10-31 22:15:08 +01:00
end
local allow_metadata_inventory_move
local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move
if def_allow_metadata_inventory_move then
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return def_allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
end
else
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return count
2018-10-31 22:15:08 +01:00
end
end
local allow_metadata_inventory_put
local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put
if def_allow_metadata_inventory_put then
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return def_allow_metadata_inventory_put(pos, listname, index, stack, player)
end
else
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return stack:get_count()
2018-10-31 22:15:08 +01:00
end
end
local allow_metadata_inventory_take
local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take
if def_allow_metadata_inventory_take then
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return def_allow_metadata_inventory_take(pos, listname, index, stack, player)
end
else
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return stack:get_count()
2018-10-31 22:15:08 +01:00
end
end
2019-01-22 23:13:48 +01:00
local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
2019-01-26 07:21:05 +01:00
if not factions.can_use_node(pos, clicker:get_player_name(), "container") then
2018-10-31 22:15:08 +01:00
return itemstack
end
2019-01-22 23:13:48 +01:00
return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
2018-10-31 22:15:08 +01:00
end
2019-01-22 23:13:48 +01:00
minetest.override_item("default:chest", {after_place_node = after_place_node,
can_dig = can_dig,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
on_rightclick = on_rightclick})
2018-10-31 22:15:08 +01:00
end
2019-01-26 07:21:05 +01:00
2019-03-12 00:38:03 +01:00
local door_items = {"doors:door_wood", "doors:door_steel", "doors:door_glass", "doors:door_obsidian_glass", "doors:woodglass_door", "doors:slide_door",
"doors:screen_door", "doors:rusty_prison_door", "doors:prison_door", "doors:japanese_door", "ts_doors:door_default_aspen_wood", "ts_doors:door_full_default_aspen_wood",
"ts_doors:door_default_pine_wood", "ts_doors:door_full_default_pine_wood", "ts_doors:door_default_acacia_wood", "ts_doors:door_full_default_acacia_wood",
"ts_doors:door_default_wood", "ts_doors:door_full_default_wood", "ts_doors:door_default_junglewood", "ts_doors:door_full_default_junglewood",
"ts_doors:door_default_bronzeblock", "ts_doors:door_full_default_bronzeblock", "ts_doors:door_default_copperblock", "ts_doors:door_full_default_copperblock",
"ts_doors:door_default_diamondblock", "ts_doors:door_full_default_diamondblock", "ts_doors:door_full_default_goldblock", "ts_doors:door_default_steelblock", "ts_doors:door_full_default_steelblock"}
local trapdoor_items = {"doors:trapdoor", "doors:trapdoor_steel", "ts_doors:trapdoor_default_aspen_wood", "ts_doors:trapdoor_full_default_aspen_wood",
"ts_doors:trapdoor_default_wood", "ts_doors:trapdoor_full_default_wood", "ts_doors:trapdoor_default_acacia_wood", "ts_doors:trapdoor_full_default_acacia_wood",
"ts_doors:trapdoor_default_bronzeblock", "ts_doors:trapdoor_full_default_bronzeblock", "ts_doors:trapdoor_default_copperblock", "ts_doors:trapdoor_full_default_copperblock", "ts_doors:trapdoor_full_default_diamondblock",
"ts_doors:door_default_goldblock", "ts_doors:trapdoor_default_steelblock", "ts_doors:trapdoor_full_default_steelblock", "ts_doors:trapdoor_default_pine_wood", "ts_doors:trapdoor_full_default_pine_wood",
"ts_doors:trapdoor_full_default_goldblock", "ts_doors:trapdoor_default_junglewood", "ts_doors:trapdoor_full_default_junglewood",
"ts_doors:trapdoor_default_diamondblock", "ts_doors:trapdoor_default_goldblock"}
2018-10-31 22:15:08 +01:00
-- Edit default doors and trapdoors to make them require the door permission.
2019-03-12 00:38:03 +01:00
local doors = {}
local all_items = {}
local item_count = 1
local old_i = 0
2019-03-12 00:38:03 +01:00
for i, l in ipairs(door_items) do
doors[item_count] = l .. "_a"
doors[item_count + 1] = l .. "_b"
all_items[i] = l
2019-03-12 00:38:03 +01:00
item_count = item_count + 2
old_i = old_i + 1
2019-03-12 00:38:03 +01:00
end
for i, l in ipairs(trapdoor_items) do
doors[item_count] = l
doors[item_count + 1] = l .. "_open"
all_items[old_i + i] = l
2019-03-12 00:38:03 +01:00
item_count = item_count + 2
end
2019-01-22 23:13:48 +01:00
for i, l in ipairs(doors) do
local dw = minetest.registered_nodes[l]
if dw then
local def_on_rightclick = dw.on_rightclick
local def_can_dig = dw.can_dig
2019-01-22 23:13:48 +01:00
local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if factions.can_use_node(pos, clicker:get_player_name(), "door") then
def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
2018-10-31 22:15:08 +01:00
end
2019-01-22 23:13:48 +01:00
return itemstack
2018-10-31 22:15:08 +01:00
end
2019-01-22 23:13:48 +01:00
local can_dig = nil
2019-01-19 16:14:22 +01:00
if def_can_dig then
2019-01-22 23:13:48 +01:00
can_dig = function(pos, digger)
if factions.can_use_node(pos, digger:get_player_name(), "door") then
2019-01-19 16:14:22 +01:00
return def_can_dig(pos, digger)
end
return false
end
else
2019-01-22 23:13:48 +01:00
can_dig = function(pos, digger)
if factions.can_use_node(pos, digger:get_player_name(), "door") then
2019-01-19 16:14:22 +01:00
return true
end
return false
2018-10-31 22:15:08 +01:00
end
end
2019-01-22 23:13:48 +01:00
minetest.override_item(l, {on_rightclick = on_rightclick,
can_dig = can_dig})
end
end
2019-03-12 00:38:03 +01:00
for i, l in ipairs(all_items) do
2019-01-22 23:13:48 +01:00
local it = minetest.registered_items[l]
if it then
local def_on_place = it.on_place
if def_on_place ~= nil then
local on_place = function(itemstack, placer, pointed_thing)
local r = def_on_place(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Door (owned by faction " ..
name .. ")")
end
return r
end
minetest.override_item(l, {on_place = on_place})
end
2018-10-31 22:15:08 +01:00
end
end
2018-10-17 04:58:15 +02:00
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.
2018-10-18 04:04:46 +02:00
local x = math.floor(factions_config.parcel_size / 2.1)
2018-10-17 04:58:15 +02:00
minetest.register_node("factions:display_node", {
tiles = {"factions_display.png"},
use_texture_alpha = true,
walkable = false,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
-- sides
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
-- top
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
-- bottom
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
-- middle (surround parcel)
{-.55,-.55,-.55, .55,.55,.55},
},
},
selection_box = {
type = "regular",
},
paramtype = "light",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "",
})
minetest.register_entity("factions:display", {
physical = false,
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "wielditem",
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
textures = {"factions:display_node"},
timer = 0,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 6 then
self.object:remove()
end
end,
})
-- End