mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-11 12:13:15 +01:00
Fix player-mcl_throwing collisions, fix chick spawning on egg collisions, luacheck fixes
This commit is contained in:
parent
9b91012854
commit
e20da5d2d4
@ -17,6 +17,24 @@ minetest.register_craftitem("mcl_throwing:egg", {
|
|||||||
groups = { craftitem = 1 },
|
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",{
|
minetest.register_entity("mcl_throwing:egg_entity",{
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer=0,
|
||||||
@ -34,24 +52,22 @@ minetest.register_entity("mcl_throwing:egg_entity",{
|
|||||||
_vl_projectile = {
|
_vl_projectile = {
|
||||||
behaviors = {
|
behaviors = {
|
||||||
vl_projectile.collides_with_solids,
|
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)
|
on_collide_with_solid = function(self, pos, node)
|
||||||
if mod_target and node.name == "mcl_target:target_off" then
|
if mod_target and node.name == "mcl_target:target_off" then
|
||||||
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 1/8 chance to spawn a chick
|
egg_spawn_chicks(pos)
|
||||||
-- FIXME: Chicks have a quite good chance to spawn in walls
|
end,
|
||||||
if math.random(1,8) ~= 1 then return end
|
on_collide_with_entity = function(self, pos, obj)
|
||||||
|
egg_spawn_chicks(pos)
|
||||||
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")
|
|
||||||
end,
|
end,
|
||||||
sounds = {
|
sounds = {
|
||||||
on_collision = {"mcl_throwing_egg_impact", {max_hear_distance=10, gain=0.5}, true}
|
on_collision = {"mcl_throwing_egg_impact", {max_hear_distance=10, gain=0.5}, true}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
local math = math
|
local math = math
|
||||||
@ -21,31 +20,7 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", {
|
|||||||
groups = { transport = 1 },
|
groups = { transport = 1 },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Ender pearl entity
|
function on_collide(self, pos, node)
|
||||||
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)
|
|
||||||
if mod_target and node.name == "mcl_target:target_off" then
|
if mod_target and node.name == "mcl_target:target_off" then
|
||||||
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
||||||
end
|
end
|
||||||
@ -123,6 +98,41 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{
|
|||||||
minetest.add_entity(oldpos, "mobs_mc:endermite")
|
minetest.add_entity(oldpos, "mobs_mc:endermite")
|
||||||
end
|
end
|
||||||
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)
|
mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local S = minetest.get_translator(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.")
|
local how_to_throw = S("Use the punch key to throw.")
|
||||||
|
|
||||||
-- Snowball
|
-- Snowball
|
||||||
@ -54,8 +55,11 @@ vl_projectile.register("mcl_throwing:snowball_entity", {
|
|||||||
vl_projectile.collides_with_entities,
|
vl_projectile.collides_with_entities,
|
||||||
},
|
},
|
||||||
allow_punching = function(self, _, _, object)
|
allow_punching = function(self, _, _, object)
|
||||||
return object.is_mob or object._hittable_by_projectile or
|
if self._owner == object:get_player_name() then
|
||||||
not object:is_player() or self._owner ~= object:get_player_name()
|
return self.timer > 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return object.is_mob or object._hittable_by_projectile or object:is_player()
|
||||||
end,
|
end,
|
||||||
on_collide_with_solid = function(self, pos, node)
|
on_collide_with_solid = function(self, pos, node)
|
||||||
if mod_target and node.name == "mcl_target:target_off" then
|
if mod_target and node.name == "mcl_target:target_off" then
|
||||||
|
Loading…
Reference in New Issue
Block a user