2017-07-05 01:15:46 +00:00
--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
2022-11-09 03:09:58 +00:00
mcl_mobs.register_mob ( " mobs_mc:pig " , {
2021-04-25 15:30:15 +00:00
description = S ( " Pig " ) ,
2017-07-05 01:15:46 +00:00
type = " animal " ,
2020-04-11 00:46:03 +00:00
spawn_class = " passive " ,
2023-01-04 21:11:55 +00:00
passive = true ,
2022-02-13 20:40:12 +00:00
runaway = true ,
2017-07-05 01:15:46 +00:00
hp_min = 10 ,
hp_max = 10 ,
2020-12-06 14:46:42 +00:00
xp_min = 1 ,
xp_max = 3 ,
2017-07-05 01:15:46 +00:00
collisionbox = { - 0.45 , - 0.01 , - 0.45 , 0.45 , 0.865 , 0.45 } ,
visual = " mesh " ,
mesh = " mobs_mc_pig.b3d " ,
2017-11-03 21:14:27 +00:00
textures = { {
" mobs_mc_pig.png " , -- base
" blank.png " , -- saddle
} } ,
2022-10-06 20:53:40 +00:00
head_swivel = " head.control " ,
bone_eye_height = 7.5 ,
2022-10-06 01:30:02 +00:00
head_eye_height = 0.8 ,
2022-10-06 20:53:40 +00:00
horrizonatal_head_height =- 1 ,
2022-10-06 01:30:02 +00:00
curiosity = 3 ,
head_yaw = " z " ,
2017-07-05 01:15:46 +00:00
makes_footstep_sound = true ,
walk_velocity = 1 ,
run_velocity = 3 ,
2020-08-03 13:37:58 +00:00
follow_velocity = 3.4 ,
2017-07-05 01:15:46 +00:00
drops = {
2022-05-25 21:25:15 +00:00
{ name = " mcl_mobitems:porkchop " ,
2017-07-05 01:15:46 +00:00
chance = 1 ,
min = 1 ,
2020-12-23 16:41:42 +00:00
max = 3 ,
looting = " common " , } ,
2017-07-05 01:15:46 +00:00
} ,
fear_height = 4 ,
sounds = {
random = " mobs_pig " ,
death = " mobs_pig_angry " ,
damage = " mobs_pig " ,
2020-12-05 22:37:12 +00:00
eat = " mobs_mc_animal_eat_generic " ,
2017-07-05 01:15:46 +00:00
distance = 16 ,
} ,
animation = {
2022-09-28 19:16:01 +00:00
stand_start = 0 , stand_end = 0 ,
walk_start = 0 , walk_end = 40 , walk_speed = 60 ,
run_start = 0 , run_end = 40 , run_speed = 90 ,
} ,
child_animations = {
stand_start = 41 , stand_end = 41 ,
walk_start = 41 , walk_end = 81 , walk_speed = 90 ,
run_start = 41 , run_end = 81 , run_speed = 135 ,
2017-07-05 01:15:46 +00:00
} ,
2022-05-25 21:25:15 +00:00
follow = {
" mcl_farming:potato_item " ,
" mcl_farming:carrot_item " ,
" mcl_farming:beetroot_item " ,
" mcl_mobitems:carrot_on_a_stick "
} ,
2020-08-03 13:37:58 +00:00
view_range = 8 ,
2022-11-04 13:02:45 +00:00
on_lightning_strike = function ( self , pos , pos2 , objects )
mcl_util.replace_mob ( self.object , " mobs_mc:zombified_piglin " )
return true
end ,
2017-07-05 01:15:46 +00:00
do_custom = function ( self , dtime )
-- set needed values if not already present
2022-09-28 19:16:01 +00:00
if not self.v3 then
self.v3 = 0
2017-07-05 01:15:46 +00:00
self.max_speed_forward = 4
self.max_speed_reverse = 2
self.accel = 4
self.terrain_type = 3
2022-09-28 19:16:01 +00:00
self.driver_attach_at = { x = 0.0 , y = 6.5 , z = - 3.75 }
2017-07-05 01:15:46 +00:00
self.driver_eye_offset = { x = 0 , y = 3 , z = 0 }
self.driver_scale = { x = 1 / self.visual_size . x , y = 1 / self.visual_size . y }
2022-09-28 19:16:01 +00:00
self.base_texture = self.texture_list [ 1 ]
self.object : set_properties ( { textures = self.base_texture } )
2017-07-05 01:15:46 +00:00
end
-- if driver present allow control of horse
2023-04-27 23:01:32 +00:00
if self.driver and self.driver : get_wielded_item ( ) : get_name ( ) == " mcl_mobitems:carrot_on_a_stick " then
2017-07-05 01:15:46 +00:00
2022-05-25 12:44:49 +00:00
mcl_mobs.drive ( self , " walk " , " stand " , false , dtime )
2017-07-05 01:15:46 +00:00
return false -- skip rest of mob functions
end
return true
end ,
on_die = function ( self , pos )
-- drop saddle when horse is killed while riding
-- also detach from horse properly
if self.driver then
2022-05-25 12:44:49 +00:00
mcl_mobs.detach ( self.driver , { x = 1 , y = 0 , z = 1 } )
2017-07-05 01:15:46 +00:00
end
end ,
on_rightclick = function ( self , clicker )
if not clicker or not clicker : is_player ( ) then
return
end
2022-02-13 20:40:12 +00:00
local wielditem = clicker : get_wielded_item ( )
-- Feed pig
2022-05-25 21:25:15 +00:00
if wielditem : get_name ( ) ~= " mcl_mobitems:carrot_on_a_stick " then
2022-11-09 03:57:48 +00:00
if self : feed_tame ( clicker , 1 , true , false ) then return end
2017-07-05 01:15:46 +00:00
end
2022-05-25 12:44:49 +00:00
if mcl_mobs : protect ( self , clicker ) then return end
2017-07-05 01:15:46 +00:00
if self.child then
return
end
-- Put saddle on pig
local item = clicker : get_wielded_item ( )
2022-05-25 21:25:15 +00:00
if item : get_name ( ) == " mcl_mobitems:saddle " and self.saddle ~= " yes " then
2017-11-03 21:14:27 +00:00
self.base_texture = {
" mobs_mc_pig.png " , -- base
" mobs_mc_pig_saddle.png " , -- saddle
}
2017-07-05 01:15:46 +00:00
self.object : set_properties ( {
textures = self.base_texture
} )
self.saddle = " yes "
self.tamed = true
self.drops = {
2022-05-25 21:25:15 +00:00
{ name = " mcl_mobitems:porkchop " ,
2017-07-05 01:15:46 +00:00
chance = 1 ,
min = 1 ,
max = 3 , } ,
2022-05-25 21:25:15 +00:00
{ name = " mcl_mobitems:saddle " ,
2017-07-05 01:15:46 +00:00
chance = 1 ,
min = 1 ,
max = 1 , } ,
}
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
local inv = clicker : get_inventory ( )
local stack = inv : get_stack ( " main " , clicker : get_wield_index ( ) )
stack : take_item ( )
inv : set_stack ( " main " , clicker : get_wield_index ( ) , stack )
end
2020-04-06 22:55:45 +00:00
minetest.sound_play ( { name = " mcl_armor_equip_leather " } , { gain = 0.5 , max_hear_distance = 8 , pos = self.object : get_pos ( ) } , true )
2017-07-05 01:15:46 +00:00
return
end
2023-04-27 23:01:32 +00:00
-- Should make pig go faster when right clicked with carrot on a stick.
-- FIXME: needs work on the going faster part.
--[[if self.driver and clicker == self.driver and self.driver:get_wielded_item():get_name() == "mcl_mobitems:carrot_on_a_stick" then
if not self.v3 then
self.v3 = 0
self.max_speed_forward = 100
self.accel = 10
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
local inv = self.driver : get_inventory ( )
-- 26 uses
if wielditem : get_wear ( ) > 63000 then
-- Break carrot on a stick
local def = wielditem : get_definition ( )
if def.sounds and def.sounds . breaks then
2020-04-06 22:55:45 +00:00
minetest.sound_play ( def.sounds . breaks , { pos = clicker : get_pos ( ) , max_hear_distance = 8 , gain = 0.5 } , true )
2017-07-05 01:15:46 +00:00
end
2022-05-25 21:25:15 +00:00
wielditem = { name = " mcl_fishing:fishing_rod " , count = 1 }
2017-07-05 01:15:46 +00:00
else
wielditem : add_wear ( 2521 )
end
inv : set_stack ( " main " , self.driver : get_wield_index ( ) , wielditem )
end
2023-04-27 23:01:32 +00:00
end ] ]
-- Mount or detach player
local name = clicker : get_player_name ( )
if self.driver and clicker == self.driver then -- and self.driver:get_wielded_item():get_name() ~= "mcl_mobitems:carrot_on_a_stick" then -- Note: This is for when the ability to make the pig go faster is implemented
-- Detach if already attached
mcl_mobs.detach ( clicker , { x = 1 , y = 0 , z = 0 } )
return
elseif not self.driver and self.saddle == " yes " then
-- Ride pig if it has a saddle
mcl_mobs.attach ( self , clicker )
2017-07-05 01:15:46 +00:00
return
2022-02-13 20:40:12 +00:00
-- Capture pig
elseif not self.driver and clicker : get_wielded_item ( ) : get_name ( ) ~= " " then
2022-05-25 12:44:49 +00:00
mcl_mobs : capture_mob ( self , clicker , 0 , 5 , 60 , false , nil )
2017-07-05 01:15:46 +00:00
end
end ,
2018-05-30 10:25:10 +00:00
on_breed = function ( parent1 , parent2 )
local pos = parent1.object : get_pos ( )
2022-11-27 20:14:19 +00:00
local child = mcl_mobs.spawn_child ( pos , parent1.name )
2018-05-31 15:32:13 +00:00
if child then
local ent_c = child : get_luaentity ( )
ent_c.tamed = true
ent_c.owner = parent1.owner
2018-05-30 10:56:39 +00:00
return false
end
2018-05-30 10:25:10 +00:00
end ,
2023-04-27 23:01:32 +00:00
after_activate = function ( self , staticdata , def , dtime )
if self.saddle == " yes " then -- Make saddle load upon rejoin
self.base_texture = {
" mobs_mc_pig.png " , -- base
" mobs_mc_pig_saddle.png " , -- saddle
}
self.object : set_properties ( {
textures = self.base_texture
} )
end
end ,
2017-07-05 01:15:46 +00:00
} )
2022-05-25 12:44:49 +00:00
mcl_mobs : spawn_specific (
2021-04-25 15:30:15 +00:00
" mobs_mc:pig " ,
" overworld " ,
2021-04-08 11:39:18 +00:00
" ground " ,
{
2022-03-22 14:16:48 +00:00
" flat " ,
" MegaTaiga " ,
" MegaSpruceTaiga " ,
" ExtremeHills " ,
" ExtremeHills_beach " ,
" ExtremeHillsM " ,
" ExtremeHills+ " ,
" StoneBeach " ,
" Plains " ,
" Plains_beach " ,
" SunflowerPlains " ,
" Taiga " ,
" Taiga_beach " ,
" Forest " ,
" Forest_beach " ,
" FlowerForest " ,
" FlowerForest_beach " ,
" BirchForest " ,
" BirchForestM " ,
" RoofedForest " ,
" Savanna " ,
" Savanna_beach " ,
" SavannaM " ,
" Jungle " ,
" Jungle_shore " ,
" JungleM " ,
" JungleM_shore " ,
" JungleEdge " ,
" JungleEdgeM " ,
" Swampland " ,
" Swampland_shore "
2021-04-08 11:39:18 +00:00
} ,
2021-04-25 15:30:15 +00:00
9 ,
minetest.LIGHT_MAX + 1 ,
30 ,
15000 ,
8 ,
2022-05-25 21:25:15 +00:00
mcl_vars.mg_overworld_min ,
mcl_vars.mg_overworld_max )
2017-07-05 01:15:46 +00:00
-- spawn eggs
2022-11-09 03:09:58 +00:00
mcl_mobs.register_egg ( " mobs_mc:pig " , S ( " Pig " ) , " #f0a5a2 " , " #db635f " , 0 )