Merge pull request 'Fish buckets save and restore object properties in item entity' (#3013) from fish_bucket_save into master

Reviewed-on: MineClone2/MineClone2#3013
Reviewed-by: PrairieWind <prairie.astronomer1@gmail.com>
This commit is contained in:
PrairieWind 2022-11-27 03:10:11 +00:00
commit 8b7b2f02e9
7 changed files with 99 additions and 104 deletions

View File

@ -1,34 +1,5 @@
--MCmobs v0.4
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
local pi = math.pi
local atann = math.atan
local atan = function(x)
if not x or x ~= x then
return 0
else
return atann(x)
end
end
local dir_to_pitch = function(dir)
local dir2 = vector.normalize(dir)
local xz = math.abs(dir.x) + math.abs(dir.z)
return -math.atan2(-dir.y, xz)
end
local function degrees(rad)
return rad * 180.0 / math.pi
end
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
--###################
--################### axolotl
--###################
local axolotl = { local axolotl = {
type = "animal", type = "animal",
spawn_class = "water", spawn_class = "water",
@ -38,7 +9,7 @@ local axolotl = {
hp_max = 14, hp_max = 14,
xp_min = 1, xp_min = 1,
xp_max = 7, xp_max = 7,
head_swivel = "head.control", head_swivel = "head.control",
bone_eye_height = -1, bone_eye_height = -1,
head_eye_height = -0.5, head_eye_height = -0.5,
@ -61,7 +32,7 @@ local axolotl = {
{"mobs_mc_axolotl_pink.png"}, {"mobs_mc_axolotl_pink.png"},
{"mobs_mc_axolotl_black.png"}, {"mobs_mc_axolotl_black.png"},
{"mobs_mc_axolotl_purple.png"}, {"mobs_mc_axolotl_purple.png"},
{"mobs_mc_axolotl_white.png"} {"mobs_mc_axolotl_white.png"}
}, },
sounds = { sounds = {
random = "mobs_mc_axolotl", random = "mobs_mc_axolotl",
@ -74,7 +45,6 @@ local axolotl = {
run_start = 61, run_end = 81, run_speed = 20, run_start = 61, run_end = 81, run_speed = 20,
}, },
-- This should should make axolotls breedable, but it doesn't.
follow = { follow = {
"mcl_fishing:clownfish_raw" "mcl_fishing:clownfish_raw"
}, },
@ -83,15 +53,20 @@ local axolotl = {
fear_height = 4, fear_height = 4,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if clicker:get_wielded_item():get_name() == "mcl_buckets:bucket_water" then local bn = clicker:get_wielded_item():get_name()
self.object:remove() if bn == "mcl_buckets:bucket_water" or bn == "mcl_buckets:bucket_river_water" then
clicker:set_wielded_item("mcl_buckets:bucket_axolotl") if clicker:set_wielded_item("mcl_buckets:bucket_axolotl") then
local it = clicker:get_wielded_item()
local m = it:get_meta()
m:set_string("properties",minetest.serialize(self.object:get_properties()))
clicker:set_wielded_item(it)
self.object:remove()
end
awards.unlock(clicker:get_player_name(), "mcl:cutestPredator") awards.unlock(clicker:get_player_name(), "mcl:cutestPredator")
return return
end end
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
end, end,
makes_footstep_sound = false, makes_footstep_sound = false,
fly = true, fly = true,
fly_in = { "mcl_core:water_source", "mclx_core:river_water_source" }, fly_in = { "mcl_core:water_source", "mclx_core:river_water_source" },
@ -101,7 +76,7 @@ local axolotl = {
reach = 2, reach = 2,
attack_type = "dogfight", attack_type = "dogfight",
attack_animals = true, attack_animals = true,
specific_attack = { specific_attack = {
"extra_mobs_cod", "extra_mobs_cod",
"mobs_mc:sheep", "mobs_mc:sheep",
"extra_mobs_glow_squid", "extra_mobs_glow_squid",
@ -110,34 +85,10 @@ local axolotl = {
"mobs_mc_squid" "mobs_mc_squid"
}, },
runaway = true, runaway = true,
do_custom = function(self)
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
if self.object:get_velocity().y < 5 then
self.object:add_velocity({ x = 0 , y = math.random(-.007, .007), z = 0 })
end
end
--]]
for _,object in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 10)) do
local lp = object:get_pos()
local s = self.object:get_pos()
local vec = {
x = lp.x - s.x,
y = lp.y - s.y,
z = lp.z - s.z
}
if object and not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "extra_mobs_tropical_fish" then
self.state = "runaway"
self.object:set_rotation({x=0,y=(atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate,z=0})
end
end
end
} }
mcl_mobs:register_mob("mobs_mc:axolotl", axolotl) mcl_mobs:register_mob("mobs_mc:axolotl", axolotl)
local water = 0 local water = 0
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(

View File

@ -102,7 +102,8 @@ local cod = {
end end
end, end,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if clicker:get_wielded_item():get_name() == "mcl_buckets:bucket_water" then local bn = clicker:get_wielded_item():get_name()
if bn == "mcl_buckets:bucket_water" or bn == "mcl_buckets:bucket_river_water" then
self.object:remove() self.object:remove()
clicker:set_wielded_item("mcl_buckets:bucket_cod") clicker:set_wielded_item("mcl_buckets:bucket_cod")
awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing") awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing")

View File

@ -58,7 +58,8 @@ local salmon = {
runaway = true, runaway = true,
fear_height = 4, fear_height = 4,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if clicker:get_wielded_item():get_name() == "mcl_buckets:bucket_water" then local bn = clicker:get_wielded_item():get_name()
if bn == "mcl_buckets:bucket_water" or bn == "mcl_buckets:bucket_river_water" then
self.object:remove() self.object:remove()
clicker:set_wielded_item("mcl_buckets:bucket_salmon") clicker:set_wielded_item("mcl_buckets:bucket_salmon")
awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing") awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing")

View File

@ -103,9 +103,15 @@ local tropical_fish = {
runaway = true, runaway = true,
fear_height = 4, fear_height = 4,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if clicker:get_wielded_item():get_name() == "mcl_buckets:bucket_water" then local bn = clicker:get_wielded_item():get_name()
self.object:remove() if bn == "mcl_buckets:bucket_water" or bn == "mcl_buckets:bucket_river_water" then
clicker:set_wielded_item("mcl_buckets:bucket_tropical_fish") if clicker:set_wielded_item("mcl_buckets:bucket_tropical_fish") then
local it = clicker:get_wielded_item()
local m = it:get_meta()
m:set_string("properties",minetest.serialize(self.object:get_properties()))
clicker:set_wielded_item(it)
self.object:remove()
end
awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing") awards.unlock(clicker:get_player_name(), "mcl:tacticalFishing")
end end
end, end,

View File

@ -0,0 +1,71 @@
local S = minetest.get_translator(minetest.get_current_modname())
-- Fish Buckets
local fish_names = {
["cod"] = "Cod",
["salmon"] = "Salmon",
["tropical_fish"] = "Tropical Fish",
["axolotl"] = "Axolotl",
--["pufferfish"] = "Pufferfish", --FIXME add pufferfish
}
local fishbucket_prefix = "mcl_buckets:bucket_"
local function on_place_fish(itemstack, placer, pointed_thing)
local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing)
if new_stack then
return new_stack
end
local pos = pointed_thing.above or pointed_thing.under
if not pos then return end
local n = minetest.get_node_or_nil(pos)
if n.name and minetest.registered_nodes[n.name].buildable_to or n.name == "mcl_portals:portal" then
local fish = itemstack:get_name():gsub(fishbucket_prefix,"")
if fish_names[fish] then
local o = minetest.add_entity(pos, "mobs_mc:" .. fish)
local props = itemstack:get_meta():get_string("properties")
if props ~= "" then
o:set_properties(minetest.deserialize(props))
end
local water = "mcl_core:water_source"
if n.name == "mclx_core:river_water_source" then
water = n.name
elseif n.name == "mclx_core:river_water_flowing" then
water = nil
end
if mcl_worlds.pos_to_dimension(pos) == "nether" then
water = nil
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true)
end
if water then
minetest.set_node(pos,{name = water})
end
if not placer or not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack = ItemStack("mcl_buckets:bucket_empty")
end
end
end
return itemstack
end
for techname, fishname in pairs(fish_names) do
minetest.register_craftitem(fishbucket_prefix .. techname, {
description = S("Bucket of @1", S(fishname)),
_doc_items_longdesc = S("This bucket is filled with water and @1.", S(fishname)),
_doc_items_usagehelp = S("Place it to empty the bucket and place a @1. Obtain by right clicking on a @2 with a bucket of water.", S(fishname), S(fishname)),
_tt_help = S("Places a water source and a @1.", S(fishname)),
inventory_image = techname .. "_bucket.png",
stack_max = 1,
groups = {bucket = 1, fish_bucket = 1},
liquids_pointable = false,
on_place = on_place_fish,
on_secondary_use = on_place_fish,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
return on_place_fish(stack, nil, {above=droppos})
end,
})
minetest.register_alias("mcl_fishing:bucket_" .. techname, "mcl_buckets:bucket_" .. techname)
end

View File

@ -160,7 +160,7 @@ local function on_place_bucket(itemstack, user, pointed_thing)
if not pointed_thing or pointed_thing.type ~= "node" then if not pointed_thing or pointed_thing.type ~= "node" then
return return
end end
-- Call on_rightclick if the pointed node defines it -- Call on_rightclick if the pointed node defines it
local new_stack = mcl_util.call_on_rightclick(itemstack, user, pointed_thing) local new_stack = mcl_util.call_on_rightclick(itemstack, user, pointed_thing)
if new_stack then if new_stack then
@ -202,7 +202,7 @@ local function on_place_bucket_empty(itemstack, user, pointed_thing)
if not use_select_box then if not use_select_box then
pointed_thing = bucket_get_pointed_thing(user) pointed_thing = bucket_get_pointed_thing(user)
end end
-- Must be pointing to node -- Must be pointing to node
if not pointed_thing or pointed_thing.type ~= "node" then if not pointed_thing or pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -358,3 +358,4 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
}) })
dofile(modpath.."/register.lua") dofile(modpath.."/register.lua")
dofile(modpath.."/fishbuckets.lua")

