aboutsummaryrefslogtreecommitdiff
path: root/src/script
Commit message (Expand)AuthorAge
...
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Add support for entities to automatic face movement directionsapier2013-08-13
* Decoration: Fix schematic probability mess with new MTS file versionkwolekr2013-08-11
* Add support for different drowning damage and allow drowning in other nodetypesBlockMen2013-08-06
* Allow mods to listen to cheat detections using minetest.register_on_cheat()Perttu Ahola2013-08-04
* Add replacements to schematicsPilzAdam2013-08-03
* Allow multiple 'wherein' nodes in oredefPilzAdam2013-08-02
* Add support for setting stepheight for entitiessapier2013-07-30
* Better snow fall, finite liquid transform, leveled nodes apiproller2013-07-28
* Weather supportproller2013-07-27
* Add an option to disable object <-> object collision for Lua entitiesPilzAdam2013-07-20
* Add liquid_range to nodedefPilzAdam2013-07-20
* Make range of tools configureablePilzAdam2013-07-20
* Add set_breath and get_breath to lua API.RealBadAngel2013-07-20
* Change ContentFeatures array to a vectorKahrl2013-07-14
* Leveled nodeboxproller2013-07-13
* LuaVoxelManip: Allow liquid updates in non-mapgen VoxelManip objectskwolekr2013-07-06
* Mapgen V7: Huge rewrite, also tweaks to cavegen et al.kwolekr2013-07-06
* Fix possible 0 pointer accesssapier2013-07-02
* Decoration: Add schematic rotation supportkwolekr2013-07-01
* LuaVoxelManip: Fix minor bug with set_lighting, remove coordinate params for ...kwolekr2013-06-29
* Apply various fixes to several thingskwolekr2013-06-27
* LuaVoxelManip: Separate VoxelManip data get/set from emerging/blitting data b...kwolekr2013-06-27
* Add Lua on_mapgen_init callback, and minetest.set_mapgen_params APIkwolekr2013-06-27
* Add Lua PerlinNoiseMap:get#dMap_flat APIkwolekr2013-06-27
* Add minetest.get_mapgen_object to APIkwolekr2013-06-27
* Add LuaVoxelManipkwolekr2013-06-27
* Decoration: Add support for zero probability, fix breakage from last commitkwolekr2013-06-22
* A handful of minor fixes to various thingskwolekr2013-06-22
* Decoration: Add Schematic decoration typekwolekr2013-06-22
* Make minetest.debug accept multiple parameters; convert them to stringKahrl2013-06-21
* Add drowningPilzAdam2013-06-19
* Decoration: Change divlen to sidelenkwolekr2013-06-17
* Add initial Decoration support, many misc. improvements & modificationskwolekr2013-06-17
* Lazy sunday typo fixing. s/unban_player_of_ip/unban_player_or_ip/gKahrl2013-06-16
* Fix class/struct forward declaration inconsistencies (good on ya, MSVC)Kahrl2013-06-06
* Corrected segfault when registering new biomes.sweetbomber2013-06-03
* Fix missing find_path and line_of_sightsapier2013-06-01
* Fix some nullptr exceptions when handling invalid node inventoriesMetaDucky2013-06-01
* Fix minetest.get_inventory(loc) always returning nil for "node" type locMetaDucky2013-06-01
* Fixed wrongly named invref:get_location() table members for nodes.MetaDucky2013-05-26
* Add ObjectRef.hud_set_hotbar_itemcount and add TOCLIENT_HUD_SET_PARAMKahrl2013-05-26
* Fix itemstack:add item not working correctsapier2013-05-25
* Move scriptapi to separate folder (by sapier)sapier2013-05-25
span>1, rx=-1, rz=0, yaw=math.pi }, [3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 } } -- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity, local function get_values(node) local ndef = minetest.registered_nodes[node.name] if ndef then local paramtype2 = ndef.paramtype2 if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then return wallmounted_values[node.param2 % 8] elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then return facedir_values[node.param2 % 32] end end end --- Gets the display entities attached with a node. Removes extra ones local function get_entities(pos) local objrefs = {} local ndef = minetest.registered_nodes[minetest.get_node(pos).name] if ndef and ndef.display_entities then for _, objref in ipairs(minetest.get_objects_inside_radius(pos, max_entity_pos)) do local entity = objref:get_luaentity() if entity and ndef.display_entities[entity.name] and entity.nodepos and vector.equals(pos, entity.nodepos) then if objrefs[entity.name] then objref:remove() -- Remove duplicates else objrefs[entity.name] = objref end end end end return objrefs end local function clip_pos_prop(posprop) if posprop then return math.max(-max_entity_pos, math.min(max_entity_pos, posprop)) else return 0 end end --- (Create and) place display entities according to the node orientation local function place_entities(pos) local node = minetest.get_node(pos) local ndef = minetest.registered_nodes[node.name] local values = get_values(node) local objrefs = get_entities(pos) if values and ndef and ndef.display_entities then for entity_name, props in pairs(ndef.display_entities) do local depth = clip_pos_prop(props.depth) local right = clip_pos_prop(props.right) local top = clip_pos_prop(props.top) if not objrefs[entity_name] then objrefs[entity_name] = minetest.add_entity(pos, entity_name, minetest.serialize({ nodepos = pos })) end objrefs[entity_name]:setpos({ x = pos.x - values.dx * depth + values.rx * right, y = pos.y - top, z = pos.z - values.dz * depth + values.rz * right}) objrefs[entity_name]:setyaw(values.yaw) end end return objrefs end --- Entity update function update_entity(entity) if not entity then return end if not entity.nodepos then entity.object:remove() -- Remove old/buggy entity return end local node = minetest.get_node(entity.nodepos) local ndef = minetest.registered_nodes[node.name] if ndef and ndef.display_entities and ndef.display_entities[entity.name] and ndef.display_entities[entity.name].on_display_update then -- Call on_display_update callback of a node for one of its display entities ndef.display_entities[entity.name].on_display_update(entity.nodepos, entity.object) end end --- Force entity update function display_api.update_entities(pos) for _, objref in pairs(place_entities(pos)) do update_entity(objref:get_luaentity()) end end --- On_activate callback for display_api entities. Calls on_display_update callbacks --- of corresponding node for each entity. function display_api.on_activate(entity, staticdata) if entity then if string.sub(staticdata, 1, string.len("return")) == "return" then local data = minetest.deserialize(staticdata) if data and type(data) == "table" then entity.nodepos = data.nodepos end entity.object:set_armor_groups({immortal=1}) end update_entity(entity) end end --- On_place callback for display_api items. -- Does nothing more than preventing node from being placed on ceiling or ground function display_api.on_place(itemstack, placer, pointed_thing, override_param2) local ndef = itemstack:get_definition() local above = pointed_thing.above local under = pointed_thing.under local dir = {x = under.x - above.x, y = 0, z = under.z - above.z} -- If item is not placed on a wall, use the player's view direction instead if dir.x == 0 and dir.z == 0 then dir = placer:get_look_dir() dir.y = 0 end local param2 = 0 if ndef then local paramtype2 = ndef.paramtype2 if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then param2 = minetest.dir_to_wallmounted(dir) elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then param2 = minetest.dir_to_facedir(dir) end end return minetest.item_place(itemstack, placer, pointed_thing, param2 + (override_param2 or 0)) end --- On_construct callback for display_api items. -- Creates entities and update them. function display_api.on_construct(pos) display_api.update_entities(pos) end --- On_destruct callback for display_api items. -- Removes entities. function display_api.on_destruct(pos) for _, objref in pairs(get_entities(pos)) do objref:remove() end end -- On_rotate (screwdriver) callback for display_api items. Prevents invalid rotations and reorients entities. function display_api.on_rotate(pos, node, user, _, new_param2) node.param2 = new_param2 if get_values(node) then minetest.swap_node(pos, node) place_entities(pos) return true else return false end end --- Creates display entity with some fields and the on_activate callback function display_api.register_display_entity(entity_name) if not minetest.registered_entity then minetest.register_entity(':'..entity_name, { collisionbox = { 0, 0, 0, 0, 0, 0 }, visual = "upright_sprite", textures = {}, on_activate = display_api.on_activate, get_staticdata = function(self) return minetest.serialize({ nodepos = self.nodepos }) end, }) end end minetest.register_lbm({ label = "Update display_api entities", name = "display_api:update_entities", run_at_every_load = true, nodenames = {"group:display_modpack_node", "group:display_lib_node"}, action = function(pos, node) display_api.update_entities(pos) end, }) -- Compatibility display_lib = display_api