VoxeLibre/mods/ENTITIES/mobs_mc/snowman.lua

201 lines
6.4 KiB
Lua
Raw Normal View History

2017-07-05 03:15:46 +02:00
--MCmobs v0.4
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
local S = minetest.get_translator("mobs_mc")
2017-07-05 03:15:46 +02:00
local snow_trail_frequency = 0.5 -- Time in seconds for checking to add a new snow trail
2018-03-25 22:27:06 +02:00
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local mod_throwing = minetest.get_modpath("mcl_throwing") ~= nil
2018-03-25 22:27:06 +02:00
2018-05-30 13:28:22 +02:00
local gotten_texture = {
"mobs_mc_snowman.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
}
mcl_mobs.register_mob("mobs_mc:snowman", {
2021-04-25 17:30:15 +02:00
description = S("Snow Golem"),
2017-07-05 03:15:46 +02:00
type = "npc",
2020-04-11 02:46:03 +02:00
spawn_class = "passive",
2017-07-05 03:15:46 +02:00
passive = true,
hp_min = 4,
hp_max = 4,
pathfinding = 1,
view_range = 10,
fall_damage = 0,
water_damage = 4,
rain_damage = 4,
2020-08-05 18:33:53 +02:00
armor = { fleshy = 100, water_vulnerable = 100 },
2017-07-05 03:15:46 +02:00
attacks_monsters = true,
collisionbox = {-0.35, -0.01, -0.35, 0.35, 1.89, 0.35},
visual = "mesh",
mesh = "mobs_mc_snowman.b3d",
2020-12-06 23:32:54 +01:00
sounds = {
2020-12-07 00:06:20 +01:00
damage = { name = "mobs_mc_snowman_hurt", gain = 0.2 },
death = { name = "mobs_mc_snowman_death", gain = 0.25 },
2020-12-06 23:32:54 +01:00
distance = 16,
},
2017-07-05 03:15:46 +02:00
textures = {
2018-05-30 13:28:22 +02:00
"mobs_mc_snowman.png", --snowman texture
2018-07-09 23:33:32 +02:00
"farming_pumpkin_side.png", --top
2018-05-30 13:28:22 +02:00
"farming_pumpkin_top.png", --down
"farming_pumpkin_face.png", --front
"farming_pumpkin_side.png", --left
"farming_pumpkin_side.png", --right
2018-07-09 23:33:32 +02:00
"farming_pumpkin_top.png", --left
2017-07-05 03:15:46 +02:00
},
2018-05-30 13:28:22 +02:00
gotten_texture = gotten_texture,
2022-05-25 23:25:15 +02:00
drops = {{ name = "mcl_throwing:snowball", chance = 1, min = 0, max = 15 }},
2017-07-05 03:15:46 +02:00
visual_size = {x=3, y=3},
walk_velocity = 0.6,
run_velocity = 2,
jump = true,
makes_footstep_sound = true,
attack_type = "shoot",
2019-12-09 09:56:38 +01:00
arrow = "mcl_throwing:snowball_entity",
shoot_arrow = function(self, pos, dir)
if mod_throwing then
2019-12-09 11:03:48 +01:00
mcl_throwing.throw("mcl_throwing:snowball", pos, dir, nil, self.object)
2019-12-09 09:56:38 +01:00
end
end,
2017-07-05 03:15:46 +02:00
shoot_interval = 1,
shoot_offset = 1,
animation = {
2018-05-30 13:33:19 +02:00
stand_speed = 25,
walk_speed = 25,
run_speed = 50,
2017-07-05 03:15:46 +02:00
stand_start = 20,
stand_end = 40,
walk_start = 0,
walk_end = 20,
run_start = 0,
run_end = 20,
2017-08-06 14:09:25 +02:00
die_start = 40,
die_end = 50,
2020-12-05 03:52:08 +01:00
die_speed = 15,
2018-05-30 13:33:19 +02:00
die_loop = false,
2017-07-05 03:15:46 +02:00
},
do_custom = function(self, dtime)
2018-03-25 22:27:06 +02:00
if not mobs_griefing then
return
end
2017-07-05 03:15:46 +02:00
-- Leave a trail of top snow behind.
-- This is done in do_custom instead of just using replace_what because with replace_what,
-- the top snop may end up floating in the air.
if not self._snowtimer then
self._snowtimer = 0
return
end
self._snowtimer = self._snowtimer + dtime
if self.health > 0 and self._snowtimer > snow_trail_frequency then
self._snowtimer = 0
2019-02-01 06:33:07 +01:00
local pos = self.object:get_pos()
2017-07-05 03:15:46 +02:00
local below = {x=pos.x, y=pos.y-1, z=pos.z}
local def = minetest.registered_nodes[minetest.get_node(pos).name]
-- Node at snow golem's position must be replacable
if def and def.buildable_to then
-- Node below must be walkable
-- and a full cube (this prevents oddities like top snow on top snow, lower slabs, etc.)
local belowdef = minetest.registered_nodes[minetest.get_node(below).name]
if belowdef and belowdef.walkable and (belowdef.node_box == nil or belowdef.node_box.type == "regular") then
-- Place top snow
2022-05-25 23:25:15 +02:00
minetest.set_node(pos, {name = "mcl_core:snow"})
2017-07-05 03:15:46 +02:00
end
end
end
end,
-- Remove pumpkin if using shears
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
2023-08-14 02:39:31 +02:00
if self.gotten ~= true and minetest.get_item_group(item:get_name(), "shears") > 0 then
2017-07-05 03:15:46 +02:00
-- Remove pumpkin
self.gotten = true
self.object:set_properties({
2018-05-30 13:28:22 +02:00
textures = gotten_texture,
2017-07-05 03:15:46 +02:00
})
2019-02-01 06:33:07 +01:00
local pos = self.object:get_pos()
2020-12-06 01:21:02 +01:00
minetest.sound_play("mcl_tools_shears_cut", {pos = pos}, true)
2017-07-05 03:15:46 +02:00
if minetest.registered_items["mcl_farming:pumpkin_face"] then
minetest.add_item({x=pos.x, y=pos.y+1.4, z=pos.z}, "mcl_farming:pumpkin_face")
end
2017-07-05 03:15:46 +02:00
-- Wear out
2020-07-10 16:08:40 +02:00
if not minetest.is_creative_enabled(clicker:get_player_name()) then
2022-05-25 23:25:15 +02:00
item:add_wear(mobs_mc.shears_wear)
2017-07-05 03:15:46 +02:00
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
end
end
end,
})
2020-08-19 18:31:45 +02:00
local summon_particles = function(obj)
local lua = obj:get_luaentity()
local min = {x=lua.collisionbox[1], y=lua.collisionbox[2], z=lua.collisionbox[3]}
local max = {x=lua.collisionbox[4], y=lua.collisionbox[5], z=lua.collisionbox[6]}
local pos = obj:get_pos()
minetest.add_particlespawner({
amount = 60,
time = 0.1,
minpos = vector.add(pos, min),
maxpos = vector.add(pos, max),
minvel = {x = -0.1, y = -0.1, z = -0.1},
maxvel = {x = 0.1, y = 0.1, z = 0.1},
minexptime = 1.0,
maxexptime = 2.0,
minsize = 2.0,
maxsize = 3.0,
2020-08-19 18:47:58 +02:00
texture = "mcl_particles_smoke.png",
2020-08-19 18:31:45 +02:00
})
end
2017-07-05 03:15:46 +02:00
-- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
-- of the node.
-- This summons a snow golen when pos is next to a row of two snow blocks.
2022-05-25 23:25:15 +02:00
function mobs_mc.check_snow_golem_summon(pos)
2017-07-05 03:15:46 +02:00
local checks = {
-- These are the possible placement patterns
-- { snow block pos. 1, snow block pos. 2, snow golem spawn position }
{ {x=pos.x, y=pos.y-1, z=pos.z}, {x=pos.x, y=pos.y-2, z=pos.z}, {x=pos.x, y=pos.y-2.5, z=pos.z} },
{ {x=pos.x, y=pos.y+1, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x+1, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z-2}, {x=pos.x, y=pos.y-0.5, z=pos.z-2} },
{ {x=pos.x, y=pos.y, z=pos.z+1}, {x=pos.x, y=pos.y, z=pos.z+2}, {x=pos.x, y=pos.y-0.5, z=pos.z+2} },
}
for c=1, #checks do
local b1 = checks[c][1]
local b2 = checks[c][2]
local place = checks[c][3]
local b1n = minetest.get_node(b1)
local b2n = minetest.get_node(b2)
2022-05-25 23:25:15 +02:00
if b1n.name == "mcl_core:snowblock" and b2n.name == "mcl_core:snowblock" then
2017-07-05 03:15:46 +02:00
-- Remove the pumpkin and both snow blocks and summon the snow golem
minetest.remove_node(pos)
minetest.remove_node(b1)
minetest.remove_node(b2)
core.check_for_falling(pos)
core.check_for_falling(b1)
core.check_for_falling(b2)
2020-08-19 18:31:45 +02:00
local obj = minetest.add_entity(place, "mobs_mc:snowman")
if obj then
summon_particles(obj)
end
2017-07-05 03:15:46 +02:00
break
end
end
end
-- Spawn egg
mcl_mobs.register_egg("mobs_mc:snowman", S("Snow Golem"), "#f2f2f2", "#fd8f47", 0)
mcl_mobs:non_spawn_specific("mobs_mc:snowman","overworld",0,minetest.LIGHT_MAX+1)