1
0
Fork 0

Merge branch 'fix_fishing_rod' of https://github.com/Rootyjr/MineClone2

This commit is contained in:
Wuzzy 2019-09-10 14:55:55 +02:00
commit 276af8a1ea
8 changed files with 339 additions and 93 deletions

View File

@ -1,108 +1,314 @@
--Fishing Rod, Bobber, and Flying Bobber mechanics and Bobber artwork by Rootyjr.
local S = minetest.get_translator("mcl_fishing") local S = minetest.get_translator("mcl_fishing")
local mod_throwing = minetest.get_modpath("mcl_throwing")
local go_fishing = function(itemstack, user, pointed_thing) local entity_mapping = {
if pointed_thing and pointed_thing.under then ["mcl_fishing:bobber"] = "mcl_fishing:bobber_entity",
-- Use pointed node's on_rightclick function first, if present }
local node = minetest.get_node(pointed_thing.under)
if user and not user:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
end
end
if string.find(node.name, "mcl_core:water") then local bobber_ENTITY={
local itemname physical = false,
local itemcount = 1 timer=0,
local itemwear = 0 textures = {"mcl_fishing_bobber.png"},
-- FIXME: Maybe use a better seeding visual_size = {x=0.5, y=0.5},
local pr = PseudoRandom(os.time() * math.random(1, 100)) collisionbox = {0.45,0.45,0.45,0.45,0.45,0.45},
local r = pr:next(1, 100) pointable = false,
if r <= 85 then
-- Fish --get_staticdata = get_staticdata,
items = mcl_loot.get_loot({ --on_activate = on_activate,
items = {
{ itemstring = "mcl_fishing:fish_raw", weight = 60 }, _lastpos={},
{ itemstring = "mcl_fishing:salmon_raw", weight = 25 }, _dive = false,
{ itemstring = "mcl_fishing:clownfish_raw", weight = 2 }, _waittick = nil,
{ itemstring = "mcl_fishing:pufferfish_raw", weight = 13 }, _tick = 0,
} player=nil,
}, pr) _oldy = nil,
elseif r <= 95 then objtype="fishing",
-- Junk }
items = mcl_loot.get_loot({
items = { local fish = function(itemstack, player)
{ itemstring = "mcl_core:bowl", weight = 10 }, local pos = player:get_pos()
{ itemstring = "mcl_fishing:fishing_rod", weight = 2, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
{ itemstring = "mcl_mobitems:leather", weight = 10 }, local objs = minetest.get_objects_inside_radius(pos, 125)
{ itemstring = "3d_armor:boots_leather", weight = 10, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage local num = 0
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10 }, local ent = nil
{ itemstring = "mcl_core:stick", weight = 5 }, local noent = true
{ itemstring = "mcl_mobitems:string", weight = 5 },
{ itemstring = "mcl_potions:potion_water", weight = 10 }, --Check for bobber if so handle.
{ itemstring = "mcl_mobitems:bone", weight = 10 }, for n = 1, #objs do
{ itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 }, ent = objs[n]:get_luaentity()
{ itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook if ent then
} if ent.player and ent.objtype=="fishing" then
}, pr) if (player:get_player_name() == ent.player) then
else noent = false
-- Treasure if ent._dive == true then
items = mcl_loot.get_loot({ local itemname
items = { local itemcount = 1
-- TODO: Enchanted Bow local itemwear = 0
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage -- FIXME: Maybe use a better seeding
-- TODO: Enchanted Book local pr = PseudoRandom(os.time() * math.random(1, 100))
{ itemstring = "mcl_books:book" }, local r = pr:next(1, 100)
-- TODO: Enchanted Fishing Rod if r <= 85 then
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage -- Fish
{ itemstring = "mcl_mobs:nametag", }, items = mcl_loot.get_loot({
{ itemstring = "mcl_mobitems:saddle", }, items = {
{ itemstring = "mcl_flowers:waterlily", }, { itemstring = "mcl_fishing:fish_raw", weight = 60 },
} { itemstring = "mcl_fishing:salmon_raw", weight = 25 },
}, pr) { itemstring = "mcl_fishing:clownfish_raw", weight = 2 },
end { itemstring = "mcl_fishing:pufferfish_raw", weight = 13 },
local item }
if #items >= 1 then }, pr)
item = ItemStack(items[1]) elseif r <= 95 then
else -- Junk
item = ItemStack() items = mcl_loot.get_loot({
end items = {
local inv = user:get_inventory() { itemstring = "mcl_core:bowl", weight = 10 },
if inv:room_for_item("main", item) then { itemstring = "mcl_fishing:fishing_rod", weight = 2, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
inv:add_item("main", item) { itemstring = "mcl_mobitems:leather", weight = 10 },
end { itemstring = "3d_armor:boots_leather", weight = 10, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
if not minetest.settings:get_bool("creative_mode") then { itemstring = "mcl_mobitems:rotten_flesh", weight = 10 },
local idef = itemstack:get_definition() { itemstring = "mcl_core:stick", weight = 5 },
itemstack:add_wear(65535/65) -- 65 uses { itemstring = "mcl_mobitems:string", weight = 5 },
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then { itemstring = "mcl_potions:potion_water", weight = 10 },
minetest.sound_play(idef.sound.breaks, {pos=pointed_thing.above, gain=0.5}) { itemstring = "mcl_mobitems:bone", weight = 10 },
{ itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 },
{ itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook
}
}, pr)
else
-- Treasure
items = mcl_loot.get_loot({
items = {
-- TODO: Enchanted Bow
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
-- TODO: Enchanted Book
{ itemstring = "mcl_books:book" },
-- TODO: Enchanted Fishing Rod
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
{ itemstring = "mcl_mobs:nametag", },
{ itemstring = "mcl_mobitems:saddle", },
{ itemstring = "mcl_flowers:waterlily", },
}
}, pr)
end
local item
if #items >= 1 then
item = ItemStack(items[1])
else
item = ItemStack()
end
local inv = player:get_inventory()
if inv:room_for_item("main", item) then
inv:add_item("main", item)
end
if not minetest.settings:get_bool("creative_mode") then
local idef = itemstack:get_definition()
itemstack:add_wear(65535/65) -- 65 uses
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
minetest.sound_play(idef.sound.breaks, {pos=player.get_pos(), gain=0.5})
end
end
end
--Check if object is on land.
local epos = ent.object:get_pos()
epos.y = math.floor(epos.y)
local node = minetest.get_node(epos)
local def = minetest.registered_nodes[node.name]
if def.walkable then
if not minetest.settings:get_bool("creative_mode") then
local idef = itemstack:get_definition()
itemstack:add_wear((65535/65)*2) -- if so and not creative then wear double like in MC.
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
minetest.sound_play(idef.sound.breaks, {pos=player.get_pos(), gain=0.5})
end
end
end
--Destroy bobber.
ent.object:remove()
return itemstack
end
end end
end end
return itemstack end
--Check for flying bobber.
for n = 1, #objs do
ent = objs[n]:get_luaentity()
if ent then
if ent._thrower and ent.objtype=="fishing" then
if player:get_player_name() == ent._thrower then
noent = false
break
end
end
end
end
--If no bobber or flying_bobber exists then throw bobber.
if noent == true then
local playerpos = player:get_pos()
local dir = player:get_look_dir()
local obj = mcl_throwing.throw("mcl_throwing:flying_bobber", {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, 15)
obj:get_luaentity()._thrower = player:get_player_name()
end
end
-- Movement function of bobber
local bobber_on_step = function(self, dtime)
self.timer=self.timer+dtime
local epos = self.object:get_pos()
epos.y = math.floor(epos.y)
local node = minetest.get_node(epos)
local def = minetest.registered_nodes[node.name]
--If we have no player remove self.
if self.player == nil then
self.object:remove()
end
--Check if player is nearby
if self._tick % 5 == 0 and self.player ~= nil then
--Destroy bobber if item not wielded.
if (minetest.get_player_by_name(self.player):get_wielded_item():get_name() ~= "mcl_fishing:fishing_rod") then
self.object:remove()
end
--Destroy bobber if player is too far away.
local objpos = self.object:get_pos()
local playerpos = minetest.get_player_by_name(self.player):get_pos()
if (((playerpos.y - objpos.y) >= 33) or ((playerpos.y - objpos.y) <= -33)) then
self.object:remove()
elseif (((playerpos.x - objpos.x) >= 33) or ((playerpos.x - objpos.x) <= -33)) then
self.object:remove()
elseif (((playerpos.z - objpos.z) >= 33) or ((playerpos.z - objpos.z) <= -33)) then
self.object:remove()
elseif ((((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) >= 33) or ((playerpos.z + playerpos.x) - (objpos.z + objpos.x)) <= -33) then
self.object:remove()
elseif ((((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) >= 33) or ((playerpos.y + playerpos.x) - (objpos.y + objpos.x)) <= -33) then
self.object:remove()
elseif ((((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) >= 33) or ((playerpos.z + playerpos.y) - (objpos.z + objpos.y)) <= -33) then
self.object:remove()
end
end
--if in liquid then bob.
if def.liquidtype == "source" and def.name == "mcl_core:water_source" then
if self._oldy == nil then
self.object:set_pos({x=self.object:get_pos().x,y=math.floor(self.object:get_pos().y)+.5,z=self.object:get_pos().z})
self._oldy = self.object:get_pos().y
end
minetest.log(self.object:get_pos().y.." "..self._oldy)
-- reset to original position after dive.
if self.object:get_pos().y > self._oldy then
self.object:set_pos({x=self.object:get_pos().x,y=self._oldy,z=self.object:get_pos().z})
self.object:set_velocity({x=0,y=0,z=0})
self.object:set_acceleration({x=0,y=0,z=0})
end
if self._dive then
for i=1,2 do
--spray bubbles there's a fish.
minetest.add_particle({
pos = {x=epos["x"]+math.random(-1,1)*math.random()/2,y=epos["y"]+0.1,z=epos["z"]+math.random(-1,1)*math.random()/2},
velocity = {x=0, y=4, z=0},
acceleration = {x=0, y=-5, z=0},
expirationtime = math.random(),
size = math.random()+0.5,
collisiondetection = true,
vertical = false,
texture = "mcl_particles_bubble.png",
})
end
if self._tick ~= self._waittick then
self._tick = self._tick + 1
else
self._waittick = nil
self._tick = 0
self._dive = false
end
else if self._waittick == nil then
--wait for random number of ticks.
self._waittick = math.random(50,800)
else
if self._tick ~= self._waittick then
self._tick = self._tick + 1
else
--wait time is over time to dive.
self._dive = true
self.object:set_velocity({x=0,y=-2,z=0})
self.object:set_acceleration({x=0,y=5,z=0})
self._waittick = 30
self._tick = 0
end
end end
end end
return nil end
-- Destroy when hitting a solid node
--if self._lastpos.x~=nil then
-- if (def and def.walkable) or not def 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
end end
bobber_ENTITY.on_step = bobber_on_step
minetest.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY)
--If player leaves area remove bobber.
minetest.register_on_leaveplayer(function(player)
local objs = minetest.get_objects_inside_radius(player:get_pos(), 250)
local num = 0
local ent = nil
local noent = true
for n = 1, #objs do
ent = objs[n]:get_luaentity()
if ent then
if ent.player and ent.objtype=="fishing" then
ent.object:remove()
elseif ent._thrower and ent.objtype=="fishing" then
ent.object:remove()
end
end
end
end)
--if player dies remove bobber.
minetest.register_on_dieplayer(function(player)
local objs = minetest.get_objects_inside_radius(player:get_pos(), 250)
local num = 0
local ent = nil
local noent = true
for n = 1, #objs do
ent = objs[n]:get_luaentity()
if ent then
if ent.player and ent.objtype=="fishing" then
ent.object:remove()
elseif ent._thrower and ent.objtype=="fishing" then
ent.object:remove()
end
end
end
end)
-- Fishing Rod -- Fishing Rod
minetest.register_tool("mcl_fishing:fishing_rod", { minetest.register_tool("mcl_fishing:fishing_rod", {
description = S("Fishing Rod"), description = S("Fishing Rod"),
_doc_items_longdesc = S("Fishing rods can be used to catch fish."), _doc_items_longdesc = S("Fishing rods can be used to catch fish."),
_doc_items_usagehelp = S("Rightclick a water source to try to go fishing. Who knows what you're going to catch?"), _doc_items_usagehelp = S("Rightclick to launch the bobber. When it sinks right-click again to reel in an item. Who knows what you're going to catch?"),
-- This item is incomplete, hide it from creative inventory -- This item is incomplete, hide it from creative inventory
groups = { tool=1, not_in_creative_inventory=1 }, groups = { tool=1},
inventory_image = "mcl_fishing_fishing_rod.png", inventory_image = "mcl_fishing_fishing_rod.png",
stack_max = 1, stack_max = 1,
liquids_pointable = true, on_place = fish,
on_place = go_fishing, on_secondary_use = fish,
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
}) })
--[[ --Make fishing rods craftable again.
Temporarily removed from crafting as the fishing rod is massively overpowered atm.
TODO: Re-enable crafting when fishing rod has been improved.
minetest.register_craft({ minetest.register_craft({
output = "mcl_fishing:fishing_rod", output = "mcl_fishing:fishing_rod",
recipe = { recipe = {
@ -119,8 +325,6 @@ minetest.register_craft({
{'mcl_mobitems:string','','mcl_core:stick'}, {'mcl_mobitems:string','','mcl_core:stick'},
} }
}) })
]]
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_fishing:fishing_rod", recipe = "mcl_fishing:fishing_rod",

View File

@ -1,7 +1,7 @@
# textdomain: mcl_fishing # textdomain: mcl_fishing
Fishing Rod= Fishing Rod=
Fishing rods can be used to catch fish.= Fishing rods can be used to catch fish.=
Rightclick a water source to try to go fishing. Who knows what you're going to catch?= Rightclick to launch the bobber. When it sinks right-click again to reel in an item. Who knows what you're going to catch?=
Raw Fish= Raw Fish=
Raw fish is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value.= Raw fish is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value.=
Cooked Fish= Cooked Fish=

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -359,8 +359,6 @@ minetest.register_craft({
}, },
}) })
--[[
TODO: Re-enable this when fishing rod is available again
minetest.register_craft({ minetest.register_craft({
output = "mcl_mobitems:carrot_on_a_stick", output = "mcl_mobitems:carrot_on_a_stick",
recipe = { recipe = {
@ -376,7 +374,6 @@ minetest.register_craft({
{ "mcl_farming:carrot_item", "" }, { "mcl_farming:carrot_item", "" },
}, },
}) })
]]
minetest.register_craft({ minetest.register_craft({
type = "shapeless", type = "shapeless",

View File

@ -1,3 +1,4 @@
mcl_core? mcl_core?
mcl_mobitems? mcl_mobitems?
doc? doc?
mcl_fishing

View File

@ -2,6 +2,7 @@ mcl_throwing = {}
local S = minetest.get_translator("mcl_throwing") local S = minetest.get_translator("mcl_throwing")
local mod_death_messages = minetest.get_modpath("mcl_death_messages") local mod_death_messages = minetest.get_modpath("mcl_death_messages")
local mod_fishing = minetest.get_modpath("mcl_fishing")
-- --
-- Snowballs and other throwable items -- 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 GRAVITY = tonumber(minetest.settings:get("movement_gravity"))
local entity_mapping = { local entity_mapping = {
["mcl_throwing:flying_bobber"] = "mcl_throwing:flying_bobber_entity",
["mcl_throwing:snowball"] = "mcl_throwing:snowball_entity", ["mcl_throwing:snowball"] = "mcl_throwing:snowball_entity",
["mcl_throwing:egg"] = "mcl_throwing:egg_entity", ["mcl_throwing:egg"] = "mcl_throwing:egg_entity",
["mcl_throwing:ender_pearl"] = "mcl_throwing:ender_pearl_entity", ["mcl_throwing:ender_pearl"] = "mcl_throwing:ender_pearl_entity",
} }
local velocities = { local velocities = {
["mcl_throwing:flying_bobber_entity"] = 5,
["mcl_throwing:snowball_entity"] = 22, ["mcl_throwing:snowball_entity"] = 22,
["mcl_throwing:egg_entity"] = 22, ["mcl_throwing:egg_entity"] = 22,
["mcl_throwing:ender_pearl_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 _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. -- Snowball on_step()--> called when snowball is moving.
local snowball_on_step = function(self, dtime) local snowball_on_step = function(self, dtime)
self.timer=self.timer+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 self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
end 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 snowball_ENTITY.on_step = snowball_on_step
egg_ENTITY.on_step = egg_on_step egg_ENTITY.on_step = egg_on_step
pearl_ENTITY.on_step = pearl_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:snowball_entity", snowball_ENTITY)
minetest.register_entity("mcl_throwing:egg_entity", egg_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: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.") local how_to_throw = S("Use the punch key to throw.")

View File

@ -3,7 +3,6 @@
local S = minetest.get_translator("mcl_wip") local S = minetest.get_translator("mcl_wip")
local wip_items = { local wip_items = {
"mcl_fishing:fishing_rod",
"mcl_maps:empty_map", "mcl_maps:empty_map",
"mcl_comparators:comparator_off_comp", "mcl_comparators:comparator_off_comp",
"mcl_minecarts:hopper_minecart", "mcl_minecarts:hopper_minecart",