forked from MineClone5/MineClone5
Update Fork #9
|
@ -227,6 +227,11 @@ functions needed for the mob to work properly which contains the following:
|
||||||
older mobs.
|
older mobs.
|
||||||
'pushable' Allows players, & other mobs to push the mob.
|
'pushable' Allows players, & other mobs to push the mob.
|
||||||
|
|
||||||
|
'spawn_with_armor' If set to true, the mob has a small chance of spawning with
|
||||||
|
random matched armor. If set to a string, the string represents
|
||||||
|
the material type of the armor. Any materials used by
|
||||||
|
mcl_armor will work. Example: "gold"
|
||||||
|
It is assumed that the first texture is for armor.
|
||||||
|
|
||||||
|
|
||||||
MineClone 2 extensions:
|
MineClone 2 extensions:
|
||||||
|
|
|
@ -13,8 +13,13 @@ mobs.can_despawn = function(self)
|
||||||
if self.tamed or self.bred or self.nametag then return false end
|
if self.tamed or self.bred or self.nametag then return false end
|
||||||
local mob_pos = self.object:get_pos()
|
local mob_pos = self.object:get_pos()
|
||||||
if not mob_pos then return true end
|
if not mob_pos then return true end
|
||||||
|
local players = minetest_get_connected_players()
|
||||||
|
if #players == 0 then return false end
|
||||||
|
-- If no players, probably this is being called from get_staticdata() at server shutdown time
|
||||||
|
-- Minetest is to buggy (as of 5.5) to delete entities at server shutdown time anyway
|
||||||
|
|
||||||
local distance = 999
|
local distance = 999
|
||||||
for _, player in pairs(minetest_get_connected_players()) do
|
for _, player in pairs(players) do
|
||||||
if player and player:get_hp() > 0 then
|
if player and player:get_hp() > 0 then
|
||||||
local player_pos = player:get_pos()
|
local player_pos = player:get_pos()
|
||||||
local new_distance = vector_distance(player_pos, mob_pos)
|
local new_distance = vector_distance(player_pos, mob_pos)
|
||||||
|
@ -63,9 +68,8 @@ mobs.mob_staticdata = function(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
mobs.armor_setup = function(self)
|
mobs.armor_setup = function(self)
|
||||||
local armor = self._armor
|
if not self._armor_items then
|
||||||
if not armor then
|
local armor = {}
|
||||||
armor = {}
|
|
||||||
-- Source: https://minecraft.fandom.com/wiki/Zombie
|
-- Source: https://minecraft.fandom.com/wiki/Zombie
|
||||||
local materials = {
|
local materials = {
|
||||||
{name = "leather", chance = 0.3706},
|
{name = "leather", chance = 0.3706},
|
||||||
|
@ -76,10 +80,9 @@ mobs.armor_setup = function(self)
|
||||||
}
|
}
|
||||||
local types = {
|
local types = {
|
||||||
{name = "helmet", chance = 0.15},
|
{name = "helmet", chance = 0.15},
|
||||||
--{name = "helmet", chance = 1},
|
|
||||||
{name = "chestplate", chance = 0.75},
|
{name = "chestplate", chance = 0.75},
|
||||||
{name = "leggings", chance = 0.5625},
|
{name = "leggings", chance = 0.75},
|
||||||
{name = "boots", chance = 0.4219}
|
{name = "boots", chance = 0.75}
|
||||||
}
|
}
|
||||||
|
|
||||||
local material
|
local material
|
||||||
|
@ -95,6 +98,7 @@ mobs.armor_setup = function(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, t in pairs(types) do
|
for i, t in pairs(types) do
|
||||||
if math.random() <= t.chance then
|
if math.random() <= t.chance then
|
||||||
armor[t.name] = material
|
armor[t.name] = material
|
||||||
|
@ -102,61 +106,56 @@ mobs.armor_setup = function(self)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self._armor = armor
|
|
||||||
end
|
|
||||||
|
|
||||||
local t = ""
|
-- Setup table containing the armor items
|
||||||
local first_image = true
|
self._armor_items = {}
|
||||||
for atype, material in pairs(armor) do
|
for atype, material in pairs(armor) do
|
||||||
if not first_image then
|
local item = "mcl_armor:" .. atype .. "_" .. material
|
||||||
t = t .. "^"
|
table.insert(self._armor_items, item)
|
||||||
end
|
end
|
||||||
t = t .. "mcl_armor_" .. atype .. "_" .. material .. ".png"
|
|
||||||
first_image = false
|
|
||||||
end
|
|
||||||
if t == "" then
|
|
||||||
t = "mobs_mc_empty.png"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Configure damage groups based on armor
|
-- Setup armor drops
|
||||||
-- Source: https://minecraft.fandom.com/wiki/Armor#Armor_points
|
for atype, material in pairs(armor) do
|
||||||
local points = 2
|
|
||||||
for atype, material in pairs(self._armor) do
|
|
||||||
local item_name = "mcl_armor:" .. atype .. "_" .. material
|
|
||||||
points = points + minetest.get_item_group(item_name, "mcl_armor_points")
|
|
||||||
end
|
|
||||||
local armor_strength = 100 - 4 * points * 0.8 -- We should realy be using the full damage calculation
|
|
||||||
local armor_groups = self.object:get_armor_groups()
|
|
||||||
armor_groups.undead = armor_strength
|
|
||||||
armor_groups.fleshy = armor_strength
|
|
||||||
self.object:set_armor_groups(armor_groups)
|
|
||||||
|
|
||||||
local props = self.object:get_properties()
|
|
||||||
props.textures[1] = t
|
|
||||||
self.object:set_properties(props)
|
|
||||||
minetest.chat_send_all(dump(self._armor))
|
|
||||||
|
|
||||||
-- Rare chance of dropping armor on death
|
|
||||||
for atype, material in pairs(self._armor) do
|
|
||||||
local wear = math.random(1, 65535)
|
|
||||||
local item = "mcl_armor:" .. atype .. "_" .. material .. " 1 " .. wear
|
|
||||||
self.drops = table.copy(self.drops)
|
|
||||||
table.insert(self.drops, {
|
|
||||||
name = item,
|
|
||||||
chance = 1/0.085, -- 8.5%
|
|
||||||
min = 1,
|
|
||||||
max = 1,
|
|
||||||
looting = "common",
|
|
||||||
looting_factor = 0.01 / 3,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
--[[for atype, material in pairs(self._armor) do
|
|
||||||
if math.random() <= 0.085 then
|
|
||||||
local wear = math.random(1, 65535)
|
local wear = math.random(1, 65535)
|
||||||
local item = "mcl_armor:" .. atype .. "_" .. material .. " 1 " .. wear
|
local item = "mcl_armor:" .. atype .. "_" .. material .. " 1 " .. wear
|
||||||
minetest.add_item(pos, item)
|
self.drops = table.copy(self.drops)
|
||||||
|
table.insert(self.drops, {
|
||||||
|
name = item,
|
||||||
|
chance = 1/0.085, -- 8.5%
|
||||||
|
min = 1,
|
||||||
|
max = 1,
|
||||||
|
looting = "rare",
|
||||||
|
looting_factor = 0.01 / 3,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end]]
|
|
||||||
|
-- Configure textures
|
||||||
|
local t = ""
|
||||||
|
local first_image = true
|
||||||
|
for atype, material in pairs(armor) do
|
||||||
|
if not first_image then
|
||||||
|
t = t .. "^"
|
||||||
|
end
|
||||||
|
t = t .. "mcl_armor_" .. atype .. "_" .. material .. ".png"
|
||||||
|
first_image = false
|
||||||
|
end
|
||||||
|
if t ~= "" then
|
||||||
|
self.base_texture = table.copy(self.base_texture)
|
||||||
|
self.base_texture[1] = t
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Configure damage groups based on armor
|
||||||
|
-- Source: https://minecraft.fandom.com/wiki/Armor#Armor_points
|
||||||
|
local points = 2
|
||||||
|
for atype, material in pairs(armor) do
|
||||||
|
local item_name = "mcl_armor:" .. atype .. "_" .. material
|
||||||
|
points = points + minetest.get_item_group(item_name, "mcl_armor_points")
|
||||||
|
end
|
||||||
|
local armor_strength = 100 - 4 * points
|
||||||
|
local armor_groups = self.object:get_armor_groups()
|
||||||
|
armor_groups.fleshy = armor_strength
|
||||||
|
self.armor = armor_groups
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,6 +201,11 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
||||||
self.base_selbox = self.selectionbox
|
self.base_selbox = self.selectionbox
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Setup armor on mobs
|
||||||
|
if self._spawn_with_armor then
|
||||||
|
mobs.armor_setup(self)
|
||||||
|
end
|
||||||
|
|
||||||
-- for current mobs that dont have this set
|
-- for current mobs that dont have this set
|
||||||
if not self.base_selbox then
|
if not self.base_selbox then
|
||||||
self.base_selbox = self.selectionbox or self.base_colbox
|
self.base_selbox = self.selectionbox or self.base_colbox
|
||||||
|
@ -321,9 +325,6 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
||||||
|
|
||||||
--update_tag(self)
|
--update_tag(self)
|
||||||
--mobs.set_animation(self, "stand")
|
--mobs.set_animation(self, "stand")
|
||||||
if self._spawn_with_armor then
|
|
||||||
mobs.armor_setup(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- run on_spawn function if found
|
-- run on_spawn function if found
|
||||||
if self.on_spawn and not self.on_spawn_run then
|
if self.on_spawn and not self.on_spawn_run then
|
||||||
|
|
|
@ -207,7 +207,6 @@ local zombie = {
|
||||||
spawn_with_armor = true,
|
spawn_with_armor = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mobs:register_mob("mobs_mc:zombie", zombie)
|
mobs:register_mob("mobs_mc:zombie", zombie)
|
||||||
|
|
||||||
-- Baby zombie.
|
-- Baby zombie.
|
||||||
|
|
Loading…
Reference in New Issue