1 local S = minetest.get_translator("mcl_end_crystal")
3 local explosion_range = 7
6 {x = 1}, {x = -1}, {z = 1}, {z = -1}
9 local dimensions = {"x", "y", "z"}
11 for _, dir in pairs(directions) do
12 for _, dim in pairs(dimensions) do
13 dir[dim] = dir[dim] or 0
17 local function crystal_explode(self, puncher)
18 if self.exploded then return end
20 local radius = puncher and explosion_range or 1
21 mcl_explosions.explode(self.object:get_pos(), radius, {drop_chance = 1}, puncher)
22 minetest.after(0, self.object.remove, self.object)
25 local function set_crystal_animation(self)
26 self.object:set_animation({x = 0, y = 60}, 30)
29 local function spawn_crystal(pos)
30 local crystal = minetest.add_entity(pos, "mcl_end_crystal:end_crystal")
31 if not vector.equals(pos, vector.floor(pos)) then return end
32 if mcl_worlds.pos_to_dimension(pos) ~= "end" then return end
34 for _, dir in pairs(directions) do
35 local node = minetest.get_node(vector.add(pos, vector.add(dir, {x = 0, y = -1, z = 0})))
36 if node.name == "mcl_portals:portal_end" then
37 portal_center = vector.add(pos, vector.multiply(dir, 3))
41 if not portal_center then return end
43 for i, dir in pairs(directions) do
44 local crystal_pos = vector.add(portal_center, vector.multiply(dir, 3))
45 print(minetest.pos_to_string(crystal_pos))
46 local objects = minetest.get_objects_inside_radius(crystal_pos, 0)
47 for _, obj in pairs(objects) do
48 local luaentity = obj:get_luaentity()
49 if luaentity and luaentity.name == "mcl_end_crystal:end_crystal" then
50 crystals[i] = luaentity
54 if not crystals[i] then return end
56 for _, crystal in pairs(crystals) do
57 crystal_explode(crystal)
59 minetest.add_entity(vector.add(portal_center, {x = 0, y = 10, z = 0}), "mobs_mc:enderdragon")
62 minetest.register_entity("mcl_end_crystal:end_crystal", {
63 initial_properties = {
66 visual_size = {x = 7.5, y = 7.5, z = 7.5},
67 collisionbox = {-0.75, -0.5, -0.75, 0.75, 1.25, 0.75},
68 mesh = "end_crystal.b3d",
69 textures = {"end_crystal_entity.png"},
70 collide_with_objects = true,
73 on_punch = crystal_explode,
74 on_activate = set_crystal_animation,
75 _cmi_is_mob = true -- Ignitable by arrows
78 minetest.register_craftitem("mcl_end_crystal:end_crystal", {
79 inventory_image = "end_crystal.png",
80 description = S("End Crystal"),
82 on_place = function(itemstack, placer, pointed_thing)
83 if pointed_thing.type == "node" and pointed_thing.above.y > pointed_thing.under.y then
84 local node = minetest.get_node(pointed_thing.under).name
85 if node == "mcl_core:obsidian" or node == "mcl_core:bedrock" then
87 spawn_crystal(pointed_thing.above)
92 _tt_help = S("Ignited by a punch or a hit with an arrow").."\n"..S("Explosion radius: @1", tostring(explosion_range)),
93 _doc_items_longdesc = S("End Crystals are explosive devices. They can be placed on Obsidian or Bedrock. Ignite them by a punch or a hit with an arrow. End Crystals can also be used the spawn the Ender Dragon by placing one at each side of the End Exit Portal."),
94 _doc_items_usagehelp = S("Place the End Crystal on Obsidian or Bedrock, then punch it or hit it with an arrow to cause an huge and probably deadly explosion. To Spawn the Ender Dragon, place one at each side of the End Exit Portal."),
98 minetest.register_craft({
99 output = "mcl_end_crystal:end_crystal",
101 {"mcl_core:glass", "mcl_core:glass", "mcl_core:glass"},
102 {"mcl_core:glass", "mcl_end:ender_eye", "mcl_core:glass"},
103 {"mcl_core:glass", "mcl_mobitems:ghast_tear", "mcl_core:glass"},