1
0
Fork 0

Make ender pearl throwable and teleport player

This commit is contained in:
Wuzzy 2017-01-25 11:45:17 +01:00
parent 55145a4e17
commit caf05770c5
4 changed files with 59 additions and 17 deletions

View File

@ -1,7 +0,0 @@
minetest.register_craftitem("mcl_ender_pearl:ender_pearl", {
description = "Ender Pearl",
wield_image = "mcl_ender_pearl_ender_pearl.png",
inventory_image = "mcl_ender_pearl_ender_pearl.png",
stack_max = 16,
})

View File

@ -1 +0,0 @@
name = mcl_ender_pearl

View File

Before

Width:  |  Height:  |  Size: 338 B

After

Width:  |  Height:  |  Size: 338 B

View File

@ -1,12 +1,13 @@
--
-- Snowballs
-- Snowballs and other throwable items
--
local GRAVITY = 9.81
local GRAVITY = tonumber(minetest.setting_get("movement_gravity"))
local snowball_VELOCITY=19
local egg_VELOCITY=19
local pearl_VELOCITY=19
--Shoot snowball.
--Shoot item
local throw_function = function (entity_name, velocity)
local func = function(item, player, pointed_thing)
local playerpos=player:getpos()
@ -14,6 +15,7 @@ local throw_function = function (entity_name, velocity)
local dir=player:get_look_dir()
obj:setvelocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity})
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
obj:get_luaentity()._thrower = player:get_player_name()
item:take_item()
return item
end
@ -25,34 +27,71 @@ local snowball_ENTITY={
physical = false,
timer=0,
textures = {"mcl_throwing_snowball.png"},
lastpos={},
_lastpos={},
collisionbox = {0,0,0,0,0,0},
}
local egg_ENTITY={
physical = false,
timer=0,
textures = {"mcl_throwing_egg.png"},
lastpos={},
_lastpos={},
collisionbox = {0,0,0,0,0,0},
}
-- Ender pearl entity
local pearl_ENTITY={
physical = false,
timer=0,
textures = {"mcl_throwing_ender_pearl.png"},
_lastpos={},
collisionbox = {0,0,0,0,0,0},
_thrower = nil, -- Player ObjectRef of the player who threw the ender pearl
}
-- Snowball_entity.on_step()--> called when snowball is moving.
-- Snowball and egg entity on_step()--> called when snowball is moving.
local on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
--Become item when hitting a node.
if self.lastpos.x~=nil then --If there is no lastpos for some reason.
-- Remove when hitting a node.
if self._lastpos.x~=nil then
if node.name ~= "air" then
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set _lastpos-->Node will be added at last pos outside the node
end
-- Movement function of ender pearl
local pearl_on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
--Become item when hitting a node.
if self._lastpos.x~=nil then
if node.name ~= "air" then
local player = minetest.get_player_by_name(self._thrower)
if player then
-- Teleport and hurt player
player:setpos(pos)
player:set_hp(player:get_hp() - 5)
end
self.object:remove()
return
end
end
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
end
snowball_ENTITY.on_step = on_step
egg_ENTITY.on_step = on_step
pearl_ENTITY.on_step = pearl_on_step
minetest.register_entity("mcl_throwing:snowball_entity", snowball_ENTITY)
minetest.register_entity("mcl_throwing:egg_entity", egg_ENTITY)
minetest.register_entity("mcl_throwing:ender_pearl_entity", pearl_ENTITY)
-- Snowball
minetest.register_craftitem("mcl_throwing:snowball", {
@ -68,6 +107,7 @@ minetest.register_craftitem("mcl_throwing:snowball", {
end,
})
-- Egg
minetest.register_craftitem("mcl_throwing:egg", {
description = "Egg",
inventory_image = "mcl_throwing_egg.png",
@ -75,3 +115,13 @@ minetest.register_craftitem("mcl_throwing:egg", {
on_use = throw_function("mcl_throwing:egg_entity", egg_VELOCITY),
groups = { craftitem = 1 },
})
-- Ender Pearl
minetest.register_craftitem("mcl_throwing:ender_pearl", {
description = "Ender Pearl",
wield_image = "mcl_throwing_ender_pearl.png",
inventory_image = "mcl_throwing_ender_pearl.png",
stack_max = 16,
on_use = throw_function("mcl_throwing:ender_pearl_entity", pearl_VELOCITY),
})