1
0
Fork 0

Merge pull request 'Add glow squids and particlespawner api for mobs' (#2741) from glow_squids into master

Reviewed-on: MineClone2/MineClone2#2741
Reviewed-by: PrairieWind <prairie.astronomer1@gmail.com>
This commit is contained in:
cora 2022-10-13 22:45:40 +00:00
commit 5b74a2e70c
13 changed files with 341 additions and 48 deletions

View File

@ -68,6 +68,8 @@ local disable_blood = minetest.settings:get_bool("mobs_disable_blood")
local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false
local player_transfer_distance = tonumber(minetest.settings:get("player_transfer_distance")) or 128
if player_transfer_distance == 0 then player_transfer_distance = math.huge end
local remove_far = true
local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0
local show_health = false
@ -84,6 +86,8 @@ if minetest.settings:get_bool("only_peaceful_mobs", false) then
end)
end
local active_particlespawners = {}
local function dir_to_pitch(dir)
--local dir2 = vector.normalize(dir)
@ -121,6 +125,60 @@ minetest.register_chatcommand("clearmobs",{
end
end})
local function remove_particlespawners(pn,self)
if not active_particlespawners[pn] then return end
if not active_particlespawners[pn][self.object] then return end
for k,v in pairs(active_particlespawners[pn][self.object]) do
minetest.delete_particlespawner(v)
end
end
local function add_particlespawners(pn,self)
if not active_particlespawners[pn] then active_particlespawners[pn] = {} end
if not active_particlespawners[pn][self.object] then active_particlespawners[pn][self.object] = {} end
for _,ps in pairs(self.particlespawners) do
ps.attached = self.object
ps.playername = pn
table.insert(active_particlespawners[pn][self.object],minetest.add_particlespawner(ps))
end
end
local function particlespawner_check(self,dtime)
if not self.particlespawners then return end
--minetest.log(dump(active_particlespawners))
if self._particle_timer and self._particle_timer >= 1 then
self._particle_timer = 0
local players = {}
for _,player in pairs(minetest.get_connected_players()) do
local pn = player:get_player_name()
table.insert(players,pn)
if not active_particlespawners[pn] then
active_particlespawners[pn] = {} end
local dst = vector.distance(player:get_pos(),self.object:get_pos())
if dst < player_transfer_distance and not active_particlespawners[pn][self.object] then
add_particlespawners(pn,self)
elseif dst >= player_transfer_distance and active_particlespawners[pn][self.object] then
remove_particlespawners(pn,self)
end
end
elseif not self._particle_timer then
self._particle_timer = 0
end
self._particle_timer = self._particle_timer + dtime
end
minetest.register_on_leaveplayer(function(player)
local pn = player:get_player_name()
if not active_particlespawners[pn] then return end
for _,m in pairs(active_particlespawners[pn]) do
for k,v in pairs(m) do
minetest.delete_particlespawner(v)
end
end
active_particlespawners[pn] = nil
end)
----For Water Flowing:
local enable_physics = function(object, luaentity, ignore_check)
if luaentity.physical_state == false or ignore_check == true then
@ -3477,7 +3535,9 @@ end
-- get entity staticdata
local mob_staticdata = function(self)
for _,p in pairs(minetest.get_connected_players()) do
remove_particlespawners(p:get_player_name(),self)
end
-- remove mob when out of range unless tamed
if remove_far
and self.can_despawn
@ -3711,6 +3771,7 @@ local mob_step = function(self, dtime)
self.lifetimer = self.lifetimer - dtime
check_item_pickup(self)
check_aggro(self,dtime)
particlespawner_check(self,dtime)
if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self)
-- mcl_burning.tick may remove object immediately
@ -4226,6 +4287,7 @@ minetest.register_entity(name, {
spawn_in_group = def.spawn_in_group,
spawn_in_group_min = def.spawn_in_group_min,
noyaw = def.noyaw or false,
particlespawners = def.particlespawners,
-- End of MCL2 extensions
on_spawn = def.on_spawn,

View File

@ -260,6 +260,8 @@ functions needed for the mob to work properly which contains the following:
'pick_up' table of itemstrings the mob will pick up (e.g. for breeding)
'on_pick_up' function that will be called on item pickup - return true to not pickup the item
'custom_visual_size' will not reset visual_size from the base class on reload
'noyaw' If true this mob will not automatically change yaw
'particlespawners' Table of particlespawners attached to the mob. This is implemented in a coord safe manner i.e. spawners are only sent to players within the player_transfer_distance (and automatically removed). This enables infinitely lived particlespawners.
mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival

View File

@ -237,7 +237,23 @@ local select_enderman_animation = function(animation_type)
end
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local spawners = {}
local psdefs = {{
amount = 5,
minpos = vector.new(-0.6,0,-0.6),
maxpos = vector.new(0.6,3,0.6),
minvel = vector.new(-0.25,-0.25,-0.25),
maxvel = vector.new(0.25,0.25,0.25),
minacc = vector.new(-0.5,-0.5,-0.5),
maxacc = vector.new(0.5,0.5,0.5),
minexptime = 0.2,
maxexptime = 3,
minsize = 0.2,
maxsize = 1.2,
collisiondetection = true,
vertical = false,
time = 0,
texture = "mcl_portals_particle"..math.random(1, 5)..".png",
}}
mcl_mobs:register_mob("mobs_mc:enderman", {
description = S("Enderman"),
@ -280,6 +296,7 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
run_velocity = 3.4,
damage = 7,
reach = 2,
particlespawners = psdefs,
drops = {
{name = "mcl_throwing:ender_pearl",
chance = 1,
@ -293,44 +310,8 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
return #minetest.find_nodes_in_area(vector.offset(pos,0,1,0),vector.offset(pos,0,3,0),{"air"}) > 2
end,
do_custom = function(self, dtime)
-- PARTICLE BEHAVIOUR HERE.
local enderpos = self.object:get_pos()
if self._particle_timer and self._particle_timer >= 1 then
for _,player in pairs(minetest.get_connected_players()) do
if not spawners[player] then spawners[player] = {} end
local dst = vector.distance(player:get_pos(),enderpos)
if dst < 128 and not spawners[player][self.object] then
self._particle_timer = 0
spawners[player][self.object] = minetest.add_particlespawner({
amount = 5,
minpos = vector.new(-0.6,0,-0.6),
maxpos = vector.new(0.6,3,0.6),
minvel = vector.new(-0.25,-0.25,-0.25),
maxvel = vector.new(0.25,0.25,0.25),
minacc = vector.new(-0.5,-0.5,-0.5),
maxacc = vector.new(0.5,0.5,0.5),
minexptime = 0.2,
maxexptime = 3,
minsize = 0.2,
maxsize = 1.2,
collisiondetection = true,
vertical = false,
time = 0,
texture = "mcl_portals_particle"..math.random(1, 5)..".png",
attached = self.object,
playername = player:get_player_name(),
})
elseif dst > 128 and spawners[player][self.object] then
minetest.delete_particlespawner(spawners[player][self.object])
spawners[player][self.object] = nil
end
end
elseif not self._particle_timer then
self._particle_timer = 0
end
self._particle_timer = self._particle_timer + dtime
-- RAIN DAMAGE / EVASIVE WARP BEHAVIOUR HERE.
enderpos = self.object:get_pos()
local enderpos = self.object:get_pos()
local dim = mcl_worlds.pos_to_dimension(enderpos)
if dim == "overworld" then
if mcl_weather.state == "rain" or mcl_weather.state == "lightning" then
@ -648,15 +629,6 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
attack_type = "dogfight",
})
minetest.register_on_leaveplayer(function(player)
if not spawners[player] then return end
for _,s in pairs(spawners[player]) do
minetest.delete_particlespawner(s)
end
spawners[player] = nil
end)
-- End spawn
mcl_mobs:spawn_specific(
"mobs_mc:enderman",

View File

@ -0,0 +1,246 @@
--MCmobs v0.4
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
local S = minetest.get_translator("mobs_mc")
local base_psdef = {
amount = 8,
time=0,
minpos = vector.new(-1,-1,-1),
maxpos = vector.new(1,1,1),
minvel = vector.new(-0.25,-0.25,-0.25),
maxvel = vector.new(0.25,0.25,0.25),
minacc = vector.new(-0.5,-0.5,-0.5),
maxacc = vector.new(0.5,0.5,0.5),
minexptime = 1,
maxexptime = 2,
minsize = 0.8,
maxsize= 1.5,
glow = 5,
collisiondetection = true,
collision_removal = true,
}
local psdefs = {}
for i=1,4 do
local p = table.copy(base_psdef)
p.texture = "extra_mobs_glow_squid_glint"..i..".png"
table.insert(psdefs,p)
end
mcl_mobs:register_mob("mobs_mc:glow_squid", {
type = "animal",
spawn_class = "water",
can_despawn = true,
passive = true,
hp_min = 10,
hp_max = 10,
xp_min = 1,
xp_max = 3,
armor = 100,
rotate = 0,
-- tilt_swim breaks the animations.
--tilt_swim = true,
-- FIXME: If the qlow squid is near the floor, it turns black
collisionbox = { -0.4, 0.0, -0.4, 0.4, 0.9, 0.4 },
visual = "mesh",
mesh = "extra_mobs_glow_squid.b3d",
textures = {
{ "extra_mobs_glow_squid.png" }
},
sounds = {
damage = { name = "mobs_mc_squid_hurt", gain = 0.3 },
death = { name = "mobs_mc_squid_death", gain = 0.4 },
flop = "mobs_mc_squid_flop",
distance = 16,
},
animation = {
stand_start = 1,
stand_end = 60,
walk_start = 1,
walk_end = 60,
run_start = 1,
run_end = 60,
},
drops = {
{ name = "mcl_mobitems:glow_ink_sac",
chance = 1,
min = 1,
max = 3,
looting = "common", },
},
visual_size = { x = 3, y = 3 },
makes_footstep_sound = false,
swim = true,
breathes_in_water = true,
jump = false,
view_range = 16,
runaway = true,
fear_height = 4,
fly = true,
fly_in = { "mcl_core:water_source", "mclx_core:river_water_source" },
-- don't add "mcl_core:water_flowing", or it won't move vertically.
glow = minetest.LIGHT_MAX,
particlespawners = psdefs,
})
-- spawning
local water = mobs_mc.water_level - 1
-- local water = mobs_mc.spawn_height.water + 1
mcl_mobs:spawn_specific(
"mobs_mc:glow_squid",
"overworld",
"water",
{
"Mesa",
"FlowerForest",
"Swampland",
"Taiga",
"ExtremeHills",
"Jungle",
"Savanna",
"BirchForest",
"MegaSpruceTaiga",
"MegaTaiga",
"ExtremeHills+",
"Forest",
"Plains",
"Desert",
"ColdTaiga",
"MushroomIsland",
"IcePlainsSpikes",
"SunflowerPlains",
"IcePlains",
"RoofedForest",
"ExtremeHills+_snowtop",
"MesaPlateauFM_grasstop",
"JungleEdgeM",
"ExtremeHillsM",
"JungleM",
"BirchForestM",
"MesaPlateauF",
"MesaPlateauFM",
"MesaPlateauF_grasstop",
"MesaBryce",
"JungleEdge",
"SavannaM",
"FlowerForest_beach",
"Forest_beach",
"StoneBeach",
"ColdTaiga_beach_water",
"Taiga_beach",
"Savanna_beach",
"Plains_beach",
"ExtremeHills_beach",
"ColdTaiga_beach",
"Swampland_shore",
"MushroomIslandShore",
"JungleM_shore",
"Jungle_shore",
"MesaPlateauFM_sandlevel",
"MesaPlateauF_sandlevel",
"MesaBryce_sandlevel",
"Mesa_sandlevel",
"RoofedForest_ocean",
"JungleEdgeM_ocean",
"BirchForestM_ocean",
"BirchForest_ocean",
"IcePlains_deep_ocean",
"Jungle_deep_ocean",
"Savanna_ocean",
"MesaPlateauF_ocean",
"ExtremeHillsM_deep_ocean",
"Savanna_deep_ocean",
"SunflowerPlains_ocean",
"Swampland_deep_ocean",
"Swampland_ocean",
"MegaSpruceTaiga_deep_ocean",
"ExtremeHillsM_ocean",
"JungleEdgeM_deep_ocean",
"SunflowerPlains_deep_ocean",
"BirchForest_deep_ocean",
"IcePlainsSpikes_ocean",
"Mesa_ocean",
"StoneBeach_ocean",
"Plains_deep_ocean",
"JungleEdge_deep_ocean",
"SavannaM_deep_ocean",
"Desert_deep_ocean",
"Mesa_deep_ocean",
"ColdTaiga_deep_ocean",
"Plains_ocean",
"MesaPlateauFM_ocean",
"Forest_deep_ocean",
"JungleM_deep_ocean",
"FlowerForest_deep_ocean",
"MushroomIsland_ocean",
"MegaTaiga_ocean",
"StoneBeach_deep_ocean",
"IcePlainsSpikes_deep_ocean",
"ColdTaiga_ocean",
"SavannaM_ocean",
"MesaPlateauF_deep_ocean",
"MesaBryce_deep_ocean",
"ExtremeHills+_deep_ocean",
"ExtremeHills_ocean",
"MushroomIsland_deep_ocean",
"Forest_ocean",
"MegaTaiga_deep_ocean",
"JungleEdge_ocean",
"MesaBryce_ocean",
"MegaSpruceTaiga_ocean",
"ExtremeHills+_ocean",
"Jungle_ocean",
"RoofedForest_deep_ocean",
"IcePlains_ocean",
"FlowerForest_ocean",
"ExtremeHills_deep_ocean",
"MesaPlateauFM_deep_ocean",
"Desert_ocean",
"Taiga_ocean",
"BirchForestM_deep_ocean",
"Taiga_deep_ocean",
"JungleM_ocean",
"FlowerForest_underground",
"JungleEdge_underground",
"StoneBeach_underground",
"MesaBryce_underground",
"Mesa_underground",
"RoofedForest_underground",
"Jungle_underground",
"Swampland_underground",
"MushroomIsland_underground",
"BirchForest_underground",
"Plains_underground",
"MesaPlateauF_underground",
"ExtremeHills_underground",
"MegaSpruceTaiga_underground",
"BirchForestM_underground",
"SavannaM_underground",
"MesaPlateauFM_underground",
"Desert_underground",
"Savanna_underground",
"Forest_underground",
"SunflowerPlains_underground",
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"ExtremeHills+_underground",
"JungleM_underground",
"ExtremeHillsM_underground",
"JungleEdgeM_underground",
},
0,
minetest.LIGHT_MAX + 1,
30,
10000,
3,
water - 16,
water)
-- spawn egg
mcl_mobs:register_egg("mobs_mc:glow_squid", S("Glow Squid"), "#095757", "#87f6c0", 0)

View File

@ -148,3 +148,5 @@ dofile(path .. "/cod.lua")
dofile(path .. "/salmon.lua")
dofile(path .. "/tropical_fish.lua")
dofile(path .. "/dolphin.lua")
dofile(path .. "/glow_squid.lua")

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

View File

@ -390,6 +390,15 @@ minetest.register_alias("mobs_mc:iron_horse_armor", "mcl_mobitems:iron_horse_arm
minetest.register_alias("mobs_mc:gold_horse_armor", "mcl_mobitems:gold_horse_armor")
minetest.register_alias("mobs_mc:diamond_horse_armor", "mcl_mobitems:diamond_horse_armor")
minetest.register_craftitem("mcl_mobitems:glow_ink_sac", {
description = S("Glow Ink Sac"),
_doc_items_longdesc = S("Use it to craft the Glow Item Frame."),
_doc_items_usagehelp = S("Use the Glow Ink Sac and the normal Item Frame to craft the Glow Item Frame."),
inventory_image = "extra_mobs_glow_ink_sac.png",
groups = { craftitem = 1 },
})
-----------
-- Crafting
-----------

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B