Cleanup
This commit is contained in:
parent
b082a746fa
commit
be4c3617af
141
init.lua
141
init.lua
@ -1,45 +1,42 @@
|
|||||||
sneeker = {}
|
|
||||||
|
|
||||||
--[[
|
sneeker = {}
|
||||||
-- DISABLED!!!
|
|
||||||
do return end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("sneeker").."/tnt_function.lua")
|
dofile(minetest.get_modpath("sneeker").."/tnt_function.lua")
|
||||||
dofile(minetest.get_modpath("sneeker").."/spawn.lua")
|
dofile(minetest.get_modpath("sneeker").."/spawn.lua")
|
||||||
|
|
||||||
local function jump(self,pos,direction)
|
|
||||||
|
local function jump(self, pos, direction)
|
||||||
local velocity = self.object:get_velocity()
|
local velocity = self.object:get_velocity()
|
||||||
if minetest.registered_nodes[minetest.get_node(pos).name].climbable then
|
if core.registered_nodes[core.get_node(pos).name].climbable then
|
||||||
self.object:set_velocity({x=velocity.x,y=4,z=velocity.z})
|
self.object:set_velocity({x=velocity.x, y=4, z=velocity.z})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local spos = {x=pos.x+direction.x,y=pos.y,z=pos.z+direction.z}
|
local spos = {x=pos.x+direction.x, y=pos.y, z=pos.z+direction.z}
|
||||||
local node = minetest.get_node_or_nil(spos)
|
local node = core.get_node_or_nil(spos)
|
||||||
spos.y = spos.y+1
|
spos.y = spos.y+1
|
||||||
local node2 = minetest.get_node_or_nil(spos)
|
local node2 = core.get_node_or_nil(spos)
|
||||||
local def,def2 = {}
|
local def, def2 = {}
|
||||||
if node and node.name then
|
if node and node.name then
|
||||||
def = minetest.registered_items[node.name]
|
def = core.registered_items[node.name]
|
||||||
end
|
end
|
||||||
if node2 and node2.name then
|
if node2 and node2.name then
|
||||||
def2 = minetest.registered_items[node2.name]
|
def2 = core.registered_items[node2.name]
|
||||||
end
|
end
|
||||||
if def and def.walkable
|
if def and def.walkable
|
||||||
and def2 and not def2.walkable
|
and def2 and not def2.walkable
|
||||||
and def.drawtype ~= "fencelike" then
|
and def.drawtype ~= "fencelike" then
|
||||||
self.object:set_velocity({
|
self.object:set_velocity({
|
||||||
x=velocity.x*2.2,
|
x = velocity.x*2.2,
|
||||||
y=self.jump_height,
|
y = self.jump_height,
|
||||||
z=velocity.z*2.2
|
z = velocity.z*2.2
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function random_turn(self)
|
local function random_turn(self)
|
||||||
if self.turn_timer > math.random(2,5) then
|
if self.turn_timer > math.random(2, 5) then
|
||||||
local select_turn = math.random(1,3)
|
local select_turn = math.random(1, 3)
|
||||||
if select_turn == 1 then
|
if select_turn == 1 then
|
||||||
self.turn = "left"
|
self.turn = "left"
|
||||||
elseif select_turn == 2 then
|
elseif select_turn == 2 then
|
||||||
@ -55,7 +52,7 @@ end
|
|||||||
local def = {
|
local def = {
|
||||||
hp_max = 20,
|
hp_max = 20,
|
||||||
physical = true,
|
physical = true,
|
||||||
collisionbox = {-0.25,-0.7,-0.25, 0.25,0.8,0.25},
|
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "character.b3d",
|
mesh = "character.b3d",
|
||||||
textures = {"sneeker.png"},
|
textures = {"sneeker.png"},
|
||||||
@ -74,7 +71,7 @@ local def = {
|
|||||||
knockback_level = 2
|
knockback_level = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
def.on_activate = function(self,staticdata)
|
def.on_activate = function(self, staticdata)
|
||||||
self.yaw = 0
|
self.yaw = 0
|
||||||
self.anim = 1
|
self.anim = 1
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
@ -84,17 +81,17 @@ def.on_activate = function(self,staticdata)
|
|||||||
self.turn_speed = 0
|
self.turn_speed = 0
|
||||||
self.powered = false
|
self.powered = false
|
||||||
self.knockback = false
|
self.knockback = false
|
||||||
self.state = math.random(1,2)
|
self.state = math.random(1, 2)
|
||||||
self.old_y = self.object:get_pos().y
|
self.old_y = self.object:get_pos().y
|
||||||
|
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = core.deserialize(staticdata)
|
||||||
if data and type(data) == "table" then
|
if data and type(data) == "table" then
|
||||||
if data.powered == true then
|
if data.powered == true then
|
||||||
self.powered = true
|
self.powered = true
|
||||||
self.object:set_properties({textures = {"sneeker_powered.png"}})
|
self.object:set_properties({textures = {"sneeker_powered.png"}})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if math.random(0,20) == 20 then
|
if math.random(0, 20) == 20 then
|
||||||
self.powered = true
|
self.powered = true
|
||||||
self.object:set_properties({textures = {"sneeker_powered.png"}})
|
self.object:set_properties({textures = {"sneeker_powered.png"}})
|
||||||
end
|
end
|
||||||
@ -116,7 +113,7 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
local inside = minetest.get_objects_inside_radius(pos,10)
|
local inside = core.get_objects_inside_radius(pos, 10)
|
||||||
local walk_speed = self.walk_speed
|
local walk_speed = self.walk_speed
|
||||||
local animation = self.animation
|
local animation = self.animation
|
||||||
local anim_speed = self.animation_speed
|
local anim_speed = self.animation_speed
|
||||||
@ -127,7 +124,7 @@ def.on_step = function(self, dtime)
|
|||||||
self.jump_timer = self.jump_timer+0.01
|
self.jump_timer = self.jump_timer+0.01
|
||||||
|
|
||||||
if not self.chase
|
if not self.chase
|
||||||
and self.timer > math.random(2,5) then
|
and self.timer > math.random(2, 5) then
|
||||||
if math.random() > 0.8 then
|
if math.random() > 0.8 then
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
else
|
else
|
||||||
@ -146,24 +143,24 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
if self.chase and self.visualx < 2 then
|
if self.chase and self.visualx < 2 then
|
||||||
if self.hiss == false then
|
if self.hiss == false then
|
||||||
minetest.sound_play("sneeker_hiss",{pos=pos,gain=1.5,max_hear_distance=2*64})
|
core.sound_play("sneeker_hiss", {pos=pos, gain=1.5, max_hear_distance=2*64})
|
||||||
end
|
end
|
||||||
self.visualx = self.visualx+0.05
|
self.visualx = self.visualx+0.05
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
visual_size = {x=self.visualx,y=1}
|
visual_size = {x=self.visualx, y=1}
|
||||||
})
|
})
|
||||||
self.hiss = true
|
self.hiss = true
|
||||||
elseif self.visualx > 1 then
|
elseif self.visualx > 1 then
|
||||||
self.visualx = self.visualx-0.05
|
self.visualx = self.visualx-0.05
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
visual_size = {x=self.visualx,y=1}
|
visual_size = {x=self.visualx, y=1}
|
||||||
})
|
})
|
||||||
self.hiss = false
|
self.hiss = false
|
||||||
end
|
end
|
||||||
|
|
||||||
self.chase = false
|
self.chase = false
|
||||||
|
|
||||||
for _,object in ipairs(inside) do
|
for _, object in ipairs(inside) do
|
||||||
if object:is_player() then
|
if object:is_player() then
|
||||||
self.state = "chase"
|
self.state = "chase"
|
||||||
end
|
end
|
||||||
@ -171,7 +168,7 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
if self.anim ~= ANIM_STAND then
|
if self.anim ~= ANIM_STAND then
|
||||||
self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
|
self.object:set_animation({x=animation.stand_START, y=animation.stand_END}, anim_speed, 0)
|
||||||
self.anim = ANIM_STAND
|
self.anim = ANIM_STAND
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -179,19 +176,19 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
if velocity.x ~= 0
|
if velocity.x ~= 0
|
||||||
or velocity.z ~= 0 then
|
or velocity.z ~= 0 then
|
||||||
self.object:set_velocity({x=0,y=velocity.y,z=0})
|
self.object:set_velocity({x=0, y=velocity.y, z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.state == "walk" then
|
if self.state == "walk" then
|
||||||
if self.anim ~= ANIM_WALK then
|
if self.anim ~= ANIM_WALK then
|
||||||
self.object:set_animation({x=animation.walk_START,y=animation.walk_END},anim_speed,0)
|
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
|
||||||
self.anim = ANIM_WALK
|
self.anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
|
||||||
self.direction = {x=math.sin(yaw)*-1,y=-10,z=math.cos(yaw)}
|
self.direction = {x=math.sin(yaw)*-1, y=-10, z=math.cos(yaw)}
|
||||||
if self.direction then
|
if self.direction then
|
||||||
self.object:set_velocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed})
|
self.object:set_velocity({x=self.direction.x*walk_speed, y=velocity.y, z=self.direction.z*walk_speed})
|
||||||
end
|
end
|
||||||
|
|
||||||
random_turn(self)
|
random_turn(self)
|
||||||
@ -200,10 +197,10 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
if self.turn_timer > 1 then
|
if self.turn_timer > 1 then
|
||||||
local direction = self.direction
|
local direction = self.direction
|
||||||
local npos = {x=pos.x+direction.x,y=pos.y+0.2,z=pos.z+direction.z}
|
local npos = {x=pos.x+direction.x, y=pos.y+0.2, z=pos.z+direction.z}
|
||||||
if velocity.x == 0 or velocity.z == 0
|
if velocity.x == 0 or velocity.z == 0
|
||||||
or minetest.registered_nodes[minetest.get_node(npos).name].walkable then
|
or core.registered_nodes[core.get_node(npos).name].walkable then
|
||||||
local select_turn = math.random(1,2)
|
local select_turn = math.random(1, 2)
|
||||||
if select_turn == 1 then
|
if select_turn == 1 then
|
||||||
self.turn = "left"
|
self.turn = "left"
|
||||||
elseif select_turn == 2 then
|
elseif select_turn == 2 then
|
||||||
@ -216,60 +213,60 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
-- Jump
|
-- Jump
|
||||||
if self.jump_timer > 0.2 then
|
if self.jump_timer > 0.2 then
|
||||||
jump(self,pos,self.direction)
|
jump(self, pos, self.direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.state == "chase" then
|
if self.state == "chase" then
|
||||||
if self.anim ~= ANIM_WALK then
|
if self.anim ~= ANIM_WALK then
|
||||||
self.object:set_animation({x=animation.walk_START,y=animation.walk_END},anim_speed,0)
|
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
|
||||||
self.anim = ANIM_WALK
|
self.anim = ANIM_WALK
|
||||||
end
|
end
|
||||||
|
|
||||||
self.turn = "straight"
|
self.turn = "straight"
|
||||||
|
|
||||||
local inside_2 = minetest.get_objects_inside_radius(pos,2)
|
local inside_2 = core.get_objects_inside_radius(pos, 2)
|
||||||
|
|
||||||
-- Boom
|
-- Boom
|
||||||
if #inside_2 ~= 0 then
|
if #inside_2 ~= 0 then
|
||||||
for _,object in ipairs(inside_2) do
|
for _, object in ipairs(inside_2) do
|
||||||
if object:is_player() and object:get_hp() ~= 0 then
|
if object:is_player() and object:get_hp() ~= 0 then
|
||||||
self.chase = true
|
self.chase = true
|
||||||
if self.visualx >= 2 then
|
if self.visualx >= 2 then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
sneeker.boom(pos,self.powered)
|
sneeker.boom(pos, self.powered)
|
||||||
minetest.sound_play("sneeker_explode",{pos=pos,gain=1.5,max_hear_distance=2*64})
|
core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #inside ~= 0 then
|
if #inside ~= 0 then
|
||||||
for _,object in ipairs(inside) do
|
for _, object in ipairs(inside) do
|
||||||
if object:is_player() and object:get_hp() ~= 0 then
|
if object:is_player() and object:get_hp() ~= 0 then
|
||||||
if #inside_2 ~= 0 then
|
if #inside_2 ~= 0 then
|
||||||
for _,object in ipairs(inside_2) do
|
for _, object in ipairs(inside_2) do
|
||||||
-- Stop move
|
-- Stop move
|
||||||
if object:is_player() then
|
if object:is_player() then
|
||||||
if self.anim ~= ANIM_STAND then
|
if self.anim ~= ANIM_STAND then
|
||||||
self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
|
self.object:set_animation({x=animation.stand_START, y=animation.stand_END}, anim_speed, 0)
|
||||||
self.anim = ANIM_STAND
|
self.anim = ANIM_STAND
|
||||||
end
|
end
|
||||||
self.object:set_velocity({x=0,y=velocity.y,z=0})
|
self.object:set_velocity({x=0, y=velocity.y, z=0})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ppos = object:get_pos()
|
local ppos = object:get_pos()
|
||||||
self.vec = {x=ppos.x-pos.x,y=ppos.y-pos.y,z=ppos.z-pos.z}
|
self.vec = {x=ppos.x-pos.x, y=ppos.y-pos.y, z=ppos.z-pos.z}
|
||||||
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
||||||
if ppos.x > pos.x then
|
if ppos.x > pos.x then
|
||||||
self.yaw = self.yaw+math.pi
|
self.yaw = self.yaw+math.pi
|
||||||
end
|
end
|
||||||
self.yaw = self.yaw-2
|
self.yaw = self.yaw-2
|
||||||
self.object:set_yaw(self.yaw)
|
self.object:set_yaw(self.yaw)
|
||||||
self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)}
|
self.direction = {x=math.sin(self.yaw)*-1, y=0, z=math.cos(self.yaw)}
|
||||||
|
|
||||||
local direction = self.direction
|
local direction = self.direction
|
||||||
|
|
||||||
@ -283,12 +280,12 @@ def.on_step = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if can_set then
|
if can_set then
|
||||||
self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5})
|
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Jump
|
-- Jump
|
||||||
if self.jump_timer > 0.2 then
|
if self.jump_timer > 0.2 then
|
||||||
jump(self,pos,direction)
|
jump(self, pos, direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -298,60 +295,60 @@ def.on_step = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Swim
|
-- Swim
|
||||||
local node = minetest.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
if minetest.get_item_group(node.name,"water") ~= 0 then
|
if core.get_item_group(node.name, "water") ~= 0 then
|
||||||
self.object:set_acceleration({x=0,y=1,z=0})
|
self.object:set_acceleration({x=0, y=1, z=0})
|
||||||
local velocity = self.object:get_velocity()
|
local velocity = self.object:get_velocity()
|
||||||
if self.object:get_velocity().y > 5 then
|
if self.object:get_velocity().y > 5 then
|
||||||
self.object:set_velocity({x=0,y=velocity.y-velocity.y/2,z=0})
|
self.object:set_velocity({x=0, y=velocity.y-velocity.y/2, z=0})
|
||||||
else
|
else
|
||||||
self.object:set_velocity({x=0,y=velocity.y+1,z=0})
|
self.object:set_velocity({x=0, y=velocity.y+1, z=0})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.object:set_acceleration({x=0,y=-10,z=0})
|
self.object:set_acceleration({x=0, y=-10, z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
|
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||||
if self.knockback == false then
|
if self.knockback == false then
|
||||||
local knockback_level = self.knockback_level
|
local knockback_level = self.knockback_level
|
||||||
self.object:set_velocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level})
|
self.object:set_velocity({x=dir.x*knockback_level, y=3, z=dir.z*knockback_level})
|
||||||
self.knockback = true
|
self.knockback = true
|
||||||
minetest.after(0.6,function()
|
core.after(0.6, function()
|
||||||
self.knockback = false
|
self.knockback = false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if self.object:get_hp() < 1 then
|
if self.object:get_hp() < 1 then
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local x = 1/math.random(1,5)*dir.x
|
local x = 1/math.random(1, 5)*dir.x
|
||||||
local z = 1/math.random(1,5)*dir.z
|
local z = 1/math.random(1, 5)*dir.z
|
||||||
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
|
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
|
||||||
local node = minetest.get_node_or_nil(p)
|
local node = core.get_node_or_nil(p)
|
||||||
if node == nil or not node.name or node.name ~= "air" then
|
if node == nil or not node.name or node.name ~= "air" then
|
||||||
p = pos
|
p = pos
|
||||||
end
|
end
|
||||||
local obj = minetest.add_item(p, {name="tnt:gunpowder",count=math.random(0,2)})
|
local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def.get_staticdata = function(self)
|
def.get_staticdata = function(self)
|
||||||
return minetest.serialize({
|
return core.serialize({
|
||||||
powered = self.powered
|
powered = self.powered
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("sneeker:sneeker",def)
|
core.register_entity("sneeker:sneeker", def)
|
||||||
|
|
||||||
minetest.register_craftitem("sneeker:spawnegg",{
|
core.register_craftitem("sneeker:spawnegg", {
|
||||||
description = "Sneeker Spawn Egg",
|
description = "Sneeker Spawn Egg",
|
||||||
inventory_image = "sneeker_spawnegg.png",
|
inventory_image = "sneeker_spawnegg.png",
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
on_place = function(itemstack,placer,pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
local pos = pointed_thing.above
|
local pos = pointed_thing.above
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y+1
|
||||||
minetest.add_entity(pos,"sneeker:sneeker")
|
core.add_entity(pos, "sneeker:sneeker")
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not core.setting_getbool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
|
17
spawn.lua
17
spawn.lua
@ -1,5 +1,6 @@
|
|||||||
minetest.register_abm({
|
|
||||||
nodenames = {"default:dirt_with_grass","default:stone"},
|
core.register_abm({
|
||||||
|
nodenames = {"default:dirt_with_grass", "default:stone"},
|
||||||
neighbors = {"air"},
|
neighbors = {"air"},
|
||||||
interval = 30,
|
interval = 30,
|
||||||
chance = 9000,
|
chance = 9000,
|
||||||
@ -8,25 +9,25 @@ minetest.register_abm({
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y+1
|
||||||
if not minetest.get_node_light(pos) then
|
if not core.get_node_light(pos) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if minetest.get_node_light(pos) > 5 then
|
if core.get_node_light(pos) > 5 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if minetest.get_node_light(pos) < -1 then
|
if core.get_node_light(pos) < -1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if pos.y > 31000 then
|
if pos.y > 31000 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
if core.get_node(pos).name ~= "air" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
pos.y = pos.y+1
|
pos.y = pos.y+1
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
if core.get_node(pos).name ~= "air" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.add_entity(pos,"sneeker:sneeker")
|
core.add_entity(pos, "sneeker:sneeker")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
-- From TNT
|
-- From TNT
|
||||||
|
|
||||||
local cid_data = {}
|
local cid_data = {}
|
||||||
local radius = tonumber(minetest.setting_get("tnt_radius") or 3)
|
local radius = tonumber(core.setting_get("tnt_radius") or 3)
|
||||||
local large_radius = 5
|
local large_radius = 5
|
||||||
local loss_prob = {
|
local loss_prob = {
|
||||||
["default:cobble"] = 3,
|
["default:cobble"] = 3,
|
||||||
["default:dirt"] = 4,
|
["default:dirt"] = 4,
|
||||||
}
|
}
|
||||||
minetest.after(0, function()
|
core.after(0, function()
|
||||||
for name, def in pairs(minetest.registered_nodes) do
|
for name, def in pairs(core.registered_nodes) do
|
||||||
cid_data[minetest.get_content_id(name)] = {
|
cid_data[core.get_content_id(name)] = {
|
||||||
name = name,
|
name = name,
|
||||||
drops = def.drops,
|
drops = def.drops,
|
||||||
flammable = def.groups.flammable,
|
flammable = def.groups.flammable,
|
||||||
@ -34,7 +35,7 @@ local function eject_drops(drops, pos, radius)
|
|||||||
item:set_count(count)
|
item:set_count(count)
|
||||||
end
|
end
|
||||||
rand_pos(pos, drop_pos, radius)
|
rand_pos(pos, drop_pos, radius)
|
||||||
local obj = minetest.add_item(drop_pos, item)
|
local obj = core.add_item(drop_pos, item)
|
||||||
if obj then
|
if obj then
|
||||||
obj:get_luaentity().collect = true
|
obj:get_luaentity().collect = true
|
||||||
obj:set_acceleration({x=0, y=-10, z=0})
|
obj:set_acceleration({x=0, y=-10, z=0})
|
||||||
@ -62,7 +63,7 @@ local function add_drop(drops, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function destroy(drops, pos, cid)
|
local function destroy(drops, pos, cid)
|
||||||
if minetest.is_protected(pos, "") then
|
if core.is_protected(pos, "") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local def = cid_data[cid]
|
local def = cid_data[cid]
|
||||||
@ -70,9 +71,9 @@ local function destroy(drops, pos, cid)
|
|||||||
def.on_blast(vector.new(pos), 1)
|
def.on_blast(vector.new(pos), 1)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.remove_node(pos)
|
core.remove_node(pos)
|
||||||
if def then
|
if def then
|
||||||
local node_drops = minetest.get_node_drops(def.name, "")
|
local node_drops = core.get_node_drops(def.name, "")
|
||||||
for _, item in ipairs(node_drops) do
|
for _, item in ipairs(node_drops) do
|
||||||
add_drop(drops, item)
|
add_drop(drops, item)
|
||||||
end
|
end
|
||||||
@ -98,7 +99,7 @@ end
|
|||||||
local function entity_physics(pos, radius)
|
local function entity_physics(pos, radius)
|
||||||
-- Make the damage radius larger than the destruction radius
|
-- Make the damage radius larger than the destruction radius
|
||||||
radius = radius * 2
|
radius = radius * 2
|
||||||
local objs = minetest.get_objects_inside_radius(pos, radius)
|
local objs = core.get_objects_inside_radius(pos, radius)
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
local obj_pos = obj:get_pos()
|
local obj_pos = obj:get_pos()
|
||||||
local obj_vel = obj:get_velocity()
|
local obj_vel = obj:get_velocity()
|
||||||
@ -115,7 +116,7 @@ local function entity_physics(pos, radius)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function add_effects(pos, radius)
|
local function add_effects(pos, radius)
|
||||||
minetest.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 128,
|
amount = 128,
|
||||||
time = 1,
|
time = 1,
|
||||||
minpos = vector.subtract(pos, radius / 2),
|
minpos = vector.subtract(pos, radius / 2),
|
||||||
@ -146,16 +147,16 @@ local function explode(pos, radius)
|
|||||||
local drops = {}
|
local drops = {}
|
||||||
local p = {}
|
local p = {}
|
||||||
|
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = core.get_content_id("air")
|
||||||
local c_tnt = nil
|
local c_tnt = nil
|
||||||
if minetest.settings:get_bool("enable_tnt", false) then
|
if core.settings:get_bool("enable_tnt", false) then
|
||||||
c_tnt = minetest.get_content_id("tnt:tnt")
|
c_tnt = core.get_content_id("tnt:tnt")
|
||||||
end
|
end
|
||||||
|
|
||||||
local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning")
|
local c_tnt_burning = core.get_content_id("tnt:tnt_burning")
|
||||||
local c_gunpowder = minetest.get_content_id("tnt:gunpowder")
|
local c_gunpowder = core.get_content_id("tnt:gunpowder")
|
||||||
local c_gunpowder_burning = minetest.get_content_id("tnt:gunpowder_burning")
|
local c_gunpowder_burning = core.get_content_id("tnt:gunpowder_burning")
|
||||||
local c_boom = minetest.get_content_id("tnt:boom")
|
local c_boom = core.get_content_id("tnt:boom")
|
||||||
|
|
||||||
for z = -radius, radius do
|
for z = -radius, radius do
|
||||||
for y = -radius, radius do
|
for y = -radius, radius do
|
||||||
@ -184,14 +185,14 @@ local function explode(pos, radius)
|
|||||||
return drops
|
return drops
|
||||||
end
|
end
|
||||||
|
|
||||||
function sneeker.boom(pos,large)
|
function sneeker.boom(pos, large)
|
||||||
local radius = radius
|
local radius = radius
|
||||||
if large then
|
if large then
|
||||||
radius = large_radius
|
radius = large_radius
|
||||||
end
|
end
|
||||||
minetest.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
|
core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
|
||||||
minetest.set_node(pos, {name="tnt:boom"})
|
core.set_node(pos, {name="tnt:boom"})
|
||||||
minetest.get_node_timer(pos):start(0.5)
|
core.get_node_timer(pos):start(0.5)
|
||||||
local drops = explode(pos, radius)
|
local drops = explode(pos, radius)
|
||||||
entity_physics(pos, radius)
|
entity_physics(pos, radius)
|
||||||
eject_drops(drops, pos, radius)
|
eject_drops(drops, pos, radius)
|
||||||
|
Loading…
Reference in New Issue
Block a user