mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
a620d24ec8
Fixes: #3913 #3915 ~~You can reproduce the crash by placing a fish bucket on top snow above an unknown node. I also noticed that the code always uses pointed_thing.above so I fixed that and also added a function to mcl_utils to figure out where a node should be placed (either above or below). Looks like the rest of the code could also use improvement but at least it does not crash now.~~ Cora fixed a bunch of related crashes in Mineclona so I am replacing my commit and cherry picking all her commits here. https://codeberg.org/mineclonia/mineclonia/pulls/549 Here is the list of fixes from that PR: - Crash when placing snow layer on unknown nodes - Crash when snow layers on unknown nodes are flooded - Crash when placing fishbucket on snow on top of unknown nodes - Crash when placing chorus flower and stem on unknown - Crash when placing mob spawners on unknown - The fishbucket on place to actually replace buildable_to Co-authored-by: cora <coradelamouche@gmx.ch> Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3914 Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me> Co-authored-by: 𝕵𝖔𝖍𝖆𝖓𝖓𝖊𝖘 𝕱𝖗𝖎𝖙𝖟 <mrrar@noreply.git.minetest.land> Co-committed-by: 𝕵𝖔𝖍𝖆𝖓𝖓𝖊𝖘 𝕱𝖗𝖎𝖙𝖟 <mrrar@noreply.git.minetest.land>
80 lines
2.7 KiB
Lua
80 lines
2.7 KiB
Lua
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
|
|
|
|
if pointed_thing.type ~= "node" then return end
|
|
|
|
local pos = pointed_thing.above
|
|
local n = minetest.get_node(pointed_thing.above)
|
|
local def = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
|
|
|
|
if ( def and def.buildable_to ) or n.name == "mcl_portals:portal" then
|
|
pos = pointed_thing.under
|
|
n = minetest.get_node(pointed_thing.under)
|
|
end
|
|
|
|
local fish = itemstack:get_definition()._mcl_buckets_fish
|
|
if fish_names[fish] then
|
|
local o = minetest.add_entity(pos, "mobs_mc:" .. fish)
|
|
if o and o:get_pos() then
|
|
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 = "mcl_buckets_" .. techname .. "_bucket.png",
|
|
stack_max = 1,
|
|
groups = {bucket = 1, fish_bucket = 1},
|
|
liquids_pointable = false,
|
|
_mcl_buckets_fish = techname,
|
|
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
|