init.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. gunpowder_barrels = {}
  2. local modpath = minetest.get_modpath("gunpowder_barrels")
  3. dofile(modpath.."/explosion.lua")
  4. dofile(modpath .. "/barrel_entity.lua")
  5. local S = minetest.get_translator("gunpowder_barrels")
  6. minetest.register_craftitem("gunpowder_barrels:barrel_item", {
  7. description = S("Gunpowder Barrel"),
  8. inventory_image = "gunpowder_barrels_barrel.png",
  9. stack_max = 16,
  10. on_use = function(itemstack, user, pointed_thing) --throw
  11. if user
  12. then
  13. if pointed_thing.type == "object"
  14. then
  15. assert(pointed_thing.ref, "ref is not")
  16. pointed_thing.ref:punch(user, 0, {})
  17. else
  18. local throwdir = minetest.serialize(vector.multiply(user:get_look_dir(), 10))
  19. minetest.add_entity(vector.add(user:get_pos(), {x = 0, y = 2, z = 0}),
  20. "gunpowder_barrels:barrel_entity", throwdir)
  21. end
  22. end
  23. itemstack:take_item(1)
  24. return itemstack
  25. end,
  26. on_place = function(itemstack, user, pointed_thing) --place
  27. if user and pointed_thing.type == "node"
  28. then
  29. minetest.add_entity(pointed_thing.above,
  30. "gunpowder_barrels:barrel_entity")
  31. end
  32. itemstack:take_item(1)
  33. return itemstack
  34. end,
  35. })
  36. minetest.register_alias("bomb", "gunpowder_barrels:barrel_item")
  37. minetest.register_alias("gunpowder_barrel", "gunpowder_barrels:barrel_item")