BuckarooBanzay 5bde26df20
Some checks failed
luacheck / build (push) Has been cancelled
test / build (push) Has been cancelled
add ignore_placed_rotation to building def
2024-11-04 14:47:50 +01:00
2024-04-28 20:18:06 +02:00
2023-03-24 13:06:49 +01:00
2023-07-07 17:36:34 +02:00
2024-06-04 20:47:03 +02:00
2024-11-04 14:10:12 +01:00
2023-04-17 07:42:43 +02:00
2023-04-17 07:42:43 +02:00
2023-04-17 07:42:43 +02:00
2023-04-17 07:42:43 +02:00
2022-11-03 15:35:16 +01:00
2023-03-14 14:09:38 +01:00
2022-11-14 15:05:17 +01:00
2024-10-18 10:22:54 +02:00
2023-07-07 17:36:34 +02:00
2022-11-10 10:58:50 +01:00
2022-11-10 10:58:50 +01:00
2022-11-10 19:58:58 +01:00
2024-10-18 10:22:54 +02:00
2024-05-02 13:18:12 +02:00
2022-11-14 15:32:23 +01:00
2024-06-04 20:47:03 +02:00
2023-03-19 22:15:53 +01:00
2024-11-04 14:31:24 +01:00
2024-10-11 10:08:48 +02:00
2024-10-18 10:22:54 +02:00
2023-03-24 13:06:49 +01:00
2024-10-15 11:10:48 +02:00
2024-10-15 11:10:48 +02:00

Building register and placement library

Api

-- check if something can be built there
local success, message = building_lib.can_build(mapblock_pos, playername, building_name, rotation)

-- build it there
local promise = building_lib.build(mapblock_pos, playername, building_name, rotation, callback)
promise:next(function()
	-- success
end):catch(function(e)
	-- error
end)

-- check if it can be removed
local success, message = building_lib.can_remove(mapblock_pos)

-- remove it
local success, message = building_lib.remove(mapblock_pos)

-- registers a placeable building
building_lib.register_building("buildings:my_building", {
	placement = "mapblock_lib",
	conditions = {
		-- can only be placed if the whole area is empty
		{["*"] = { empty = true }}
	},
	remove_conditions = {
		-- can only be removed if nothing is built above
		{["above"] = { empty = true }}
	},
	-- simple catalog
	catalog = "my.zip",
	-- more catalog options
	catalog = {
		filename = "my.zip",
		-- offset in the catalog
		offset = {x=0, y=2, z=0},
		-- size
		size = {x=1, y=1, z=1},
		-- enable cache (only for 1x1x1 sized buildings, for mapgens)
		cache = true
	},
	-- optional groups attribute
	groups = {
		building = true
	},
	-- replacements
	replace = {
		["old_mod:node"] = "new_mod:node"
	},
	-- replacements as a function, can be used for biome-replacements
	replace = function(mapblock_pos, building_def)
		return {
			["old_mod:node"] = "new_mod:node"
		}
	end,
})

-- registers a placement type (connected, simple, etc)
building_lib.register_placement("simple", {
	-- place the building
	place = function(self, mapblock_pos, building_def, rotation, callback) end,
	-- return the size of the building if it would be placed there
	get_size = function(self, mapblock_pos, building_def, rotation)
		return { x=1, y=1, z=1 }
	end,
	-- validation function for startup-checks (optional)
	validate = function(self, building_def)
		return success, err_msg
	end
})

-- registers a condition that checks for certain world conditions
building_lib.register_condition("on_flat_surface", {
    can_build = function(mapblock_pos, flag_value)
		return false, msg
    end
})

Conditions

Built-in conditions:

  • group=<groupname> checks if there is already a building with the specified groupname
  • on_group=<groupname> checks if there is a building with the specified groupname below

Events

building_lib.register_on("placed", function(event) end)
-- event payload fields: mapblock_pos, playername, building_def, rotation, size
building_lib.register_on("placed_over", function(event) end)
-- event payload fields: mapblock_pos, playername, old_building_def, new_building_def, rotation, size
building_lib.register_on("placed_mapgen", function(event) end)
-- event payload fields: mapblock_pos, playername, building_def, rotation, size
building_lib.register_on("removed", function(event) end)
-- event payload fields: mapblock_pos, playername, old_building_def, building_info

Building timers

WIP

building_lib.register_building("buildings:my_building_with_timer", {
	on_timer = function(mapblock_pos, elapsed)
		-- do periodic stuff
		return true -- schedule again with same timeout
	end
})

local timer = building_lib.get_building_timer(mapblock_pos)
timer:set(timeout, elapsed)
timer:start(10)
timer:stop()
timer:get_timeout()
timer:get_elapsed()
timer:is_started()

Chat commands

  • /building_info

License

  • Code: MIT
  • Textures: CC-BY-SA-3.0
Description
No description provided
Readme 143 KiB
Languages
Lua 100%