2017-07-05 01:15:46 +00:00
|
|
|
--MCmobs v0.4
|
|
|
|
--maikerumine
|
|
|
|
--made for MC like Survival game
|
|
|
|
--License for code WTFPL and otherwise stated in readmes
|
|
|
|
|
2022-02-13 20:40:12 +00:00
|
|
|
local S = minetest.get_translator("mobs_mc")
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
--###################
|
|
|
|
--################### IRON GOLEM
|
|
|
|
--###################
|
|
|
|
|
2022-05-20 21:43:19 +00:00
|
|
|
local etime = 0
|
2017-07-05 01:15:46 +00:00
|
|
|
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs:register_mob("mobs_mc:iron_golem", {
|
2021-04-25 15:30:15 +00:00
|
|
|
description = S("Iron Golem"),
|
2017-07-05 01:15:46 +00:00
|
|
|
type = "npc",
|
2020-04-11 00:46:03 +00:00
|
|
|
spawn_class = "passive",
|
2017-07-05 01:15:46 +00:00
|
|
|
passive = true,
|
|
|
|
hp_min = 100,
|
2021-05-23 13:10:20 +00:00
|
|
|
hp_max = 100,
|
2019-10-02 16:31:16 +00:00
|
|
|
breath_max = -1,
|
2017-07-05 01:15:46 +00:00
|
|
|
collisionbox = {-0.7, -0.01, -0.7, 0.7, 2.69, 0.7},
|
|
|
|
visual = "mesh",
|
|
|
|
mesh = "mobs_mc_iron_golem.b3d",
|
|
|
|
textures = {
|
|
|
|
{"mobs_mc_iron_golem.png"},
|
|
|
|
},
|
|
|
|
visual_size = {x=3, y=3},
|
|
|
|
makes_footstep_sound = true,
|
2018-09-14 14:27:58 +00:00
|
|
|
-- TODO: sounds
|
2017-07-05 01:15:46 +00:00
|
|
|
view_range = 16,
|
|
|
|
stepheight = 1.1,
|
|
|
|
owner = "",
|
|
|
|
order = "follow",
|
|
|
|
floats = 0,
|
|
|
|
walk_velocity = 0.6,
|
|
|
|
run_velocity = 1.2,
|
|
|
|
-- Approximation
|
|
|
|
damage = 14,
|
2022-06-07 07:55:19 +00:00
|
|
|
knock_back = false,
|
2017-07-25 22:26:18 +00:00
|
|
|
reach = 3,
|
2017-07-05 01:15:46 +00:00
|
|
|
group_attack = true,
|
|
|
|
attacks_monsters = true,
|
2022-02-13 20:40:12 +00:00
|
|
|
attack_type = "dogfight",
|
2022-05-20 22:37:20 +00:00
|
|
|
_got_poppy = false,
|
2022-05-20 21:43:19 +00:00
|
|
|
pick_up = {"mcl_flowers:poppy"},
|
2022-05-20 22:37:20 +00:00
|
|
|
on_pick_up = function(self,n)
|
|
|
|
if n.itemstring:find("mcl_flowers:poppy") then
|
|
|
|
if not self._got_poppy then
|
|
|
|
self._got_poppy=true
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
replace_what = {"mcl_flowers:poppy"},
|
|
|
|
replace_with = {"air"},
|
|
|
|
on_replace = function(self, pos, oldnode, newnode)
|
|
|
|
if not self.got_poppy and oldnode.name == "mcl_flowers:poppy" then
|
|
|
|
self._got_poppy=true
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end,
|
2017-07-05 01:15:46 +00:00
|
|
|
drops = {
|
2022-05-25 21:25:15 +00:00
|
|
|
{name = "mcl_core:iron_ingot",
|
2017-07-05 01:15:46 +00:00
|
|
|
chance = 1,
|
|
|
|
min = 3,
|
|
|
|
max = 5,},
|
2022-05-25 21:25:15 +00:00
|
|
|
{name = "mcl_flowers:poppy",
|
2017-07-05 01:15:46 +00:00
|
|
|
chance = 1,
|
|
|
|
min = 0,
|
|
|
|
max = 2,},
|
|
|
|
},
|
|
|
|
fall_damage = 0,
|
|
|
|
animation = {
|
|
|
|
stand_speed = 15, walk_speed = 15, run_speed = 25, punch_speed = 15,
|
|
|
|
stand_start = 0, stand_end = 0,
|
|
|
|
walk_start = 0, walk_end = 40,
|
|
|
|
run_start = 0, run_end = 40,
|
|
|
|
punch_start = 40, punch_end = 50,
|
|
|
|
},
|
|
|
|
jump = true,
|
2022-05-20 21:43:19 +00:00
|
|
|
on_step = function(self,dtime)
|
|
|
|
etime = etime + dtime
|
|
|
|
if etime > 10 then
|
|
|
|
if self._home and vector.distance(self._home,self.object:get_pos()) > 50 then
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs:gopath(self,self._home)
|
2022-05-20 21:43:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
2017-07-05 01:15:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- spawn eggs
|
2022-10-02 15:50:43 +00:00
|
|
|
mcl_mobs:register_egg("mobs_mc:iron_golem", S("Iron Golem"), "(spawn_egg.png^[multiply:#3b3b3b)^(spawn_egg_overlay.png^[multiply:#f57223)", 0)
|
2017-07-05 01:15:46 +00: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 an iron golen if placing the pumpkin created an iron golem summon pattern:
|
|
|
|
|
|
|
|
.P.
|
|
|
|
III
|
|
|
|
.I.
|
|
|
|
|
|
|
|
P = Pumpkin or jack'o lantern
|
|
|
|
I = Iron block
|
|
|
|
. = Air
|
|
|
|
]]
|
|
|
|
|
2022-05-25 21:25:15 +00:00
|
|
|
function mobs_mc.check_iron_golem_summon(pos)
|
2017-07-05 01:15:46 +00:00
|
|
|
local checks = {
|
|
|
|
-- These are the possible placement patterns, with offset from the pumpkin block.
|
|
|
|
-- These tables include the positions of the iron blocks (1-4) and air blocks (5-8)
|
|
|
|
-- 4th element is used to determine spawn position.
|
|
|
|
-- If a 9th element is present, that one is used for the spawn position instead.
|
|
|
|
-- Standing (x axis)
|
|
|
|
{
|
|
|
|
{x=-1, y=-1, z=0}, {x=1, y=-1, z=0}, {x=0, y=-1, z=0}, {x=0, y=-2, z=0}, -- iron blocks
|
|
|
|
{x=-1, y=0, z=0}, {x=1, y=0, z=0}, {x=-1, y=-2, z=0}, {x=1, y=-2, z=0}, -- air
|
|
|
|
},
|
|
|
|
-- Upside down standing (x axis)
|
|
|
|
{
|
|
|
|
{x=-1, y=1, z=0}, {x=1, y=1, z=0}, {x=0, y=1, z=0}, {x=0, y=2, z=0},
|
|
|
|
{x=-1, y=0, z=0}, {x=1, y=0, z=0}, {x=-1, y=2, z=0}, {x=1, y=2, z=0},
|
|
|
|
{x=0, y=0, z=0}, -- Different offset for upside down pattern
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Standing (z axis)
|
|
|
|
{
|
|
|
|
{x=0, y=-1, z=-1}, {x=0, y=-1, z=1}, {x=0, y=-1, z=0}, {x=0, y=-2, z=0},
|
|
|
|
{x=0, y=0, z=-1}, {x=0, y=0, z=1}, {x=0, y=-2, z=-1}, {x=0, y=-2, z=1},
|
|
|
|
},
|
|
|
|
-- Upside down standing (z axis)
|
|
|
|
{
|
|
|
|
{x=0, y=1, z=-1}, {x=0, y=1, z=1}, {x=0, y=1, z=0}, {x=0, y=2, z=0},
|
|
|
|
{x=0, y=0, z=-1}, {x=0, y=0, z=1}, {x=0, y=2, z=-1}, {x=0, y=2, z=1},
|
|
|
|
{x=0, y=0, z=0},
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Lying
|
|
|
|
{
|
|
|
|
{x=-1, y=0, z=-1}, {x=0, y=0, z=-1}, {x=1, y=0, z=-1}, {x=0, y=0, z=-2},
|
|
|
|
{x=-1, y=0, z=0}, {x=1, y=0, z=0}, {x=-1, y=0, z=-2}, {x=1, y=0, z=-2},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{x=-1, y=0, z=1}, {x=0, y=0, z=1}, {x=1, y=0, z=1}, {x=0, y=0, z=2},
|
|
|
|
{x=-1, y=0, z=0}, {x=1, y=0, z=0}, {x=-1, y=0, z=2}, {x=1, y=0, z=2},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{x=-1, y=0, z=-1}, {x=-1, y=0, z=0}, {x=-1, y=0, z=1}, {x=-2, y=0, z=0},
|
|
|
|
{x=0, y=0, z=-1}, {x=0, y=0, z=1}, {x=-2, y=0, z=-1}, {x=-2, y=0, z=1},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{x=1, y=0, z=-1}, {x=1, y=0, z=0}, {x=1, y=0, z=1}, {x=2, y=0, z=0},
|
|
|
|
{x=0, y=0, z=-1}, {x=0, y=0, z=1}, {x=2, y=0, z=-1}, {x=2, y=0, z=1},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for c=1, #checks do
|
|
|
|
-- Check all possible patterns
|
|
|
|
local ok = true
|
|
|
|
-- Check iron block nodes
|
|
|
|
for i=1, 4 do
|
|
|
|
local cpos = vector.add(pos, checks[c][i])
|
|
|
|
local node = minetest.get_node(cpos)
|
2022-05-25 21:25:15 +00:00
|
|
|
if node.name ~= "mcl_core:ironblock" then
|
2017-07-05 01:15:46 +00:00
|
|
|
ok = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Check air nodes
|
|
|
|
for a=5, 8 do
|
|
|
|
local cpos = vector.add(pos, checks[c][a])
|
|
|
|
local node = minetest.get_node(cpos)
|
|
|
|
if node.name ~= "air" then
|
|
|
|
ok = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Pattern found!
|
|
|
|
if ok then
|
|
|
|
-- Remove the nodes
|
|
|
|
minetest.remove_node(pos)
|
2022-02-13 20:40:12 +00:00
|
|
|
core.check_for_falling(pos)
|
2017-07-05 01:15:46 +00:00
|
|
|
for i=1, 4 do
|
|
|
|
local cpos = vector.add(pos, checks[c][i])
|
|
|
|
minetest.remove_node(cpos)
|
2022-02-13 20:40:12 +00:00
|
|
|
core.check_for_falling(cpos)
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
-- Summon iron golem
|
|
|
|
local place
|
|
|
|
if checks[c][9] then
|
|
|
|
place = vector.add(pos, checks[c][9])
|
|
|
|
else
|
|
|
|
place = vector.add(pos, checks[c][4])
|
|
|
|
end
|
|
|
|
place.y = place.y - 0.5
|
|
|
|
minetest.add_entity(place, "mobs_mc:iron_golem")
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|