2017-07-05 01:15:46 +00:00
|
|
|
--License for code WTFPL and otherwise stated in readmes
|
|
|
|
|
2019-03-07 19:43:39 +00:00
|
|
|
local S = minetest.get_translator("mobs_mc")
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
local default_walk_chance = 50
|
|
|
|
|
|
|
|
local pr = PseudoRandom(os.time()*10)
|
|
|
|
|
2017-07-05 22:43:34 +00:00
|
|
|
local is_food = function(itemstring)
|
|
|
|
for f=1, #mobs_mc.follow.dog do
|
|
|
|
if itemstring == mobs_mc.follow.dog[f] then
|
|
|
|
return true
|
|
|
|
elseif string.sub(itemstring, 1, 6) == "group:" and minetest.get_item_group(itemstring, string.sub(itemstring, 7, -1)) ~= 0 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Wolf
|
|
|
|
local wolf = {
|
|
|
|
type = "animal",
|
2020-04-11 00:46:03 +00:00
|
|
|
spawn_class = "passive",
|
2018-09-14 12:48:48 +00:00
|
|
|
can_despawn = true,
|
2021-04-23 03:30:32 +00:00
|
|
|
neutral = true,
|
2017-07-05 01:15:46 +00:00
|
|
|
hp_min = 8,
|
|
|
|
hp_max = 8,
|
2020-12-06 14:46:42 +00:00
|
|
|
xp_min = 1,
|
|
|
|
xp_max = 3,
|
2021-04-23 03:30:32 +00:00
|
|
|
rotate = 270,
|
2017-07-05 01:15:46 +00:00
|
|
|
passive = false,
|
|
|
|
group_attack = true,
|
2021-04-23 03:30:32 +00:00
|
|
|
collisionbox = {-0.3, -0.00, -0.3, 0.3, 0.85, 0.3},
|
2017-07-05 01:15:46 +00:00
|
|
|
visual = "mesh",
|
|
|
|
mesh = "mobs_mc_wolf.b3d",
|
|
|
|
textures = {
|
|
|
|
{"mobs_mc_wolf.png"},
|
|
|
|
},
|
|
|
|
visual_size = {x=3, y=3},
|
|
|
|
makes_footstep_sound = true,
|
2020-12-05 21:36:59 +00:00
|
|
|
sounds = {
|
|
|
|
attack = "mobs_mc_wolf_bark",
|
|
|
|
war_cry = "mobs_mc_wolf_growl",
|
|
|
|
damage = {name = "mobs_mc_wolf_hurt", gain=0.6},
|
|
|
|
death = {name = "mobs_mc_wolf_death", gain=0.6},
|
2020-12-05 23:50:54 +00:00
|
|
|
eat = "mobs_mc_animal_eat_generic",
|
2020-12-05 21:36:59 +00:00
|
|
|
distance = 16,
|
|
|
|
},
|
2017-07-05 01:15:46 +00:00
|
|
|
pathfinding = 1,
|
|
|
|
floats = 1,
|
|
|
|
view_range = 16,
|
|
|
|
walk_chance = default_walk_chance,
|
|
|
|
walk_velocity = 2,
|
|
|
|
run_velocity = 3,
|
|
|
|
damage = 4,
|
2017-07-25 22:26:18 +00:00
|
|
|
reach = 2,
|
2021-04-23 03:30:32 +00:00
|
|
|
attack_type = "punch",
|
2017-07-05 01:15:46 +00:00
|
|
|
fear_height = 4,
|
2017-07-05 22:43:34 +00:00
|
|
|
follow = mobs_mc.follow.wolf,
|
2017-07-05 01:15:46 +00:00
|
|
|
on_rightclick = function(self, clicker)
|
|
|
|
-- Try to tame wolf (intentionally does NOT use mobs:feed_tame)
|
|
|
|
local tool = clicker:get_wielded_item()
|
|
|
|
|
|
|
|
local dog, ent
|
2017-07-05 22:43:34 +00:00
|
|
|
if tool:get_name() == mobs_mc.items.bone then
|
2017-07-05 01:15:46 +00:00
|
|
|
|
2020-12-06 00:09:55 +00:00
|
|
|
minetest.sound_play("mobs_mc_wolf_take_bone", {object=self.object, max_hear_distance=16}, true)
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2017-07-05 01:15:46 +00:00
|
|
|
tool:take_item()
|
|
|
|
clicker:set_wielded_item(tool)
|
|
|
|
end
|
|
|
|
-- 1/3 chance of getting tamed
|
|
|
|
if pr:next(1, 3) == 1 then
|
|
|
|
local yaw = self.object:get_yaw()
|
2019-02-01 05:33:07 +00:00
|
|
|
dog = minetest.add_entity(self.object:get_pos(), "mobs_mc:dog")
|
2017-07-05 01:15:46 +00:00
|
|
|
dog:set_yaw(yaw)
|
|
|
|
ent = dog:get_luaentity()
|
|
|
|
ent.owner = clicker:get_player_name()
|
2021-04-24 04:38:50 +00:00
|
|
|
ent.tamed = true
|
2020-12-05 21:57:46 +00:00
|
|
|
-- cornfirm taming
|
2020-12-06 00:09:55 +00:00
|
|
|
minetest.sound_play("mobs_mc_wolf_bark", {object=dog, max_hear_distance=16}, true)
|
|
|
|
-- Replace wolf
|
2017-07-05 01:15:46 +00:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
animation = {
|
|
|
|
speed_normal = 50, speed_run = 100,
|
|
|
|
stand_start = 40, stand_end = 45,
|
|
|
|
walk_start = 0, walk_end = 40,
|
|
|
|
run_start = 0, run_end = 40,
|
|
|
|
},
|
|
|
|
jump = true,
|
|
|
|
attacks_monsters = true,
|
2018-05-30 14:16:44 +00:00
|
|
|
attack_animals = true,
|
|
|
|
specific_attack = { "player", "mobs_mc:sheep" },
|
2017-07-05 01:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mobs:register_mob("mobs_mc:wolf", wolf)
|
|
|
|
|
|
|
|
-- Tamed wolf
|
|
|
|
|
|
|
|
-- Collar colors
|
|
|
|
local colors = {
|
|
|
|
["unicolor_black"] = "#000000",
|
|
|
|
["unicolor_blue"] = "#0000BB",
|
|
|
|
["unicolor_dark_orange"] = "#663300", -- brown
|
|
|
|
["unicolor_cyan"] = "#01FFD8",
|
|
|
|
["unicolor_dark_green"] = "#005B00",
|
|
|
|
["unicolor_grey"] = "#C0C0C0",
|
|
|
|
["unicolor_darkgrey"] = "#303030",
|
|
|
|
["unicolor_green"] = "#00FF01",
|
|
|
|
["unicolor_red_violet"] = "#FF05BB", -- magenta
|
|
|
|
["unicolor_orange"] = "#FF8401",
|
|
|
|
["unicolor_light_red"] = "#FF65B5", -- pink
|
|
|
|
["unicolor_red"] = "#FF0000",
|
|
|
|
["unicolor_violet"] = "#5000CC",
|
|
|
|
["unicolor_white"] = "#FFFFFF",
|
|
|
|
["unicolor_yellow"] = "#FFFF00",
|
|
|
|
|
|
|
|
["unicolor_light_blue"] = "#B0B0FF",
|
|
|
|
}
|
|
|
|
|
|
|
|
local get_dog_textures = function(color)
|
|
|
|
if colors[color] then
|
|
|
|
return {"mobs_mc_wolf_tame.png^(mobs_mc_wolf_collar.png^[colorize:"..colors[color]..":192)"}
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Tamed wolf (aka “dog”)
|
|
|
|
local dog = table.copy(wolf)
|
2018-09-14 12:48:48 +00:00
|
|
|
dog.can_despawn = false
|
2017-07-05 01:15:46 +00:00
|
|
|
dog.passive = true
|
|
|
|
dog.hp_min = 20
|
|
|
|
dog.hp_max = 20
|
|
|
|
-- Tamed wolf texture + red collar
|
|
|
|
dog.textures = get_dog_textures("unicolor_red")
|
|
|
|
dog.owner = ""
|
|
|
|
-- TODO: Start sitting by default
|
|
|
|
dog.order = "roam"
|
|
|
|
dog.owner_loyal = true
|
2020-08-03 13:37:58 +00:00
|
|
|
dog.follow_velocity = 3.2
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Automatically teleport dog to owner
|
|
|
|
dog.do_custom = mobs_mc.make_owner_teleport_function(12)
|
2018-05-30 14:16:44 +00:00
|
|
|
dog.attack_animals = nil
|
|
|
|
dog.specific_attack = nil
|
2021-04-24 04:38:50 +00:00
|
|
|
dog.breed_distance = 1.5
|
|
|
|
dog.baby_size = 0.5
|
|
|
|
dog.follow_distance = 2
|
|
|
|
dog.follow = "mcl_mobitems:beef"
|
|
|
|
|
2017-07-05 01:15:46 +00:00
|
|
|
dog.on_rightclick = function(self, clicker)
|
|
|
|
local item = clicker:get_wielded_item()
|
|
|
|
|
2021-04-24 04:38:50 +00:00
|
|
|
if self.owner and self.owner == clicker:get_player_name() and clicker:get_player_control().sneak then
|
|
|
|
--attempt to enter breed state
|
|
|
|
if mobs.enter_breed_state(self,clicker) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
--make baby grow faster
|
|
|
|
if self.baby then
|
|
|
|
mobs.make_baby_grow_faster(self,clicker)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-19 01:24:31 +00:00
|
|
|
if is_food(item:get_name()) then
|
2017-07-05 22:43:34 +00:00
|
|
|
-- Feed to increase health
|
|
|
|
local hp = self.health
|
|
|
|
local hp_add = 0
|
|
|
|
-- Use eatable group to determine health boost
|
|
|
|
local eatable = minetest.get_item_group(item, "eatable")
|
|
|
|
if eatable > 0 then
|
|
|
|
hp_add = eatable
|
|
|
|
elseif item:get_name() == mobs_mc.items.rotten_flesh then
|
|
|
|
hp_add = 4
|
|
|
|
else
|
|
|
|
hp_add = 4
|
|
|
|
end
|
|
|
|
local new_hp = hp + hp_add
|
|
|
|
if new_hp > self.hp_max then
|
|
|
|
new_hp = self.hp_max
|
|
|
|
end
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2017-07-05 01:15:46 +00:00
|
|
|
item:take_item()
|
|
|
|
clicker:set_wielded_item(item)
|
|
|
|
end
|
2017-07-05 22:43:34 +00:00
|
|
|
self.health = new_hp
|
2017-07-05 01:15:46 +00:00
|
|
|
return
|
|
|
|
elseif minetest.get_item_group(item:get_name(), "dye") == 1 then
|
|
|
|
-- Dye (if possible)
|
|
|
|
for group, _ in pairs(colors) do
|
|
|
|
-- Check if color is supported
|
|
|
|
if minetest.get_item_group(item:get_name(), group) == 1 then
|
|
|
|
-- Dye collar
|
|
|
|
local tex = get_dog_textures(group)
|
|
|
|
if tex then
|
|
|
|
self.base_texture = tex
|
|
|
|
self.object:set_properties({
|
|
|
|
textures = self.base_texture
|
|
|
|
})
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2017-07-05 01:15:46 +00:00
|
|
|
item:take_item()
|
|
|
|
clicker:set_wielded_item(item)
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Toggle sitting order
|
|
|
|
|
|
|
|
if not self.owner or self.owner == "" then
|
|
|
|
-- Huh? This wolf has no owner? Let's fix this! This should never happen.
|
|
|
|
self.owner = clicker:get_player_name()
|
|
|
|
end
|
|
|
|
|
2020-12-05 21:57:46 +00:00
|
|
|
local pos = self.object:get_pos()
|
|
|
|
local particle
|
2017-07-05 01:15:46 +00:00
|
|
|
if not self.order or self.order == "" or self.order == "sit" then
|
2020-12-05 21:57:46 +00:00
|
|
|
particle = "mobs_mc_wolf_icon_roam.png"
|
2017-07-05 01:15:46 +00:00
|
|
|
self.order = "roam"
|
|
|
|
self.walk_chance = default_walk_chance
|
|
|
|
self.jump = true
|
|
|
|
-- TODO: Add sitting model
|
2020-12-05 21:57:46 +00:00
|
|
|
else
|
|
|
|
particle = "mobs_mc_wolf_icon_sit.png"
|
2017-07-05 01:15:46 +00:00
|
|
|
self.order = "sit"
|
|
|
|
self.walk_chance = 0
|
|
|
|
self.jump = false
|
|
|
|
end
|
2020-12-05 21:57:46 +00:00
|
|
|
-- Display icon to show current order (sit or roam)
|
|
|
|
minetest.add_particle({
|
|
|
|
pos = vector.add(pos, {x=0,y=1,z=0}),
|
|
|
|
velocity = {x=0,y=0.2,z=0},
|
|
|
|
expirationtime = 1,
|
|
|
|
size = 4,
|
|
|
|
texture = particle,
|
|
|
|
playername = self.owner,
|
|
|
|
glow = minetest.LIGHT_MAX,
|
|
|
|
})
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mobs:register_mob("mobs_mc:dog", dog)
|
|
|
|
|
|
|
|
-- Spawn
|
2021-04-08 11:39:18 +00:00
|
|
|
mobs:spawn_specific(
|
|
|
|
"mobs_mc:wolf",
|
|
|
|
"overworld",
|
|
|
|
"ground",
|
|
|
|
{
|
|
|
|
"FlowerForest",
|
|
|
|
"Swampland",
|
|
|
|
"Taiga",
|
|
|
|
"ExtremeHills",
|
|
|
|
"BirchForest",
|
|
|
|
"MegaSpruceTaiga",
|
|
|
|
"MegaTaiga",
|
|
|
|
"ExtremeHills+",
|
|
|
|
"Forest",
|
|
|
|
"Plains",
|
|
|
|
"ColdTaiga",
|
|
|
|
"SunflowerPlains",
|
|
|
|
"RoofedForest",
|
|
|
|
"MesaPlateauFM_grasstop",
|
|
|
|
"ExtremeHillsM",
|
|
|
|
"BirchForestM",
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
minetest.LIGHT_MAX+1,
|
|
|
|
30,
|
|
|
|
9000,
|
|
|
|
7,
|
|
|
|
mobs_mc.spawn_height.water+3,
|
|
|
|
mobs_mc.spawn_height.overworld_max)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
mobs:register_egg("mobs_mc:wolf", S("Wolf"), "mobs_mc_spawn_icon_wolf.png", 0)
|