Fix player-mcl_throwing collisions, fix chick spawning on egg collisions, luacheck fixes

This commit is contained in:
teknomunk 2024-09-22 07:04:20 -05:00
parent 0f75387cc8
commit 0db975c39f
3 changed files with 122 additions and 92 deletions

View file

@ -17,6 +17,24 @@ minetest.register_craftitem("mcl_throwing:egg", {
groups = { craftitem = 1 },
})
local function egg_spawn_chicks(pos)
-- 1/8 chance to spawn a chick
if math.random(1,8) ~= 1 then return end
pos.y = math.ceil(pos.y)
if not mcl_mobs.spawn_child(pos, "mobs_mc:chicken") then
minetest.log("unable to spawn chick at "..vector.to_string(pos))
end
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
if math.random(1,32) ~= 1 then return end
mcl_mobs.spawn_child(vector.offset(pos, 0.7, 0, 0 ), "mobs_mc:chicken")
mcl_mobs.spawn_child(vector.offset(pos, -0.7, 0, -0.7), "mobs_mc:chicken")
mcl_mobs.spawn_child(vector.offset(pos, -0.7, 0, 0.7), "mobs_mc:chicken")
end
minetest.register_entity("mcl_throwing:egg_entity",{
physical = false,
timer=0,
@ -34,24 +52,22 @@ minetest.register_entity("mcl_throwing:egg_entity",{
_vl_projectile = {
behaviors = {
vl_projectile.collides_with_solids,
vl_projectile.collides_with_entities,
},
allow_punching = function(self, _, _, object)
if self._owner == object:get_player_name() then
return self.timer > 1
end
end,
on_collide_with_solid = function(self, pos, node)
if mod_target and node.name == "mcl_target:target_off" then
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
end
-- 1/8 chance to spawn a chick
-- FIXME: Chicks have a quite good chance to spawn in walls
if math.random(1,8) ~= 1 then return end
mcl_mobs.spawn_child(pos, "mobs_mc:chicken")
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
if math.random(1,32) ~= 1 then return end
mcl_mobs.spawn_child(vector.offset(pos, 0.7, 0, 0 ), "mobs_mc:chicken")
mcl_mobs.spawn_child(vector.offset(pos, -0.7, 0, -0.7), "mobs_mc:chicken")
mcl_mobs.spawn_child(vector.offset(pos, -0.7, 0, 0.7), "mobs_mc:chicken")
egg_spawn_chicks(pos)
end,
on_collide_with_entity = function(self, pos, obj)
egg_spawn_chicks(pos)
end,
sounds = {
on_collision = {"mcl_throwing_egg_impact", {max_hear_distance=10, gain=0.5}, true}

View file

@ -1,5 +1,4 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local S = minetest.get_translator(modname)
local math = math
@ -21,31 +20,7 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", {
groups = { transport = 1 },
})
-- Ender pearl entity
vl_projectile.register("mcl_throwing:ender_pearl_entity",{
physical = false,
timer=0,
textures = {"mcl_throwing_ender_pearl.png"},
visual_size = {x=0.9, y=0.9},
collisionbox = {0,0,0,0,0,0},
pointable = false,
get_staticdata = mcl_throwing.get_staticdata,
on_activate = mcl_throwing.on_activate,
on_step = vl_projectile.update_projectile,
_lastpos={},
_thrower = nil, -- Player ObjectRef of the player who threw the ender pearl
_vl_projectile = {
behaviors = {
vl_projectile.collides_with_solids,
},
collides_with = {
"mcl_core:vine", "mcl_core:deadbush",
"group:flower", "group:sapling",
"group:plant", "group:mushroom",
},
on_collide_with_solid = function(self, pos, node)
function on_collide(self, pos, node)
if mod_target and node.name == "mcl_target:target_off" then
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
end
@ -122,7 +97,42 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
if math.random(1,20) == 1 then
minetest.add_entity(oldpos, "mobs_mc:endermite")
end
end
-- Ender pearl entity
vl_projectile.register("mcl_throwing:ender_pearl_entity",{
physical = false,
timer=0,
textures = {"mcl_throwing_ender_pearl.png"},
visual_size = {x=0.9, y=0.9},
collisionbox = {0,0,0,0,0,0},
pointable = false,
get_staticdata = mcl_throwing.get_staticdata,
on_activate = mcl_throwing.on_activate,
on_step = vl_projectile.update_projectile,
_lastpos={},
_thrower = nil, -- Player ObjectRef of the player who threw the ender pearl
_vl_projectile = {
behaviors = {
vl_projectile.collides_with_solids,
vl_projectile.collides_with_entities,
},
collides_with = {
"mcl_core:vine", "mcl_core:deadbush",
"group:flower", "group:sapling",
"group:plant", "group:mushroom",
},
allow_punching = function(self, _, _, object)
if self._owner == object:get_player_name() then
return self.timer > 1
end
end,
on_collide_with_entity = function(self, pos, entity)
on_collide(self, pos, minetest.get_node(pos))
end,
on_collide_with_solid = on_collide,
},
})
mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22)

View file

@ -1,6 +1,7 @@
local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local mod_target = minetest.get_modpath("mcl_target")
local how_to_throw = S("Use the punch key to throw.")
-- Snowball
@ -54,8 +55,11 @@ vl_projectile.register("mcl_throwing:snowball_entity", {
vl_projectile.collides_with_entities,
},
allow_punching = function(self, _, _, object)
return object.is_mob or object._hittable_by_projectile or
not object:is_player() or self._owner ~= object:get_player_name()
if self._owner == object:get_player_name() then
return self.timer > 1
end
return object.is_mob or object._hittable_by_projectile or object:is_player()
end,
on_collide_with_solid = function(self, pos, node)
if mod_target and node.name == "mcl_target:target_off" then