master
runs 2019-04-18 20:22:39 +02:00
parent d334990220
commit 934ff81c4e
16 changed files with 254 additions and 72 deletions

85
api.lua
View File

@ -1,4 +1,4 @@
local S = ...
local modpath, S = ...
petz = {}
@ -329,3 +329,86 @@ end
petz.do_sound_effect = function(dest, dest_name, soundfile)
minetest.sound_play(soundfile, {dest = dest_name, gain = 0.4})
end
--
--Semiaquatic beahaviour
--for beaver and frog
--
petz.set_behaviour= function(self, behaviour, water_type)
if behaviour == "aquatic" then
self.behaviour = "aquatic"
self.fly = true
self.fly_in = water_type
self.floats = 0
self.animation = self.animation_aquatic
elseif behaviour == "terrestrial" then
self.behaviour = "terrestrial"
self.fly = false -- make terrestrial
self.floats = 1
self.animation = self.animation_terrestrial
end
end
petz.semiaquatic_behaviour = function(self)
local pos = self.object:get_pos() -- check the beaver pos to togle between aquatic-terrestrial
local node = minetest.get_node_or_nil(pos)
if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].groups.water then
if not(self.behaviour == "aquatic") then
petz.set_behaviour(self, "aquatic", node.name)
end
if self.petz_type == "beaver" then --beaver's dam
petz.create_dam(self, pos)
end
else
local pos_underwater = { --check if water below (when the mob is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 3.5,
z = pos.z,
}
node = minetest.get_node_or_nil(pos_underwater)
if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].groups.water
and self.floats == false then
local pos_below = {
x = pos.x,
y = pos.y - 2.0,
z = pos.z,
}
self.object:move_to(pos_below, true) -- move the mob underwater
if not(self.behaviour == "aquatic") then
petz.set_behaviour(self, "aquatic", node.name)
end
if self.petz_type == "beaver" then --beaver's dam
petz.create_dam(self, pos)
end
else
if not(self.behaviour == "terrestrial") then
petz.set_behaviour(self, "terrestrial", nil)
end
end
end
end
petz.create_dam = function(self, pos)
if petz.settings.beaver_create_dam == true and self.dam_created == false then --a beaver can create only one dam
if math.random(1, 60000) > 1 then --chance of the dam to be created
return false
end
local pos_underwater = { --check if water below (when the beaver is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 4.5,
z = pos.z,
}
if minetest.get_node(pos_underwater).name == "default:sand" then
local pos_dam = { --check if water below (when the beaver is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 2.0,
z = pos.z,
}
minetest.place_schematic(pos_dam, modpath..'/schematics/beaver_dam.mts', 0, nil, true)
self.dam_created = true
return true
end
end
return false
end

View File

@ -21,14 +21,14 @@ local animation_terrestrial = {
speed_run = 25, run_start = 13, run_end = 25,
stand_start = 26, stand_end = 46,
stand2_start = 47, stand2_end = 59, --sit
stand3_start = 71, stand4_end = 91,
stand3_start = 71, stand3_end = 91,
stand4_start = 82, stand4_end = 95,
}
local animation_aquatic = {
speed_normal = 15, walk_start = 96, walk_end = 121, --swin
speed_run = 25, run_start = 96, run_end = 121,
stand_start = 26, stand_end = 46,
stand2_start = 82, stand4_end = 95,
stand2_start = 82, stand2_end = 95,
}
if petz.settings.type_model == "cubic" then
@ -63,42 +63,6 @@ else
collisionbox = {-0.35, -0.75*scale_beaver, -0.28, 0.35, -0.3125, 0.28}
end
local create_dam = function(self, mod_path, pos)
if petz.settings.beaver_create_dam == true and self.dam_created == false then --a beaver can create only one dam
if math.random(1, 60000) > 1 then --chance of the dam to be created
return false
end
local pos_underwater = { --check if water below (when the beaver is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 4.5,
z = pos.z,
}
if minetest.get_node(pos_underwater).name == "default:sand" then
local pos_dam = { --check if water below (when the beaver is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 2.0,
z = pos.z,
}
minetest.place_schematic(pos_dam, modpath..'/schematics/beaver_dam.mts', 0, nil, true)
self.dam_created = true
return true
end
end
return false
end
local set_behaviour= function(self, behaviour)
if behaviour == "aquatic" then
self.fly = true
self.floats = 0
self.animation = animation_aquatic
elseif behaviour == "terrestrial" then
self.fly = false -- make terrestrial
self.floats = 1
self.animation = animation_terrestrial
end
end
mobs:register_mob("petz:"..pet_name, {
type = "animal",
rotate = petz.settings.rotate,
@ -142,8 +106,8 @@ mobs:register_mob("petz:"..pet_name, {
petz.on_rightclick(self, clicker)
end,
do_custom = function(self, dtime)
if not self.custom_vars_set03 then
self.custom_vars_set03 = 0
if not self.custom_vars_set05 then
self.custom_vars_set05 = 0
self.petz_type = "beaver"
self.is_pet = false
self.is_wild = false
@ -153,35 +117,11 @@ mobs:register_mob("petz:"..pet_name, {
self.fed= false
self.brushed = false
self.beaver_oil_applied = false
self.dam_created = false
self.dam_created = false
self.animation_terrestrial = animation_terrestrial
self.animation_aquatic = animation_aquatic
end
local beaver_behaviour --terrestrial, floating or aquatic
local pos = self.object:get_pos() -- check the beaver pos to togle between aquatic-terrestrial
local node = minetest.get_node_or_nil(pos)
if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].groups.water then
set_behaviour(self, "aquatic")
create_dam(self, modpath, pos)
else
local pos_underwater = { --check if water below (when the beaver is still terrestrial but float in the surface of the water)
x = pos.x,
y = pos.y - 3.5,
z = pos.z,
}
node = minetest.get_node_or_nil(pos_underwater)
if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].groups.water
and self.floats == false then
local pos_below = {
x = pos.x,
y = pos.y - 2.0,
z = pos.z,
}
self.object:move_to(pos_below, true) -- move the beaver underwater
set_behaviour(self, "aquatic")
create_dam(self, modpath, pos)
else
set_behaviour(self, "terrestrial")
end
end
petz.semiaquatic_behaviour(self)
end,
})
@ -197,4 +137,4 @@ mobs:spawn({
min_height = 1,
max_height = -8,
day_toggle = true,
})
})

143
frog_mobs_redo.lua Normal file
View File

@ -0,0 +1,143 @@
--
--FROG
--
local S, modpath, mg_name = ...
local pet_name = "frog"
local mesh = nil
local scale_frog = 0.8
local textures = {}
local collisionbox = {}
local fixed = {}
local tiles = {}
local spawn_nodes = {}
if mg_name == "valleys" then
spawn_nodes = {"default:river_water_source"}
else
spawn_nodes = {"default:water_source"}
end
local animation_terrestrial = {
speed_normal = 15, walk_start = 26, walk_end = 38,
speed_run = 25, run_start = 26, run_end = 38,
stand_start = 0, stand_end = 12,
}
local animation_aquatic = {
speed_normal = 15, walk_start = 39, walk_end = 51, --swin
speed_run = 25, run_start = 39, run_end = 51,
stand_start = 52, stand_end = 61,
}
if petz.settings.type_model == "cubic" then
local node_name = "petz:"..pet_name.."_block"
fixed = {
{-0.1875, -0.5, -0.1875, -0.125, -0.4375, -0.125}, -- front_right_finger
{-0.25, -0.5, -0.125, -0.1875, -0.4375, -0.0625}, -- back_right_finger
{-0.1875, -0.5, -0.125, -0.125, -0.375, -0.0625}, -- bottom_right_leg
{-0.125, -0.4375, 0, -0.1875, -0.3125, -0.0625}, -- top_right_leg
{-0.1875, -0.375, 0.0625, -0.125, -0.3125, 0.1875}, -- NodeBox5
{-0.1875, -0.5, 0.125, -0.125, -0.4375, 0.1875}, -- NodeBox6
{-0.25, -0.5, 0.125, -0.1875, -0.4375, 0.1875}, -- NodeBox8
{-0.1875, -0.5, 0.0625, -0.125, -0.4375, 0.125}, -- NodeBox9
{-0.125, -0.4375, -0.125, 0.0625, -0.375, 0.1875}, -- NodeBox10
{-0.125, -0.375, -0.1875, 0.0625, -0.1875, 4.47035e-08}, -- NodeBox11
{-0.125, -0.375, 0, 0.0625, -0.25, 0.125}, -- NodeBox12
{0.0625, -0.5, -0.1875, 0.125, -0.4375, -0.125}, -- NodeBox14
{0.125, -0.5, -0.125, 0.1875, -0.4375, -0.0625}, -- NodeBoX45
{0.0625, -0.5, -0.125, 0.125, -0.375, -0.0625}, -- NodeBox15
{0.0625, -0.4375, -0.0625, 0.125, -0.3125, 5.21541e-08}, -- NodeBox16
{0.0625, -0.375, 0.0625, 0.125, -0.3125, 0.1875}, -- NodeBox17
{0.0625, -0.5, 0.125, 0.125, -0.4375, 0.1875}, -- NodeBox18
{0.125, -0.5, 0.125, 0.1875, -0.4375, 0.1875}, -- NodeBox19
{0.0625, -0.5, 0.0625, 0.125, -0.4375, 0.125}, -- NodeBox20
{-0.1875, -0.4375, 0.125, -0.125, -0.375, 0.25}, -- NodeBox21
{0.0625, -0.4375, 0.125, 0.125, -0.375, 0.25}, -- NodeBox22
}
tiles = {
"petz_frog_top.png",
"petz_frog_bottom.png",
"petz_frog_right.png",
"petz_frog_left.png",
"petz_frog_back.png",
"petz_frog_front.png"
}
petz.register_cubic(node_name, fixed, tiles)
textures= {"petz:frog_block"}
collisionbox = {-0.35, -0.75*scale_frog, -0.28, 0.35, -0.125, 0.28}
else
mesh = 'petz_frog.b3d'
textures= {{"petz_frog.png"}, {"petz_frog2.png"}, {"petz_frog3.png"}}
collisionbox = {-0.35, -0.75*scale_frog, -0.28, 0.35, -0.3125, 0.28}
end
mobs:register_mob("petz:"..pet_name, {
type = "animal",
rotate = petz.settings.rotate,
damage = 8,
hp_min = 4,
hp_max = 8,
armor = 200,
visual = petz.settings.visual,
visual_size = {x=petz.settings.visual_size.x*scale_frog, y=petz.settings.visual_size.y*scale_frog},
mesh = mesh,
textures = textures,
collisionbox = collisionbox,
makes_footstep_sound = false,
walk_velocity = 0.75,
run_velocity = 1,
runaway = true,
pushable = true,
fly = true,
fly_in = spawn_nodes,
floats = 1,
jump = true,
follow = petz.settings.frog_follow,
drops = {
{name = "mobs:meat_raw", chance = 1, min = 1, max = 1,},
},
water_damage = 0,
lava_damage = 6,
light_damage = 0,
sounds = {
random = "petz_frog_croak",
},
animation = animation_aquatic,
view_range = 4,
fear_height = 3,
stay_near= {
nodes = spawn_nodes,
chance = 3,
},
on_rightclick = function(self, clicker)
petz.on_rightclick(self, clicker)
end,
do_custom = function(self, dtime)
if not self.custom_vars_set04 then
self.custom_vars_set04 = 0
self.petz_type = "frog"
self.is_pet = false
self.is_wild = false
self.give_orders = false
self.affinity = 100
self.init_timer = false
self.fed= false
self.brushed = false
self.animation_terrestrial = animation_terrestrial
self.animation_aquatic = animation_aquatic
end
petz.semiaquatic_behaviour(self)
end,
})
mobs:register_egg("petz:frog", S("Frog"), "petz_spawnegg_frog.png", 0)
mobs:spawn({
name = "petz:frog",
nodes = spawn_nodes,
--neighbors = {"default:sand", "default:dirt", "group:seaplants"},
min_light = 14,
interval = 90,
chance = petz.settings.frog_spawn_chance,
min_height = 1,
max_height = -8,
day_toggle = true,
})

View File

@ -10,7 +10,7 @@ local mg_name = minetest.get_mapgen_setting("mg_name")
-- internationalization boilerplate
local S = minetest.get_translator(minetest.get_current_modname())
assert(loadfile(modpath .. "/api.lua"))(S)
assert(loadfile(modpath .. "/api.lua"))(modpath, S)
assert(loadfile(modpath .. "/settings.lua"))(modpath, S) --Load the settings
assert(loadfile(modpath .. "/nodes.lua"))(modpath, S) --Load the nodes
@ -38,3 +38,6 @@ end
if petz.settings.panda_spawn then
assert(loadfile(modpath .. "/panda_"..petz.settings.type_api..".lua"))(S)
end
if petz.settings.frog_spawn then
assert(loadfile(modpath .. "/frog_"..petz.settings.type_api..".lua"))(S, modpath, mg_name)
end

Binary file not shown.

BIN
models/petz_frog.b3d Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -51,3 +51,7 @@ calf_spawn_chance = 1200
##Panda Specific
panda_follow = default:papyrus
panda_spawn_chance = 1200
##Frog Specific
frog_follow = fireflies:firefly
frog_spawn_chance = 1200

View File

@ -50,6 +50,9 @@ petz.settings.calf_follow = settings:get("calf_follow", "")
petz.settings.panda_spawn = settings:get_bool("panda_spawn", true)
petz.settings.panda_spawn_chance = tonumber(settings:get("panda_spawn_chance"))
petz.settings.panda_follow = settings:get("panda_follow", "")
petz.settings.frog_spawn = settings:get_bool("frog_spawn", true)
petz.settings.frog_spawn_chance = tonumber(settings:get("frog_spawn_chance"))
petz.settings.frog_follow = settings:get("frog_follow", "")
if petz.settings.type_model == "mesh" then
petz.settings.visual = "mesh"

View File

@ -80,4 +80,10 @@ License: Unknown
filename: petz_panda_moaning.ogg
Author: San Diego Zoo
https://animals.sandiegozoo.org/animals/giant-panda
License: Unknown
License: Unknown
--------------------------------------------
filename: petz_frog_croak.ogg
Author: Alexander
http://www.orangefreesounds.com/frog-sound/
License: The sound effect is permitted for non-commercial use
under license “Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)

BIN
sounds/petz_frog_croak.ogg Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 594 B

BIN
textures/petz_frog2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

BIN
textures/petz_frog3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B