View File

@ -118,39 +118,3 @@ minetest.register_craft({
burntime = 1000, burntime = 1000,
replacements = {{"mcl_buckets:bucket_lava", "mcl_buckets:bucket_empty"}}, replacements = {{"mcl_buckets:bucket_lava", "mcl_buckets:bucket_empty"}},
}) })
-- Fish Buckets
fish_names = {
{ techname = "cod", name = "Cod" },
{ techname = "salmon", name = "Salmon" },
{ techname = "axolotl", name = "Axolotl" },
--{ techname = "pufferfish", name = "Pufferfish" } FIXME: Uncomment when pufferfish mobs are added.
{ techname = "tropical_fish", name = "Tropical Fish" }
}
for _, fish in pairs(fish_names) do
mcl_buckets.register_liquid({
bucketname = "mcl_buckets:bucket_" .. fish.techname,
source_place = function(pos)
minetest.add_entity(pos, "mobs_mc:" .. fish.techname)
return "mcl_core:water_source"
end,
source_take = {"mobs_mc:" .. fish.techname},
inventory_image = fish.techname .. "_bucket.png",
name = S("Bucket of @1", S(fish.name)),
longdesc = S("This bucket is filled with water and @1.", S(fish.name)),
usagehelp = S("Place it to empty the bucket and place a @1. Obtain by right clicking on a @2 with a bucket of water.", S(fish.name), S(fish.name)),
tt_help = S("Places a water source and a @1.", S(fish.name)),
extra_check = function(pos, placer)
local dim = mcl_worlds.pos_to_dimension(pos)
if dim == "nether" then
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true)
return false, true
else
return true, true
end
end,
})
minetest.register_alias("mcl_fishing:bucket_" .. fish.techname, "mcl_buckets:bucket_" .. fish.techname)
end