Completely rework fishing rod to simulate a much more MC-like behaviour

This commit is contained in:
Rootyjr 2019-07-30 21:22:28 -05:00
parent d4facaf503
commit 379dd847ee
4 changed files with 342 additions and 12 deletions

View file

@ -2,6 +2,7 @@ mcl_throwing = {}
local S = minetest.get_translator("mcl_throwing")
local mod_death_messages = minetest.get_modpath("mcl_death_messages")
local mod_fishing = minetest.get_modpath("mcl_fishing")
--
-- Snowballs and other throwable items
@ -10,12 +11,14 @@ local mod_death_messages = minetest.get_modpath("mcl_death_messages")
local GRAVITY = tonumber(minetest.settings:get("movement_gravity"))
local entity_mapping = {
["mcl_throwing:flying_bobber"] = "mcl_throwing:flying_bobber_entity",
["mcl_throwing:snowball"] = "mcl_throwing:snowball_entity",
["mcl_throwing:egg"] = "mcl_throwing:egg_entity",
["mcl_throwing:ender_pearl"] = "mcl_throwing:ender_pearl_entity",
}
local velocities = {
["mcl_throwing:flying_bobber_entity"] = 5,
["mcl_throwing:snowball_entity"] = 22,
["mcl_throwing:egg_entity"] = 22,
["mcl_throwing:ender_pearl_entity"] = 22,
@ -117,6 +120,22 @@ local pearl_ENTITY={
_thrower = nil, -- Player ObjectRef of the player who threw the ender pearl
}
local flying_bobber_ENTITY={
physical = false,
timer=0,
textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture.
visual_size = {x=0.5, y=0.5},
collisionbox = {0,0,0,0,0,0},
pointable = false,
get_staticdata = get_staticdata,
on_activate = on_activate,
_lastpos={},
_thrower = nil,
objtype="fishing",
}
-- Snowball on_step()--> called when snowball is moving.
local snowball_on_step = function(self, dtime)
self.timer=self.timer+dtime
@ -284,13 +303,39 @@ local pearl_on_step = function(self, dtime)
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 flying bobber
local flying_bobber_on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:get_pos()
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
--local player = minetest.get_player_by_name(self._thrower)
-- Destroy when hitting a solid node
if self._lastpos.x~=nil then
if (def and (def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source")) or not def then
local make_child= function(object)
local ent = object:get_luaentity()
ent.player = self._thrower
ent.child = true
end
make_child(minetest.add_entity(self._lastpos, "mcl_fishing:bobber_entity"))
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 = snowball_on_step
egg_ENTITY.on_step = egg_on_step
pearl_ENTITY.on_step = pearl_on_step
flying_bobber_ENTITY.on_step = flying_bobber_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)
minetest.register_entity("mcl_throwing:flying_bobber_entity", flying_bobber_ENTITY)
local how_to_throw = S("Use the punch key to throw.")