diff --git a/appunti b/appunti index a6eb7ef..edcaef2 100644 --- a/appunti +++ b/appunti @@ -15,3 +15,23 @@ Per ogni bomba bisogna definire: Aggiuntivi: -> velocity -> recipe_number + + +Bombe presenti: +mobs_examples.lua: + - stone_wall_bomb + - Cubic Ice Shell bomb + - Fire circle + - Lava pool + - schematic bomb + +Nssm_weapons: + - cobweb_bomb + - cubic mantis clay shell bomb + - + + nssbombs:register_throwitem("nssm:", "", { + textures = "", + recipe_number = , + recipe = , + }) diff --git a/bombs_api.lua b/bombs_api.lua index c370d07..3db2e70 100644 --- a/bombs_api.lua +++ b/bombs_api.lua @@ -1,25 +1,30 @@ function nssbombs:register_throwitem(name, descr, def) - minetest.register_craftitem("nssbombs:"..name.."_bomb", { + minetest.register_craftitem(name, { description = descr, inventory_image = def.textures, on_use = function(itemstack, placer, pointed_thing) local velocity = def.velocity or 15 + local dir = placer:get_look_dir() local playerpos = placer:getpos() - local obj = minetest.env:add_entity({x=playerpos.x+dir.x,y=playerpos.y+2+dir.y,z=playerpos.z+dir.z}, "nssbombs:"..name.."_bomb_flying") + local obj = minetest.add_entity({x=playerpos.x+dir.x,y=playerpos.y+2+dir.y,z=playerpos.z+dir.z}, name.."_flying") local vec = {x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity} local acc = {x=0, y=-9.8, z=0} + obj:setvelocity(vec) obj:setacceleration(acc) + obj:get_luaentity().placer = placer + itemstack:take_item() return itemstack end, }) - minetest.register_entity("nssbombs:"..name.."_bomb_flying",{ + minetest.register_entity(name.."_flying",{ textures = {def.textures}, hp_max = 50, + placer = nil, collisionbox = {-0.1,-0.1,-0.1, 0.1,0.1,0.1}, visual_size = def.visual_size or {x=1, y=1}, explosion = def.explosion or {}, @@ -31,13 +36,17 @@ function nssbombs:register_throwitem(name, descr, def) if def.hit_node then def.hit_node(self, pos) else - default_hit_node(self, self.explosion, vec) + if self.explosion then + default_hit_node(self, self.explosion) + else + minetest.chat_send_player(self.placer, "No hit_node function defined") + end end self.object:remove() end end, }) - + local recepy if def.recipe_block then recepy = { {def.recipe_block, def.recipe_block, def.recipe_block}, @@ -48,13 +57,14 @@ function nssbombs:register_throwitem(name, descr, def) local number = def.recipe_number or 1 minetest.register_craft({ - output = "nssbombs:"..name.."_bomb "..number, + output = name.." "..number, + type = def.recipe_type or nil, recipe = def.recipe or recepy }) end -function perpendicular_vector(vec) --returns a vector rotated of 90° in 2D +function perpendicular_vector(vec) --returns a vector rotated of 90° in 2D (x and z directions) local ang = math.pi/2 local c = math.cos(ang) local s = math.sin(ang) @@ -79,10 +89,6 @@ function default_hit_node(self, explosion) center = {x=p.x, y=p.y+radius, z=p.z} end - if particles then - add_effects(center, radius, block) - end - if shape == "cube" then for dx = -radius,radius do for dy = 0,2*radius do @@ -94,6 +100,17 @@ function default_hit_node(self, explosion) end end end + elseif shape == "pool" then + for dx = -radius,radius do + for dy = -1,0 do + for dz = -radius,radius do + local pos1 = {x = p.x+dx, y=p.y+dy, z=p.z+dz} + if not minetest.is_protected(pos1, "") or not minetest.get_item_group(minetest.get_node(pos1).name, "unbreakable") == 1 then + minetest.set_node(pos1, {name=block}) + end + end + end + end elseif shape == "sphere" then for dx = -radius,radius do for dy = 0,2*radius do @@ -107,12 +124,40 @@ function default_hit_node(self, explosion) end end end + elseif shape == "sphere_shell" then + for dx = -radius,radius do + for dy = 0,2*radius do + for dz = -radius,radius do + local pos1 = {x = p.x+dx, y=p.y+dy, z=p.z+dz} + if round(math.abs(vector.length(vector.subtract(pos1,center)))) == radius then + if not minetest.is_protected(pos1, "") or not minetest.get_item_group(minetest.get_node(pos1).name, "unbreakable") == 1 then + minetest.set_node(pos1, {name=block}) + end + end + end + end + end + elseif shape == "cubic_shell" then + local y = p.y + radius + for dx = -radius,radius do + for dy = -radius,radius do + for dz = -radius,radius do + local pos1 = {x = p.x+dx, y=y+dy, z=p.z+dz} + if ((math.abs(dz)==radius)or(math.abs(dx)==radius)or(math.abs(dy)==radius)) then + --if math.abs(vector.length(vector.subtract(pos1,center))) == radius then + if not minetest.is_protected(pos1, "") or not minetest.get_item_group(minetest.get_node(pos1).name, "unbreakable") == 1 then + minetest.set_node(pos1, {name=block}) + end + end + end + end + end elseif shape == "column" then - local base_side = 1 + local base_side = 0 if round(radius/4) > 1 then base_side = round(radius/4) end - local height = 2*radius + local height = radius for dx = -base_side,base_side do for dy = 0,height do for dz = -base_side,base_side do @@ -126,11 +171,13 @@ function default_hit_node(self, explosion) elseif shape == "circle" then center = {x=p.x, y=p.y+1, z=p.z} for dx = -radius,radius do - for dz = -radius,radius do - local pos1 = {x = p.x+dx, y=p.y+1, z=p.z+dz} - if round(math.abs(vector.length(vector.subtract(pos1,center)))) == radius then - if not minetest.is_protected(pos1, "") or not minetest.get_item_group(minetest.get_node(pos1).name, "unbreakable") == 1 then - minetest.set_node(pos1, {name=block}) + for dy = 0, 1 do + for dz = -radius,radius do + local pos1 = {x = p.x+dx, y=p.y+1+dy, z=p.z+dz} + if round(math.abs(vector.length(vector.subtract(pos1,center)))) == radius then + if not minetest.is_protected(pos1, "") or not minetest.get_item_group(minetest.get_node(pos1).name, "unbreakable") == 1 then + minetest.set_node(pos1, {name=block}) + end end end end @@ -151,12 +198,43 @@ function default_hit_node(self, explosion) if not minetest.is_protected(pp, "") or not minetest.get_item_group(minetest.get_node(pp).name, "unbreakable") == 1 then minetest.set_node(pp, {name=block}) end + if radius >= 10 then + local pp2 = vector.add(pp,vec) + if not minetest.is_protected(pp2, "") or not minetest.get_item_group(minetest.get_node(pp2).name, "unbreakable") == 1 then + minetest.set_node(pp2, {name=block}) + end + end end p = vector.add(p,pr) end elseif shape == "schematic" then - --Adds a defined schematic in the landing position of the bomb - minetest.place_schematic(p, block, "0", {}, true) + --[[ + Adds a defined schematic in the landing position of the bomb. + If you want the schematic appear with its center in the landing pos of the bomb + you have to specify the dimensione of the base of the schematic using + explosion.radius parameter + --]] + if radius then + center = {x = p.x - radius/2, y = p.y, z = p.z - radius/2} + minetest.place_schematic(center, block, "0", {}, true) + else + minetest.place_schematic(p, block, "0", {}, true) + end + elseif shape == "add_entity" then + --[[ + Adds an entity in the landing position. + In this case block contains the name of the entity + to be added. + ]] + minetest.add_entity(p, block) + elseif shape == "tnt_explosion" then + tnt.boom(p, {damage_radius=radius,radius=radius,ignore_protection=false}) + end + + + + if particles and block and center and not shape == "tnt_explosion" then + add_effects(center, radius, block) end end diff --git a/bombs_examples.lua b/bombs_examples.lua index 8707e00..0191f24 100644 --- a/bombs_examples.lua +++ b/bombs_examples.lua @@ -1,20 +1,34 @@ ---Ice bomb -nssbombs:register_throwitem("ice", "Ice Bomb", { +--Stone Wall bomb +nssbombs:register_throwitem("nssbombs:stone_wall_bomb", "Stone Wall Bomb", { + textures = "ice_bomb.png", + recipe_number = 8, + recipe_block = "default:cobble", + explosion = { + shape = "wall", + radius = 10, + block = "default:stone", + particles = true, + }, +}) + +--Cubic Ice Shell bomb +nssbombs:register_throwitem("nssbombs:ice_bomb", "Cubic Ice Shell bomb", { textures = "ice_bomb.png", recipe_number = 8, recipe_block = "default:ice", explosion = { - shape = "wall", - radius = 20, + shape = "cubic_shell", + radius = 2, block = "default:ice", particles = true, }, }) ---Fire bomb -nssbombs:register_throwitem("fire", "Fire Bomb", { +--Fire Circle bomb +nssbombs:register_throwitem("nssbombs:fire_bomb", "Fire Bomb", { textures = "fire_bomb.png", - recipe_block = "bucket:lava_bucket", + recipe_block = "fire:flint_and_steel", + recipe_number = 4, explosion = { shape = "circle", radius = 6, @@ -23,15 +37,41 @@ nssbombs:register_throwitem("fire", "Fire Bomb", { }, }) ---Schematic bomb -nssbombs:register_throwitem("schematic", "Schematic Bomb", { - textures = "fire_bomb.png", +--Lava pool +nssbombs:register_throwitem("nssbombs:lava_bomb", "Lava Bomb", { + textures = "lava_bomb.png", + recipe_block = "bucket:lava_bucket", + recipe_number = 3, + explosion = { + shape = "pool", + radius = 2, + block = "default:lava_source", + particles = false, + } +}) + +--Water column +nssbombs:register_throwitem("nssbombs:water_column_bomb", "Water Colun Bomb", { + textures = "water_column_bomb.png", recipe_block = "bucket:water_bucket", + recipe_number = 6, + explosion = { + shape = "column", + radius = 5, + block = "default:water_source", + particles = false, + } +}) + +--Schematic bomb +nssbombs:register_throwitem("nssbombs:schematic_bomb", "Schematic Bomb", { + textures = "fire_bomb.png", + recipe_block = "bucket:empty_bucket", explosion = { shape = "schematic", - --radius = 5, - block = minetest.get_modpath("nssb").."/schems/piccoghiaccio.mts", - --particles = true, + radius = 9, + block = minetest.get_modpath("nssbombs").."/schems/simple_house.mts", + particles = true, }, }) diff --git a/depends.txt b/depends.txt index bf28a9d..1c3cc41 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,3 @@ tnt +bucket +fire diff --git a/schems/simple_house.mts b/schems/simple_house.mts new file mode 100644 index 0000000..26fd2e5 Binary files /dev/null and b/schems/simple_house.mts differ diff --git a/textures/boom_bomb.png b/textures/boom_bomb.png new file mode 100644 index 0000000..4826ea6 Binary files /dev/null and b/textures/boom_bomb.png differ diff --git a/textures/cage_bomb.png b/textures/cage_bomb.png new file mode 100644 index 0000000..a026684 Binary files /dev/null and b/textures/cage_bomb.png differ diff --git a/textures/cobweb_bomb.png b/textures/cobweb_bomb.png new file mode 100644 index 0000000..ff7d7c9 Binary files /dev/null and b/textures/cobweb_bomb.png differ diff --git a/textures/empty_evocation_bomb.png b/textures/empty_evocation_bomb.png new file mode 100644 index 0000000..2319fdd Binary files /dev/null and b/textures/empty_evocation_bomb.png differ diff --git a/textures/evocation_bomb.png b/textures/evocation_bomb.png new file mode 100644 index 0000000..dbd2038 Binary files /dev/null and b/textures/evocation_bomb.png differ diff --git a/textures/fire_ring_bomb.png b/textures/fire_ring_bomb.png new file mode 100644 index 0000000..8c75acc Binary files /dev/null and b/textures/fire_ring_bomb.png differ diff --git a/textures/food_bomb.png b/textures/food_bomb.png new file mode 100644 index 0000000..7594041 Binary files /dev/null and b/textures/food_bomb.png differ diff --git a/textures/hole_bomb.png b/textures/hole_bomb.png new file mode 100644 index 0000000..da36a3f Binary files /dev/null and b/textures/hole_bomb.png differ diff --git a/textures/kaboom_bomb.png b/textures/kaboom_bomb.png new file mode 100644 index 0000000..ea968c8 Binary files /dev/null and b/textures/kaboom_bomb.png differ diff --git a/textures/lava_bomb.png b/textures/lava_bomb.png new file mode 100644 index 0000000..57724c2 Binary files /dev/null and b/textures/lava_bomb.png differ diff --git a/textures/mantis_bomb.png b/textures/mantis_bomb.png new file mode 100644 index 0000000..b55a188 Binary files /dev/null and b/textures/mantis_bomb.png differ diff --git a/textures/mornar_bomb.png b/textures/mornar_bomb.png new file mode 100644 index 0000000..753cf09 Binary files /dev/null and b/textures/mornar_bomb.png differ diff --git a/textures/phoenix_fire_bomb.png b/textures/phoenix_fire_bomb.png new file mode 100644 index 0000000..772c4c2 Binary files /dev/null and b/textures/phoenix_fire_bomb.png differ diff --git a/textures/poison_bomb.png b/textures/poison_bomb.png new file mode 100644 index 0000000..3d45cfa Binary files /dev/null and b/textures/poison_bomb.png differ diff --git a/textures/smoke_bomb.png b/textures/smoke_bomb.png new file mode 100644 index 0000000..517e476 Binary files /dev/null and b/textures/smoke_bomb.png differ diff --git a/textures/stone_bomb.png b/textures/stone_bomb.png new file mode 100644 index 0000000..8740a5a Binary files /dev/null and b/textures/stone_bomb.png differ diff --git a/textures/teleport_bomb.png b/textures/teleport_bomb.png new file mode 100644 index 0000000..1708167 Binary files /dev/null and b/textures/teleport_bomb.png differ diff --git a/textures/thick_web_bomb.png b/textures/thick_web_bomb.png new file mode 100644 index 0000000..f536ece Binary files /dev/null and b/textures/thick_web_bomb.png differ diff --git a/textures/water_bomb.png b/textures/water_bomb.png new file mode 100644 index 0000000..1bcc405 Binary files /dev/null and b/textures/water_bomb.png differ diff --git a/textures/water_column_bomb.png b/textures/water_column_bomb.png new file mode 100644 index 0000000..27e20b9 Binary files /dev/null and b/textures/water_column_bomb.png differ