3 minetest
.register_entity("mcl_end:ender_eye", {
5 textures
= {"mcl_end_ender_eye.png"},
6 visual_size
= {x
=1.5, y
=1.5},
7 collisionbox
= {0,0,0,0,0,0},
9 -- Save and restore age
10 get_staticdata
= function(self
)
11 return tostring(self
._age
)
13 on_activate
= function(self
, staticdata
, dtime_s
)
14 local age
= tonumber(staticdata
)
15 if type(age
) == "number" then
17 if self
._age
>= 2 then
25 on_step
= function(self
, dtime
)
26 self
._age
= self
._age
+ dtime
27 if self
._age
>= 3 then
29 local r
= math
.random(1,5)
30 if r
== 1 or minetest
.settings
:get_bool("creative_mode") then
31 -- 20% chance to get destroyed completely.
32 -- 100% if in Creative Mode
36 -- 80% to drop as an item
37 local pos
= self
.object
:get_pos()
38 local v
= self
.object
:getvelocity()
40 local item
= minetest
.add_item(pos
, "mcl_end:ender_eye")
44 elseif self
._age
>= 2 then
45 if self
._phase
== 0 then
47 -- Stop the eye and wait for another second.
48 -- The vertical speed changes are just eye candy.
49 self
.object
:setacceleration({x
=0, y
=-3, z
=0})
50 self
.object
:setvelocity({x
=0, y
=self
.object
:getvelocity().y
*0.2, z
=0})
53 -- Fly normally and generate particles
54 local pos
= self
.object
:get_pos()
55 pos
.x
= pos
.x
+ math
.random(-1, 1)*0.5
56 pos
.y
= pos
.y
+ math
.random(-1, 0)*0.5
57 pos
.z
= pos
.z
+ math
.random(-1, 1)*0.5
58 minetest
.add_particle({
60 texture
= "mcl_particles_teleport.png",
62 velocity
= {x
=math
.random(-1, 1)*0.1, y
=math
.random(-30, 0)*0.1, z
=math
.random(-1, 1)*0.1},
63 acceleration
= {x
=0, y
=0, z
=0},
69 _age
= 0, -- age in seconds
70 _phase
= 0, -- phase 0: flying. phase 1: idling in mid air, about to drop or shatter
73 minetest
.register_craftitem("mcl_end:ender_eye", {
74 description
= "Eye of Ender",
75 _doc_items_longdesc
= "This item is used to locate End portal shrines in the Overworld and to activate End portals." .. "\n" .. "NOTE: The End dimension is currently incomplete and boring.",
76 _doc_items_usagehelp
= "Use the attack key to release the eye of ender. It will rise and fly in the horizontal direction of the closest end portal shrine. If you're very close, the eye of ender will take the direct path to the End portal shrine instead. After a few seconds, it stops. It may drop as an item, but there's a 20% chance it shatters." .. "\n" .. "To activate an End portal, eyes of ender need to be placed into each block of an intact End portal frame.",
77 wield_image
= "mcl_end_ender_eye.png",
78 inventory_image
= "mcl_end_ender_eye.png",
80 -- Throw eye of ender to make it fly to the closest stronghold
81 on_use
= function(itemstack
, user
, pointed_thing
)
85 local origin
= user
:get_pos()
86 origin
.y
= origin
.y
+ 1.5
87 local strongholds
= mcl_structures
.get_registered_structures("stronghold")
88 local dim
= mcl_worlds
.pos_to_dimension(origin
)
89 local is_creative
= minetest
.settings
:get_bool("creative_mode")
91 -- Just drop the eye of ender if there are no strongholds
92 if #strongholds
<= 0 or dim
~= "overworld" then
93 if not is_creative
then
94 minetest
.item_drop(ItemStack("mcl_end:ender_eye"), user
, user
:get_pos())
100 -- Find closest stronghold.
101 -- Note: Only the horizontal axes are taken into account.
102 local closest_stronghold
104 for s
=1, #strongholds
do
105 local h_pos
= table.copy(strongholds
[s
].pos
)
106 local h_origin
= table.copy(origin
)
109 local dist
= vector
.distance(h_origin
, h_pos
)
110 if not closest_stronghold
then
111 closest_stronghold
= strongholds
[s
]
114 if dist
< lowest_dist
then
115 closest_stronghold
= strongholds
[s
]
122 local obj
= minetest
.add_entity(origin
, "mcl_end:ender_eye")
125 if lowest_dist
<= 25 then
127 -- Stronghold is close: Fly directly to stronghold and take Y into account.
128 dir
= vector
.normalize(vector
.direction(origin
, closest_stronghold
.pos
))
129 obj
:setvelocity({x
=dir
.x
*velocity
, y
=dir
.y
*velocity
, z
=dir
.z
*velocity
})
132 -- Don't care about Y if stronghold is still far away.
133 -- Fly to direction of X/Z, and always upwards so it can be seen easily.
134 local o
= {x
=origin
.x
, y
=0, z
=origin
.z
}
135 local s
= {x
=closest_stronghold
.pos
.x
, y
=0, z
=closest_stronghold
.pos
.z
}
136 dir
= vector
.normalize(vector
.direction(o
, s
))
137 obj
:setacceleration({x
=dir
.x
*-3, y
=4, z
=dir
.z
*-3})
138 obj
:setvelocity({x
=dir
.x
*velocity
, y
=3, z
=dir
.z
*velocity
})
142 if not is_creative
then
143 itemstack
:take_item()
149 minetest
.register_craft({
151 output
= "mcl_end:ender_eye",
152 recipe
= {"mcl_mobitems:blaze_powder", "mcl_throwing:ender_pearl"},