This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
minetest.register_entity("towntest_worker:worker", { | |
hp_max = 1, | |
physical = false, | |
collisionbox = {-0.4, -1, -0.4, 0.4, 1, 0.4}, | |
visual = "upright_sprite", | |
visual_size = {x=1, y=2}, | |
textures = {"towntest_worker.png", "towntest_worker_back.png"}, | |
makes_footstep_sound = true, | |
target = nil, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- return a table of filenames | |
get_files = function(directory) | |
local modpath = minetest.get_modpath("my_mod") | |
local output | |
if os.getenv('HOME')~=nil then -- linux/mac | |
os.execute('\ls -a "'..modpath..'/'..directory..'/" | grep .we > "'..modpath..'/'..directory..'/_files"') | |
local file, err = io.open(modpath..'/'..directory..'/_files', "rb") | |
if err ~= nil then | |
return | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The reason this is needed is because the following code does not work as expected: | |
local node = minetest.registered_nodes["default:sapling"] | |
node.after_place_node = function(pos) print("TESTING123") end | |
minetest.register_node(":default:sapling", node) | |
-- | |
-- inline solution | |
-- | |
local node = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generate_sphere = function(pos,radius,nodename,hollow) | |
pos.x = math.floor(pos.x+0.5) | |
pos.y = math.floor(pos.y+0.5) | |
pos.z = math.floor(pos.z+0.5) | |
for x=-radius,radius do | |
for y=-radius,radius do | |
for z=-radius,radius do | |
if hollow ~= nil then | |
if x*x+y*y+z*z >= (radius-hollow) * (radius-hollow) + (radius-hollow) and x*x+y*y+z*z <= radius * radius + radius then | |
minetest.env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z},{name=nodename}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Tables in Lua may contain both ordered (numbered) and unordered (named) members. Most of the time, you'll use just named elements, or just numbered elements, but there are surprisingly frequent occasions when it's useful to use both. You then need to remember if you iterate through members that ... | |
- #tablename will only go through numbered elements, and will give you nil if there's a gap in the numbering | |
- pairs will take you through all elements with non-nil values, but won't give you any members which are explicitly or implicitly set to nil | |
- ipairs will start at the element numbered 1, and go up through numbered elements until it reaches a nil, at which point it will go no further. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local minetest_register_craft = minetest.register_craft -- preserve the old function | |
minetest.register_craft = function (options) | |
minetest_register_craft(options) -- call the old function | |
-- insert your code here -- | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Jeija wrote this for blockplanet a while back. | |
-- In item_entity.lua add timer = 0, under the line physical_state = true, | |
-- And in the beginning of on_step add this in: | |
self.timer = self.timer + dtime | |
if (self.timer > 300) then | |
self.object:remove() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- DEBUG | |
xp = function(self) | |
local p = self.object:getpos() | |
p.x = p.x + 5 | |
self.moveto(self, p, 1, function(self) | |
zm(self) | |
end) | |
end | |
xm = function(self) | |
local p = self.object:getpos() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- custom settings go in minetest.conf like this: | |
my_setting = foobar | |
my_other_setting = 1 | |
-- read custom or existing settings at load time | |
local my_setting = minetest.setting_get("my_setting") or "barfoo" | |
local my_other_setting= minetest.setting_getbool("my_other_setting") or false | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
super_flat = minetest.setting_getbool("super_flat") | |
minetest.register_node("super_flat:bedrock", { | |
description = "Bedrock (You hacker)", | |
tiles = {"default_cobble.png"}, | |
is_ground_content = true, | |
groups = {unbreakable=1,not_in_creative_inventory=1}, | |
drop = 'default:cobble', | |
sounds = default.node_sound_stone_defaults(), | |
}) |
OlderNewer