This repository has been archived on 2024-12-09. You can view files and clone it, but cannot push or open issues or pull requests.
Mineclonia/mods/ENTITIES/mobs_mc/pig.lua

183 lines
4.8 KiB
Lua
Raw Normal View History

--MCmobs v0.2
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
--dofile(minetest.get_modpath("mobs").."/api.lua")
mobs:register_mob("mobs_mc:pig", {
type = "animal",
2017-01-20 20:24:56 +00:00
hp_min = 10,
2017-01-16 19:52:09 +00:00
hp_max = 10,
2017-02-23 19:02:48 +00:00
collisionbox = {-0.5, -0.01, -0.5, 0.5, 0.874, 0.5},
visual = "mesh",
2017-02-23 19:02:48 +00:00
visual_size = {x=0.875, y=0.875},
mesh = "mobs_pig.x",
textures = {
{"mobs_pig.png"}
},
makes_footstep_sound = true,
walk_velocity = 1,
2017-01-16 19:52:09 +00:00
armor = 100,
drops = {
2017-02-07 05:40:30 +00:00
{name = "mcl_mobitems:porkchop",
chance = 1,
min = 1,
max = 3,},
},
drawtype = "front",
lava_damage = minetest.registered_nodes["mcl_core:lava_source"].damage_per_second,
light_damage = 0,
2017-02-23 17:14:39 +00:00
fear_height = 4,
jump_height = 4.5,
sounds = {
2017-02-20 01:36:12 +00:00
random = "mobs_pig",
death = "mobs_pig_angry",
damage = "mobs_pig",
},
animation = {
speed_normal = 24,
stand_start = 0,
stand_end = 23,
walk_start = 24,
walk_end = 49,
hurt_start = 118,
hurt_end = 154,
death_start = 154,
death_end = 179,
eat_start = 49,
eat_end = 78,
look_start = 78,
look_end = 108,
},
2017-02-23 16:44:48 +00:00
follow = {"mcl_farming:beetroot_item", "mcl_farming:carrot_item", "mcl_mobitems:carrot_on_a_stick", "mcl_farming:potato_item"},
view_range = 5,
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then
return
end
2017-02-23 16:44:48 +00:00
local wielditem = clicker:get_wielded_item()
-- Feed pig
if wielditem:get_name() ~= "mcl_mobitems:carrot_on_a_stick" then
if mobs:feed_tame(self, clicker, 1, true, true) then
2017-02-23 16:44:48 +00:00
return
end
end
2017-02-23 16:44:48 +00:00
-- Put saddle on pig
local item = clicker:get_wielded_item()
2017-01-20 20:09:29 +00:00
if item:get_name() == "mcl_mobitems:saddle" and self.saddle ~= "yes" then
self.object:set_properties({
textures = {"mobs_pig_with_saddle.png"},
})
self.saddle = "yes"
self.tamed = true
self.drops = {
2017-02-07 05:40:30 +00:00
{name = "mcl_mobitems:porkchop",
chance = 1,
min = 1,
max = 3,},
2017-01-20 20:09:29 +00:00
{name = "mcl_mobitems:saddle",
chance = 1,
min = 1,
max = 1,},
}
if not minetest.setting_getbool("creative_mode") then
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
return
end
2017-02-23 16:44:48 +00:00
-- from boats mod
2017-02-23 16:44:48 +00:00
-- Ride pig if it has a saddle and player uses a carrot on a stick
local name = clicker:get_player_name()
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
mcl_player.player_attached[name] = false
mcl_player.player_set_animation(clicker, "stand" , 30)
elseif not self.driver and self.saddle == "yes" then
self.driver = clicker
clicker:set_attach(self.object, "", {x = 0, y = 19, z = 0}, {x = 0, y = 0, z = 0})
mcl_player.player_attached[name] = true
minetest.after(0.2, function()
mcl_player.player_set_animation(clicker, "sit" , 30)
end)
2017-02-01 16:06:31 +00:00
if self.name == "mobs_mc:pig" and self.saddle == "yes" and self.driver then
2017-02-23 16:44:48 +00:00
if wielditem:get_name() == "mcl_mobitems:carrot_on_a_stick" then
local yaw = self.driver:get_look_yaw() - math.pi / 2
local velo = self.object:getvelocity()
local v = 1.5
if math.abs(velo.x) + math.abs(velo.z) < .6 then velo.y = 5 end
self.state = "walk"
self.object:setyaw(yaw)
self.object:setvelocity({x = -math.sin(yaw) * v, y = velo.y, z = math.cos(yaw) * v})
local inv = self.driver:get_inventory()
2017-02-01 16:27:18 +00:00
-- 26 uses
2017-02-23 16:44:48 +00:00
if wielditem:get_wear() > 63000 then
wielditem = {name = "mcl_fishing:fishing_rod", count = 1}
2017-02-01 16:27:18 +00:00
else
2017-02-23 16:44:48 +00:00
wielditem:add_wear(2521)
end
2017-02-23 16:44:48 +00:00
inv:set_stack("main", self.driver:get_wield_index(), wielditem)
return
end
end
2017-02-23 16:44:48 +00:00
end
end,
})
2017-02-20 02:00:03 +00:00
mobs:register_spawn("mobs_mc:pig", {"mcl_core:dirt_with_grass"}, 20, 9, 5000, 1, 31000)
--[[
on_step = function(self, dtime)
-- ridable pigs
if self.name == "mobs:pig" and self.saddle == "yes" and self.driver then
local item = self.driver:get_wielded_item()
if item:get_name() == "mobs:carrotstick" then
local yaw = self.driver:get_look_yaw() - math.pi / 2
local velo = self.object:getvelocity()
local v = 1.5
if math.abs(velo.x) + math.abs(velo.z) < .6 then velo.y = 5 end
self.state = "walk"
self.object:setyaw(yaw)
self.object:setvelocity({x = -math.sin(yaw) * v, y = velo.y, z = math.cos(yaw) * v})
local inv = self.driver:get_inventory()
local stack = inv:get_stack("main", self.driver:get_wield_index())
stack:add_wear(100)
if stack:get_wear() > 65400 then
stack = {name = "fishing:pole", count = 1}
end
inv:set_stack("main", self.driver:get_wield_index(), stack)
return
end
end
end,
]]
-- compatibility
mobs:alias_mob("mobs:pig", "mobs_mc:pig")
-- spawn eggs
mobs:register_egg("mobs_mc:pig", "Spawn Pig", "spawn_egg_pig.png")
if minetest.setting_get("log_mods") then
minetest.log("action", "MC Pig loaded")
end