]> git.lizzy.rs Git - mcl_end_crystal.git/blob - init.lua
Add deprecation warning
[mcl_end_crystal.git] / init.lua
1 local S = minetest.get_translator("mcl_end_crystal")
2
3 local explosion_range = 7
4
5 local directions = {
6         {x = 1}, {x = -1}, {z = 1}, {z = -1}
7 }
8
9 local dimensions = {"x", "y", "z"}
10
11 for _, dir in pairs(directions) do
12         for _, dim in pairs(dimensions) do
13                 dir[dim] = dir[dim] or 0
14         end
15 end
16
17 local function crystal_explode(self, puncher)
18         if self.exploded then return end
19         self.exploded = true
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)
23 end
24
25 local function set_crystal_animation(self)
26         self.object:set_animation({x = 0, y = 60}, 30)
27 end
28
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
33         local portal_center
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))
38                         break
39                 end
40         end
41         if not portal_center then return end
42         local crystals = {}
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
51                                 break
52                         end
53                 end
54                 if not crystals[i] then return end
55         end
56         for _, crystal in pairs(crystals) do
57                 crystal_explode(crystal)
58         end
59         minetest.add_entity(vector.add(portal_center, {x = 0, y = 10, z = 0}), "mobs_mc:enderdragon")
60 end
61
62 minetest.register_entity("mcl_end_crystal:end_crystal", {
63         initial_properties = {
64                 physical = true,
65                 visual = "mesh",
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,
71         },
72         exploded = false,
73         on_punch = crystal_explode,
74         on_activate = set_crystal_animation,
75         _cmi_is_mob = true -- Ignitable by arrows
76 })
77  
78 minetest.register_craftitem("mcl_end_crystal:end_crystal", {
79         inventory_image = "end_crystal.png",
80         description = S("End Crystal"),
81         stack_max = 64,
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
86                                 itemstack:take_item()
87                                 spawn_crystal(pointed_thing.above)
88                         end
89                 end
90                 return itemstack
91         end,
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."),
95
96 })
97
98 minetest.register_craft({
99         output = "mcl_end_crystal:end_crystal",
100         recipe = {
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"},
104         }
105 })