A mining machine:
(/giveme drill:drill)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function drill(pos)
--open up voxel manip
local min = {x=pos.x-1,y=pos.y-1,z=pos.z-1}
local max = {x=pos.x+1,y=pos.y+1,z=pos.z+1}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(min,max)
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
local p_pos = area:index(pos.x+1, pos.y, pos.z)
data[p_pos] = minetest.get_content_id("air")
local drop= vm:get_node_at({x=pos.x+1,y=pos.y,z=pos.z}).name
--check if node and add particles
if drop ~= "air" then
--get the texture of the node from definition
local texture = minetest.registered_nodes[drop].tiles[1]
minetest.add_item(pos, drop)
minetest.add_particlespawner({
amount = 10,
time = 1,
minpos = {x=pos.x-0.5, y=pos.y-0.5, z=pos.z-0.5},
maxpos = {x=pos.x+0.5, y=pos.y+0.5, z=pos.z+0.5},
minvel = {x=0, y=-1, z=0},
maxvel = {x=0, y=-2, z=0},
minacc = {x=0, y=-1, z=0},
maxacc = {x=0, y=-2, z=0},
minexptime = 1,
maxexptime = 1,
minsize = 0.5,
maxsize = 1,
collisiondetection = true,
vertical = false,
texture = texture,
})
end
vm:set_data(data)
vm:calc_lighting()
vm:write_to_map()
vm:update_map()
end
function drill_stuff(pos,object)
local pos = {x=math.floor(pos.x+0.5),y=math.floor(pos.y+0.5),z=math.floor(pos.z+0.5)}
local node = minetest.get_node({x=pos.x,y=pos.y,z=pos.z})
--do a 15 tick delay before moving again
if object:get_luaentity().timer == nil then
object:get_luaentity().timer = 0
end
object:get_luaentity().timer = object:get_luaentity().timer + 1
--drill and go again when timer is passed the limit
if object:get_luaentity().timer > 15 then
object:get_luaentity().timer = 0
object:moveto({x=pos.x+1,y=pos.y,z=pos.z})
drill(pos)
end
end
local drill = {
physical = true,
collisionbox = {-0.4, -0.4, -0.4, 0.4, 0.3, 0.4},
visual = "mesh",
mesh = "boat.obj",
textures = {"default_wood.png"},
automatic_face_movement_dir = -90.0,
driver = nil,
v = 0,
last_v = 0,
removed = false,
in_water = false,
}
function drill.on_activate(self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
if staticdata then
self.v = tonumber(staticdata)
end
self.last_v = self.v
end
function drill.get_staticdata(self)
return tostring(self.v)
end
function drill.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove()
if not minetest.setting_getbool("creative_mode") then
puncher:get_inventory():add_item("main", "drill:drill")
end
end
function drill.on_step(self, dtime)
local pos = self.object:getpos()
drill_stuff(pos,self.object)
end
minetest.register_entity("drill:drill", drill)
minetest.register_craftitem("drill:drill", {
description = "drill drill drill",
inventory_image = "boat_inventory.png",
wield_image = "boat_wield.png",
wield_scale = {x = 2, y = 2, z = 1},
liquids_pointable = true,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
--if not is_water(pointed_thing.under) then
-- return
--end
pointed_thing.under.y = pointed_thing.under.y + 1.0
pointed_thing.under.y = pointed_thing.under.y
minetest.add_entity(pointed_thing.under, "drill:drill")
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
})

Rain Cloud:
(/giveme cloud:cloud)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function cloud(pos)
minetest.add_particlespawner({
amount = 50,
time = 1,
minpos = {x=pos.x-2.5, y=pos.y-0.5, z=pos.z-2.5},
maxpos = {x=pos.x+2.5, y=pos.y-0.5, z=pos.z+2.5},
minvel = {x=0, y=-1, z=0},
maxvel = {x=0, y=-2, z=0},
minacc = {x=0, y=-1, z=0},
maxacc = {x=0, y=-2, z=0},
minexptime = 1,
maxexptime = 2,
minsize = 0.5,
maxsize = 1,
collisiondetection = true,
vertical = true,
texture = "default_water.png",
})
end
function cloud_stuff(pos,object)
local pos = {x=math.floor(pos.x+0.5),y=math.floor(pos.y+0.5),z=math.floor(pos.z+0.5)}
local node = minetest.get_node({x=pos.x,y=pos.y,z=pos.z})
--do a 15 tick delay before moving again
if object:get_luaentity().timer == nil then
object:get_luaentity().timer = 0
end
object:get_luaentity().timer = object:get_luaentity().timer + 1
--cloud and go again when timer is passed the limit
if object:get_luaentity().timer > 15 then
object:get_luaentity().timer = 0
object:moveto({x=pos.x+1,y=pos.y+1,z=pos.z})
cloud(pos)
end
end
local cloud = {
physical = false,
collisionbox = {-0.4, -0.4, -0.4, 0.4, 0.3, 0.4},
visual_size = {x=5, y=1},
visual = "cube",
textures = {"default_aspen_wood.png","default_aspen_wood.png","default_aspen_wood.png","default_aspen_wood.png","default_aspen_wood.png","default_aspen_wood.png"},
automatic_face_movement_dir = -90.0,
driver = nil,
v = 0,
last_v = 0,
removed = false,
in_water = false,
}
function cloud.on_activate(self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
if staticdata then
self.v = tonumber(staticdata)
end
self.last_v = self.v
end
function cloud.get_staticdata(self)
return tostring(self.v)
end
function cloud.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove()
if not minetest.setting_getbool("creative_mode") then
puncher:get_inventory():add_item("main", "cloud:cloud")
end
end
function cloud.on_step(self, dtime)
local pos = self.object:getpos()
cloud_stuff(pos,self.object)
end
minetest.register_entity("cloud:cloud", cloud)
minetest.register_craftitem("cloud:cloud", {
description = "cloud cloud cloud",
inventory_image = "boat_inventory.png",
wield_scale = {x = 2, y = 2, z = 1},
liquids_pointable = true,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
--if not is_water(pointed_thing.under) then
-- return
--end
pointed_thing.under.y = pointed_thing.under.y + 1.0
pointed_thing.under.y = pointed_thing.under.y
minetest.add_entity(pointed_thing.under, "cloud:cloud")
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
})
