Guest User

Untitled

a guest
Jul 8th, 2012
25
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. minetest.register_craft({
  2. output = 'node "uranium:nuclear_lauch" 1',
  3. recipe = {
  4. {'cobble','cobble','cobble'},
  5. {'cobble','uranium:uranium_gem','cobble'},
  6. {'cobble','cobble',''}
  7. }
  8. })
  9. minetest.register_node("uranium:nuclear_launch", {
  10. tile_images = {"uranium_nucleartop.png", "uranium_nuclearbottom.png",
  11. "uranium_nuclearside.png", "uranium_nuclearside.png",
  12. "uranium_nuclearside.png", "uranium_nuclearside.png"},
  13. dug_item = '', -- Get nothing
  14. material = {
  15. diggability = "not",
  16. },
  17. description = "Nuclear Launch",
  18. })
  19.  
  20. minetest.register_on_punchnode(function(p, node)
  21. if node.name == "uranium:nuclear_launch" then
  22. minetest.env:remove_node(p)
  23. spawn_tnt(p, "uranium:nuclear_launch")
  24. nodeupdate(p)
  25. end
  26. end)
  27.  
  28. local URANIUM_LAUNCH_RANGE = 1
  29. local URANIUM_LAUNCH = {
  30. -- Static definition
  31. physical = true, -- Collides with things
  32. -- weight = 5,
  33. collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
  34. visual = "cube",
  35. textures = {"uranium_nucleartop.png", "uranium_nuclearbottom.png",
  36. "uranium_nuclearside.png", "uranium_nuclearside.png",
  37. "uranium_nuclearside.png", "uranium_nuclearside.png"},
  38. -- Initial value for our timer
  39. timer = 0,
  40. -- Number of punches required to defuse
  41. health = 1,
  42. blinktimer = 0,
  43. blinkstatus = true,}
  44.  
  45. function URANIUM_LAUNCH:on_activate(staticdata)
  46. self.object:setvelocity({x=0, y=4, z=0})
  47. self.object:setacceleration({x=0, y=-10, z=0})
  48. self.object:settexturemod("^[brighten")
  49. end
  50.  
  51. function URANIUM_LAUNCH:on_step(dtime)
  52. self.timer = self.timer + dtime
  53. self.blinktimer = self.blinktimer + dtime
  54. if self.timer>5 then
  55. self.blinktimer = self.blinktimer + dtime
  56. if self.timer>8 then
  57. self.blinktimer = self.blinktimer + dtime
  58. self.blinktimer = self.blinktimer + dtime
  59. end
  60. end
  61. if self.blinktimer > 0.5 then
  62. self.blinktimer = self.blinktimer - 0.5
  63. if self.blinkstatus then
  64. self.object:settexturemod("")
  65. else
  66. self.object:settexturemod("^[brighten")
  67. end
  68. self.blinkstatus = not self.blinkstatus
  69. end
  70. if self.timer > 10 then
  71. local pos = self.object:getpos()
  72. pos.x = math.floor(pos.x+0.5)
  73. pos.y = math.floor(pos.y+0.5)
  74. pos.z = math.floor(pos.z+0.5)
  75. do_tnt_physics(pos, URANIUM_LAUNCH_RANGE)
  76. minetest.sound_play("nuke_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
  77. if minetest.env:get_node(pos).name == "default:water_source" or minetest.env:get_node(pos).name == "default:water_flowing" then
  78. -- Cancel the Explosion
  79. self.object:remove()
  80. return
  81. end
  82. for x=-URANIUM_LAUNCH_RANGE,URANIUM_LAUNCH_RANGE do
  83. for y=-URANIUM_LAUNCH_RANGE,URANIUM_LAUNCH_RANGE do
  84. for z=-URANIUM_LAUNCH_RANGE,URANIUM_LAUNCH_RANGE do
  85. if x*x+y*y+z*z <= URANIUM_LAUNCH_RANGE * URANIUM_LAUNCH_RANGE + URANIUM_LAUNCH_RANGE then
  86. local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
  87. local n = minetest.env:get_node(np)
  88. if n.name ~= "air" and n.name ~= "dirt" then
  89. minetest.env:remove_node(np)
  90. end
  91. activate_if_tnt(n.name, np, pos, URANIUM_LAUNCH_RANGE)
  92. end
  93. end
  94. end
  95. end
  96. self.object:remove()
  97. end
  98. end
  99.  
  100. function URANIUM_LAUNCH:on_punch(hitter)
  101. self.health = self.health - 1
  102. if self.health <= 0 then
  103. self.object:remove()
  104. hitter:get_inventory():add_item("main", "uranium:nuclear_launch")
  105. end
  106. end
  107.  
  108. minetest.register_entity("uranium:nuclear_launch", URANIUM_LAUNCH)
RAW Paste Data