123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- local function is_ground(pos)
- local nn = minetest.get_node(pos).name
- return minetest.get_item_group(nn, "crumbly") ~= 0 or
- minetest.get_item_group(nn, "cracky") ~= 0 or
- minetest.get_item_group(nn, "choppy") ~= 0 or
- minetest.get_item_group(nn, "snappy") ~= 0
- end
- local function get_sign(i)
- if i == 0 then
- return 0
- else
- return i/math.abs(i)
- end
- end
- local function get_velocity(v, yaw, y)
- local x = math.cos(yaw)*v
- local z = math.sin(yaw)*v
- return {x=x, y=y, z=z}
- end
- local function get_v(v)
- return math.sqrt(v.x^2+v.z^2)
- end
- function lottmobs:register_horse(name, craftitem, horse)
- if craftitem ~= nil then
- function craftitem.on_place(itemstack, placer, pointed_thing)
- if pointed_thing.above then
- minetest.add_entity(pointed_thing.above, name)
-
- if not minetest.setting_getbool("creative_mode") then
- itemstack:take_item()
- end
- end
- return itemstack
- end
- minetest.register_craftitem(name, craftitem)
- end
- horse.v = 0
- horse.driver = nil
- function horse:set_animation(type)
- if not self.animation then
- return
- end
- if not self.animation.current then
- self.animation.current = ""
- end
- if type == "stand" and self.animation.current ~= "stand" then
- if
- self.animation.stand_start
- and self.animation.stand_end
- and self.animation.speed_normal
- then
- self.object:set_animation(
- {x=self.animation.stand_start,y=self.animation.stand_end},
- self.animation.speed_normal * 0.6, 0
- )
- self.animation.current = "stand"
- end
- elseif type == "walk" and self.animation.current ~= "walk" then
- if
- self.animation.walk_start
- and self.animation.walk_end
- and self.animation.speed_normal
- then
- self.object:set_animation(
- {x=self.animation.walk_start,y=self.animation.walk_end},
- self.animation.speed_normal * 3, 0
- )
- self.animation.current = "walk"
- end
- elseif type == "punch" and self.animation.current ~= "punch" then
- if
- self.animation.punch_start
- and self.animation.punch_end
- and self.animation.speed_normal
- then
- self.object:set_animation(
- {x=self.animation.punch_start,y=self.animation.punch_end},
- self.animation.speed_normal * 3, 0
- )
- self.animation.current = "punch"
- end
- end
- end
- function horse:on_step(dtime)
- local p = self.object:getpos()
- p.y = p.y - 0.1
- local on_ground = is_ground(p)
- self.v = get_v(self.object:get_velocity())*get_sign(self.v)
- -- driver controls
- if self.driver then
- local ctrl = self.driver:get_player_control()
- -- rotation (the faster we go, the less we rotate)
- if ctrl.left then
- self.object:setyaw(self.object:getyaw()+2*(1.5-math.abs(self.v/self.max_speed))*math.pi/90 +dtime*math.pi/90)
- end
- if ctrl.right then
- self.object:setyaw(self.object:getyaw()-2*(1.5-math.abs(self.v/self.max_speed))*math.pi/90 -dtime*math.pi/90)
- end
- -- jumping (only if on ground)
- if ctrl.jump and on_ground then
- local v = self.object:getvelocity()
- v.y = (self.jump_speed or 3)
- self.object:setvelocity(v)
- end
- -- forwards/backwards
- if ctrl.up then
- self.v = self.v + self.forward_boost
- elseif ctrl.down then
- self.v = self.v - 0.3
- elseif on_ground then
- if math.abs(self.v) < 1 then
- self.v = 0
- else
- self.v = self.v * 0.8
- end
- end
- else
- if math.abs(self.v) < 1 then
- self.v = 0
- else
- self.v = self.v * 0.95
- end
- end
- local underattack = self.underattack or false
- if self.v == 0 then
- if underattack ~= true then
- self.object:setvelocity({x=0,y=0,z=0})
- self:set_animation("stand")
- return
- else
- self:set_animation("punch")
- end
- else
- self:set_animation("walk")
- end
- -- make sure we don't go past the limit
- if math.abs(self.v) > self.max_speed then
- self.v = self.max_speed*get_sign(self.v)
- end
- local p = self.object:getpos()
- p.y = p.y+1
- if not is_ground(p) then
- if minetest.registered_nodes[minetest.get_node(p).name].walkable then
- self.v = 0
- end
- self.object:setacceleration({x=0, y=-10, z=0})
- self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
- else
- self.object:setacceleration({x=0, y=0, z=0})
- -- falling
- if math.abs(self.object:getvelocity().y) < 1 then
- local pos = self.object:getpos()
- pos.y = math.floor(pos.y)+0.5
- self.object:setpos(pos)
- self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
- else
- self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
- end
- end
- if self.object:getvelocity().y > 0.1 then
- local yaw = self.object:getyaw()
- if self.drawtype == "side" then
- yaw = yaw+(math.pi/2)
- end
- local x = math.sin(yaw) * -2
- local z = math.cos(yaw) * 2
- if minetest.get_item_group(minetest.get_node(self.object:getpos()).name, "water") ~= 0 then
- self.object:setacceleration({x = x, y = 2, z = z})
- else
- self.object:setacceleration({x = x, y = -5, z = z})
- end
- else
- if minetest.get_item_group(minetest.get_node(self.object:getpos()).name, "water") ~= 0 then
- self.object:setacceleration({x = 0, y = 2, z = 0})
- else
- self.object:setacceleration({x = 0, y = -5, z = 0})
- end
- end
- end
- function horse:on_rightclick(clicker)
- if not clicker or not clicker:is_player() then
- return
- end
- if self.driver and clicker == self.driver then
- self.driver = nil
- clicker:set_detach()
- default.player_attached[clicker:get_player_name()] = false
- if self.offset == true then
- clicker:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
- end
- elseif not self.driver then
- self.driver = clicker
- attach_h = self.attach_h or 5
- attach_r = self.attach_r or 90
- clicker:set_attach(self.object, "", {x=0,y= attach_h ,z=0}, {x=0,y= attach_r ,z=0})
- default.player_attached[clicker:get_player_name()] = true
- self.object:setyaw(clicker:get_look_yaw())
- self.ridername = clicker:get_player_name()
-
- if self.offset == true then
- offset_h = self.offset_h or 0
- offset_r = self.offset_r or 0
- clicker:set_eye_offset({x=0,y= offset_h ,z=0},{x=0,y= offset_r ,z=0})
- end
- end
- end
- function horse:on_activate(staticdata, dtime_s)
- self.object:set_armor_groups({fleshy=100})
- if staticdata then
- self.v = tonumber(staticdata)
- end
-
- local hp = self.hp or 10
- self.object:set_hp(hp)
- end
- function horse:get_staticdata()
- return tostring(self.v)
- end
-
- function horse:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
- local ridername = self.ridername
- if ridername ~= nil then
- rider = minetest.get_player_by_name(ridername)
- end
-
-
- if puncher and puncher:is_player() then
- if puncher:get_player_name() == ridername or ridername == nil then
- puncher:get_inventory():add_item("main", name)
- default.player_attached[puncher:get_player_name()] = false
- puncher:set_detach()
- self.object:remove()
- if self.offset == true then
- puncher:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
- end
- elseif self.aggressive == true then
- local objs = minetest.get_objects_inside_radius(self.object:getpos(), 4)
- local _,obj
- for _,obj in ipairs(objs) do
- if obj:is_player() and puncher:get_player_name() == obj:get_player_name() then
- self.underattack = true
- minetest.after(2, function()
- self.underattack = false
- end)
-
- puncher:punch(self.object, 1.0, {
- full_punch_interval = 1.0,
- damage_groups = {fleshy = self.dps}
- }, nil)
- end
- end
- end
- else
- if puncher and self.aggressive == true then
- local objs = minetest.get_objects_inside_radius(self.object:getpos(), 4)
- local _,obj
- for _,obj in ipairs(objs) do
- if puncher:get_luaentity() == obj:get_luaentity() then
- self.underattack = true
- minetest.after(2, function()
- self.underattack = false
- end)
-
- puncher:punch(self.object, 1.0, {
- full_punch_interval = 1.0,
- damage_groups = {fleshy = self.dps}
- }, nil)
- end
- end
- end
- end
-
- if self.object:get_hp() <= 0 then
- default.player_attached[ridername] = false
- rider:set_detach()
- self.object:remove()
- if self.offset == true then
- rider:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
- end
- end
- end
- minetest.register_entity(name, horse)
- end
- ---------------------
- lottmobs:register_horse("lottmobs:horseh1", {
- description = "Brown Horse",
- inventory_image = "lottmobs_horse_inventory.png",
- }, {
- physical = true,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- visual = "mesh",
- stepheight = 1.1,
- visual_size = {x=1,y=1},
- mesh = "horseh1_model.x",
- textures = {"lottmobs_horse.png"},
- animation = {
- speed_normal = 10,
- stand_start = 0,
- stand_end = 50,
- walk_start = 75,
- walk_end = 98,
-
- },
- max_speed = 7,
- forward_boost = 2.33,
- jump_boost = 4
- })
- --horse white
- lottmobs:register_horse("lottmobs:horsepegh1", {
- description = "White Horse",
- inventory_image = "lottmobs_horsepeg_inventory.png",
- }, {
- physical = true,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- visual = "mesh",
- stepheight = 1.1,
- visual_size = {x=1,y=1},
- mesh = "horseh1_model.x",
- textures = {"lottmobs_horsepeg.png"},
- animation = {
- speed_normal = 10,
- stand_start = 0,
- stand_end = 50,
- walk_start = 75,
- walk_end = 98,
- },
- max_speed = 7,
- forward_boost = 2.33,
- jump_boost = 4
- })
- --horse arabik
- lottmobs:register_horse("lottmobs:horsearah1", {
- description = "Black Horse",
- inventory_image = "lottmobs_horseara_inventory.png",
- }, {
- physical = true,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- visual = "mesh",
- stepheight = 1.1,
- visual_size = {x=1,y=1},
- mesh = "horseh1_model.x",
- textures = {"lottmobs_horseara.png"},
- animation = {
- speed_normal = 10,
- stand_start = 0,
- stand_end = 50,
- walk_start = 75,
- walk_end = 98,
- },
- max_speed = 7,
- forward_boost = 2.33,
- jump_boost = 4
- })
- lottmobs:register_horse("lottmobs:shireponyblackh1", {
- description = "Shire Pony",
- inventory_image = "lottmobs_shireponyblack_inventory.png",
- }, {
- physical = true,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- visual = "mesh",
- stepheight = 1.1,
- visual_size = {x=1.3,y=1.3},
- mesh = "shireponyh1_model.x",
- textures = {"lottmobs_shireponyblack.png"},
- animation = {
- speed_normal = 15,
- stand_start = 0,
- stand_end = 39,
- walk_start = 45,
- walk_end = 85,
- },
- max_speed = 5,
- forward_boost = 1.67,
- jump_boost = 3
- })
- lottmobs:register_horse("lottmobs:shireponyh1", {
- description = "Shire Pony",
- inventory_image = "lottmobs_shirepony_inventory.png",
- }, {
- physical = true,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- visual = "mesh",
- stepheight = 1.1,
- visual_size = {x=1.3,y=1.3},
- mesh = "shireponyh1_model.x",
- textures = {"lottmobs_shirepony.png"},
- animation = {
- speed_normal = 15,
- stand_start = 0,
- stand_end = 39,
- walk_start = 45,
- walk_end = 85,
- },
- max_speed = 5,
- forward_boost = 1.67,
- jump_boost = 3
- })
- ----------------------
- mobs:register_mob("lottmobs:horse", {
- type = "animal",
- hp_min = 5,
- hp_max = 7,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- textures = {
- {"lottmobs_horse.png"},
- },
- visual = "mesh",
- mesh = "horse_model.x",
- makes_footstep_sound = true,
- walk_velocity = 1,
- armor = 200,
- drops = {
- {name = "lottmobs:meat_raw",
- chance = 1,
- min = 2,
- max = 3,},
- },
- drawtype = "front",
- water_damage = 1,
- lava_damage = 5,
- light_damage = 0,
- sounds = {
- random = "",
- },
- animation = {
- speed_normal = 15,
- stand_start = 25,
- stand_end = 75,
- walk_start = 75,
- walk_end = 100,
- },
- follow = "farming:wheat",
- view_range = 5,
- on_rightclick = function(self, clicker)
- local item = clicker:get_wielded_item()
- if item:get_name() == "farming:wheat" then
- minetest.add_entity(self.object:getpos(), "lottmobs:horseh1")
- if not minetest.setting_getbool("creative_mode") then
- item:take_item()
- clicker:set_wielded_item(item)
- end
- self.object:remove()
- end
- end,
- jump = true,
- step=1,
- passive = true,
- })
- mobs:register_spawn("lottmobs:horse", {"lottmapgen:rohan_grass"}, 20, -1, 6000, 3, 31000)
- mobs:register_mob("lottmobs:horsepeg", {
- type = "animal",
- hp_min = 5,
- hp_max = 7,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- textures = {
- {"lottmobs_horsepeg.png"},
- },
- visual = "mesh",
- mesh = "horse_model.x",
- makes_footstep_sound = true,
- walk_velocity = 1,
- armor = 200,
- drops = {
- {name = "lottmobs:meat_raw",
- chance = 1,
- min = 2,
- max = 3,},
- },
- drawtype = "front",
- water_damage = 1,
- lava_damage = 5,
- light_damage = 0,
- sounds = {
- random = "",
- },
- animation = {
- speed_normal = 15,
- stand_start = 25,
- stand_end = 75,
- walk_start = 75,
- walk_end = 100,
- },
- follow = "farming:wheat",
- view_range = 5,
- on_rightclick = function(self, clicker)
- local item = clicker:get_wielded_item()
- if item:get_name() == "farming:wheat" then
- minetest.add_entity(self.object:getpos(), "lottmobs:horsepegh1")
- if not minetest.setting_getbool("creative_mode") then
- item:take_item()
- clicker:set_wielded_item(item)
- end
- self.object:remove()
- end
- end,
- jump = true,
- step=1,
- passive = true,
- })
- mobs:register_spawn("lottmobs:horsepeg", {"lottmapgen:rohan_grass"}, 20, -1, 7000, 3, 31000)
- mobs:register_mob("lottmobs:horseara", {
- type = "animal",
- hp_min = 5,
- hp_max = 7,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- textures = {
- {"lottmobs_horseara.png"},
- },
- visual = "mesh",
- mesh = "horse_model.x",
- makes_footstep_sound = true,
- walk_velocity = 1,
- armor = 200,
- drops = {
- {name = "lottmobs:meat_raw",
- chance = 1,
- min = 2,
- max = 3,},
- },
- drawtype = "front",
- water_damage = 1,
- lava_damage = 5,
- light_damage = 0,
- sounds = {
- random = "",
- },
- animation = {
- speed_normal = 15,
- stand_start = 25,
- stand_end = 75,
- walk_start = 75,
- walk_end = 100,
- },
- follow = "farming:wheat",
- view_range = 5,
- on_rightclick = function(self, clicker)
- local item = clicker:get_wielded_item()
- if item:get_name() == "farming:wheat" then
- minetest.add_entity(self.object:getpos(), "lottmobs:horsearah1")
- if not minetest.setting_getbool("creative_mode") then
- item:take_item()
- clicker:set_wielded_item(item)
- end
- self.object:remove()
- end
- end,
- jump = true,
- step=1,
- passive = true,
- })
- mobs:register_spawn("lottmobs:horseara", {"lottmapgen:rohan_grass"}, 20, -1, 7000, 3, 31000)
- mobs:register_mob("lottmobs:shirepony", {
- type = "animal",
- hp_min = 5,
- hp_max = 7,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- textures = {
- {"lottmobs_shirepony.png"},
- },
- visual = "mesh",
- mesh = "shirepony_model.x",
- makes_footstep_sound = true,
- walk_velocity = 1,
- armor = 200,
- visual_size = {x=1.3,y=1.3},
- drops = {
- {name = "lottmobs:meat_raw",
- chance = 1,
- min = 2,
- max = 3,},
- },
- drawtype = "front",
- water_damage = 1,
- lava_damage = 5,
- light_damage = 0,
- sounds = {
- random = "",
- },
- animation = {
- speed_normal = 15,
- stand_start = 0,
- stand_end = 40,
- walk_start = 45,
- walk_end = 85,
- },
- follow = "farming:wheat",
- view_range = 5,
- on_rightclick = function(self, clicker)
- local item = clicker:get_wielded_item()
- if item:get_name() == "farming:wheat" then
- minetest.add_entity(self.object:getpos(), "lottmobs:shireponyh1")
- if not minetest.setting_getbool("creative_mode") then
- item:take_item()
- clicker:set_wielded_item(item)
- end
- self.object:remove()
- end
- end,
- jump = true,
- step=1,
- passive = true,
- })
- mobs:register_spawn("lottmobs:shirepony", {"lottmapgen:shire_grass"}, 20, -1, 6000, 3, 31000)
- mobs:register_mob("lottmobs:shireponyblack", {
- type = "animal",
- hp_min = 5,
- hp_max = 7,
- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4},
- textures = {
- {"lottmobs_shireponyblack.png"},
- },
- visual = "mesh",
- mesh = "shirepony_model.x",
- makes_footstep_sound = true,
- walk_velocity = 1,
- armor = 200,
- visual_size = {x=1.3,y=1.3},
- drops = {
- {name = "lottmobs:meat_raw",
- chance = 1,
- min = 2,
- max = 3,},
- },
- drawtype = "front",
- water_damage = 1,
- lava_damage = 5,
- light_damage = 0,
- sounds = {
- random = "",
- },
- animation = {
- speed_normal = 15,
- stand_start = 0,
- stand_end = 40,
- walk_start = 45,
- walk_end = 85,
- },
- follow = "farming:wheat",
- view_range = 5,
- on_rightclick = function(self, clicker)
- local item = clicker:get_wielded_item()
- if item:get_name() == "farming:wheat" then
- minetest.add_entity(self.object:getpos(), "lottmobs:shireponyblackh1")
- if not minetest.setting_getbool("creative_mode") then
- item:take_item()
- clicker:set_wielded_item(item)
- end
- self.object:remove()
- end
- end,
- jump = true,
- step=1,
- passive = true,
- })
- mobs:register_spawn("lottmobs:shireponyblack", {"lottmapgen:shire_grass"}, 20, -1, 9000, 3, 31000)
|