Page 1 of 1

[Solved] making orbs with voxel fails?

PostPosted: Sat Jan 14, 2017 15:18
by AiTechEye
Im trying to make holes or orbs with voxel, because it seems to use significantly less cpu.

im checked how the tnt mod works, but are confused that the positions of the changed data always places or parts on wrong/randomly positions.

this does not happen if im using set_node

what is wrong?

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
minetest.register_tool("tools:rad", {
   description = "rad",
   inventory_image = "default_stick.png",
   groups={not_in_creative_inventory = 0,},
      on_use = function(itemstack, user, pointed_thing)

   local radius=5

   local pos = user:getpos()
   local pos1 = vector.subtract(pos, radius)
   local pos2 = vector.add(pos, radius)

   local vox = VoxelManip()
   local min, max = vox:read_from_map(pos1, pos2)
   local area = VoxelArea:new({MinEdge = min, MaxEdge = max})
   local data = vox:get_data()

   local air=minetest.get_content_id("air")
   local dirt=minetest.get_content_id("default:dirt")
   for z = -radius, radius do
   for y = -radius, radius do
   for x = -radius, radius do

      local rad = vector.length(vector.new(x,y,z))
      --local p={x=pos.x+x,y=pos.y+y,z=pos.z+z}
      --local node=minetest.get_node(p)
      local v = area:index(pos.x+x,pos.y+y,pos.z+z)

      if radius/rad>=1 and data[v]==air then
         --minetest.set_node(p,{name="air"})
         data[v]=dirt
      end

   end
   end
   end

   vox:set_data(data)
   vox:write_to_map()
   vox:update_map()
   vox:update_liquids()
end
})



Image

Re: making orbs with voxel?

PostPosted: Sat Jan 14, 2017 21:05
by paramat
See https://github.com/paramat/catacomb/blob/master/init.lua#L212
Your line
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
local vox = VoxelManip()

looks wrong.

Re: making orbs with voxel?

PostPosted: Sun Jan 15, 2017 08:40
by AiTechEye
maybe, but it does same

Re: making orbs with voxel?

PostPosted: Sat Jan 21, 2017 09:04
by AiTechEye
got it, the position have to be rounded.

Re: [Solved] making orbs with voxel fails?

PostPosted: Mon Jan 23, 2017 03:09
by paramat
Probably needs integers when calculating the index.