0
0
Fork 0

Snow golems use mcl_throwing snowball

This commit is contained in:
Wuzzy 2019-12-09 11:03:48 +01:00
parent e2fb3a562d
commit 9e31c2b62b
3 changed files with 71 additions and 12 deletions

View File

@ -55,7 +55,7 @@ mobs:register_mob("mobs_mc:snowman", {
arrow = "mcl_throwing:snowball_entity",
shoot_arrow = function(self, pos, dir)
if mod_throwing then
mcl_throwing.throw("mcl_throwing:snowball", pos, dir)
mcl_throwing.throw("mcl_throwing:snowball", pos, dir, nil, self.object)
end
end,
shoot_interval = 1,

View File

@ -146,8 +146,7 @@ local fish = function(itemstack, player)
if noent == true then
local playerpos = player:get_pos()
local dir = player:get_look_dir()
local obj = mcl_throwing.throw("mcl_throwing:flying_bobber", {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, 15)
obj:get_luaentity()._thrower = player:get_player_name()
local obj = mcl_throwing.throw("mcl_throwing:flying_bobber", {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, 15, player:get_player_name())
end
end

View File

@ -24,7 +24,7 @@ local velocities = {
["mcl_throwing:ender_pearl_entity"] = 22,
}
mcl_throwing.throw = function(throw_item, pos, dir, velocity)
mcl_throwing.throw = function(throw_item, pos, dir, velocity, thrower)
if velocity == nil then
velocity = velocities[throw_item]
end
@ -36,16 +36,18 @@ mcl_throwing.throw = function(throw_item, pos, dir, velocity)
local obj = minetest.add_entity(pos, entity_mapping[itemstring])
obj:set_velocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity})
obj:set_acceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
if thrower then
obj:get_luaentity()._thrower = thrower
end
return obj
end
-- Throw item
local throw_function = function(entity_name, velocity)
local player_throw_function = function(entity_name, velocity)
local func = function(item, player, pointed_thing)
local playerpos = player:get_pos()
local dir = player:get_look_dir()
local obj = mcl_throwing.throw(item, {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, velocity)
obj:get_luaentity()._thrower = player:get_player_name()
local obj = mcl_throwing.throw(item, {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, velocity, player:get_player_name())
if not minetest.settings:get_bool("creative_mode") then
item:take_item()
end
@ -62,9 +64,14 @@ end
-- Staticdata handling because objects may want to be reloaded
local get_staticdata = function(self)
local thrower
-- Only save thrower if it's a player name
if type(self._thrower) == "string" then
thrower = self._thrower
end
local data = {
_lastpos = self._lastpos,
_thrower = self._thrower,
_thrower = thrower,
}
return minetest.serialize(data)
end
@ -88,6 +95,7 @@ local snowball_ENTITY={
get_staticdata = get_staticdata,
on_activate = on_activate,
_thrower = nil,
_lastpos={},
}
@ -101,6 +109,7 @@ local egg_ENTITY={
get_staticdata = get_staticdata,
on_activate = on_activate,
_thrower = nil,
_lastpos={},
}
@ -136,6 +145,38 @@ local flying_bobber_ENTITY={
objtype="fishing",
}
local check_object_hit = function(self, pos, mob_damage)
for _,object in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
local entity = object:get_luaentity()
if entity
and entity.name ~= self.object:get_luaentity().name then
if object:is_player() and self._thrower ~= object:get_player_name() then
-- TODO: Deal knockback
self.object:remove()
return true
elseif entity._cmi_is_mob == true and (self._thrower ~= object) then
local dmg = {}
if mob_damage then
dmg = mob_damage(entity.name)
end
-- FIXME: Knockback is broken
object:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = dmg,
}, nil)
self.object:remove()
return true
end
end
end
return false
end
-- Snowball on_step()--> called when snowball is moving.
local snowball_on_step = function(self, dtime)
self.timer=self.timer+dtime
@ -150,6 +191,19 @@ local snowball_on_step = function(self, dtime)
return
end
end
local mob_damage = function(mobname)
if mobname == "mobs_mc:blaze" then
return {fleshy = 3}
else
return {}
end
end
if check_object_hit(self, pos, mob_damage) then
return
end
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set _lastpos-->Node will be added at last pos outside the node
end
@ -160,7 +214,7 @@ local egg_on_step = function(self, dtime)
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
-- Destroy when hitting a solid node
-- Destroy when hitting a solid node with chance to spawn chicks
if self._lastpos.x~=nil then
if (def and def.walkable) or not def then
-- 1/8 chance to spawn a chick
@ -204,6 +258,12 @@ local egg_on_step = function(self, dtime)
return
end
end
-- Destroy when hitting a mob or player (no chick spawning)
if check_object_hit(self, pos) then
return
end
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
end
@ -347,7 +407,7 @@ minetest.register_craftitem("mcl_throwing:snowball", {
inventory_image = "mcl_throwing_snowball.png",
stack_max = 16,
groups = { weapon_ranged = 1 },
on_use = throw_function("mcl_throwing:snowball_entity"),
on_use = player_throw_function("mcl_throwing:snowball_entity"),
_on_dispense = dispense_function,
})
@ -358,7 +418,7 @@ minetest.register_craftitem("mcl_throwing:egg", {
_doc_items_usagehelp = how_to_throw,
inventory_image = "mcl_throwing_egg.png",
stack_max = 16,
on_use = throw_function("mcl_throwing:egg_entity"),
on_use = player_throw_function("mcl_throwing:egg_entity"),
_on_dispense = dispense_function,
groups = { craftitem = 1 },
})
@ -371,7 +431,7 @@ minetest.register_craftitem("mcl_throwing:ender_pearl", {
wield_image = "mcl_throwing_ender_pearl.png",
inventory_image = "mcl_throwing_ender_pearl.png",
stack_max = 16,
on_use = throw_function("mcl_throwing:ender_pearl_entity"),
on_use = player_throw_function("mcl_throwing:ender_pearl_entity"),
groups = { transport = 1 },
})