Address most of kno10's comments about mcl_utils/node.lua and a couple others, fix lingering potion sound

This commit is contained in:
teknomunk 2024-09-08 14:34:12 -05:00
parent 0cd074104a
commit a29c267d52
4 changed files with 34 additions and 67 deletions

View File

@ -50,9 +50,6 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
local above = pointed_thing.above local above = pointed_thing.above
local under = pointed_thing.under local under = pointed_thing.under
local is_x = (above.x ~= under.x)
local is_y = (above.y ~= under.y)
local is_z = (above.z ~= under.z)
local anode = minetest.get_node_or_nil(above) local anode = minetest.get_node_or_nil(above)
if not anode then if not anode then
@ -77,11 +74,11 @@ function mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing, infini
end end
local p2 local p2
if is_y then if above.y ~= under.y then
p2 = 0 p2 = 0
elseif is_x then elseif above.x ~= under.x then
p2 = 12 p2 = 12
elseif is_z then elseif above.z ~= under.z then
p2 = 6 p2 = 6
end end
minetest.set_node(pos, {name = wield_name, param2 = p2}) minetest.set_node(pos, {name = wield_name, param2 = p2})
@ -108,26 +105,16 @@ end
-- * param2: param2 of that node -- * param2: param2 of that node
-- * side: Which "half" the investigated node is. "left" or "right" -- * side: Which "half" the investigated node is. "left" or "right"
function mcl_util.get_double_container_neighbor_pos(pos, param2, side) function mcl_util.get_double_container_neighbor_pos(pos, param2, side)
if side == "right" then local sign = (side == "right" and 1 or -1)
if param2 == 0 then
return vector.offset(pos, -1, 0, 0) if param2 == 0 then
elseif param2 == 1 then return vector.offset(pos, -sign, 0, 0)
return vector.offset(pos, 0, 0, 1) elseif param2 == 1 then
elseif param2 == 2 then return vector.offset(pos, 0, 0, sign)
return vector.offset(pos, 1, 0, 0) elseif param2 == 2 then
elseif param2 == 3 then return vector.offset(pos, sign, 0, 0)
return vector.offset(pos, 0, 0, -1) elseif param2 == 3 then
end return vector.offset(pos, 0, 0, -sign)
else
if param2 == 0 then
return vector.offset(pos, 1, 0, 0)
elseif param2 == 1 then
return vector.offset(pos, 0, 0, -1)
elseif param2 == 2 then
return vector.offset(pos, -1, 0, 0)
elseif param2 == 3 then
return vector.offset(pos, 0, 0, 1)
end
end end
end end
@ -147,9 +134,11 @@ function mcl_util.generate_on_place_plant_function(condition)
-- Call on_rightclick if the pointed node defines it -- Call on_rightclick if the pointed node defines it
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)
local node_def = minetest.registered_nodes[node.name]
if placer and not placer:get_player_control().sneak then if placer and not placer:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then if node_def and node_def.on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack return node_def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end end
end end
@ -194,10 +183,6 @@ end
---@param func fun(node_name: string): boolean Return `true` if node must not replace the buildable_to node which have `node_name` ---@param func fun(node_name: string): boolean Return `true` if node must not replace the buildable_to node which have `node_name`
---@return fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: pointed_thing, param2: integer): ItemStack? ---@return fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: pointed_thing, param2: integer): ItemStack?
function mcl_util.bypass_buildable_to(func) function mcl_util.bypass_buildable_to(func)
--------------------------
-- MINETEST CODE: UTILS --
--------------------------
local function copy_pointed_thing(pointed_thing) local function copy_pointed_thing(pointed_thing)
return { return {
type = pointed_thing.type, type = pointed_thing.type,
@ -256,16 +241,11 @@ function mcl_util.bypass_buildable_to(func)
local p2 = vector.add(p, d) local p2 = vector.add(p, d)
local nn = core.get_node(p2).name local nn = core.get_node(p2).name
local def2 = core.registered_nodes[nn] local def2 = core.registered_nodes[nn]
if def2 and not def2.walkable then
return false return not def2 or def2.walkable
end
return true
end end
return function(itemstack, placer, pointed_thing, param2) return function(itemstack, placer, pointed_thing, param2)
-------------------
-- MINETEST CODE --
-------------------
local def = itemstack:get_definition() local def = itemstack:get_definition()
if def.type ~= "node" or pointed_thing.type ~= "node" then if def.type ~= "node" or pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -284,10 +264,8 @@ function mcl_util.bypass_buildable_to(func)
return itemstack return itemstack
end end
local olddef_under = minetest.registered_nodes[oldnode_under.name] local olddef_under = minetest.registered_nodes[oldnode_under.name] or minetest.nodedef_default
olddef_under = olddef_under or minetest.nodedef_default local olddef_above = minetest.registered_nodes[oldnode_above.name] or minetest.nodedef_default
local olddef_above = minetest.registered_nodes[oldnode_above.name]
olddef_above = olddef_above or minetest.nodedef_default
if not olddef_above.buildable_to and not olddef_under.buildable_to then if not olddef_above.buildable_to and not olddef_under.buildable_to then
log("info", playername .. " tried to place" log("info", playername .. " tried to place"
@ -296,10 +274,6 @@ function mcl_util.bypass_buildable_to(func)
return itemstack return itemstack
end end
---------------------
-- CUSTOMIZED CODE --
---------------------
-- Place above pointed node -- Place above pointed node
local place_to = vector.copy(above) local place_to = vector.copy(above)
@ -309,10 +283,6 @@ function mcl_util.bypass_buildable_to(func)
place_to = vector.copy(under) place_to = vector.copy(under)
end end
-------------------
-- MINETEST CODE --
-------------------
if minetest.is_protected(place_to, playername) then if minetest.is_protected(place_to, playername) then
log("action", playername log("action", playername
.. " tried to place " .. def.name .. " tried to place " .. def.name
@ -330,8 +300,7 @@ function mcl_util.bypass_buildable_to(func)
newnode.param2 = def.place_param2 newnode.param2 = def.place_param2
elseif (def.paramtype2 == "wallmounted" or elseif (def.paramtype2 == "wallmounted" or
def.paramtype2 == "colorwallmounted") and not param2 then def.paramtype2 == "colorwallmounted") and not param2 then
local dir = vector.subtract(under, above) newnode.param2 = minetest.dir_to_wallmounted(vector.subtract(under, above))
newnode.param2 = minetest.dir_to_wallmounted(dir)
-- Calculate the direction for furnaces and chests and stuff -- Calculate the direction for furnaces and chests and stuff
elseif (def.paramtype2 == "facedir" or elseif (def.paramtype2 == "facedir" or
def.paramtype2 == "colorfacedir" or def.paramtype2 == "colorfacedir" or
@ -339,8 +308,7 @@ function mcl_util.bypass_buildable_to(func)
def.paramtype2 == "color4dir") and not param2 then def.paramtype2 == "color4dir") and not param2 then
local placer_pos = placer and placer:get_pos() local placer_pos = placer and placer:get_pos()
if placer_pos then if placer_pos then
local dir = vector.subtract(above, placer_pos) newnode.param2 = minetest.dir_to_facedir(vector.subtract(above, placer_pos))
newnode.param2 = minetest.dir_to_facedir(dir)
log("info", "facedir: " .. newnode.param2) log("info", "facedir: " .. newnode.param2)
end end
end end
@ -423,20 +391,20 @@ function mcl_util.bypass_buildable_to(func)
end end
end end
local palette_indexes = {grass_palette_index = 0, foliage_palette_index = 0, water_palette_index = 0} local DEFAULT_PALETTE_INDEXES = {grass_palette_index = 0, foliage_palette_index = 0, water_palette_index = 0}
function mcl_util.get_palette_indexes_from_pos(pos) function mcl_util.get_palette_indexes_from_pos(pos)
local biome_data = minetest.get_biome_data(pos) local biome_data = minetest.get_biome_data(pos)
local biome = biome_data.biome local biome = biome_data.biome
local biome_name = minetest.get_biome_name(biome) local biome_name = minetest.get_biome_name(biome)
local reg_biome = minetest.registered_biomes[biome_name] local reg_biome = minetest.registered_biomes[biome_name]
if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index and reg_biome._mcl_water_palette_index then if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index and reg_biome._mcl_water_palette_index then
local gpi = reg_biome._mcl_grass_palette_index return {
local fpi = reg_biome._mcl_foliage_palette_index grass_palette_index = reg_biome._mcl_grass_palette_index,
local wpi = reg_biome._mcl_water_palette_index foliage_palette_index = reg_biome._mcl_foliage_palette_index,
local palette_indexes = {grass_palette_index = gpi, foliage_palette_index = fpi, water_palette_index = wpi} water_palette_index = reg_biome._mcl_water_palette_index,
return palette_indexes }
else else
return palette_indexes return DEFAULT_PALETTE_INDEXES
end end
end end

View File

@ -310,8 +310,8 @@ local arrow_entity = {
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 20, amount = 20,
time = .2, time = .2,
minpos = vector.new(0,0,0), minpos = vector.zero(),
maxpos = vector.new(0,0,0), maxpos = vector.zero(),
minvel = vector.new(-0.1,-0.1,-0.1), minvel = vector.new(-0.1,-0.1,-0.1),
maxvel = vector.new(0.1,0.1,0.1), maxvel = vector.new(0.1,0.1,0.1),
minexptime = 0.5, minexptime = 0.5,

View File

@ -220,7 +220,7 @@ function mcl_potions.register_lingering(name, descr, color, def)
on_collide(self, pos) on_collide(self, pos)
end, end,
sounds = { sounds = {
{"mcl_potions_breaking_glass", {max_hear_distance = 16, gain = 1}}, on_collision = {"mcl_potions_breaking_glass", {max_hear_distance = 16, gain = 1}},
}, },
}, },
}) })

View File

@ -67,9 +67,8 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
local v = self.object:get_velocity() local v = self.object:get_velocity()
if node_def and node_def.walkable then if node_def and node_def.walkable then
local vc = table.copy(v) -- vector for calculating local vc = vector.normalize(v) -- vector for calculating
-- Node is walkable, we have to find a place somewhere outside of that node -- Node is walkable, we have to find a place somewhere outside of that node
vc = vector.normalize(vc)
-- Zero-out the two axes with a lower absolute value than the axis with the strongest force -- Zero-out the two axes with a lower absolute value than the axis with the strongest force
local lv, ld = math.abs(vc.y), "y" local lv, ld = math.abs(vc.y), "y"