diff --git a/mods/minetest-3d_armor/.gitignore b/mods/minetest-3d_armor/.gitignore new file mode 100644 index 00000000..ba96b081 --- /dev/null +++ b/mods/minetest-3d_armor/.gitignore @@ -0,0 +1,11 @@ +## Generic ignorable patterns and files +*~ +.*.swp +*bak* +tags +*.vim +armor.conf + +## Eclipse project files & directories +.project +.settings diff --git a/mods/minetest-3d_armor/3d_armor/LICENSE.txt b/mods/minetest-3d_armor/3d_armor/LICENSE.txt new file mode 100644 index 00000000..f253f299 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/LICENSE.txt @@ -0,0 +1,26 @@ +[mod] 3d Armor [3d_armor] +========================= + +License Source Code +------------------- + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +License Textures +---------------- + +Copyright (C) 2017-2019 davidthecreator - CC-BY-SA 3.0 diff --git a/mods/minetest-3d_armor/3d_armor/README.txt b/mods/minetest-3d_armor/3d_armor/README.txt new file mode 100644 index 00000000..7dbe82d0 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/README.txt @@ -0,0 +1,191 @@ +[mod] Visible Player Armor [3d_armor] +===================================== + +Depends: default + +Recommends: sfinv, unified_inventory or smart_inventory (use only one to avoid conflicts) + +Supports: player_monoids and armor_monoid + +Adds craftable armor that is visible to other players. Each armor item worn contributes to +a player's armor group level making them less vulnerable to weapons. + +Armor takes damage when a player is hurt but also offers a percentage chance of healing. +Overall level is boosted by 10% when wearing a full matching set. + +Fire protection added by TenPlus1 when using crystal armor if Ethereal mod active, level 1 +protects against torches, level 2 for crystal spike, level 3 for fire, level 5 for lava. + +Armor Configuration +------------------- + +Override the following default settings by adding them to your minetest.conf file. + +-- Set false to disable individual armor materials. +armor_material_wood = true +armor_material_cactus = true +armor_material_steel = true +armor_material_bronze = true +armor_material_diamond = true +armor_material_gold = true +armor_material_mithril = true +armor_material_crystal = true + +-- Increase this if you get initialization glitches when a player first joins. +armor_init_delay = 2 + +-- Number of initialization attempts. +-- Use in conjunction with armor_init_delay if initialization problems persist. +armor_init_times = 10 + +-- Increase this if armor is not getting into bones due to server lag. +armor_bones_delay = 1 + +-- How often player armor items are updated. +armor_update_time = 1 + +-- Drop armor when a player dies. +-- Uses bones mod if present, otherwise items are dropped around the player. +armor_drop = true + +-- Pulverise armor when a player dies, overrides armor_drop. +armor_destroy = false + +-- You can use this to increase or decrease overall armor effectiveness, +-- eg: level_multiplier = 0.5 will reduce armor level by half. +armor_level_multiplier = 1 + +-- You can use this to increase or decrease overall armor healing, +-- eg: armor_heal_multiplier = 0 will disable healing altogether. +armor_heal_multiplier = 1 + +-- Enable water protection (periodically restores breath when activated) +armor_water_protect = true + +-- Enable fire protection (defaults true if using ethereal mod) +armor_fire_protect = false + +-- Enable punch damage effects. +armor_punch_damage = true + +-- Enable migration of old armor inventories +armor_migrate_old_inventory = true + +API +--- + +Armor Registration: + +armor:register_armor(name, def) + +Wrapper function for `minetest.register_tool`, while registering armor as +a tool item is still supported, this may be deprecated in future so new code +should use this method. + +Additional fields supported by 3d_armor: + + texture = + preview = + armor_groups = + damage_groups =
+ reciprocate_damage = + on_equip = + on_unequip = + on_destroy = + on_damage = + on_punched = + +armor:register_armor_group(group, base) + +Example: + +armor:register_armor_group("radiation", 100) + +armor:register_armor("mod_name:speed_boots", { + description = "Speed Boots", + inventory_image = "mod_name_speed_boots_inv.png", + texture = "mod_name_speed_boots.png", + preview = "mod_name_speed_boots_preview.png", + groups = {armor_feet=1, armor_use=500, physics_speed=1.2, flammable=1}, + armor_groups = {fleshy=10, radiation=10}, + damage_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1}, + reciprocate_damage = true, + on_destroy = function(player, index, stack) + local pos = player:get_pos() + if pos then + minetest.sound_play({ + name = "mod_name_break_sound", + pos = pos, + gain = 0.5, + }) + end + end, +}) + +See armor.lua, technic_armor and shields mods for more examples. + +Default groups: + +Elements: armor_head, armor_torso, armor_legs, armor_feet +Attributes: armor_heal, armor_fire, armor_water +Physics: physics_jump, physics_speed, physics_gravity +Durability: armor_use, flammable + +Notes: + +Elements may be modified by dependent mods, eg shields adds armor_shield. +Attributes and physics values are 'stackable', durability is determined +by the level of armor_use, total uses == approx (65535/armor_use), non-fleshy +damage groups need to be defined in the tool/weapon used against the player. + +Reciprocal tool damage will be done only by the first armor inventory item + with `reciprocate_damage = true` + +Armor Functions: + +armor:set_player_armor(player) + +Primarily an internal function but can be called externally to apply any +changes that might not otherwise get handled. + +armor:punch(player, hitter, time_from_last_punch, tool_capabilities) + +Used to apply damage to all equipped armor based on the damage groups of +each individual item.`hitter`, `time_from_last_punch` and `tool_capabilities` +are optional but should be valid if included. + +armor:damage(player, index, stack, use) + +Adds wear to a single armor itemstack, triggers `on_damage` callbacks and +updates the necessary inventories. Also handles item destruction callbacks +and so should NOT be called from `on_unequip` to avoid an infinite loop. + +Item Callbacks: + +on_equip = func(player, index, stack) +on_unequip = func(player, index, stack) +on_destroy = func(player, index, stack) +on_damage = func(player, index, stack) +on_punched = func(player, hitter, time_from_last_punch, tool_capabilities) + +Notes: + +`on_punched` is called every time a player is punched or takes damage, `hitter`, +`time_from_last_punch` and `tool_capabilities` can be `nil` and will be in the +case of fall damage, etc. When fire protection is enabled, hitter == "fire" +in the event of fire damage. Return `false` to override armor damage effects. +When armor is destroyed `stack` will contain a copy of the previous stack. + +Global Callbacks: + +armor:register_on_update(func(player)) +armor:register_on_equip(func(player, index, stack)) +armor:register_on_unequip(func(player, index, stack)) +armor:register_on_destroy(func(player, index, stack)) + +Global Callback Example: + +armor:register_on_update(function(player) + print(player:get_player_name().." armor updated!") +end) + diff --git a/mods/minetest-3d_armor/3d_armor/api.lua b/mods/minetest-3d_armor/3d_armor/api.lua new file mode 100644 index 00000000..8b234184 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/api.lua @@ -0,0 +1,524 @@ +-- support for i18n +local S = armor_i18n.gettext + +local skin_previews = {} +local use_player_monoids = minetest.global_exists("player_monoids") +local use_armor_monoid = minetest.global_exists("armor_monoid") +local use_pova_mod = minetest.get_modpath("pova") +local armor_def = setmetatable({}, { + __index = function() + return setmetatable({ + groups = setmetatable({}, { + __index = function() + return 0 + end}) + }, { + __index = function() + return 0 + end + }) + end, +}) +local armor_textures = setmetatable({}, { + __index = function() + return setmetatable({}, { + __index = function() + return "blank.png" + end + }) + end +}) + +armor = { + timer = 0, + elements = {"head", "torso", "legs", "feet"}, + physics = {"jump", "speed", "gravity"}, + attributes = {"heal", "fire", "water"}, + formspec = "image[2.5,0;2,4;armor_preview]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + default.get_hotbar_bg(0, 4.7).. + "list[current_player;main;0,4.7;8,1;]".. + "list[current_player;main;0,5.85;8,3;8]", + def = armor_def, + textures = armor_textures, + default_skin = "character", + materials = { + wood = "group:wood", + durasteel = "default:durasteel_ingot", + bronze = "default:bronze_ingot", + beskar = "default:beskar_ingot", + gold = "default:gold_ingot", + }, + fire_nodes = { + {"default:lava_source", 5, 8}, + {"default:lava_flowing", 5, 8}, + {"fire:basic_flame", 3, 4}, + {"fire:permanent_flame", 3, 4}, + {"ethereal:crystal_spike", 2, 1}, + {"ethereal:fire_flower", 2, 1}, + {"default:torch", 1, 1}, + {"default:torch_ceiling", 1, 1}, + {"default:torch_wall", 1, 1}, + }, + registered_groups = {["fleshy"]=100}, + registered_callbacks = { + on_update = {}, + on_equip = {}, + on_unequip = {}, + on_damage = {}, + on_destroy = {}, + }, + migrate_old_inventory = true, + version = "0.4.13", +} + +armor.config = { + init_delay = 2, + init_times = 10, + bones_delay = 1, + update_time = 1, + drop = minetest.get_modpath("bones") ~= nil, + destroy = false, + level_multiplier = 1, + heal_multiplier = 1, + material_wood = true, + material_durasteel = true, + material_bronze = true, + material_beskar = true, + material_gold = true, + water_protect = true, + fire_protect = minetest.get_modpath("ethereal") ~= nil, + punch_damage = true, +} + +-- Armor Registration + +armor.register_armor = function(self, name, def) + minetest.register_tool(name, def) +end + +armor.register_armor_group = function(self, group, base) + base = base or 100 + self.registered_groups[group] = base + if use_armor_monoid then + armor_monoid.register_armor_group(group, base) + end +end + +-- Armor callbacks + +armor.register_on_update = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_update, func) + end +end + +armor.register_on_equip = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_equip, func) + end +end + +armor.register_on_unequip = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_unequip, func) + end +end + +armor.register_on_damage = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_damage, func) + end +end + +armor.register_on_destroy = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_destroy, func) + end +end + +armor.run_callbacks = function(self, callback, player, index, stack) + if stack then + local def = stack:get_definition() or {} + if type(def[callback]) == "function" then + def[callback](player, index, stack) + end + end + local callbacks = self.registered_callbacks[callback] + if callbacks then + for _, func in pairs(callbacks) do + func(player, index, stack) + end + end +end + +armor.update_player_visuals = function(self, player) + if not player then + return + end + local name = player:get_player_name() + if self.textures[name] then + default.player_set_textures(player, { + self.textures[name].skin, + self.textures[name].armor, + self.textures[name].wielditem, + }) + end + self:run_callbacks("on_update", player) +end + +armor.set_player_armor = function(self, player) + local name, armor_inv = self:get_valid_player(player, "[set_player_armor]") + if not name then + return + end + local state = 0 + local count = 0 + local material = {count=1} + local preview = armor:get_preview(name) + local texture = "3d_armor_trans.png" + local textures = {} + local physics = {} + local attributes = {} + local levels = {} + local groups = {} + local change = {} + for _, phys in pairs(self.physics) do + physics[phys] = 1 + end + for _, attr in pairs(self.attributes) do + attributes[attr] = 0 + end + for group, _ in pairs(self.registered_groups) do + change[group] = 1 + levels[group] = 0 + end + local list = armor_inv:get_list("armor") + if type(list) ~= "table" then + return + end + for i, stack in pairs(list) do + if stack:get_count() == 1 then + local def = stack:get_definition() + for _, element in pairs(self.elements) do + if def.groups["armor_"..element] then + if def.armor_groups then + for group, level in pairs(def.armor_groups) do + if levels[group] then + levels[group] = levels[group] + level + end + end + else + local level = def.groups["armor_"..element] + levels["fleshy"] = levels["fleshy"] + level + end + break + end + -- DEPRECATED, use armor_groups instead + if def.groups["armor_radiation"] and levels["radiation"] then + levels["radiation"] = def.groups["armor_radiation"] + end + end + local item = stack:get_name() + local tex = def.texture or item:gsub("%:", "_") + tex = tex:gsub(".png$", "") + local prev = def.preview or tex.."_preview" + prev = prev:gsub(".png$", "") + texture = texture.."^"..tex..".png" + preview = preview.."^"..prev..".png" + state = state + stack:get_wear() + count = count + 1 + for _, phys in pairs(self.physics) do + local value = def.groups["physics_"..phys] or 0 + physics[phys] = physics[phys] + value + end + for _, attr in pairs(self.attributes) do + local value = def.groups["armor_"..attr] or 0 + attributes[attr] = attributes[attr] + value + end + local mat = string.match(item, "%:.+_(.+)$") + if material.name then + if material.name == mat then + material.count = material.count + 1 + end + else + material.name = mat + end + end + end + for group, level in pairs(levels) do + if level > 0 then + level = level * armor.config.level_multiplier + if material.name and material.count == #self.elements then + level = level * 1.1 + end + end + local base = self.registered_groups[group] + self.def[name].groups[group] = level + if level > base then + level = base + end + groups[group] = base - level + change[group] = groups[group] / base + end + for _, attr in pairs(self.attributes) do + local mult = attr == "heal" and self.config.heal_multiplier or 1 + self.def[name][attr] = attributes[attr] * mult + end + for _, phys in pairs(self.physics) do + self.def[name][phys] = physics[phys] + end + if use_armor_monoid then + armor_monoid.monoid:add_change(player, change, "3d_armor:armor") + else + -- Preserve immortal group (damage disabled for player) + local immortal = player:get_armor_groups().immortal + if immortal and immortal ~= 0 then + groups.immortal = 1 + end + player:set_armor_groups(groups) + end + if use_player_monoids then + player_monoids.speed:add_change(player, physics.speed, + "3d_armor:physics") + player_monoids.jump:add_change(player, physics.jump, + "3d_armor:physics") + player_monoids.gravity:add_change(player, physics.gravity, + "3d_armor:physics") + elseif use_pova_mod then + -- only add the changes, not the default 1.0 for each physics setting + pova.add_override(name, "3d_armor", { + speed = physics.speed - 1, + jump = physics.jump - 1, + gravity = physics.gravity - 1, + }) + pova.do_override(player) + else + player:set_physics_override(physics) + end + self.textures[name].armor = texture + self.textures[name].preview = preview + self.def[name].level = self.def[name].groups.fleshy or 0 + self.def[name].state = state + self.def[name].count = count + self:update_player_visuals(player) +end + +armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabilities) + local name, armor_inv = self:get_valid_player(player, "[punch]") + if not name then + return + end + local state = 0 + local count = 0 + local recip = true + local default_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1} + local list = armor_inv:get_list("armor") + for i, stack in pairs(list) do + if stack:get_count() == 1 then + local name = stack:get_name() + local use = minetest.get_item_group(name, "armor_use") or 0 + local damage = use > 0 + local def = stack:get_definition() or {} + if type(def.on_punched) == "function" then + damage = def.on_punched(player, hitter, time_from_last_punch, + tool_capabilities) ~= false and damage == true + end + if damage == true and tool_capabilities then + local damage_groups = def.damage_groups or default_groups + local level = damage_groups.level or 0 + local groupcaps = tool_capabilities.groupcaps or {} + local uses = 0 + damage = false + for group, caps in pairs(groupcaps) do + local maxlevel = caps.maxlevel or 0 + local diff = maxlevel - level + if diff == 0 then + diff = 1 + end + if diff > 0 and caps.times then + local group_level = damage_groups[group] + if group_level then + local time = caps.times[group_level] + if time then + local dt = time_from_last_punch or 0 + if dt > time / diff then + if caps.uses then + uses = caps.uses * math.pow(3, diff) + end + damage = true + break + end + end + end + end + end + if damage == true and recip == true and hitter and + def.reciprocate_damage == true and uses > 0 then + local item = hitter:get_wielded_item() + if item and item:get_name() ~= "" then + item:add_wear(65535 / uses) + hitter:set_wielded_item(item) + end + -- reciprocate tool damage only once + recip = false + end + end + if damage == true and hitter == "fire" then + damage = minetest.get_item_group(name, "flammable") > 0 + end + if damage == true then + self:damage(player, i, stack, use) + end + state = state + stack:get_wear() + count = count + 1 + end + end + self.def[name].state = state + self.def[name].count = count +end + +armor.damage = function(self, player, index, stack, use) + local old_stack = ItemStack(stack) + stack:add_wear(use) + self:run_callbacks("on_damage", player, index, stack) + self:set_inventory_stack(player, index, stack) + if stack:get_count() == 0 then + self:run_callbacks("on_unequip", player, index, old_stack) + self:run_callbacks("on_destroy", player, index, old_stack) + self:set_player_armor(player) + end +end + +armor.get_player_skin = function(self, name) + if (self.skin_mod == "skins" or self.skin_mod == "simple_skins") and skins.skins[name] then + return skins.skins[name]..".png" + elseif self.skin_mod == "u_skins" and u_skins.u_skins[name] then + return u_skins.u_skins[name]..".png" + elseif self.skin_mod == "wardrobe" and wardrobe.playerSkins and wardrobe.playerSkins[name] then + return wardrobe.playerSkins[name] + end + return armor.default_skin..".png" +end + +armor.add_preview = function(self, preview) + skin_previews[preview] = true +end + +armor.get_preview = function(self, name) + local preview = string.gsub(armor:get_player_skin(name), ".png", "_preview.png") + if skin_previews[preview] then + return preview + end + return "character_preview.png" +end + +armor.get_armor_formspec = function(self, name, listring) + if armor.def[name].init_time == 0 then + return "label[0,0;Armor not initialized!]" + end + local formspec = armor.formspec.. + "list[detached:"..name.."_armor;armor;0,0.5;2,3;]" + if listring == true then + formspec = formspec.."listring[current_player;main]".. + "listring[detached:"..name.."_armor;armor]" + end + formspec = formspec:gsub("armor_preview", armor.textures[name].preview) + formspec = formspec:gsub("armor_level", armor.def[name].level) + for _, attr in pairs(self.attributes) do + formspec = formspec:gsub("armor_attr_"..attr, armor.def[name][attr]) + end + for group, _ in pairs(self.registered_groups) do + formspec = formspec:gsub("armor_group_"..group, + armor.def[name].groups[group]) + end + return formspec +end + +armor.get_element = function(self, item_name) + for _, element in pairs(armor.elements) do + if minetest.get_item_group(item_name, "armor_"..element) > 0 then + return element + end + end +end + +armor.serialize_inventory_list = function(self, list) + local list_table = {} + for _, stack in ipairs(list) do + table.insert(list_table, stack:to_string()) + end + return minetest.serialize(list_table) +end + +armor.deserialize_inventory_list = function(self, list_string) + local list_table = minetest.deserialize(list_string) + local list = {} + for _, stack in ipairs(list_table or {}) do + table.insert(list, ItemStack(stack)) + end + return list +end + +armor.load_armor_inventory = function(self, player) + local _, inv = self:get_valid_player(player, "[load_armor_inventory]") + if inv then + local armor_list_string = player:get_attribute("3d_armor_inventory") + if armor_list_string then + inv:set_list("armor", + self:deserialize_inventory_list(armor_list_string)) + return true + end + end +end + +armor.save_armor_inventory = function(self, player) + local _, inv = self:get_valid_player(player, "[save_armor_inventory]") + if inv then + player:set_attribute("3d_armor_inventory", + self:serialize_inventory_list(inv:get_list("armor"))) + end +end + +armor.update_inventory = function(self, player) + -- DEPRECATED: Legacy inventory support +end + +armor.set_inventory_stack = function(self, player, i, stack) + local _, inv = self:get_valid_player(player, "[set_inventory_stack]") + if inv then + inv:set_stack("armor", i, stack) + self:save_armor_inventory(player) + end +end + +armor.get_valid_player = function(self, player, msg) + msg = msg or "" + if not player then + minetest.log("warning", S("3d_armor: Player reference is nil @1", msg)) + return + end + local name = player:get_player_name() + if not name then + minetest.log("warning", S("3d_armor: Player name is nil @1", msg)) + return + end + local inv = minetest.get_inventory({type="detached", name=name.."_armor"}) + if not inv then + minetest.log("warning", S("3d_armor: Detached armor inventory is nil @1", msg)) + return + end + return name, inv +end + +armor.drop_armor = function(pos, stack) + local node = minetest.get_node_or_nil(pos) + if node then + local obj = minetest.add_item(pos, stack) + if obj then + obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)}) + end + end +end diff --git a/mods/minetest-3d_armor/3d_armor/armor.conf.example b/mods/minetest-3d_armor/3d_armor/armor.conf.example new file mode 100644 index 00000000..9ce34b45 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/armor.conf.example @@ -0,0 +1,65 @@ +-- DEPRECATED, will not be supported in future versions + +-- See README.txt for new configuration options. + +-- Armor Configuration (defaults) + +-- You can remove any unwanted armor materials from this table. +-- Note that existing armor that is removed will show up as an unknown item. +ARMOR_MATERIALS = { + wood = "group:wood", + cactus = "default:cactus", + steel = "default:steel_ingot", + bronze = "default:bronze_ingot", + diamond = "default:diamond", + gold = "default:gold_ingot", + mithril = "moreores:mithril_ingot", + crystal = "ethereal:crystal_ingot", +} + +-- Enable fire protection (defaults true if using ethereal mod) +ARMOR_FIRE_PROTECT = false + +-- Fire protection nodes, (name, protection level, damage) +ARMOR_FIRE_NODES = { + {"default:lava_source", 5, 4}, + {"default:lava_flowing", 5, 4}, + {"fire:basic_flame", 3, 4}, + {"fire:permanent_flame", 3, 4}, + {"ethereal:crystal_spike", 2, 1}, + {"ethereal:fire_flower", 2, 1}, + {"default:torch", 1, 1}, +} + +-- Increase this if you get initialization glitches when a player first joins. +ARMOR_INIT_DELAY = 1 + +-- Number of initialization attempts. +-- Use in conjunction with ARMOR_INIT_DELAY if initialization problems persist. +ARMOR_INIT_TIMES = 1 + +-- Increase this if armor is not getting into bones due to server lag. +ARMOR_BONES_DELAY = 1 + +-- How often player armor/wield items are updated. +ARMOR_UPDATE_TIME = 1 + +-- Drop armor when a player dies. +-- Uses bones mod if present, otherwise items are dropped around the player. +ARMOR_DROP = true + +-- Pulverise armor when a player dies, overrides ARMOR_DROP. +ARMOR_DESTROY = false + +-- You can use this to increase or decrease overall armor effectiveness, +-- eg: ARMOR_LEVEL_MULTIPLIER = 0.5 will reduce armor level by half. +ARMOR_LEVEL_MULTIPLIER = 1 + +-- You can use this to increase or decrease overall armor healing, +-- eg: ARMOR_HEAL_MULTIPLIER = 0 will disable healing altogether. +ARMOR_HEAL_MULTIPLIER = 1 + +-- You can use this to increase or decrease overall armor radiation protection, +-- eg: ARMOR_RADIATION_MULTIPLIER = 0 will completely disable radiation protection. +-- Note: patched technic mod is required +ARMOR_RADIATION_MULTIPLIER = 1 diff --git a/mods/minetest-3d_armor/3d_armor/armor.lua b/mods/minetest-3d_armor/3d_armor/armor.lua new file mode 100644 index 00000000..478a4fd8 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/armor.lua @@ -0,0 +1,252 @@ +-- support for i18n +local S = armor_i18n.gettext + +armor:register_armor("3d_armor:helmet_admin", { + description = S("Admin Helmet"), + inventory_image = "3d_armor_inv_helmet_admin.png", + armor_groups = {fleshy=100}, + groups = {armor_head=1, armor_heal=100, armor_use=0, armor_water=1, + not_in_creative_inventory=1}, + on_drop = function(itemstack, dropper, pos) + return + end, +}) + +armor:register_armor("3d_armor:chestplate_admin", { + description = S("Admin Chestplate"), + inventory_image = "3d_armor_inv_chestplate_admin.png", + armor_groups = {fleshy=100}, + groups = {armor_torso=1, armor_heal=100, armor_use=0, + not_in_creative_inventory=1}, + on_drop = function(itemstack, dropper, pos) + return + end, +}) + +armor:register_armor("3d_armor:leggings_admin", { + description = S("Admin Leggings"), + inventory_image = "3d_armor_inv_leggings_admin.png", + armor_groups = {fleshy=100}, + groups = {armor_legs=1, armor_heal=100, armor_use=0, + not_in_creative_inventory=1}, + on_drop = function(itemstack, dropper, pos) + return + end, +}) + +armor:register_armor("3d_armor:boots_admin", { + description = S("Admin Boots"), + inventory_image = "3d_armor_inv_boots_admin.png", + armor_groups = {fleshy=100}, + groups = {armor_feet=1, armor_heal=100, armor_use=0, + not_in_creative_inventory=1}, + on_drop = function(itemstack, dropper, pos) + return + end, +}) + +minetest.register_alias("adminboots", "3d_armor:boots_admin") +minetest.register_alias("adminhelmet", "3d_armor:helmet_admin") +minetest.register_alias("adminchestplate", "3d_armor:chestplate_admin") +minetest.register_alias("adminleggings", "3d_armor:leggings_admin") + +if armor.materials.wood then + armor:register_armor("3d_armor:helmet_wood", { + description = S("Wood Helmet"), + inventory_image = "3d_armor_inv_helmet_wood.png", + groups = {armor_head=1, armor_heal=0, armor_use=2000, flammable=1}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, + }) + armor:register_armor("3d_armor:chestplate_wood", { + description = S("Wood Chestplate"), + inventory_image = "3d_armor_inv_chestplate_wood.png", + groups = {armor_torso=1, armor_heal=0, armor_use=2000, flammable=1}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, + }) + armor:register_armor("3d_armor:leggings_wood", { + description = S("Wood Leggings"), + inventory_image = "3d_armor_inv_leggings_wood.png", + groups = {armor_legs=1, armor_heal=0, armor_use=2000, flammable=1}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, + }) + armor:register_armor("3d_armor:boots_wood", { + description = S("Wood Boots"), + inventory_image = "3d_armor_inv_boots_wood.png", + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, + groups = {armor_feet=1, armor_heal=0, armor_use=2000, flammable=1}, + }) +end + +if armor.materials.durasteel then + armor:register_armor("3d_armor:helmet_durasteel", { + description = S("Durasteel Helmet"), + inventory_image = "3d_armor_inv_helmet_durasteel.png", + groups = {armor_head=1, armor_heal=0, armor_use=800, + physics_speed=-0.01, physics_gravity=0.01}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:chestplate_durasteel", { + description = S("Durasteel Chestplate"), + inventory_image = "3d_armor_inv_chestplate_durasteel.png", + groups = {armor_torso=1, armor_heal=0, armor_use=800, + physics_speed=-0.04, physics_gravity=0.04}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:leggings_durasteel", { + description = S("Durasteel Leggings"), + inventory_image = "3d_armor_inv_leggings_durasteel.png", + groups = {armor_legs=1, armor_heal=0, armor_use=800, + physics_speed=-0.03, physics_gravity=0.03}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:boots_durasteel", { + description = S("Durasteel Boots"), + inventory_image = "3d_armor_inv_boots_durasteel.png", + groups = {armor_feet=1, armor_heal=0, armor_use=800, + physics_speed=-0.01, physics_gravity=0.01}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + }) +end + +if armor.materials.bronze then + armor:register_armor("3d_armor:helmet_bronze", { + description = S("Bronze Helmet"), + inventory_image = "3d_armor_inv_helmet_bronze.png", + groups = {armor_head=1, armor_heal=6, armor_use=400, + physics_speed=-0.01, physics_gravity=0.01}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:chestplate_bronze", { + description = S("Bronze Chestplate"), + inventory_image = "3d_armor_inv_chestplate_bronze.png", + groups = {armor_torso=1, armor_heal=6, armor_use=400, + physics_speed=-0.04, physics_gravity=0.04}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:leggings_bronze", { + description = S("Bronze Leggings"), + inventory_image = "3d_armor_inv_leggings_bronze.png", + groups = {armor_legs=1, armor_heal=6, armor_use=400, + physics_speed=-0.03, physics_gravity=0.03}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, + }) + armor:register_armor("3d_armor:boots_bronze", { + description = S("Bronze Boots"), + inventory_image = "3d_armor_inv_boots_bronze.png", + groups = {armor_feet=1, armor_heal=6, armor_use=400, + physics_speed=-0.01, physics_gravity=0.01}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, + }) +end + +if armor.materials.beskar then + armor:register_armor("3d_armor:helmet_mandalorian", { + description = S("Mandalorian Helmet"), + inventory_image = "3d_armor_inv_helmet_mandalorian.png", + groups = {armor_head=1, armor_heal=12, armor_use=200}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, + }) + armor:register_armor("3d_armor:chestplate_mandalorian", { + description = S("Mandalorian Chestplate"), + inventory_image = "3d_armor_inv_chestplate_mandalorian.png", + groups = {armor_torso=1, armor_heal=12, armor_use=200}, + armor_groups = {fleshy=20}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, + }) + armor:register_armor("3d_armor:leggings_mandalorian", { + description = S("Mandalorian Leggings"), + inventory_image = "3d_armor_inv_leggings_mandalorian.png", + groups = {armor_legs=1, armor_heal=12, armor_use=200}, + armor_groups = {fleshy=20}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, + }) + armor:register_armor("3d_armor:boots_mandalorian", { + description = S("Mandalorian Boots"), + inventory_image = "3d_armor_inv_boots_mandalorian.png", + groups = {armor_feet=1, armor_heal=12, armor_use=200}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, + }) +end + +if armor.materials.gold then + armor:register_armor("3d_armor:helmet_gold", { + description = S("Gold Helmet"), + inventory_image = "3d_armor_inv_helmet_gold.png", + groups = {armor_head=1, armor_heal=6, armor_use=300, + physics_speed=-0.02, physics_gravity=0.02}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, + }) + armor:register_armor("3d_armor:chestplate_gold", { + description = S("Gold Chestplate"), + inventory_image = "3d_armor_inv_chestplate_gold.png", + groups = {armor_torso=1, armor_heal=6, armor_use=300, + physics_speed=-0.05, physics_gravity=0.05}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, + }) + armor:register_armor("3d_armor:leggings_gold", { + description = S("Gold Leggings"), + inventory_image = "3d_armor_inv_leggings_gold.png", + groups = {armor_legs=1, armor_heal=6, armor_use=300, + physics_speed=-0.04, physics_gravity=0.04}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, + }) + armor:register_armor("3d_armor:boots_gold", { + description = S("Gold Boots"), + inventory_image = "3d_armor_inv_boots_gold.png", + groups = {armor_feet=1, armor_heal=6, armor_use=300, + physics_speed=-0.02, physics_gravity=0.02}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, + }) +end + +for k, v in pairs(armor.materials) do + minetest.register_craft({ + output = "3d_armor:helmet_"..k, + recipe = { + {v, v, v}, + {v, "", v}, + {"", "", ""}, + }, + }) + minetest.register_craft({ + output = "3d_armor:chestplate_"..k, + recipe = { + {v, "", v}, + {v, v, v}, + {v, v, v}, + }, + }) + minetest.register_craft({ + output = "3d_armor:leggings_"..k, + recipe = { + {v, v, v}, + {v, "", v}, + {v, "", v}, + }, + }) + minetest.register_craft({ + output = "3d_armor:boots_"..k, + recipe = { + {v, "", v}, + {v, "", v}, + }, + }) +end diff --git a/mods/minetest-3d_armor/3d_armor/crafting_guide.txt b/mods/minetest-3d_armor/3d_armor/crafting_guide.txt new file mode 100644 index 00000000..abd1519b --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/crafting_guide.txt @@ -0,0 +1,79 @@ +3d_armor -- Crafting Guide +-------------------------- + +Helmets: + ++---+---+---+ +| X | X | X | ++---+---+---+ +| X | | X | ++---+---+---+ +| | | | ++---+---+---+ + +[3d_armor:helmet_wood] X = [default:wood] +[3d_armor:helmet_cactus] X = [default:cactus] +[3d_armor:helmet_steel] X = [default:steel_ingot] +[3d_armor:helmet_bronze] X = [default:bronze_ingot] +[3d_armor:helmet_diamond] X = [default:diamond] +[3d_armor:helmet_gold] X = [default:gold_ingot] +[3d_armor:helmet_mithril] X = [moreores:mithril_ingot] * +[3d_armor:helmet_crystal] X = [ethereal:crystal_ingot] ** + +Chestplates: + ++---+---+---+ +| X | | X | ++---+---+---+ +| X | X | X | ++---+---+---+ +| X | X | X | ++---+---+---+ + +[3d_armor:chestplate_wood] X = [default:wood] +[3d_armor:chestplate_cactus] X = [default:cactus] +[3d_armor:chestplate_steel] X = [default:steel_ingot] +[3d_armor:chestplate_bronze] X = [default:bronze_ingot] +[3d_armor:chestplate_diamond] X = [default:diamond] +[3d_armor:chestplate_gold] X = [default:gold_ingot] +[3d_armor:chestplate_mithril] X = [moreores:mithril_ingot] * +[3d_armor:chestplate_crystal] X = [ethereal:crystal_ingot] ** + +Leggings: + ++---+---+---+ +| X | X | X | ++---+---+---+ +| X | | X | ++---+---+---+ +| X | | X | ++---+---+---+ + +[3d_armor:leggings_wood] X = [default:wood] +[3d_armor:leggings_cactus] X = [default:cactus] +[3d_armor:leggings_steel] X = [default:steel_ingot] +[3d_armor:leggings_bronze] X = [default:bronze_ingot] +[3d_armor:leggings_diamond] X = [default:diamond] +[3d_armor:leggings_gold] X = [default:gold_ingot] +[3d_armor:leggings_mithril] X = [moreores:mithril_ingot] * +[3d_armor:leggings_crystal] X = [ethereal:crystal_ingot] ** + +Boots: + ++---+---+---+ +| X | | X | ++---+---+---+ +| X | | X | ++---+---+---+ + +[3d_armor:boots_wood] X = [default:wood] +[3d_armor:boots_cactus] X = [default:cactus] +[3d_armor:boots_steel] X = [default:steel_ingot] +[3d_armor:boots_bronze] X = [default:bronze_ingot +[3d_armor:boots_diamond] X = [default:diamond] +[3d_armor:boots_gold] X = [default:gold_ingot] +[3d_armor:boots_mithril] X = [moreores:mithril_ingot] * +[3d_armor:boots_crystal] X = [ethereal:crystal_ingot] ** + + * Requires moreores mod by Calinou - https://forum.minetest.net/viewtopic.php?id=549 +** Requires ethereal mod by Chinchow & TenPlus1 - https://github.com/tenplus1/ethereal diff --git a/mods/minetest-3d_armor/3d_armor/depends.txt b/mods/minetest-3d_armor/3d_armor/depends.txt new file mode 100644 index 00000000..a33755db --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/depends.txt @@ -0,0 +1,8 @@ +default +player_monoids? +armor_monoid? +pova? +fire? +ethereal? +bakedclay? +intllib? diff --git a/mods/minetest-3d_armor/3d_armor/description.txt b/mods/minetest-3d_armor/3d_armor/description.txt new file mode 100644 index 00000000..b0a9b0a5 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/description.txt @@ -0,0 +1 @@ +Adds craftable armor that is visible to other players. diff --git a/mods/minetest-3d_armor/3d_armor/init.lua b/mods/minetest-3d_armor/3d_armor/init.lua new file mode 100644 index 00000000..bfd9444e --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/init.lua @@ -0,0 +1,463 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) +local worldpath = minetest.get_worldpath() +local last_punch_time = {} +local pending_players = {} +local timer = 0 + +-- support for i18n +armor_i18n = { } +armor_i18n.gettext, armor_i18n.ngettext = dofile(modpath.."/intllib.lua") + +-- local functions +local S = armor_i18n.gettext +local F = minetest.formspec_escape + +dofile(modpath.."/api.lua") + +-- Legacy Config Support + +local input = io.open(modpath.."/armor.conf", "r") +if input then + dofile(modpath.."/armor.conf") + input:close() + input = nil +end +input = io.open(worldpath.."/armor.conf", "r") +if input then + dofile(worldpath.."/armor.conf") + input:close() + input = nil +end +for name, _ in pairs(armor.config) do + local global = "ARMOR_"..name:upper() + if minetest.global_exists(global) then + armor.config[name] = _G[global] + end +end +if minetest.global_exists("ARMOR_MATERIALS") then + armor.materials = table.copy(ARMOR_MATERIALS) +end +if minetest.global_exists("ARMOR_FIRE_NODES") then + armor.fire_nodes = table.copy(ARMOR_FIRE_NODES) +end + +-- Load Configuration + +for name, config in pairs(armor.config) do + local setting = minetest.settings:get("armor_"..name) + if type(config) == "number" then + setting = tonumber(setting) + elseif type(config) == "boolean" then + setting = minetest.settings:get_bool("armor_"..name) + end + if setting ~= nil then + armor.config[name] = setting + end +end +for material, _ in pairs(armor.materials) do + local key = "material_"..material + if armor.config[key] == false then + armor.materials[material] = nil + end +end + +-- Mod Compatibility + +if minetest.get_modpath("technic") then + armor.formspec = armor.formspec.. + "label[5,2.5;"..F(S("Radiation"))..": armor_group_radiation]" + armor:register_armor_group("radiation") +end +local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"} +for _, mod in pairs(skin_mods) do + local path = minetest.get_modpath(mod) + if path then + local dir_list = minetest.get_dir_list(path.."/textures") + for _, fn in pairs(dir_list) do + if fn:find("_preview.png$") then + armor:add_preview(fn) + end + end + armor.skin_mod = mod + end +end + +dofile(modpath.."/armor.lua") + +-- Armor Initialization + +armor.formspec = armor.formspec.. + "label[5,1;"..F(S("Level"))..": armor_level]".. + "label[5,1.5;"..F(S("Heal"))..": armor_attr_heal]" +if armor.config.fire_protect then + armor.formspec = armor.formspec.."label[5,2;"..F(S("Fire"))..": armor_attr_fire]" +end +armor:register_on_destroy(function(player, index, stack) + local name = player:get_player_name() + local def = stack:get_definition() + if name and def and def.description then + minetest.chat_send_player(name, S("Your @1 got destroyed!", def.description)) + end +end) + +local function validate_armor_inventory(player) + -- Workaround for detached inventory swap exploit + local _, inv = armor:get_valid_player(player, "[validate_armor_inventory]") + if not inv then + return + end + local armor_prev = {} + local armor_list_string = player:get_attribute("3d_armor_inventory") + if armor_list_string then + local armor_list = armor:deserialize_inventory_list(armor_list_string) + for i, stack in ipairs(armor_list) do + if stack:get_count() > 0 then + armor_prev[stack:get_name()] = i + end + end + end + local elements = {} + local player_inv = player:get_inventory() + for i = 1, 6 do + local stack = inv:get_stack("armor", i) + if stack:get_count() > 0 then + local item = stack:get_name() + local element = armor:get_element(item) + if element and not elements[element] then + if armor_prev[item] then + armor_prev[item] = nil + else + -- Item was not in previous inventory + armor:run_callbacks("on_equip", player, i, stack) + end + elements[element] = true; + else + inv:remove_item("armor", stack) + -- The following code returns invalid items to the player's main + -- inventory but could open up the possibity for a hacked client + -- to receive items back they never really had. I am not certain + -- so remove the is_singleplayer check at your own risk :] + if minetest.is_singleplayer() and player_inv and + player_inv:room_for_item("main", stack) then + player_inv:add_item("main", stack) + end + end + end + end + for item, i in pairs(armor_prev) do + local stack = ItemStack(item) + -- Previous item is not in current inventory + armor:run_callbacks("on_unequip", player, i, stack) + end +end + +local function init_player_armor(player) + local name = player:get_player_name() + local pos = player:get_pos() + if not name or not pos then + return false + end + local armor_inv = minetest.create_detached_inventory(name.."_armor", { + on_put = function(inv, listname, index, stack, player) + validate_armor_inventory(player) + armor:save_armor_inventory(player) + armor:set_player_armor(player) + end, + on_take = function(inv, listname, index, stack, player) + validate_armor_inventory(player) + armor:save_armor_inventory(player) + armor:set_player_armor(player) + end, + on_move = function(inv, from_list, from_index, to_list, to_index, count, player) + validate_armor_inventory(player) + armor:save_armor_inventory(player) + armor:set_player_armor(player) + end, + allow_put = function(inv, listname, index, put_stack, player) + local element = armor:get_element(put_stack:get_name()) + if not element then + return 0 + end + for i = 1, 6 do + local stack = inv:get_stack("armor", i) + local def = stack:get_definition() or {} + if def.groups and def.groups["armor_"..element] + and i ~= index then + return 0 + end + end + return 1 + end, + allow_take = function(inv, listname, index, stack, player) + return stack:get_count() + end, + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + return count + end, + }, name) + armor_inv:set_size("armor", 6) + if not armor:load_armor_inventory(player) and armor.migrate_old_inventory then + local player_inv = player:get_inventory() + player_inv:set_size("armor", 6) + for i=1, 6 do + local stack = player_inv:get_stack("armor", i) + armor_inv:set_stack("armor", i, stack) + end + armor:save_armor_inventory(player) + player_inv:set_size("armor", 0) + end + for i=1, 6 do + local stack = armor_inv:get_stack("armor", i) + if stack:get_count() > 0 then + armor:run_callbacks("on_equip", player, i, stack) + end + end + armor.def[name] = { + init_time = minetest.get_gametime(), + level = 0, + state = 0, + count = 0, + groups = {}, + } + for _, phys in pairs(armor.physics) do + armor.def[name][phys] = 1 + end + for _, attr in pairs(armor.attributes) do + armor.def[name][attr] = 0 + end + for group, _ in pairs(armor.registered_groups) do + armor.def[name].groups[group] = 0 + end + local skin = armor:get_player_skin(name) + armor.textures[name] = { + skin = skin, + armor = "3d_armor_trans.png", + wielditem = "3d_armor_trans.png", + preview = armor.default_skin.."_preview.png", + } + local texture_path = minetest.get_modpath("player_textures") + if texture_path then + local dir_list = minetest.get_dir_list(texture_path.."/textures") + for _, fn in pairs(dir_list) do + if fn == "player_"..name..".png" then + armor.textures[name].skin = fn + break + end + end + end + armor:set_player_armor(player) + return true +end + +-- Armor Player Model + +default.player_register_model("3d_armor_character.b3d", { + animation_speed = 30, + textures = { + armor.default_skin..".png", + "3d_armor_trans.png", + "3d_armor_trans.png", + }, + animations = { + stand = {x=0, y=79}, + lay = {x=162, y=166}, + walk = {x=168, y=187}, + mine = {x=189, y=198}, + walk_mine = {x=200, y=219}, + sit = {x=81, y=160}, + }, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local name = armor:get_valid_player(player, "[on_player_receive_fields]") + if not name then + return + end + for field, _ in pairs(fields) do + if string.find(field, "skins_set") then + minetest.after(0, function(player) + local skin = armor:get_player_skin(name) + armor.textures[name].skin = skin + armor:set_player_armor(player) + end, player) + end + end +end) + +minetest.register_on_joinplayer(function(player) + default.player_set_model(player, "3d_armor_character.b3d") + minetest.after(0, function(player) + if init_player_armor(player) == false then + pending_players[player] = 0 + end + end, player) +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + if name then + armor.def[name] = nil + armor.textures[name] = nil + end + pending_players[player] = nil +end) + +if armor.config.drop == true or armor.config.destroy == true then + minetest.register_on_dieplayer(function(player) + local name, armor_inv = armor:get_valid_player(player, "[on_dieplayer]") + if not name then + return + end + local drop = {} + for i=1, armor_inv:get_size("armor") do + local stack = armor_inv:get_stack("armor", i) + if stack:get_count() > 0 then + table.insert(drop, stack) + armor:run_callbacks("on_unequip", player, i, stack) + armor_inv:set_stack("armor", i, nil) + end + end + armor:save_armor_inventory(player) + armor:set_player_armor(player) + local pos = player:get_pos() + if pos and armor.config.destroy == false then + minetest.after(armor.config.bones_delay, function() + local meta = nil + local maxp = vector.add(pos, 8) + local minp = vector.subtract(pos, 8) + local bones = minetest.find_nodes_in_area(minp, maxp, {"bones:bones"}) + for _, p in pairs(bones) do + local m = minetest.get_meta(p) + if m:get_string("owner") == name then + meta = m + break + end + end + if meta then + local inv = meta:get_inventory() + for _,stack in ipairs(drop) do + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + else + armor.drop_armor(pos, stack) + end + end + else + for _,stack in ipairs(drop) do + armor.drop_armor(pos, stack) + end + end + end) + end + end) +end + +if armor.config.punch_damage == true then + minetest.register_on_punchplayer(function(player, hitter, + time_from_last_punch, tool_capabilities) + local name = player:get_player_name() + if name then + armor:punch(player, hitter, time_from_last_punch, tool_capabilities) + last_punch_time[name] = minetest.get_gametime() + end + end) +end + +minetest.register_on_player_hpchange(function(player, hp_change) + if player and hp_change < 0 then + local name = player:get_player_name() + if name then + local heal = armor.def[name].heal + if heal >= math.random(100) then + hp_change = 0 + end + -- check if armor damage was handled by fire or on_punchplayer + local time = last_punch_time[name] or 0 + if time == 0 or time + 1 < minetest.get_gametime() then + armor:punch(player) + end + end + end + return hp_change +end, true) + +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer > armor.config.init_delay then + for player, count in pairs(pending_players) do + local remove = init_player_armor(player) == true + pending_players[player] = count + 1 + if remove == false and count > armor.config.init_times then + minetest.log("warning", S("3d_armor: Failed to initialize player")) + remove = true + end + if remove == true then + pending_players[player] = nil + end + end + timer = 0 + end +end) + +-- Fire Protection and water breating, added by TenPlus1 + +if armor.config.fire_protect == true then + -- override hot nodes so they do not hurt player anywhere but mod + for _, row in pairs(armor.fire_nodes) do + if minetest.registered_nodes[row[1]] then + minetest.override_item(row[1], {damage_per_second = 0}) + end + end +else + print (S("[3d_armor] Fire Nodes disabled")) +end + +if armor.config.water_protect == true or armor.config.fire_protect == true then + minetest.register_globalstep(function(dtime) + armor.timer = armor.timer + dtime + if armor.timer < armor.config.update_time then + return + end + for _,player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local pos = player:get_pos() + local hp = player:get_hp() + if not name or not pos or not hp then + return + end + -- water breathing + if armor.config.water_protect == true then + if armor.def[name].water > 0 and + player:get_breath() < 10 then + player:set_breath(10) + end + end + -- fire protection + if armor.config.fire_protect == true then + local fire_damage = true + pos.y = pos.y + 1.4 -- head level + local node_head = minetest.get_node(pos).name + pos.y = pos.y - 1.2 -- feet level + local node_feet = minetest.get_node(pos).name + -- is player inside a hot node? + for _, row in pairs(armor.fire_nodes) do + -- check fire protection, if not enough then get hurt + if row[1] == node_head or row[1] == node_feet then + if fire_damage == true then + armor:punch(player, "fire") + last_punch_time[name] = minetest.get_gametime() + fire_damage = false + end + if hp > 0 and armor.def[name].fire < row[2] then + hp = hp - row[3] * armor.config.update_time + player:set_hp(hp) + break + end + end + end + end + end + armor.timer = 0 + end) +end diff --git a/mods/minetest-3d_armor/3d_armor/intllib.lua b/mods/minetest-3d_armor/3d_armor/intllib.lua new file mode 100644 index 00000000..6669d720 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.b3d b/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.b3d new file mode 100644 index 00000000..c4d45b50 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.b3d differ diff --git a/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.blend b/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.blend new file mode 100644 index 00000000..44f7e27d Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/models/3d_armor_character.blend differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin.png new file mode 100644 index 00000000..23be004f Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin_preview.png new file mode 100644 index 00000000..77acce68 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_admin_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze.png new file mode 100644 index 00000000..2f4fd83e Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze_preview.png new file mode 100644 index 00000000..1f83af34 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_bronze_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel.png new file mode 100644 index 00000000..72ec88b7 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel_preview.png new file mode 100644 index 00000000..170d094c Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_durasteel_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold.png new file mode 100644 index 00000000..f431d9b4 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold_preview.png new file mode 100644 index 00000000..9daae14f Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_gold_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian.png new file mode 100644 index 00000000..b91694d0 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian_preview.png new file mode 100644 index 00000000..2eb3f4ce Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_mandalorian_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood.png new file mode 100644 index 00000000..411ce9c6 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood_preview.png new file mode 100644 index 00000000..d9f192c0 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_boots_wood_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin.png new file mode 100644 index 00000000..a17d0a48 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin_preview.png new file mode 100644 index 00000000..5395810a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_admin_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze.png new file mode 100644 index 00000000..ac43ddb2 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze_preview.png new file mode 100644 index 00000000..ab1d1ce6 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_bronze_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel.png new file mode 100644 index 00000000..bccb99d1 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel_preview.png new file mode 100644 index 00000000..804e785b Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_durasteel_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold.png new file mode 100644 index 00000000..cc3e9102 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold_preview.png new file mode 100644 index 00000000..df47bf0c Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_gold_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian.png new file mode 100644 index 00000000..ec5db943 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian_preview.png new file mode 100644 index 00000000..771820b9 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_mandalorian_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood.png new file mode 100644 index 00000000..bae48174 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood_preview.png new file mode 100644 index 00000000..8f75f26a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_chestplate_wood_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin.png new file mode 100644 index 00000000..0a042517 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin_preview.png new file mode 100644 index 00000000..9f449216 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_admin_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze.png new file mode 100644 index 00000000..7ef55957 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze_preview.png new file mode 100644 index 00000000..9a62f820 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_bronze_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel.png new file mode 100644 index 00000000..8d21e8a5 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel_preview.png new file mode 100644 index 00000000..774d284d Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_durasteel_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold.png new file mode 100644 index 00000000..24da53b2 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold_preview.png new file mode 100644 index 00000000..d4d9d0cb Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_gold_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian.png new file mode 100644 index 00000000..6df1c323 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian_preview.png new file mode 100644 index 00000000..6fc9d373 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_mandalorian_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood.png new file mode 100644 index 00000000..01e243a9 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood_preview.png new file mode 100644 index 00000000..0e0c3b17 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_helmet_wood_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_admin.png new file mode 100644 index 00000000..69fc00a8 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_bronze.png new file mode 100644 index 00000000..448f41d7 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_durasteel.png new file mode 100644 index 00000000..82fc5918 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_gold.png new file mode 100644 index 00000000..55d78b71 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_mandalorian.png new file mode 100644 index 00000000..f3aa489c Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_wood.png new file mode 100644 index 00000000..53bb5575 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_boots_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_admin.png new file mode 100644 index 00000000..dafef2cb Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_bronze.png new file mode 100644 index 00000000..8fc2f17a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_durasteel.png new file mode 100644 index 00000000..47ef4f20 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_gold.png new file mode 100644 index 00000000..efe76ca6 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_mandalorian.png new file mode 100644 index 00000000..184de984 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_wood.png new file mode 100644 index 00000000..dac3b06f Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_chestplate_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_admin.png new file mode 100644 index 00000000..494cc84c Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_bronze.png new file mode 100644 index 00000000..c0028dd6 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_durasteel.png new file mode 100644 index 00000000..1c8bfe83 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_gold.png new file mode 100644 index 00000000..6820d8f0 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_mandalorian.png new file mode 100644 index 00000000..a3f8746f Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_wood.png new file mode 100644 index 00000000..fbb3e3ff Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_helmet_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_admin.png new file mode 100644 index 00000000..e652ef11 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_bronze.png new file mode 100644 index 00000000..f194f9f1 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_durasteel.png new file mode 100644 index 00000000..1ca9975a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_gold.png new file mode 100644 index 00000000..2e4b2446 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_mandalorian.png new file mode 100644 index 00000000..eadb323f Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_wood.png new file mode 100644 index 00000000..9e73b722 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_inv_leggings_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin.png new file mode 100644 index 00000000..bedfbc15 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin_preview.png new file mode 100644 index 00000000..1d32265d Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_admin_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze.png new file mode 100644 index 00000000..bcba3727 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze_preview.png new file mode 100644 index 00000000..c3781487 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_bronze_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel.png new file mode 100644 index 00000000..cca4e31a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel_preview.png new file mode 100644 index 00000000..dbcfcf2b Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_durasteel_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold.png new file mode 100644 index 00000000..dfdd094a Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold_preview.png new file mode 100644 index 00000000..ff2e3d04 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_gold_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian.png new file mode 100644 index 00000000..20e90822 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian_preview.png new file mode 100644 index 00000000..7ac10a51 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_mandalorian_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood.png new file mode 100644 index 00000000..eb610344 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood_preview.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood_preview.png new file mode 100644 index 00000000..1545b4b0 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_leggings_wood_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_trans.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_trans.png new file mode 100644 index 00000000..4a31242b Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_trans.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/3d_armor_ui_form.png b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_ui_form.png new file mode 100644 index 00000000..993809f2 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/3d_armor_ui_form.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/character_preview.png b/mods/minetest-3d_armor/3d_armor/textures/character_preview.png new file mode 100644 index 00000000..82a0ae45 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/character_preview.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/inventory_plus_armor.png b/mods/minetest-3d_armor/3d_armor/textures/inventory_plus_armor.png new file mode 100644 index 00000000..f317c709 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor/textures/inventory_plus_armor.png differ diff --git a/mods/minetest-3d_armor/3d_armor/textures/preview_index.txt b/mods/minetest-3d_armor/3d_armor/textures/preview_index.txt new file mode 100644 index 00000000..9e2fe9d4 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/textures/preview_index.txt @@ -0,0 +1,44 @@ +3d_armor/textures/3d_armor_helmet_wood.png:head +3d_armor/textures/3d_armor_chestplate_wood.png:torso +3d_armor/textures/3d_armor_leggings_wood.png:legs +3d_armor/textures/3d_armor_boots_wood.png:feet + +3d_armor/textures/3d_armor_helmet_cactus.png:head +3d_armor/textures/3d_armor_chestplate_cactus.png:torso +3d_armor/textures/3d_armor_leggings_cactus.png:legs +3d_armor/textures/3d_armor_boots_cactus.png:feet + +3d_armor/textures/3d_armor_helmet_steel.png:head +3d_armor/textures/3d_armor_chestplate_steel.png:torso +3d_armor/textures/3d_armor_leggings_steel.png:legs +3d_armor/textures/3d_armor_boots_steel.png:feet + +3d_armor/textures/3d_armor_helmet_bronze.png:head +3d_armor/textures/3d_armor_chestplate_bronze.png:torso +3d_armor/textures/3d_armor_leggings_bronze.png:legs +3d_armor/textures/3d_armor_boots_bronze.png:feet + +3d_armor/textures/3d_armor_helmet_gold.png:head +3d_armor/textures/3d_armor_chestplate_gold.png:torso +3d_armor/textures/3d_armor_leggings_gold.png:legs +3d_armor/textures/3d_armor_boots_gold.png:feet + +3d_armor/textures/3d_armor_helmet_diamond.png:head +3d_armor/textures/3d_armor_chestplate_diamond.png:torso +3d_armor/textures/3d_armor_leggings_diamond.png:legs +3d_armor/textures/3d_armor_boots_diamond.png:feet + +3d_armor/textures/3d_armor_helmet_mithril.png:head +3d_armor/textures/3d_armor_chestplate_mithril.png:torso +3d_armor/textures/3d_armor_leggings_mithril.png:legs +3d_armor/textures/3d_armor_boots_mithril.png:feet + +3d_armor/textures/3d_armor_helmet_crystal.png:head +3d_armor/textures/3d_armor_chestplate_crystal.png:torso +3d_armor/textures/3d_armor_leggings_crystal.png:legs +3d_armor/textures/3d_armor_boots_crystal.png:feet + +3d_armor/textures/3d_armor_helmet_admin.png:head +3d_armor/textures/3d_armor_chestplate_admin.png:torso +3d_armor/textures/3d_armor_leggings_admin.png:legs +3d_armor/textures/3d_armor_boots_admin.png:feet diff --git a/mods/minetest-3d_armor/3d_armor/tools/README.md b/mods/minetest-3d_armor/3d_armor/tools/README.md new file mode 100644 index 00000000..6aa7ffed --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/tools/README.md @@ -0,0 +1,7 @@ +# Intllib tool + +please consider using the intllib tool to update locale files: + +```../../intllib/tools/xgettext.sh ../**/*.lua``` + +make sure you are in `3d_armor` derectory before running this command diff --git a/mods/minetest-3d_armor/3d_armor/tools/updatepo.sh b/mods/minetest-3d_armor/3d_armor/tools/updatepo.sh new file mode 100644 index 00000000..52de9908 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor/tools/updatepo.sh @@ -0,0 +1,24 @@ +#! /bin/bash + +# To create a new translation: +# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot + +cd "$(dirname "${BASH_SOURCE[0]}")/.."; + +# Extract translatable strings. +xgettext --from-code=UTF-8 \ + --language=Lua \ + --sort-by-file \ + --keyword=S \ + --keyword=NS:1,2 \ + --keyword=N_ \ + --add-comments='Translators:' \ + --add-location=file \ + -o locale/template.pot \ + $(find .. -name '*.lua') + +# Update translations. +find locale -name '*.po' | while read -r file; do + echo $file + msgmerge --update $file locale/template.pot; +done diff --git a/mods/minetest-3d_armor/3d_armor_ip/LICENSE.txt b/mods/minetest-3d_armor/3d_armor_ip/LICENSE.txt new file mode 100644 index 00000000..b924ac07 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ip/LICENSE.txt @@ -0,0 +1,18 @@ +[mod] 3d Armor integration to inventory plus [3d_armor_ip] +========================================================== + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/mods/minetest-3d_armor/3d_armor_ip/depends.txt b/mods/minetest-3d_armor/3d_armor_ip/depends.txt new file mode 100644 index 00000000..e96293b9 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ip/depends.txt @@ -0,0 +1,2 @@ +3d_armor +inventory_plus? diff --git a/mods/minetest-3d_armor/3d_armor_ip/description.txt b/mods/minetest-3d_armor/3d_armor_ip/description.txt new file mode 100644 index 00000000..01e1b54c --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ip/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the inventory plus diff --git a/mods/minetest-3d_armor/3d_armor_ip/init.lua b/mods/minetest-3d_armor/3d_armor_ip/init.lua new file mode 100644 index 00000000..7701a707 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ip/init.lua @@ -0,0 +1,38 @@ +-- support for i18n +local S = armor_i18n.gettext +local F = minetest.formspec_escape + +if not minetest.global_exists("inventory_plus") then + minetest.log("warning", S("3d_armor_ip: Mod loaded but unused.")) + return +end + +armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;"..F(S("Back")).."]"..armor.formspec +armor:register_on_update(function(player) + local name = player:get_player_name() + local formspec = armor:get_armor_formspec(name, true) + local page = player:get_inventory_formspec() + if page:find("detached:"..name.."_armor") then + inventory_plus.set_inventory_formspec(player, formspec) + end +end) + +if minetest.get_modpath("crafting") then + inventory_plus.get_formspec = function(player, page) + end +end + +minetest.register_on_joinplayer(function(player) + inventory_plus.register_button(player,"armor", S("Armor")) +end) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.armor then + local name = armor:get_valid_player(player, "[on_player_receive_fields]") + if not name then + return + end + local formspec = armor:get_armor_formspec(name, true) + inventory_plus.set_inventory_formspec(player, formspec) + end +end) diff --git a/mods/minetest-3d_armor/3d_armor_sfinv/LICENSE.txt b/mods/minetest-3d_armor/3d_armor_sfinv/LICENSE.txt new file mode 100644 index 00000000..2b2a9f64 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_sfinv/LICENSE.txt @@ -0,0 +1,18 @@ +[mod] 3d Armor sfinv integration [3d_armor_sfinv] +================================================= + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/mods/minetest-3d_armor/3d_armor_sfinv/depends.txt b/mods/minetest-3d_armor/3d_armor_sfinv/depends.txt new file mode 100644 index 00000000..c7beedae --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_sfinv/depends.txt @@ -0,0 +1,2 @@ +3d_armor +sfinv? diff --git a/mods/minetest-3d_armor/3d_armor_sfinv/description.txt b/mods/minetest-3d_armor/3d_armor_sfinv/description.txt new file mode 100644 index 00000000..0ef2ae93 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_sfinv/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the sfinv inventory diff --git a/mods/minetest-3d_armor/3d_armor_sfinv/init.lua b/mods/minetest-3d_armor/3d_armor_sfinv/init.lua new file mode 100644 index 00000000..a9371278 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_sfinv/init.lua @@ -0,0 +1,21 @@ +-- support for i18n +local S = armor_i18n.gettext + +if not minetest.global_exists("sfinv") then + minetest.log("warning", S("3d_armor_sfinv: Mod loaded but unused.")) + return +end + +sfinv.register_page("3d_armor:armor", { + title = S("Armor"), + get = function(self, player, context) + local name = player:get_player_name() + local formspec = armor:get_armor_formspec(name, true) + return sfinv.make_formspec(player, context, formspec, false) + end +}) +armor:register_on_update(function(player) + if sfinv.enabled then + sfinv.set_player_inventory_formspec(player) + end +end) diff --git a/mods/minetest-3d_armor/3d_armor_stand/LICENSE.txt b/mods/minetest-3d_armor/3d_armor_stand/LICENSE.txt new file mode 100644 index 00000000..e3cb55d6 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/LICENSE.txt @@ -0,0 +1,43 @@ +[mod] 3d Armor Stand [3d_armor_stand] +===================================== + +License Source Code +------------------- + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Lecense Models +-------------- + +Copyright (C) 2016-2019 Stuart Jones - CC BY-SA 3.0 + +UV model mapping by tobyplowy(aka toby109tt) + +License Textures +---------------- + +3d_armor_stand.png +3d_armor_stand_locked.png + +Copyright (C) 2017-2019 tobyplowy - CC BY-SA 3.0 + +3d_armor_stand_feet.png +3d_armor_stand_head.png +3d_armor_stand_legs.png +3d_armor_stand_torso.png + +Copyright (C) 2016-2019 Stuart Jones - CC BY-SA 3.0 diff --git a/mods/minetest-3d_armor/3d_armor_stand/README.txt b/mods/minetest-3d_armor/3d_armor_stand/README.txt new file mode 100644 index 00000000..6a98ab99 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/README.txt @@ -0,0 +1,21 @@ +[mod] 3d Armor Stand [3d_armor_stand] +===================================== + +Depends: 3d_armor + +Adds a chest-like armor stand for armor storage and display. + +Crafting +-------- + +F = Wooden Fence [default:fence_wood] +S = Steel Ingot [default:steel_ingot] + ++---+---+---+ +| | F | | ++---+---+---+ +| | F | | ++---+---+---+ +| S | S | S | ++---+---+---+ + diff --git a/mods/minetest-3d_armor/3d_armor_stand/depends.txt b/mods/minetest-3d_armor/3d_armor_stand/depends.txt new file mode 100644 index 00000000..fdbb2900 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/depends.txt @@ -0,0 +1,2 @@ +3d_armor + diff --git a/mods/minetest-3d_armor/3d_armor_stand/init.lua b/mods/minetest-3d_armor/3d_armor_stand/init.lua new file mode 100644 index 00000000..ab525c93 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/init.lua @@ -0,0 +1,346 @@ +-- support for i18n +local S = armor_i18n.gettext + +local armor_stand_formspec = "size[8,7]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + default.get_hotbar_bg(0,3) .. + "list[current_name;armor_head;3,0.5;1,1;]" .. + "list[current_name;armor_torso;4,0.5;1,1;]" .. + "list[current_name;armor_legs;3,1.5;1,1;]" .. + "list[current_name;armor_feet;4,1.5;1,1;]" .. + "image[3,0.5;1,1;3d_armor_stand_head.png]" .. + "image[4,0.5;1,1;3d_armor_stand_torso.png]" .. + "image[3,1.5;1,1;3d_armor_stand_legs.png]" .. + "image[4,1.5;1,1;3d_armor_stand_feet.png]" .. + "list[current_player;main;0,3;8,1;]" .. + "list[current_player;main;0,4.25;8,3;8]" + +local elements = {"head", "torso", "legs", "feet"} + +local function drop_armor(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + for _, element in pairs(elements) do + local stack = inv:get_stack("armor_"..element, 1) + if stack and stack:get_count() > 0 then + armor.drop_armor(pos, stack) + inv:set_stack("armor_"..element, 1, nil) + end + end +end + +local function get_stand_object(pos) + local object = nil + local objects = minetest.get_objects_inside_radius(pos, 0.5) or {} + for _, obj in pairs(objects) do + local ent = obj:get_luaentity() + if ent then + if ent.name == "3d_armor_stand:armor_entity" then + -- Remove duplicates + if object then + obj:remove() + else + object = obj + end + end + end + end + return object +end + +local function update_entity(pos) + local node = minetest.get_node(pos) + local object = get_stand_object(pos) + if object then + if not string.find(node.name, "3d_armor_stand:") then + object:remove() + return + end + else + object = minetest.add_entity(pos, "3d_armor_stand:armor_entity") + end + if object then + local texture = "3d_armor_trans.png" + local textures = {} + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local yaw = 0 + if inv then + for _, element in pairs(elements) do + local stack = inv:get_stack("armor_"..element, 1) + if stack:get_count() == 1 then + local item = stack:get_name() or "" + local def = stack:get_definition() or {} + local groups = def.groups or {} + if groups["armor_"..element] then + if def.texture then + table.insert(textures, def.texture) + else + table.insert(textures, item:gsub("%:", "_")..".png") + end + end + end + end + end + if #textures > 0 then + texture = table.concat(textures, "^") + end + if node.param2 then + local rot = node.param2 % 4 + if rot == 1 then + yaw = 3 * math.pi / 2 + elseif rot == 2 then + yaw = math.pi + elseif rot == 3 then + yaw = math.pi / 2 + end + end + object:setyaw(yaw) + object:set_properties({textures={texture}}) + end +end + +local function has_locked_armor_stand_privilege(meta, player) + local name = "" + if player then + if minetest.check_player_privs(player, "protection_bypass") then + return true + end + name = player:get_player_name() + end + if name ~= meta:get_string("owner") then + return false + end + return true +end + +local function add_hidden_node(pos, player) + local p = {x=pos.x, y=pos.y + 1, z=pos.z} + local name = player:get_player_name() + local node = minetest.get_node(p) + if node.name == "air" and not minetest.is_protected(pos, name) then + minetest.set_node(p, {name="3d_armor_stand:top"}) + end +end + +local function remove_hidden_node(pos) + local p = {x=pos.x, y=pos.y + 1, z=pos.z} + local node = minetest.get_node(p) + if node.name == "3d_armor_stand:top" then + minetest.remove_node(p) + end +end + +minetest.register_node("3d_armor_stand:top", { + description = S("Armor stand top"), + paramtype = "light", + drawtype = "plantlike", + sunlight_propagates = true, + walkable = true, + pointable = false, + diggable = false, + buildable_to = false, + drop = "", + groups = {not_in_creative_inventory = 1}, + on_blast = function() end, + tiles = {"3d_armor_trans.png"}, +}) + +minetest.register_node("3d_armor_stand:armor_stand", { + description = S("Armor stand"), + drawtype = "mesh", + mesh = "3d_armor_stand.obj", + tiles = {"3d_armor_stand.png"}, + paramtype = "light", + paramtype2 = "facedir", + walkable = false, + selection_box = { + type = "fixed", + fixed = { + {-0.25, -0.4375, -0.25, 0.25, 1.4, 0.25}, + {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, + }, + }, + groups = {choppy=2, oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", armor_stand_formspec) + meta:set_string("infotext", S("Armor Stand")) + local inv = meta:get_inventory() + for _, element in pairs(elements) do + inv:set_size("armor_"..element, 1) + end + end, + can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + for _, element in pairs(elements) do + if not inv:is_empty("armor_"..element) then + return false + end + end + return true + end, + after_place_node = function(pos, placer) + minetest.add_entity(pos, "3d_armor_stand:armor_entity") + add_hidden_node(pos, placer) + end, + allow_metadata_inventory_put = function(pos, listname, index, stack) + local def = stack:get_definition() or {} + local groups = def.groups or {} + if groups[listname] then + return 1 + end + return 0 + end, + allow_metadata_inventory_move = function(pos) + return 0 + end, + on_metadata_inventory_put = function(pos) + update_entity(pos) + end, + on_metadata_inventory_take = function(pos) + update_entity(pos) + end, + after_destruct = function(pos) + update_entity(pos) + remove_hidden_node(pos) + end, + on_blast = function(pos) + drop_armor(pos) + armor.drop_armor(pos, "3d_armor_stand:armor_stand") + minetest.remove_node(pos) + end, +}) + +minetest.register_node("3d_armor_stand:locked_armor_stand", { + description = S("Locked Armor stand"), + drawtype = "mesh", + mesh = "3d_armor_stand.obj", + tiles = {"3d_armor_stand_locked.png"}, + paramtype = "light", + paramtype2 = "facedir", + walkable = false, + selection_box = { + type = "fixed", + fixed = { + {-0.25, -0.4375, -0.25, 0.25, 1.4, 0.25}, + {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, + }, + }, + groups = {choppy=2, oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", armor_stand_formspec) + meta:set_string("infotext", S("Armor Stand")) + meta:set_string("owner", "") + local inv = meta:get_inventory() + for _, element in pairs(elements) do + inv:set_size("armor_"..element, 1) + end + end, + can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + for _, element in pairs(elements) do + if not inv:is_empty("armor_"..element) then + return false + end + end + return true + end, + after_place_node = function(pos, placer) + minetest.add_entity(pos, "3d_armor_stand:armor_entity") + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name() or "") + meta:set_string("infotext", S("Armor Stand (owned by @1)", meta:get_string("owner"))) + add_hidden_node(pos, placer) + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if not has_locked_armor_stand_privilege(meta, player) then + return 0 + end + local def = stack:get_definition() or {} + local groups = def.groups or {} + if groups[listname] then + return 1 + end + return 0 + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if not has_locked_armor_stand_privilege(meta, player) then + return 0 + end + return stack:get_count() + end, + allow_metadata_inventory_move = function(pos) + return 0 + end, + on_metadata_inventory_put = function(pos) + update_entity(pos) + end, + on_metadata_inventory_take = function(pos) + update_entity(pos) + end, + after_destruct = function(pos) + update_entity(pos) + remove_hidden_node(pos) + end, + on_blast = function(pos) + -- Not affected by TNT + end, +}) + +minetest.register_entity("3d_armor_stand:armor_entity", { + physical = true, + visual = "mesh", + mesh = "3d_armor_entity.obj", + visual_size = {x=1, y=1}, + collisionbox = {0,0,0,0,0,0}, + textures = {"3d_armor_trans.png"}, + pos = nil, + timer = 0, + on_activate = function(self) + local pos = self.object:get_pos() + if pos then + self.pos = vector.round(pos) + update_entity(pos) + end + end, + on_blast = function(self, damage) + local drops = {} + local node = minetest.get_node(self.pos) + if node.name == "3d_armor_stand:armor_stand" then + drop_armor(self.pos) + self.object:remove() + end + return false, false, drops + end, +}) + +minetest.register_abm({ + nodenames = {"3d_armor_stand:locked_armor_stand", "3d_armor_stand:armor_stand"}, + interval = 15, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local num + num = #minetest.get_objects_inside_radius(pos, 0.5) + if num > 0 then return end + update_entity(pos) + end +}) + +minetest.register_craft({ + output = "3d_armor_stand:armor_stand", + recipe = { + {"", "group:fence", ""}, + {"", "group:fence", ""}, + {"default:durasteel_ingot", "default:durasteel_ingot", "default:durasteel_ingot"}, + } +}) diff --git a/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_entity.obj b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_entity.obj new file mode 100644 index 00000000..052f6925 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_entity.obj @@ -0,0 +1,193 @@ +# Blender v2.73 (sub 0) OBJ File: '3d_armor_entity_3.blend' +# www.blender.org +mtllib 3d_armor_entity.mtl +o Player_Cube +v 2.200000 9.763893 1.200000 +v 2.200000 9.763893 -1.200000 +v 2.200000 2.663871 1.200000 +v 2.200000 2.663871 -1.200000 +v -2.200000 9.763893 -1.200000 +v -2.200000 9.763893 1.200000 +v -2.200000 2.663871 -1.200000 +v -2.200000 2.663871 1.200000 +v 2.300000 13.863962 2.300000 +v 2.300000 13.863962 -2.300000 +v 2.300000 9.263885 2.300000 +v 2.300000 9.263885 -2.300000 +v -2.300000 13.863962 -2.300000 +v -2.300000 13.863962 2.300000 +v -2.300000 9.263885 -2.300000 +v -2.300000 9.263885 2.300000 +v -2.322686 2.473175 -1.300000 +v -2.322686 2.473175 1.300000 +v -4.713554 2.682348 1.300000 +v -4.713554 2.682348 -1.300000 +v -1.686446 9.745432 -1.300000 +v -1.686446 9.745432 1.300000 +v -4.077313 9.954605 1.300000 +v -4.077313 9.954605 -1.300000 +v 4.077313 9.954605 -1.300000 +v 4.077313 9.954605 1.300000 +v 1.686446 9.745432 1.300000 +v 1.686446 9.745432 -1.300000 +v 4.713554 2.682348 -1.300000 +v 4.713554 2.682348 1.300000 +v 2.322686 2.473175 1.300000 +v 2.322686 2.473175 -1.300000 +v 0.139099 2.938947 -1.200000 +v 0.139099 2.938947 1.200000 +v 0.261266 -4.059988 1.200000 +v 0.261266 -4.059988 -1.200000 +v 2.660901 -4.018101 1.190000 +v 2.660901 -4.018101 -1.210000 +v 2.538733 2.980834 1.190000 +v 2.538733 2.980834 -1.210000 +v -0.139099 2.938947 -1.200000 +v -0.139099 2.938947 1.200000 +v -0.261266 -4.059988 1.200000 +v -0.261266 -4.059988 -1.200000 +v -2.538734 2.980834 -1.210000 +v -2.538734 2.980834 1.190000 +v -2.660901 -4.018101 -1.210000 +v -2.660901 -4.018101 1.190000 +v -2.799999 -4.387500 1.390000 +v -2.799999 -4.387500 -1.410000 +v -2.800000 -0.812499 1.390000 +v -2.800000 -0.812499 -1.410000 +v -0.000000 -4.387500 -1.400000 +v -0.000000 -4.387500 1.400000 +v -0.000000 -0.812499 1.400000 +v -0.000000 -0.812499 -1.400000 +v 2.800000 -0.812499 -1.410000 +v 2.800000 -0.812499 1.390000 +v 2.799999 -4.387500 -1.410000 +v 2.799999 -4.387500 1.390000 +v 0.000000 -4.387500 -1.400000 +v 0.000000 -4.387500 1.400000 +v 0.000000 -0.812499 1.400000 +v 0.000000 -0.812499 -1.400000 +v 2.267006 13.830965 2.267006 +v 2.267006 13.830965 -2.267006 +v 2.267006 9.296881 2.267006 +v 2.267006 9.296881 -2.267006 +v -2.267006 13.830965 -2.267006 +v -2.267006 13.830965 2.267006 +v -2.267006 9.296881 -2.267006 +v -2.267006 9.296881 2.267006 +vt 0.250000 0.375000 +vt 0.250000 0.000000 +vt 0.312500 0.000000 +vt 0.312500 0.375000 +vt 0.437500 0.375000 +vt 0.437500 0.500000 +vt 0.312500 0.500000 +vt 0.562500 0.375000 +vt 0.562500 0.500000 +vt 0.437500 0.000000 +vt 0.500000 0.000000 +vt 0.500000 0.375000 +vt 0.625000 0.000000 +vt 0.625000 0.375000 +vt 0.500000 0.750000 +vt 0.500000 0.500000 +vt 0.625000 0.500000 +vt 0.625000 0.750000 +vt 0.750000 0.750000 +vt 0.750000 1.000000 +vt 0.625000 1.000000 +vt 0.875000 0.750000 +vt 0.875000 1.000000 +vt 0.750000 0.500000 +vt 0.875000 0.500000 +vt 1.000000 0.750000 +vt 1.000000 0.500000 +vt 0.750000 0.375000 +vt 0.812500 0.500000 +vt 0.812500 0.375000 +vt 0.687500 0.375000 +vt 0.687500 0.500000 +vt 0.687500 0.000000 +vt 0.750000 0.000000 +vt 0.812500 0.000000 +vt 0.875000 0.375000 +vt 0.875000 0.000000 +vt 0.125000 0.375000 +vt 0.062500 0.375000 +vt 0.062500 0.500000 +vt 0.125000 0.500000 +vt 0.187500 0.375000 +vt 0.187500 0.500000 +vt 0.000000 0.375000 +vt 0.000000 0.000000 +vt 0.062500 0.000000 +vt 0.187500 0.000000 +vt 0.125000 0.000000 +vt 0.437500 0.875000 +vt 0.437500 1.000000 +vt 0.375000 1.000000 +vt 0.375000 0.875000 +vt 0.250000 0.875000 +vt 0.312500 0.875000 +vt 0.312500 0.656250 +vt 0.250000 0.656250 +vt 0.500000 0.875000 +vt 0.437500 0.656250 +vt 0.500000 0.656250 +vt 0.375000 0.656250 +vt 0.312500 1.000000 +usemtl Armor +s off +f 1/1 3/2 4/3 2/4 +f 5/5 6/6 1/7 2/4 +f 8/6 7/5 4/8 3/9 +f 5/5 2/4 4/3 7/10 +f 7/10 8/11 6/12 5/5 +f 8/11 3/13 1/14 6/12 +f 9/15 11/16 12/17 10/18 +f 13/19 14/20 9/21 10/18 +f 12/22 11/23 16/20 15/19 +f 13/19 10/18 12/17 15/24 +f 14/22 13/19 15/24 16/25 +f 9/26 14/22 16/25 11/27 +f 17/28 18/24 19/29 20/30 +f 24/31 23/32 22/24 21/28 +f 23/31 24/14 20/13 19/33 +f 24/31 21/28 17/34 20/33 +f 21/28 22/30 18/35 17/34 +f 22/30 23/36 19/37 18/35 +f 27/30 31/35 30/37 26/36 +f 28/28 32/34 31/35 27/30 +f 25/31 29/33 32/34 28/28 +f 26/31 30/33 29/13 25/14 +f 25/31 28/28 27/24 26/32 +f 32/28 29/30 30/29 31/24 +f 40/38 33/39 34/40 39/41 +f 36/42 38/38 37/41 35/43 +f 39/44 37/45 38/46 40/39 +f 34/1 35/2 37/47 39/42 +f 40/38 38/48 36/46 33/39 +f 33/42 36/47 35/48 34/38 +f 45/38 46/41 42/40 41/39 +f 41/42 42/38 43/48 44/47 +f 45/38 41/39 44/46 47/48 +f 42/1 46/42 48/47 43/2 +f 46/44 45/39 47/46 48/45 +f 44/42 43/43 48/41 47/38 +f 53/49 54/50 49/51 50/52 +f 51/53 52/54 50/55 49/56 +f 55/57 51/49 49/58 54/59 +f 52/52 56/54 53/55 50/60 +f 56/49 55/52 54/60 53/58 +f 52/52 51/51 55/61 56/54 +f 64/49 61/58 62/60 63/52 +f 57/52 59/60 61/55 64/54 +f 63/57 62/59 60/58 58/49 +f 58/53 60/56 59/55 57/54 +f 61/49 59/52 60/51 62/50 +f 57/52 64/54 63/61 58/51 +f 65/15 66/18 68/17 67/16 +f 69/19 66/18 65/21 70/20 +f 68/22 71/19 72/20 67/23 +f 69/19 71/24 68/17 66/18 +f 70/22 72/25 71/24 69/19 +f 65/26 67/27 72/25 70/22 diff --git a/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.obj b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.obj new file mode 100644 index 00000000..0df6dc78 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.obj @@ -0,0 +1,280 @@ +# Blender v2.72 (sub 0) OBJ File: '' +# www.blender.org +mtllib 3d_armor_stand.mtl +o Armor_Stand_Player_Cube_Stand +v 0.062500 0.125002 -0.062500 +v 0.062500 -0.437500 -0.062500 +v 0.062500 -0.437500 0.062500 +v 0.062500 0.125002 0.062500 +v -0.187500 0.250004 0.062500 +v -0.187500 0.250004 -0.062500 +v -0.250000 0.250004 -0.062500 +v -0.250000 0.250004 0.062500 +v -0.062500 -0.437500 -0.062500 +v -0.062500 -0.437500 0.062500 +v -0.187500 -0.437500 0.062500 +v -0.187500 -0.437500 -0.062500 +v -0.187500 0.125002 0.062500 +v -0.187500 0.125002 -0.062500 +v -0.187500 0.937504 0.062500 +v -0.187500 0.937504 -0.062500 +v -0.375000 0.937504 -0.062500 +v -0.375000 0.937504 0.062500 +v -0.062500 0.125002 0.062500 +v 0.187500 0.125002 -0.062500 +v 0.187500 -0.437500 -0.062500 +v -0.062500 0.125002 -0.062500 +v -0.250000 0.125007 -0.062500 +v -0.250000 0.125007 0.062500 +v 0.187500 -0.437500 0.062500 +v 0.187500 0.125002 0.062500 +v -0.062500 0.937504 0.062500 +v -0.187500 0.812504 0.062500 +v -0.062500 0.812504 0.062500 +v -0.062500 0.937504 -0.062500 +v 0.187500 0.250004 -0.062500 +v 0.187500 0.250004 0.062500 +v 0.250000 0.250004 0.062500 +v 0.250000 0.250004 -0.062500 +v 0.250000 0.125007 0.062500 +v 0.250000 0.125007 -0.062500 +v 0.187500 0.812504 0.062500 +v 0.187500 0.812504 -0.062500 +v 0.375000 0.812504 -0.062500 +v 0.375000 0.812504 0.062500 +v 0.187500 0.937504 -0.062500 +v 0.187500 0.937504 0.062500 +v 0.375000 0.937504 0.062500 +v 0.375000 0.937504 -0.062500 +v 0.062500 0.937504 -0.062500 +v 0.062500 0.937504 0.062500 +v -0.062500 0.812504 -0.062500 +v -0.187500 0.812504 -0.062500 +v 0.062500 0.812504 -0.062500 +v 0.062500 0.812504 0.062500 +v -0.375000 0.812504 -0.062500 +v -0.375000 0.812504 0.062500 +v -0.062500 0.250004 0.062500 +v 0.062500 0.250004 0.062500 +v 0.062500 0.250004 -0.062500 +v -0.062500 0.250004 -0.062500 +v -0.062500 1.312504 -0.062500 +v 0.062500 1.312504 -0.062500 +v -0.062500 1.312504 0.062500 +v 0.062500 1.312504 0.062500 +v -0.500000 -0.437500 -0.500000 +v -0.500000 -0.437500 0.500000 +v 0.500000 -0.437500 0.500000 +v 0.500000 -0.437500 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 0.500000 +vt 0.062500 0.140625 +vt 0.062500 0.000000 +vt 0.093750 0.000000 +vt 0.093750 0.140625 +vt 0.140625 0.234375 +vt 0.140625 0.203125 +vt 0.156250 0.203125 +vt 0.156250 0.234375 +vt 0.093750 0.171875 +vt 0.062500 0.171875 +vt 0.218750 0.140625 +vt 0.187500 0.140625 +vt 0.187500 0.000000 +vt 0.218750 0.000000 +vt 0.078125 0.437500 +vt 0.078125 0.468750 +vt 0.031250 0.468750 +vt 0.031250 0.437500 +vt 0.250000 0.140625 +vt 0.250000 0.000000 +vt 0.031250 0.140625 +vt 0.031250 0.000000 +vt 0.156250 0.140625 +vt 0.156250 0.000000 +vt 0.187500 0.203125 +vt 0.156250 0.171875 +vt 0.187500 0.171875 +vt 0.125000 0.000000 +vt 0.125000 0.140625 +vt 0.000000 0.140625 +vt 0.000000 0.000000 +vt 0.328125 0.437500 +vt 0.296875 0.437500 +vt 0.296875 0.406250 +vt 0.328125 0.406250 +vt 0.109375 0.437500 +vt 0.109375 0.468750 +vt 0.046875 0.203125 +vt 0.046875 0.234375 +vt 0.031250 0.234375 +vt 0.031250 0.203125 +vt 0.000000 0.203125 +vt 0.000000 0.171875 +vt 0.031250 0.171875 +vt 0.265625 0.468750 +vt 0.265625 0.437500 +vt 0.218750 0.437500 +vt 0.218750 0.468750 +vt 0.218750 0.171875 +vt 0.171875 0.468750 +vt 0.171875 0.437500 +vt 0.078125 0.406250 +vt 0.031250 0.406250 +vt 0.140625 0.468750 +vt 0.140625 0.437500 +vt 0.140625 0.406250 +vt 0.171875 0.406250 +vt 0.109375 0.406250 +vt 0.359375 0.437500 +vt 0.359375 0.406250 +vt 0.390625 0.406250 +vt 0.390625 0.437500 +vt 0.437500 0.406250 +vt 0.437500 0.437500 +vt 0.000000 0.437500 +vt 0.000000 0.406250 +vt 0.250000 0.437500 +vt 0.218750 0.406250 +vt 0.250000 0.406250 +vt 0.359375 0.468750 +vt 0.406250 0.468750 +vt 0.406250 0.437500 +vt 0.109375 0.234375 +vt 0.078125 0.234375 +vt 0.078125 0.203125 +vt 0.109375 0.203125 +vt 0.062500 0.468750 +vt 0.062500 0.562500 +vt 0.031250 0.562500 +vt 0.328125 0.468750 +vt 0.296875 0.468750 +vt 0.062500 0.593750 +vt 0.031250 0.593750 +vt 0.093750 0.468750 +vt 0.093750 0.562500 +vt 0.125000 0.468750 +vt 0.125000 0.562500 +vt 0.000000 0.562500 +vt 0.000000 0.468750 +vt 0.078125 0.171875 +vt 0.046875 0.171875 +vt 0.265625 0.203125 +vt 0.265625 0.171875 +vt 0.296875 0.171875 +vt 0.296875 0.203125 +vt 0.265625 0.234375 +vt 0.281250 0.234375 +vt 0.281250 0.203125 +vt 0.312500 0.171875 +vt 0.312500 0.203125 +vt 0.140625 0.171875 +vt 0.171875 0.234375 +vt 0.171875 0.203125 +vt 0.109375 0.171875 +vt 0.234375 0.203125 +vt 0.203125 0.203125 +vt 0.203125 0.171875 +vt 0.234375 0.171875 +vt 0.234375 0.234375 +vt 0.203125 0.234375 +vt 0.062500 0.375000 +vt 0.062500 0.234375 +vt 0.093750 0.234375 +vt 0.093750 0.375000 +vt 0.031250 0.375000 +vt 0.125000 0.234375 +vt 0.125000 0.375000 +vt 0.000000 0.375000 +vt 0.000000 0.234375 +vt 0.218750 0.375000 +vt 0.187500 0.375000 +vt 0.187500 0.234375 +vt 0.218750 0.234375 +vt 0.250000 0.375000 +vt 0.250000 0.234375 +vt 0.156250 0.375000 +vt 0.250000 1.000000 +vt 0.250000 0.750000 +vt 0.500000 0.750000 +vt 0.500000 1.000000 +vt 0.750000 0.750000 +vt 0.750000 1.000000 +vt 0.750000 0.734375 +vt 1.000000 0.734375 +vt 1.000000 0.750000 +vt 0.000000 0.750000 +vt 0.000000 0.734375 +vt 0.250000 0.734375 +vt 0.500000 0.734375 +usemtl Stand +s off +f 1/1 2/2 3/3 4/4 +f 5/5 6/6 7/7 8/8 +f 9/1 10/4 11/9 12/10 +f 13/11 14/12 12/13 11/14 +f 15/15 16/16 17/17 18/18 +f 19/19 13/11 11/14 10/20 +f 2/2 1/1 20/21 21/22 +f 14/12 22/23 9/24 12/13 +f 8/25 7/7 23/26 24/27 +f 4/4 3/3 25/28 26/29 +f 22/23 19/29 10/28 9/24 +f 26/30 25/31 21/22 20/21 +f 27/32 15/33 28/34 29/35 +f 16/16 15/15 27/36 30/37 +f 31/38 32/39 33/40 34/41 +f 33/42 35/43 36/44 34/41 +f 37/45 38/46 39/47 40/48 +f 2/49 21/27 25/12 3/11 +f 41/50 42/51 43/47 44/48 +f 38/52 41/15 44/18 39/53 +f 41/50 45/54 46/55 42/51 +f 16/51 30/55 47/56 48/57 +f 41/15 38/52 49/58 45/36 +f 46/59 50/60 37/61 42/62 +f 42/62 37/61 40/63 43/64 +f 43/65 40/66 39/53 44/18 +f 18/67 17/47 51/68 52/69 +f 28/34 15/33 18/67 52/69 +f 16/51 48/57 51/68 17/47 +f 48/59 28/70 52/71 51/72 +f 53/73 54/74 55/75 56/76 +f 30/77 57/78 58/79 45/17 +f 50/60 46/59 27/32 29/35 +f 29/80 47/32 49/33 50/81 +f 47/56 30/55 45/36 49/58 +f 57/78 59/82 60/83 58/79 +f 27/84 59/85 57/78 30/77 +f 46/86 60/87 59/85 27/84 +f 45/17 58/79 60/88 46/89 +f 1/90 55/75 31/38 20/91 +f 54/92 4/93 26/94 32/95 +f 26/92 20/96 36/97 35/98 +f 20/91 31/38 34/41 36/44 +f 32/95 26/94 35/99 33/100 +f 6/6 14/101 23/26 7/7 +f 14/102 13/103 24/7 23/8 +f 6/6 56/76 22/104 14/101 +f 53/105 5/106 13/107 19/108 +f 13/107 5/106 8/25 24/27 +f 1/90 22/104 56/76 55/75 +f 53/105 19/108 4/93 54/92 +f 1/109 4/105 19/106 22/110 +f 49/111 55/112 54/113 50/114 +f 38/115 31/40 55/112 49/111 +f 50/114 54/113 32/116 37/117 +f 37/118 32/119 31/40 38/115 +f 28/120 48/121 6/122 5/123 +f 29/124 28/120 5/123 53/125 +f 48/121 47/126 56/8 6/122 +f 47/126 29/117 53/116 56/8 +usemtl Base +f 61/127 62/128 63/129 64/130 +f 65/129 66/131 67/132 68/130 +f 62/131 68/133 67/134 63/135 +f 63/136 67/137 66/138 64/128 +f 61/129 64/128 66/138 65/139 +f 62/131 61/129 65/139 68/133 diff --git a/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.png b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.png new file mode 100644 index 00000000..aeb26de9 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand_locked.png b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand_locked.png new file mode 100644 index 00000000..3ee08b4b Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/models/3d_armor_stand_locked.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_feet.png b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_feet.png new file mode 100644 index 00000000..6b34d666 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_feet.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_head.png b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_head.png new file mode 100644 index 00000000..864bf5cf Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_head.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_legs.png b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_legs.png new file mode 100644 index 00000000..5441f0c4 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_legs.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_shield.png b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_shield.png new file mode 100644 index 00000000..51b490f6 Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_shield.png differ diff --git a/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_torso.png b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_torso.png new file mode 100644 index 00000000..1856baea Binary files /dev/null and b/mods/minetest-3d_armor/3d_armor_stand/textures/3d_armor_stand_torso.png differ diff --git a/mods/minetest-3d_armor/3d_armor_ui/LICENSE.txt b/mods/minetest-3d_armor/3d_armor_ui/LICENSE.txt new file mode 100644 index 00000000..6ae23a6f --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ui/LICENSE.txt @@ -0,0 +1,18 @@ +[mod] 3d Armor integration to unified inventory [3d_armor_ui] +============================================================= + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/mods/minetest-3d_armor/3d_armor_ui/depends.txt b/mods/minetest-3d_armor/3d_armor_ui/depends.txt new file mode 100644 index 00000000..cf4ccf91 --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ui/depends.txt @@ -0,0 +1,2 @@ +3d_armor +unified_inventory? diff --git a/mods/minetest-3d_armor/3d_armor_ui/description.txt b/mods/minetest-3d_armor/3d_armor_ui/description.txt new file mode 100644 index 00000000..873f876b --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ui/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the unified inventory diff --git a/mods/minetest-3d_armor/3d_armor_ui/init.lua b/mods/minetest-3d_armor/3d_armor_ui/init.lua new file mode 100644 index 00000000..41eec7bb --- /dev/null +++ b/mods/minetest-3d_armor/3d_armor_ui/init.lua @@ -0,0 +1,53 @@ +-- support for i18n +local S = armor_i18n.gettext +local F = minetest.formspec_escape +local has_technic = minetest.get_modpath("technic") ~= nil + +if not minetest.global_exists("unified_inventory") then + minetest.log("warning", S("3d_armor_ui: Mod loaded but unused.")) + return +end + +if unified_inventory.sfinv_compat_layer then + return +end + +armor:register_on_update(function(player) + local name = player:get_player_name() + if unified_inventory.current_page[name] == "armor" then + unified_inventory.set_inventory_formspec(player, "armor") + end +end) + +unified_inventory.register_button("armor", { + type = "image", + image = "inventory_plus_armor.png", + tooltip = S("3d Armor") +}) + +unified_inventory.register_page("armor", { + get_formspec = function(player, perplayer_formspec) + local fy = perplayer_formspec.formspec_y + local name = player:get_player_name() + if armor.def[name].init_time == 0 then + return {formspec="label[0,0;"..F(S("Armor not initialized!")).."]"} + end + local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]".. + "label[0,0;"..F(S("Armor")).."]".. + "list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]".. + "image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]".. + "label[5.0,"..(fy + 0.0)..";"..F(S("Level"))..": "..armor.def[name].level.."]".. + "label[5.0,"..(fy + 0.5)..";"..F(S("Heal"))..": "..armor.def[name].heal.."]".. + "listring[current_player;main]".. + "listring[detached:"..name.."_armor;armor]" + if armor.config.fire_protect then + formspec = formspec.."label[5.0,"..(fy + 1.0)..";".. + F(S("Fire"))..": "..armor.def[name].fire.."]" + end + if has_technic then + formspec = formspec.."label[5.0,"..(fy + 1.5)..";".. + F(S("Radiation"))..": "..armor.def[name].groups["radiation"].."]" + end + return {formspec=formspec} + end, +}) diff --git a/mods/minetest-3d_armor/LICENSE.md b/mods/minetest-3d_armor/LICENSE.md new file mode 100644 index 00000000..56c93cdd --- /dev/null +++ b/mods/minetest-3d_armor/LICENSE.md @@ -0,0 +1,9 @@ +3D Armor - Visible Player Armor +=============================== + +License Source Code: Copyright (C) 2013-2018 Stuart Jones - LGPL v2.1 + +Armor Textures: Copyright (C) 2017-2018 davidthecreator - CC-BY-SA 3.0 + +Special credit to Jordach and MirceaKitsune for providing the default 3d character model. + diff --git a/mods/minetest-3d_armor/README.md b/mods/minetest-3d_armor/README.md new file mode 100644 index 00000000..204bf9d1 --- /dev/null +++ b/mods/minetest-3d_armor/README.md @@ -0,0 +1,69 @@ +Modpack - 3d Armor [0.4.13] +=========================== + +### Table of Contents + + + + +- [[mod] Visible Player Armor [3d_armor]](#mod-visible-player-armor-3d_armor) +- [[mod] Visible Wielded Items [wieldview]](#mod-visible-wielded-items-wieldview) +- [[mod] Shields [shields]](#mod-shields-shields) +- [[mod] 3d Armor Stand [3d_armor_stand]](#mod-3d-armor-stand-3d_armor_stand) + + + + +[mod] Visible Player Armor [3d_armor] +------------------------------------- + +Minetest Version: 5.0.0 + +Game: minetest_game and many derivatives + +Depends: default + +Adds craftable armor that is visible to other players. Each armor item worn contributes to +a player's armor group level making them less vulnerable to attack. + +Armor takes damage when a player is hurt, however, many armor items offer a 'stackable' +percentage chance of restoring the lost health points. Overall armor level is boosted by 10% +when wearing a full matching set (helmet, chestplate, leggings and boots of the same material) + +Fire protection has been added by TenPlus1 and in use when ethereal mod is found and crystal +armor has been enabled. each piece of armor offers 1 fire protection, level 1 protects +against torches, level 2 against crystal spikes, 3 for fire and 5 protects when in lava. + +Compatible with sfinv, inventory plus or unified inventory by enabling the appropriate +inventory module, [3d_armor_sfinv], [3d_armor_ip] and [3d_armor_ui] respectively. +Also compatible with [smart_inventory] without the need for additional modules. + +built in support player skins [skins] by Zeg9 and Player Textures [player_textures] by PilzAdam +and [simple_skins] by TenPlus1. + +Armor can be configured by adding a file called armor.conf in 3d_armor mod or world directory. +see armor.conf.example for all available options. + +For mod installation instructions, please visit: http://wiki.minetest.com/wiki/Installing_Mods + +[mod] Visible Wielded Items [wieldview] +--------------------------------------- + +Depends: 3d_armor + +Makes hand wielded items visible to other players. + +[mod] Shields [shields] +----------------------- + +Depends: 3d_armor + +Originally a part of 3d_armor, shields have been re-included as an optional extra. +If you do not want shields then simply remove the shields folder from the modpack. + +[mod] 3d Armor Stand [3d_armor_stand] +------------------------------------- + +Depends: 3d_armor + +Adds a chest-like armor stand for armor storage and display. diff --git a/mods/minetest-3d_armor/description.txt b/mods/minetest-3d_armor/description.txt new file mode 100644 index 00000000..2da5ba4d --- /dev/null +++ b/mods/minetest-3d_armor/description.txt @@ -0,0 +1 @@ +Visible player armor & wielded items. diff --git a/mods/minetest-3d_armor/modpack.txt b/mods/minetest-3d_armor/modpack.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/mods/minetest-3d_armor/modpack.txt @@ -0,0 +1 @@ + diff --git a/mods/minetest-3d_armor/preview_gen.py b/mods/minetest-3d_armor/preview_gen.py new file mode 100644 index 00000000..a18954df --- /dev/null +++ b/mods/minetest-3d_armor/preview_gen.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +import os +import sys +import Image + +try : + arg = sys.argv[1] +except IndexError : + print "Usage: preview_gen.py " + sys.exit(1) + +try : + index = open(arg, "r") +except IOError : + print "Failed to open index file%s" %s (arg) + sys.exit(1) + +preview = [] + +for line in index.readlines() : + if ":" in line : + line = line.rstrip('\n') + preview.append(line.split(':')) + +print "Generating preview images..." +for fn, place in preview : + try : + imi = Image.open(fn) + except IOError : + print "Failed to open %s" % (fn) + sys.exit(1) + + w, h = imi.size + if h != w / 2: + print "Incompatible texture size %s" % (fn) + sys.exit(1) + + s = w / 64 + imo = Image.new("RGBA", (16 * s, 32 * s)) + + if place == "all" or place == "head" : + face = (40 * s, 8 * s, 48 * s, 16 * s) + side_l = (56 * s, 8 * s, 57 * s, 16 * s) + side_r = (63 * s, 8 * s, 64 * s, 16 * s) + imo.paste(imi.crop(side_l), (4 * s, 0, 5 * s, 8 * s)) + imo.paste(imi.crop(side_r), (11 * s, 0, 12 * s, 8 * s)) + imo.paste(imi.crop(face), (4 * s, 0, 12 * s, 8 * s)) + + if place == "all" or place == "torso" : + arm = (44 * s, 20 * s, 48 * s, 32 * s) + body = (20 * s, 20 * s, 28 * s, 32 * s) + imo.paste(imi.crop(arm), (0 * s, 8 * s, 4 * s, 20 * s)) + imo.paste(imi.crop(arm).transpose(Image.FLIP_LEFT_RIGHT), + (12 * s, 8 * s, 16 * s, 20 * s)) + imo.paste(imi.crop(body), (4 * s, 8 * s, 12 * s, 20 * s)) + + if place == "all" or place == "legs" : + leg = (4 * s, 20 * s, 8 * s, 32 * s) + imo.paste(imi.crop(leg), (4 * s, 20 * s, 8 * s, 32 * s)) + imo.paste(imi.crop(leg).transpose(Image.FLIP_LEFT_RIGHT), + (8 * s, 20 * s, 12 * s, 32 * s)) + + if place == "all" or place == "feet" : + boot = (20 * s, 4 * s, 24 * s, 11 * s) + imo.paste(imi.crop(boot), (4 * s, 25 * s, 8 * s, 32 * s)) + imo.paste(imi.crop(boot).transpose(Image.FLIP_LEFT_RIGHT), + (8 * s, 25 * s, 12 * s, 32 * s)) + + size = (32 * s, 64 * s) + imo = imo.resize(size) + + if place == "shield" : + shield = (0, 0, 16 * s, 16 * s) + imo.paste(imi.crop(shield), (16 * s, 32 * s, 32 * s, 48 * s)) + + outfile = fn.replace(".png", "_preview.png") + imo.save(outfile) + print outfile + + diff --git a/mods/minetest-3d_armor/screenshot.png b/mods/minetest-3d_armor/screenshot.png new file mode 100644 index 00000000..c1f9e582 Binary files /dev/null and b/mods/minetest-3d_armor/screenshot.png differ diff --git a/mods/minetest-3d_armor/settingtypes.txt b/mods/minetest-3d_armor/settingtypes.txt new file mode 100644 index 00000000..c6c90de0 --- /dev/null +++ b/mods/minetest-3d_armor/settingtypes.txt @@ -0,0 +1,65 @@ + +[3d_armor] + +armor_material_wood (Enable wood armor) bool true +armor_material_cactus (Enable cactus armor) bool true +armor_material_steel (Enable steel armor) bool true +armor_material_bronze (Enable bronze armor) bool true +armor_material_diamond (Enable diamond armor) bool true +armor_material_gold (Enable gold armor) bool true +armor_material_mithril (Enable mithril armor) bool true +armor_material_crystal (Enable crystal armor) bool true + +# Increase this if you get initialization glitches when a player first joins. +armor_init_delay (Initialization delay) int 2 + +# Number of initialization attempts. +# Use in conjunction with armor_init_delay if initialization problems persist. +armor_init_times (Initialization attempts) int 10 + +# Increase this if armor is not getting into bones due to server lag. +armor_bones_delay (Delay for bones) int 1 + +# How often player armor items are updated. +armor_update_time (Armor refresh rate [seconds]) int 1 + +# Drop armor when a player dies. +# Uses bones mod if present, otherwise items are dropped around the player. +armor_drop (Drop armor on death) bool true + +# Pulverize armor when a player dies, overrides armor_drop. +armor_destroy (Pulverize armor on death) bool false + +# You can use this to increase or decrease overall armor effectiveness, +# eg: level_multiplier = 0.5 will reduce armor level by half. +armor_level_multiplier (Armor effectiveness multiplier) float 1 + +# You can use this to increase or decrease overall armor healing, +# eg: armor_heal_multiplier = 0 will disable healing altogether. +armor_heal_multiplier (Armor healing multiplier) float 1 + +# Enable water protection (periodically restores breath when activated). +armor_water_protect (Enable water protection) bool true + +# Enable fire protection (defaults true if using ethereal mod). +armor_fire_protect (Enable fire protection) bool false + +# Enable punch damage effects. +armor_punch_damage (Enable damage effects) bool true + +# Enable migration of old armor inventories. +armor_migrate_old_inventory (Migrate old armor inventories) bool true + + +[shields] + +shields_disable_sounds (Disable shield sounds) bool false + + +[wieldview] + +# Set number of seconds between visible wielded item updates. +wieldview_update_time (Wieldview refresh rate [seconds]) int 2 + +# Show nodes as tiles, disabled by default. +wieldview_node_tiles (Show nodes as tiles) bool false diff --git a/mods/minetest-3d_armor/wieldview/LICENSE.txt b/mods/minetest-3d_armor/wieldview/LICENSE.txt new file mode 100644 index 00000000..e1552c06 --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/LICENSE.txt @@ -0,0 +1,18 @@ +[mod] visible wielded items [wieldview] +======================================= + +Copyright (C) 2012-2019 stujones11, Stuart Jones + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/mods/minetest-3d_armor/wieldview/README.txt b/mods/minetest-3d_armor/wieldview/README.txt new file mode 100644 index 00000000..ffa5ef0c --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/README.txt @@ -0,0 +1,23 @@ +[mod] visible wielded items [wieldview] +======================================= + +Depends on: 3d_armor + +Makes hand wielded items visible to other players. + +default settings: [minetest.conf] + +# Set number of seconds between visible wielded item updates. +wieldview_update_time = 2 + +# Show nodes as tiles, disabled by default +wieldview_node_tiles = false + + +Info for modders +################ + +Wield image transformation: To apply a simple transformation to the item in +hand, add the group “wieldview_transform” to the item definition. The group +rating equals one of the numbers used for the [transform texture modifier +of the Lua API. diff --git a/mods/minetest-3d_armor/wieldview/depends.txt b/mods/minetest-3d_armor/wieldview/depends.txt new file mode 100644 index 00000000..b6cac219 --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/depends.txt @@ -0,0 +1 @@ +3d_armor diff --git a/mods/minetest-3d_armor/wieldview/description.txt b/mods/minetest-3d_armor/wieldview/description.txt new file mode 100644 index 00000000..0d51ad95 --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/description.txt @@ -0,0 +1 @@ +Makes hand wielded items visible to other players. diff --git a/mods/minetest-3d_armor/wieldview/init.lua b/mods/minetest-3d_armor/wieldview/init.lua new file mode 100644 index 00000000..45f9fcaf --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/init.lua @@ -0,0 +1,83 @@ +local time = 0 +local update_time = tonumber(minetest.settings:get("wieldview_update_time")) +if not update_time then + update_time = 2 + minetest.settings:set("wieldview_update_time", tostring(update_time)) +end +local node_tiles = minetest.settings:get_bool("wieldview_node_tiles") +if not node_tiles then + node_tiles = false + minetest.settings:set("wieldview_node_tiles", "false") +end + +wieldview = { + wielded_item = {}, + transform = {}, +} + +dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua") + +wieldview.get_item_texture = function(self, item) + local texture = "3d_armor_trans.png" + if item ~= "" then + if minetest.registered_items[item] then + if minetest.registered_items[item].inventory_image ~= "" then + texture = minetest.registered_items[item].inventory_image + elseif node_tiles == true and minetest.registered_items[item].tiles + and type(minetest.registered_items[item].tiles[1]) == "string" + and minetest.registered_items[item].tiles[1] ~= "" then + texture = minetest.inventorycube(minetest.registered_items[item].tiles[1]) + end + end + -- Get item image transformation, first from group, then from transform.lua + local transform = minetest.get_item_group(item, "wieldview_transform") + if transform == 0 then + transform = wieldview.transform[item] + end + if transform then + -- This actually works with groups ratings because transform1, transform2, etc. + -- have meaning and transform0 is used for identidy, so it can be ignored + texture = texture.."^[transform"..tostring(transform) + end + end + return texture +end + +wieldview.update_wielded_item = function(self, player) + if not player then + return + end + local name = player:get_player_name() + local stack = player:get_wielded_item() + local item = stack:get_name() + if not item then + return + end + if self.wielded_item[name] then + if self.wielded_item[name] == item then + return + end + armor.textures[name].wielditem = self:get_item_texture(item) + armor:update_player_visuals(player) + end + self.wielded_item[name] = item +end + +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + wieldview.wielded_item[name] = "" + minetest.after(0, function(player) + wieldview:update_wielded_item(player) + end, player) +end) + +minetest.register_globalstep(function(dtime) + time = time + dtime + if time > update_time then + for _,player in ipairs(minetest.get_connected_players()) do + wieldview:update_wielded_item(player) + end + time = 0 + end +end) + diff --git a/mods/minetest-3d_armor/wieldview/transform.lua b/mods/minetest-3d_armor/wieldview/transform.lua new file mode 100644 index 00000000..4d5133e8 --- /dev/null +++ b/mods/minetest-3d_armor/wieldview/transform.lua @@ -0,0 +1,24 @@ +-- Wielded Item Transformations - http://dev.minetest.net/texture + +wieldview.transform = { + ["default:torch"]="R270", + ["default:sapling"]="R270", + ["flowers:dandelion_white"]="R270", + ["flowers:dandelion_yellow"]="R270", + ["flowers:geranium"]="R270", + ["flowers:rose"]="R270", + ["flowers:tulip"]="R270", + ["flowers:viola"]="R270", + ["bucket:bucket_empty"]="R270", + ["bucket:bucket_water"]="R270", + ["bucket:bucket_lava"]="R270", + ["screwdriver:screwdriver"]="R270", + ["screwdriver:screwdriver1"]="R270", + ["screwdriver:screwdriver2"]="R270", + ["screwdriver:screwdriver3"]="R270", + ["screwdriver:screwdriver4"]="R270", + ["vessels:glass_bottle"]="R270", + ["vessels:drinking_glass"]="R270", + ["vessels:steel_bottle"]="R270", +} + diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua new file mode 100644 index 00000000..20636453 --- /dev/null +++ b/mods/mobs/api.lua @@ -0,0 +1,4273 @@ + +-- Intllib and CMI support check +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP .. "/intllib.lua") +local use_cmi = minetest.global_exists("cmi") + +mobs = { + mod = "redo", + version = "20191116", + intllib = S, + invis = minetest.global_exists("invisibility") and invisibility or {} +} + +-- creative check +local creative_cache = minetest.settings:get_bool("creative_mode") +function mobs.is_creative(name) + return creative_cache or minetest.check_player_privs(name, {creative = true}) +end + + +-- localize math functions +local pi = math.pi +local square = math.sqrt +local sin = math.sin +local cos = math.cos +local abs = math.abs +local min = math.min +local max = math.max +local atann = math.atan +local random = math.random +local floor = math.floor +local atan = function(x) + if not x or x ~= x then + --error("atan bassed NaN") + return 0 + else + return atann(x) + end +end + + +-- Load settings +local damage_enabled = minetest.settings:get_bool("enable_damage") +local mobs_spawn = minetest.settings:get_bool("mobs_spawn") ~= false +local peaceful_only = minetest.settings:get_bool("only_peaceful_mobs") +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 creative = minetest.settings:get_bool("creative_mode") +local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false +local remove_far = minetest.settings:get_bool("remove_far_mobs") ~= false +local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0 +local show_health = minetest.settings:get_bool("mob_show_health") ~= false +local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 99) +local mob_chance_multiplier = tonumber(minetest.settings:get("mob_chance_multiplier") or 1) + +-- Peaceful mode message so players will know there are no monsters +if peaceful_only then + minetest.register_on_joinplayer(function(player) + minetest.chat_send_player(player:get_player_name(), + S("** Peaceful Mode Active - No Monsters Will Spawn")) + end) +end + +-- calculate aoc range for mob count +local aoc_range = tonumber(minetest.settings:get("active_block_range")) * 16 + +-- pathfinding settings +local enable_pathfinding = true +local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching +local stuck_path_timeout = 10 -- how long will mob follow path before giving up + +-- default nodes +local node_fire = "fire:basic_flame" +local node_permanent_flame = "fire:permanent_flame" +local node_ice = "default:ice" +local node_snowblock = "default:snowblock" +local node_snow = "default:snow" +mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt" + +local mob_class = { + stepheight = 1.1, + fly_in = "air", + owner = "", + order = "", + jump_height = 4, + lifetimer = 180, -- 3 minutes + physical = true, + collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}, + visual_size = {x = 1, y = 1}, + makes_footstep_sound = false, + view_range = 5, + walk_velocity = 1, + run_velocity = 2, + light_damage = 0, + light_damage_min = 14, + light_damage_max = 15, + water_damage = 0, + lava_damage = 0, + suffocation = 2, + fall_damage = 1, + fall_speed = -10, -- must be lower than -2 (default: -10) + drops = {}, + armor = 100, + sounds = {}, + jump = true, + knock_back = true, + walk_chance = 50, + stand_chance = 30, + attack_chance = 5, + passive = false, + blood_amount = 5, + blood_texture = "mobs_blood.png", + shoot_offset = 0, + floats = 1, -- floats in water by default + replace_offset = 0, + timer = 0, + env_damage_timer = 0, -- only used when state = "attack" + tamed = false, + pause_timer = 0, + horny = false, + hornytimer = 0, + child = false, + gotten = false, + health = 0, + reach = 3, + htimer = 0, + docile_by_day = false, + time_of_day = 0.5, + fear_height = 0, + runaway_timer = 0, + immune_to = {}, + explosion_timer = 3, + allow_fuse_reset = true, + stop_to_explode = true, + dogshoot_count = 0, + dogshoot_count_max = 5, + dogshoot_count2_max = 5, + group_attack = false, + attack_monsters = false, + attack_animals = false, + attack_players = true, + attack_npcs = true, + facing_fence = false, + _cmi_is_mob = true +} + +local mob_class_meta = {__index = mob_class} + +-- play sound +function mob_class:mob_sound(sound) + + if sound then + minetest.sound_play(sound, { + object = self.object, + gain = 1.0, + max_hear_distance = self.sounds.distance + }) + end +end + + +-- attack player/mob +function mob_class:do_attack(player) + + if self.state == "attack" then + return + end + + self.attack = player + self.state = "attack" + + if random(0, 100) < 90 then + self:mob_sound(self.sounds.war_cry) + end +end + + +-- calculate distance +local get_distance = function(a, b) + + local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z + + return square(x * x + y * y + z * z) +end + + +-- collision function based on jordan4ibanez' open_ai mod +function mob_class:collision() + + local pos = self.object:get_pos() + local vel = self.object:get_velocity() + local x, z = 0, 0 + local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5 + + for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do + + if object:is_player() + or (object:get_luaentity() + and object:get_luaentity()._cmi_is_mob == true + and object ~= self.object) then + + local pos2 = object:get_pos() + local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z} + + x = x + vec.x + z = z + vec.z + end + end + + return({x, z}) +end + + +-- move mob in facing direction +function mob_class:set_velocity(v) + + local c_x, c_y = 0, 0 + + -- can mob be pushed, if so calculate direction + if self.pushable then + c_x, c_y = unpack(self:collision()) + end + + -- halt mob if it has been ordered to stay + if self.order == "stand" then + self.object:set_velocity({x = 0, y = 0, z = 0}) + return + end + + local yaw = (self.object:get_yaw() or 0) + self.rotate + + self.object:set_velocity({ + x = (sin(yaw) * -v) + c_x, + y = self.object:get_velocity().y, + z = (cos(yaw) * v) + c_y + }) +end + +-- global version of above function +function mobs:set_velocity(entity, v) + mob_class.set_velocity(entity, v) +end + + +-- calculate mob velocity +function mob_class:get_velocity() + + local v = self.object:get_velocity() + + return (v.x * v.x + v.z * v.z) ^ 0.5 +end + + +-- set and return valid yaw +function mob_class:set_yaw(yaw, delay) + + if not yaw or yaw ~= yaw then + yaw = 0 + end + + delay = delay or 0 + + if delay == 0 then + self.object:set_yaw(yaw) + return yaw + end + + self.target_yaw = yaw + self.delay = delay + + return self.target_yaw +end + +-- global function to set mob yaw +function mobs:yaw(entity, yaw, delay) + mob_class.set_yaw(entity, yaw, delay) +end + + +-- set defined animation +function mob_class:set_animation(anim, force) + + if not self.animation + or not anim then return end + + self.animation.current = self.animation.current or "" + + -- only use different animation for attacks when using same set + if force ~= true and anim ~= "punch" and anim ~= "shoot" + and string.find(self.animation.current, anim) then + return + end + + -- check for more than one animation + local num = 0 + + for n = 1, 4 do + + if self.animation[anim .. n .. "_start"] + and self.animation[anim .. n .. "_end"] then + num = n + end + end + + -- choose random animation from set + if num > 0 then + num = random(0, num) + anim = anim .. (num ~= 0 and num or "") + end + + if anim == self.animation.current + or not self.animation[anim .. "_start"] + or not self.animation[anim .. "_end"] then + return + end + + self.animation.current = anim + + self.object:set_animation({ + x = self.animation[anim .. "_start"], + y = self.animation[anim .. "_end"]}, + self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, + 0, self.animation[anim .. "_loop"] ~= false) +end + +-- above function exported for mount.lua +function mobs:set_animation(entity, anim) + mob_class.set_animation(entity, anim) +end + + +-- check line of sight (BrunoMine) +local line_of_sight = function(self, pos1, pos2, stepsize) + + stepsize = stepsize or 1 + + local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) + + -- normal walking and flying mobs can see you through air + if s == true then + return true + end + + -- New pos1 to be analyzed + local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} + + local r, pos = minetest.line_of_sight(npos1, pos2, stepsize) + + -- Checks the return + if r == true then return true end + + -- Nodename found + local nn = minetest.get_node(pos).name + + -- Target Distance (td) to travel + local td = get_distance(pos1, pos2) + + -- Actual Distance (ad) traveled + local ad = 0 + + -- It continues to advance in the line of sight in search of a real + -- obstruction which counts as 'normal' nodebox. + while minetest.registered_nodes[nn] + and (minetest.registered_nodes[nn].walkable == false) do +-- or minetest.registered_nodes[nn].drawtype == "nodebox") do + + -- Check if you can still move forward + if td < ad + stepsize then + return true -- Reached the target + end + + -- Moves the analyzed pos + local d = get_distance(pos1, pos2) + + npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x + npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y + npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z + + -- NaN checks + if d == 0 + or npos1.x ~= npos1.x + or npos1.y ~= npos1.y + or npos1.z ~= npos1.z then + return false + end + + ad = ad + stepsize + + -- scan again + r, pos = minetest.line_of_sight(npos1, pos2, stepsize) + + if r == true then return true end + + -- New Nodename found + nn = minetest.get_node(pos).name + end + + return false +end + + +-- check line of sight (by BrunoMine, tweaked by Astrobe) +local new_line_of_sight = function(self, pos1, pos2, stepsize) + + if not pos1 or not pos2 then return end + + stepsize = stepsize or 1 + + local stepv = vector.multiply(vector.direction(pos1, pos2), stepsize) + + local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) + + -- normal walking and flying mobs can see you through air + if s == true then return true end + + -- New pos1 to be analyzed + local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} + + local r, pos = minetest.line_of_sight(npos1, pos2, stepsize) + + -- Checks the return + if r == true then return true end + + -- Nodename found + local nn = minetest.get_node(pos).name + + -- It continues to advance in the line of sight in search of a real + -- obstruction which counts as 'normal' nodebox. + while minetest.registered_nodes[nn] + and (minetest.registered_nodes[nn].walkable == false) do +-- or minetest.registered_nodes[nn].drawtype == "nodebox") do + + npos1 = vector.add(npos1, stepv) + + if get_distance(npos1, pos2) < stepsize then return true end + + -- scan again + r, pos = minetest.line_of_sight(npos1, pos2, stepsize) + + if r == true then return true end + + -- New Nodename found + nn = minetest.get_node(pos).name + end + + return false +end + +-- check line of sight using raycasting (thanks Astrobe) +local ray_line_of_sight = function(self, pos1, pos2) + + local ray = minetest.raycast(pos1, pos2, true, false) + local thing = ray:next() + + while thing do + + if thing.type == "object" + and thing.ref ~= self.object + and not thing.ref:is_player() then return false end + + if thing.type == "node" then + + local name = minetest.get_node(thing.under).name + + if minetest.registered_items[name] + and minetest.registered_items[name].walkable then return false end + end + + thing = ray:next() + end + + return true +end + +-- detect if using minetest 5.0 by searching for permafrost node +local is_50 = nil -- minetest.registered_nodes["default:permafrost"] + +function mob_class:line_of_sight(pos1, pos2, stepsize) + + if is_50 then -- only use if minetest 5.0 is detected + return ray_line_of_sight(self, pos1, pos2) + end + + return line_of_sight(self, pos1, pos2, stepsize) +end + +-- global function +function mobs:line_of_sight(entity, pos1, pos2, stepsize) + return entity:line_of_sight(pos1, pos2, stepsize) +end + + +function mob_class:attempt_flight_correction() + + if self:flight_check() then return true end + + -- We are not flying in what we are supposed to. + -- See if we can find intended flight medium and return to it + local pos = self.object:get_pos() + local searchnodes = self.fly_in + + if type(searchnodes) == "string" then + searchnodes = {self.fly_in} + end + + local flyable_nodes = minetest.find_nodes_in_area( + {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, + {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, + searchnodes) + + if #flyable_nodes < 1 then + return false + end + + local escape_target = flyable_nodes[math.random(1, #flyable_nodes)] + local escape_direction = vector.direction(pos, escape_target) + + self.object:set_velocity( + vector.multiply(escape_direction, self.run_velocity)) + + return true +end + + +-- are we flying in what we are suppose to? (taikedz) +function mob_class:flight_check() + + local def = minetest.registered_nodes[self.standing_in] + + if not def then return false end + + if type(self.fly_in) == "string" + and self.standing_in == self.fly_in then + + return true + + elseif type(self.fly_in) == "table" then + + for _,fly_in in pairs(self.fly_in) do + + if self.standing_in == fly_in then + + return true + end + end + end + + -- stops mobs getting stuck inside stairs and plantlike nodes + if def.drawtype ~= "airlike" + and def.drawtype ~= "liquid" + and def.drawtype ~= "flowingliquid" then + return true + end + + return false +end + + +-- if self.stay_near set then check periodically for nodes and turn to face/move +function mob_class:do_stay_near() + + if not self.stay_near then return false end + + local pos = self.object:get_pos() + local searchnodes = self.stay_near[1] + local chance = self.stay_near[2] or 10 + + if random(1, chance) > 1 then + return false + end + + if type(searchnodes) == "string" then + searchnodes = {self.stay_near[1]} + end + + local r = self.view_range + local nearby_nodes = minetest.find_nodes_in_area( + {x = pos.x - r, y = pos.y - 1, z = pos.z - r}, + {x = pos.x + r, y = pos.y + 1, z = pos.z + r}, + searchnodes) + + if #nearby_nodes < 1 then + return false + end + + local target = nearby_nodes[math.random(1, #nearby_nodes)] + local direction = vector.direction(pos, target) + local vec = {x = target.x - pos.x, z = target.z - pos.z} + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if target.x > pos.x then + yaw = yaw + pi + end + + yaw = self:set_yaw(yaw, 4) + + self:set_animation("walk") + + self:set_velocity(self.walk_velocity) + + return true +end + + +-- custom particle effects +local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow) + + radius = radius or 2 + min_size = min_size or 0.5 + max_size = max_size or 1 + gravity = gravity or -10 + glow = glow or 0 + + minetest.add_particlespawner({ + amount = amount, + time = 0.25, + minpos = pos, + maxpos = pos, + minvel = {x = -radius, y = -radius, z = -radius}, + maxvel = {x = radius, y = radius, z = radius}, + minacc = {x = 0, y = gravity, z = 0}, + maxacc = {x = 0, y = gravity, z = 0}, + minexptime = 0.1, + maxexptime = 1, + minsize = min_size, + maxsize = max_size, + texture = texture, + glow = glow + }) +end + + +-- update nametag colour +function mob_class:update_tag() + + local col = "#00FF00" + local qua = self.hp_max / 4 + + if self.health <= floor(qua * 3) then + col = "#FFFF00" + end + + if self.health <= floor(qua * 2) then + col = "#FF6600" + end + + if self.health <= floor(qua) then + col = "#FF0000" + end + + self.object:set_properties({ + nametag = self.nametag, + nametag_color = col + }) +end + + +-- drop items +function mob_class:item_drop() + + local pos = self.object:get_pos() + + -- check for drops function + self.drops = type(self.drops) == "function" and self.drops(pos) or self.drops + + -- check for nil or no drops + if not self.drops or #self.drops == 0 then + return + end + + -- no drops if disabled by setting + if not mobs_drop_items then return end + + -- no drops for child mobs + if self.child then return end + + -- was mob killed by player? + local death_by_player = self.cause_of_death and self.cause_of_death.puncher + and self.cause_of_death.puncher:is_player() or nil + + local obj, item, num + + for n = 1, #self.drops do + + if random(1, self.drops[n].chance) == 1 then + + num = random(self.drops[n].min or 0, self.drops[n].max or 1) + item = self.drops[n].name + + -- cook items on a hot death + if self.cause_of_death.hot then + + local output = minetest.get_craft_result({ + method = "cooking", width = 1, items = {item}}) + + if output and output.item and not output.item:is_empty() then + item = output.item:get_name() + end + end + + -- only drop rare items (drops.min=0) if killed by player + if death_by_player then + obj = minetest.add_item(pos, ItemStack(item .. " " .. num)) + + elseif self.drops[n].min ~= 0 then + obj = minetest.add_item(pos, ItemStack(item .. " " .. num)) + end + + if obj and obj:get_luaentity() then + + obj:set_velocity({ + x = random(-10, 10) / 9, + y = 6, + z = random(-10, 10) / 9 + }) + + elseif obj then + obj:remove() -- item does not exist + end + end + end + + self.drops = {} +end + + +-- check if mob is dead or only hurt +function mob_class:check_for_death(cmi_cause) + + -- has health actually changed? + if self.health == self.old_health and self.health > 0 then + return + end + + self.old_health = self.health + + -- still got some health? play hurt sound + if self.health > 0 then + + self:mob_sound(self.sounds.damage) + + -- make sure health isn't higher than max + if self.health > self.hp_max then + self.health = self.hp_max + end + + -- backup nametag so we can show health stats + if not self.nametag2 then + self.nametag2 = self.nametag or "" + end + + if show_health + and (cmi_cause and cmi_cause.type == "punch") then + + self.htimer = 2 + self.nametag = "♥ " .. self.health .. " / " .. self.hp_max + + self:update_tag() + end + + return false + end + + self.cause_of_death = cmi_cause + + -- drop items + self:item_drop() + + self:mob_sound(self.sounds.death) + + local pos = self.object:get_pos() + + -- execute custom death function + if self.on_die then + + self:on_die(pos) + + if use_cmi then + cmi.notify_die(self.object, cmi_cause) + end + + self.object:remove() + + return true + end + + -- default death function and die animation (if defined) + if self.animation + and self.animation.die_start + and self.animation.die_end then + + local frames = self.animation.die_end - self.animation.die_start + local speed = self.animation.die_speed or 15 + local length = max(frames / speed, 0) + + self.attack = nil + self.v_start = false + self.timer = 0 + self.blinktimer = 0 + self.passive = true + self.state = "die" + self:set_velocity(0) + self:set_animation("die") + + minetest.after(length, function(self) + + if use_cmi and self.object:get_luaentity() then + cmi.notify_die(self.object, cmi_cause) + end + + self.object:remove() + end, self) + else + + if use_cmi then + cmi.notify_die(self.object, cmi_cause) + end + + self.object:remove() + end + + effect(pos, 20, "tnt_smoke.png") + + return true +end + + +-- is mob facing a cliff +function mob_class:is_at_cliff() + + if self.fear_height == 0 then -- 0 for no falling protection! + return false + end + + local yaw = self.object:get_yaw() + local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + local pos = self.object:get_pos() + local ypos = pos.y + self.collisionbox[2] -- just above floor + + if minetest.line_of_sight( + {x = pos.x + dir_x, y = ypos, z = pos.z + dir_z}, + {x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}, 1) then + + return true + end + + return false +end + + +-- get node but use fallback for nil or unknown +local node_ok = function(pos, fallback) + + fallback = fallback or mobs.fallback_node + + local node = minetest.get_node_or_nil(pos) + + if node and minetest.registered_nodes[node.name] then + return node + end + + return minetest.registered_nodes[fallback] +end + + +-- environmental damage (water, lava, fire, light etc.) +function mob_class:do_env_damage() + + -- feed/tame text timer (so mob 'full' messages dont spam chat) + if self.htimer > 0 then + self.htimer = self.htimer - 1 + end + + -- reset nametag after showing health stats + if self.htimer < 1 and self.nametag2 then + + self.nametag = self.nametag2 + self.nametag2 = nil + + self:update_tag() + end + + local pos = self.object:get_pos() + + self.time_of_day = minetest.get_timeofday() + + -- remove mob if standing inside ignore node + if self.standing_in == "ignore" then + self.object:remove() + return + end + + -- is mob light sensative, or scared of the dark :P + if self.light_damage ~= 0 then + + local light = minetest.get_node_light(pos) or 0 + + if light >= self.light_damage_min + and light <= self.light_damage_max then + + self.health = self.health - self.light_damage + + effect(pos, 5, "tnt_smoke.png") + + if self:check_for_death({type = "light"}) then return end + end + end + + local nodef = minetest.registered_nodes[self.standing_in] + + pos.y = pos.y + 1 -- for particle effect position + + -- water + if self.water_damage + and nodef.groups.water then + + if self.water_damage ~= 0 then + + self.health = self.health - self.water_damage + + effect(pos, 5, "bubble.png", nil, nil, 1, nil) + + if self:check_for_death({type = "environment", + pos = pos, node = self.standing_in}) then return end + end + + -- lava or fire or ignition source + elseif self.lava_damage + and nodef.groups.igniter then +-- and (nodef.groups.lava +-- or self.standing_in == node_fire +-- or self.standing_in == node_permanent_flame) then + + if self.lava_damage ~= 0 then + + self.health = self.health - self.lava_damage + + effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil) + + if self:check_for_death({type = "environment", + pos = pos, node = self.standing_in, hot = true}) then return end + end + + -- damage_per_second node check + elseif nodef.damage_per_second ~= 0 then + + self.health = self.health - nodef.damage_per_second + + effect(pos, 5, "tnt_smoke.png") + + if self:check_for_death({type = "environment", + pos = pos, node = self.standing_in}) then return end + end +--[[ + --- suffocation inside solid node + if self.suffocation ~= 0 + and nodef.walkable == true + and nodef.groups.disable_suffocation ~= 1 + and nodef.drawtype == "normal" then + + self.health = self.health - self.suffocation + + if self:check_for_death({type = "environment", + pos = pos, node = self.standing_in}) then return end + end +]] + self:check_for_death({type = "unknown"}) +end + + +-- jump if facing a solid node (not fences or gates) +function mob_class:do_jump() + + if not self.jump + or self.jump_height == 0 + or self.fly + or self.child + or self.order == "stand" then + return false + end + + self.facing_fence = false + + -- something stopping us while moving? + if self.state ~= "stand" + and self:get_velocity() > 0.5 + and self.object:get_velocity().y ~= 0 then + return false + end + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + + -- what is mob standing on? + pos.y = pos.y + self.collisionbox[2] - 0.2 + + local nod = node_ok(pos) + +--print ("standing on:", nod.name, pos.y) + + if minetest.registered_nodes[nod.name].walkable == false then + return false + end + + -- where is front + local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + + -- what is in front of mob? + local nod = node_ok({ + x = pos.x + dir_x, + y = pos.y + 0.5, + z = pos.z + dir_z + }) + + -- thin blocks that do not need to be jumped + if nod.name == node_snow then + return false + end + +--print ("in front:", nod.name, pos.y + 0.5) + + if self.walk_chance == 0 + or minetest.registered_items[nod.name].walkable then + + if not nod.name:find("fence") + and not nod.name:find("gate") then + + local v = self.object:get_velocity() + + v.y = self.jump_height + + self:set_animation("jump") -- only when defined + + self.object:set_velocity(v) + + -- when in air move forward + minetest.after(0.3, function(self, v) + + if self.object:get_luaentity() then + + self.object:set_acceleration({ + x = v.x * 2, + y = 0, + z = v.z * 2 + }) + end + end, self, v) + + if self:get_velocity() > 0 then + self:mob_sound(self.sounds.jump) + end + else + self.facing_fence = true + end + + -- if we jumped against a block/wall 4 times then turn + if self.object:get_velocity().x ~= 0 + or self.object:get_velocity().z ~= 0 then + + self.jump_count = (self.jump_count or 0) + 1 +--print ("----", self.jump_count) + if self.jump_count == 4 then + + local yaw = self.object:get_yaw() or 0 + + yaw = self:set_yaw(yaw + 1.35, 8) +--print ("---- turn") + self.jump_count = 0 + end + end + + return true + end + + return false +end + + +-- blast damage to entities nearby (modified from TNT mod) +local entity_physics = function(pos, radius) + + radius = radius * 2 + + local objs = minetest.get_objects_inside_radius(pos, radius) + local obj_pos, dist + + for n = 1, #objs do + + obj_pos = objs[n]:get_pos() + + dist = get_distance(pos, obj_pos) + + if dist < 1 then dist = 1 end + + local damage = floor((4 / dist) * radius) + local ent = objs[n]:get_luaentity() + + -- punches work on entities AND players + objs[n]:punch(objs[n], 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = damage}, + }, pos) + end +end + + +-- should mob follow what I'm holding ? +function mob_class:follow_holding(clicker) + + if mobs.invis[clicker:get_player_name()] then + return false + end + + local item = clicker:get_wielded_item() + local t = type(self.follow) + + -- single item + if t == "string" + and item:get_name() == self.follow then + return true + + -- multiple items + elseif t == "table" then + + for no = 1, #self.follow do + + if self.follow[no] == item:get_name() then + return true + end + end + end + + return false +end + + +-- find two animals of same type and breed if nearby and horny +function mob_class:breed() + + -- child takes 240 seconds before growing into adult + if self.child == true then + + self.hornytimer = self.hornytimer + 1 + + if self.hornytimer > 240 then + + self.child = false + self.hornytimer = 0 + + self.object:set_properties({ + textures = self.base_texture, + mesh = self.base_mesh, + visual_size = self.base_size, + collisionbox = self.base_colbox, + selectionbox = self.base_selbox + }) + + -- custom function when child grows up + if self.on_grown then + self.on_grown(self) + else + -- jump when fully grown so as not to fall into ground + self.object:set_velocity({ + x = 0, + y = self.jump_height, + z = 0 + }) + end + end + + return + end + + -- horny animal can mate for 40 seconds, + -- afterwards horny animal cannot mate again for 200 seconds + if self.horny == true + and self.hornytimer < 240 then + + self.hornytimer = self.hornytimer + 1 + + if self.hornytimer >= 240 then + self.hornytimer = 0 + self.horny = false + end + end + + -- find another same animal who is also horny and mate if nearby + if self.horny == true + and self.hornytimer <= 40 then + + local pos = self.object:get_pos() + + effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8, "heart.png", 3, 4, 1, 0.1) + + local objs = minetest.get_objects_inside_radius(pos, 3) + local num = 0 + local ent = nil + + for n = 1, #objs do + + ent = objs[n]:get_luaentity() + + -- check for same animal with different colour + local canmate = false + + if ent then + + if ent.name == self.name then + canmate = true + else + local entname = string.split(ent.name,":") + local selfname = string.split(self.name,":") + + if entname[1] == selfname[1] then + entname = string.split(entname[2],"_") + selfname = string.split(selfname[2],"_") + + if entname[1] == selfname[1] then + canmate = true + end + end + end + end + + if ent + and canmate == true + and ent.horny == true + and ent.hornytimer <= 40 then + num = num + 1 + end + + -- found your mate? then have a baby + if num > 1 then + + self.hornytimer = 41 + ent.hornytimer = 41 + + -- spawn baby + minetest.after(5, function(self, ent) + + if not self.object:get_luaentity() then + return + end + + -- custom breed function + if self.on_breed then + + -- when false skip going any further + if self:on_breed(ent) == false then + return + end + else + effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5) + end + + local mob = minetest.add_entity(pos, self.name) + local ent2 = mob:get_luaentity() + local textures = self.base_texture + + -- using specific child texture (if found) + if self.child_texture then + textures = self.child_texture[1] + end + + -- and resize to half height + mob:set_properties({ + textures = textures, + visual_size = { + x = self.base_size.x * .5, + y = self.base_size.y * .5 + }, + collisionbox = { + self.base_colbox[1] * .5, + self.base_colbox[2] * .5, + self.base_colbox[3] * .5, + self.base_colbox[4] * .5, + self.base_colbox[5] * .5, + self.base_colbox[6] * .5 + }, + selectionbox = { + self.base_selbox[1] * .5, + self.base_selbox[2] * .5, + self.base_selbox[3] * .5, + self.base_selbox[4] * .5, + self.base_selbox[5] * .5, + self.base_selbox[6] * .5 + }, + }) + -- tamed and owned by parents' owner + ent2.child = true + ent2.tamed = true + ent2.owner = self.owner + end, self, ent) + + num = 0 + + break + end + end + end +end + + +-- find and replace what mob is looking for (grass, wheat etc.) +function mob_class:replace(pos) + + if not mobs_griefing + or not self.replace_rate + or not self.replace_what + or self.child == true + or self.object:get_velocity().y ~= 0 + or random(1, self.replace_rate) > 1 then + return + end + + local what, with, y_offset + + if type(self.replace_what[1]) == "table" then + + local num = random(#self.replace_what) + + what = self.replace_what[num][1] or "" + with = self.replace_what[num][2] or "" + y_offset = self.replace_what[num][3] or 0 + else + what = self.replace_what + with = self.replace_with or "" + y_offset = self.replace_offset or 0 + end + + pos.y = pos.y + y_offset + + if #minetest.find_nodes_in_area(pos, pos, what) > 0 then + +-- print ("replace node = ".. minetest.get_node(pos).name, pos.y) + + local oldnode = {name = what} + local newnode = {name = with} + local on_replace_return + + if self.on_replace then + on_replace_return = self:on_replace(pos, oldnode, newnode) + end + + if on_replace_return ~= false then + minetest.set_node(pos, {name = with}) + end + end +end + + +-- check if daytime and also if mob is docile during daylight hours +function mob_class:day_docile() + + if self.docile_by_day == false then + + return false + + elseif self.docile_by_day == true + and self.time_of_day > 0.2 + and self.time_of_day < 0.8 then + + return true + end +end + + +local los_switcher = false +local height_switcher = false + +-- path finding and smart mob routine by rnd, line_of_sight and other edits by Elkien3 +function mob_class:smart_mobs(s, p, dist, dtime) + + local s1 = self.path.lastpos + + local target_pos = self.attack:get_pos() + + -- is it becoming stuck? + if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then + self.path.stuck_timer = self.path.stuck_timer + dtime + else + self.path.stuck_timer = 0 + end + + self.path.lastpos = {x = s.x, y = s.y, z = s.z} + + local use_pathfind = false + local has_lineofsight = minetest.line_of_sight( + {x = s.x, y = (s.y) + .5, z = s.z}, + {x = target_pos.x, y = (target_pos.y) + 1.5, z = target_pos.z}, .2) + + -- im stuck, search for path + if not has_lineofsight then + + if los_switcher == true then + use_pathfind = true + los_switcher = false + end -- cannot see target! + else + if los_switcher == false then + + los_switcher = true + use_pathfind = false + + minetest.after(1, function(self) + + if self.object:get_luaentity() then + + if has_lineofsight then + self.path.following = false + end + end + end, self) + end -- can see target! + end + + if (self.path.stuck_timer > stuck_timeout and not self.path.following) then + + use_pathfind = true + self.path.stuck_timer = 0 + + minetest.after(1, function(self) + + if self.object:get_luaentity() then + + if has_lineofsight then + self.path.following = false + end + end + end, self) + end + + if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then + + use_pathfind = true + self.path.stuck_timer = 0 + + minetest.after(1, function(self) + + if self.object:get_luaentity() then + + if has_lineofsight then + self.path.following = false + end + end + end, self) + end + + if abs(vector.subtract(s,target_pos).y) > self.stepheight then + + if height_switcher then + use_pathfind = true + height_switcher = false + end + else + if not height_switcher then + use_pathfind = false + height_switcher = true + end + end + + if use_pathfind then + -- lets try find a path, first take care of positions + -- since pathfinder is very sensitive + local sheight = self.collisionbox[5] - self.collisionbox[2] + + -- round position to center of node to avoid stuck in walls + -- also adjust height for player models! + s.x = floor(s.x + 0.5) +-- s.y = floor(s.y + 0.5) - sheight + s.z = floor(s.z + 0.5) + + local ssight, sground = minetest.line_of_sight(s, { + x = s.x, y = s.y - 4, z = s.z}, 1) + + -- determine node above ground + if not ssight then + s.y = sground.y + 1 + end + + local p1 = self.attack:get_pos() + + p1.x = floor(p1.x + 0.5) + p1.y = floor(p1.y + 0.5) + p1.z = floor(p1.z + 0.5) + + local dropheight = 6 + if self.fear_height ~= 0 then dropheight = self.fear_height end + + self.path.way = minetest.find_path(s, p1, 16, self.stepheight, dropheight, "Dijkstra") + +--[[ + -- show path using particles + if self.path.way and #self.path.way > 0 then + print ("-- path length:" .. tonumber(#self.path.way)) + for _,pos in pairs(self.path.way) do + minetest.add_particle({ + pos = pos, + velocity = {x=0, y=0, z=0}, + acceleration = {x=0, y=0, z=0}, + expirationtime = 1, + size = 4, + collisiondetection = false, + vertical = false, + texture = "heart.png", + }) + end + end +]] + + self.state = "" + self:do_attack(self.attack) + + -- no path found, try something else + if not self.path.way then + + self.path.following = false + + -- lets make way by digging/building if not accessible + if self.pathfinding == 2 and mobs_griefing then + + -- is player higher than mob? + if s.y < p1.y then + + -- build upwards + if not minetest.is_protected(s, "") then + + local ndef1 = minetest.registered_nodes[self.standing_in] + + if ndef1 and (ndef1.buildable_to or ndef1.groups.liquid) then + + minetest.set_node(s, {name = mobs.fallback_node}) + end + end + + local sheight = math.ceil(self.collisionbox[5]) + 1 + + -- assume mob is 2 blocks high so it digs above its head + s.y = s.y + sheight + + -- remove one block above to make room to jump + if not minetest.is_protected(s, "") then + + local node1 = node_ok(s, "air").name + local ndef1 = minetest.registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest.set_node(s, {name = "air"}) + minetest.add_item(s, ItemStack(node1)) + + end + end + + s.y = s.y - sheight + self.object:set_pos({x = s.x, y = s.y + 2, z = s.z}) + + else -- dig 2 blocks to make door toward player direction + + local yaw1 = self.object:get_yaw() + pi / 2 + local p1 = { + x = s.x + cos(yaw1), + y = s.y, + z = s.z + sin(yaw1) + } + + if not minetest.is_protected(p1, "") then + + local node1 = node_ok(p1, "air").name + local ndef1 = minetest.registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest.add_item(p1, ItemStack(node1)) + minetest.set_node(p1, {name = "air"}) + end + + p1.y = p1.y + 1 + node1 = node_ok(p1, "air").name + ndef1 = minetest.registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest.add_item(p1, ItemStack(node1)) + minetest.set_node(p1, {name = "air"}) + end + + end + end + end + + -- will try again in 2 second + self.path.stuck_timer = stuck_timeout - 2 + + -- frustration! cant find the damn path :( + --self:mob_sound(self.sounds.random) + else + -- yay i found path + self:mob_sound(self.sounds.war_cry) + self:set_velocity(self.walk_velocity) + + -- follow path now that it has it + self.path.following = true + end + end +end + + +-- specific attacks +local specific_attack = function(list, what) + + -- no list so attack default (player, animals etc.) + if list == nil then + return true + end + + -- found entity on list to attack? + for no = 1, #list do + + if list[no] == what then + return true + end + end + + return false +end + + +-- general attack function for all mobs +function mob_class:general_attack() + + -- return if already attacking, passive or docile during day + if self.passive + or self.state == "attack" + or self:day_docile() then + return + end + + local s = self.object:get_pos() + local objs = minetest.get_objects_inside_radius(s, self.view_range) + + -- remove entities we aren't interested in + for n = 1, #objs do + + local ent = objs[n]:get_luaentity() + + -- are we a player? + if objs[n]:is_player() then + + -- if player invisible or mob not setup to attack then remove from list + if self.attack_players == false + or (self.owner and self.type ~= "monster") + or mobs.invis[objs[n]:get_player_name()] + or not specific_attack(self.specific_attack, "player") then + objs[n] = nil +--print("- pla", n) + end + + -- or are we a mob? + elseif ent and ent._cmi_is_mob then + + -- remove mobs not to attack + if self.name == ent.name + or (not self.attack_animals and ent.type == "animal") + or (not self.attack_monsters and ent.type == "monster") + or (not self.attack_npcs and ent.type == "npc") + or not specific_attack(self.specific_attack, ent.name) then + objs[n] = nil +--print("- mob", n, self.name, ent.name) + end + + -- remove all other entities + else +--print(" -obj", n) + objs[n] = nil + end + end + + local p, sp, dist, min_player + local min_dist = self.view_range + 1 + + -- go through remaining entities and select closest + for _,player in pairs(objs) do + + p = player:get_pos() + sp = s + + dist = get_distance(p, s) + + -- aim higher to make looking up hills more realistic + p.y = p.y + 1 + sp.y = sp.y + 1 + + -- choose closest player to attack that isnt self + if dist ~= 0 + and dist < min_dist + and self:line_of_sight(sp, p, 2) == true then + min_dist = dist + min_player = player + end + end + + -- attack closest player or mob + if min_player and random(1, 100) > self.attack_chance then + self:do_attack(min_player) + end +end + + +-- specific runaway +local specific_runaway = function(list, what) + + -- no list so do not run + if list == nil then + return false + end + + -- found entity on list to attack? + for no = 1, #list do + + if list[no] == what then + return true + end + end + + return false +end + + +-- find someone to runaway from +function mob_class:do_runaway_from() + + if not self.runaway_from then + return + end + + local s = self.object:get_pos() + local p, sp, dist, pname + local player, obj, min_player, name + local min_dist = self.view_range + 1 + local objs = minetest.get_objects_inside_radius(s, self.view_range) + + for n = 1, #objs do + + if objs[n]:is_player() then + + pname = objs[n]:get_player_name() + + if mobs.invis[pname] + or self.owner == pname then + + name = "" + else + player = objs[n] + name = "player" + end + else + obj = objs[n]:get_luaentity() + + if obj then + player = obj.object + name = obj.name or "" + end + end + + -- find specific mob to runaway from + if name ~= "" and name ~= self.name + and specific_runaway(self.runaway_from, name) then + + p = player:get_pos() + sp = s + + -- aim higher to make looking up hills more realistic + p.y = p.y + 1 + sp.y = sp.y + 1 + + dist = get_distance(p, s) + + -- choose closest player/mob to runaway from + if dist < min_dist + and self:line_of_sight(sp, p, 2) == true then + min_dist = dist + min_player = player + end + end + end + + if min_player then + + local lp = player:get_pos() + local vec = { + x = lp.x - s.x, + y = lp.y - s.y, + z = lp.z - s.z + } + + local yaw = (atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate + + if lp.x > s.x then + yaw = yaw + pi + end + + yaw = self:set_yaw(yaw, 4) + self.state = "runaway" + self.runaway_timer = 3 + self.following = nil + end +end + + +-- follow player if owner or holding item, if fish outta water then flop +function mob_class:follow_flop() + + -- find player to follow + if (self.follow ~= "" + or self.order == "follow") + and not self.following + and self.state ~= "attack" + and self.state ~= "runaway" then + + local s = self.object:get_pos() + local players = minetest.get_connected_players() + + for n = 1, #players do + + if get_distance(players[n]:get_pos(), s) < self.view_range + and not mobs.invis[ players[n]:get_player_name() ] then + + self.following = players[n] + + break + end + end + end + + if self.type == "npc" + and self.order == "follow" + and self.state ~= "attack" + and self.owner ~= "" then + + -- npc stop following player if not owner + if self.following + and self.owner + and self.owner ~= self.following:get_player_name() then + self.following = nil + end + else + -- stop following player if not holding specific item + if self.following + and self.following:is_player() + and self:follow_holding(self.following) == false then + self.following = nil + end + + end + + -- follow that thing + if self.following then + + local s = self.object:get_pos() + local p + + if self.following:is_player() then + + p = self.following:get_pos() + + elseif self.following.object then + + p = self.following.object:get_pos() + end + + if p then + + local dist = get_distance(p, s) + + -- dont follow if out of range + if dist > self.view_range then + self.following = nil + else + local vec = { + x = p.x - s.x, + z = p.z - s.z + } + + local yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if p.x > s.x then yaw = yaw + pi end + + yaw = self:set_yaw(yaw, 6) + + -- anyone but standing npc's can move along + if dist > self.reach + and self.order ~= "stand" then + + self:set_velocity(self.walk_velocity) + + if self.walk_chance ~= 0 then + self:set_animation("walk") + end + else + self:set_velocity(0) + self:set_animation("stand") + end + + return + end + end + end + + -- swimmers flop when out of their element, and swim again when back in + if self.fly then + + local s = self.object:get_pos() + + if not self:attempt_flight_correction() then + + self.state = "flop" + self.object:set_velocity({x = 0, y = -5, z = 0}) + + self:set_animation("stand") + + return + elseif self.state == "flop" then + self.state = "stand" + end + end +end + + +-- dogshoot attack switch and counter function +function mob_class:dogswitch(dtime) + + -- switch mode not activated + if not self.dogshoot_switch + or not dtime then + return 0 + end + + self.dogshoot_count = self.dogshoot_count + dtime + + if (self.dogshoot_switch == 1 + and self.dogshoot_count > self.dogshoot_count_max) + or (self.dogshoot_switch == 2 + and self.dogshoot_count > self.dogshoot_count2_max) then + + self.dogshoot_count = 0 + + if self.dogshoot_switch == 1 then + self.dogshoot_switch = 2 + else + self.dogshoot_switch = 1 + end + end + + return self.dogshoot_switch +end + + +-- execute current state (stand, walk, run, attacks) +function mob_class:do_states(dtime) + + local yaw = self.object:get_yaw() or 0 + + if self.state == "stand" then + + if random(1, 4) == 1 then + + local lp = nil + local s = self.object:get_pos() + local objs = minetest.get_objects_inside_radius(s, 3) + + for n = 1, #objs do + + if objs[n]:is_player() then + lp = objs[n]:get_pos() + break + end + end + + -- look at any players nearby, otherwise turn randomly + if lp then + + local vec = { + x = lp.x - s.x, + z = lp.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if lp.x > s.x then yaw = yaw + pi end + else + yaw = yaw + random(-0.5, 0.5) + end + + yaw = self:set_yaw(yaw, 8) + end + + self:set_velocity(0) + self:set_animation("stand") + + -- mobs ordered to stand stay standing + if self.order ~= "stand" + and self.walk_chance ~= 0 + and self.facing_fence ~= true + and random(1, 100) <= self.walk_chance + and self.at_cliff == false then + + self:set_velocity(self.walk_velocity) + self.state = "walk" + self:set_animation("walk") + end + + elseif self.state == "walk" then + + local s = self.object:get_pos() + local lp = nil + + -- is there something I need to avoid? + if self.water_damage > 0 + and self.lava_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:water", "group:lava"}) + + elseif self.water_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:water"}) + + elseif self.lava_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:lava"}) + end + + if lp then + + -- if mob in water or lava then look for land + if (self.lava_damage + and minetest.registered_nodes[self.standing_in].groups.lava) + or (self.water_damage + and minetest.registered_nodes[self.standing_in].groups.water) then + + lp = minetest.find_node_near(s, 5, {"group:soil", "group:stone", + "group:sand", node_ice, node_snowblock}) + + -- did we find land? + if lp then + + local vec = { + x = lp.x - s.x, + z = lp.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if lp.x > s.x then yaw = yaw + pi end + + -- look towards land and jump/move in that direction + yaw = self:set_yaw(yaw, 6) + self:do_jump() + self:set_velocity(self.walk_velocity) + else + yaw = yaw + random(-0.5, 0.5) + end + + else + + local vec = { + x = lp.x - s.x, + z = lp.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if lp.x > s.x then yaw = yaw + pi end + end + + yaw = self:set_yaw(yaw, 8) + + -- otherwise randomly turn + elseif random(1, 100) <= 30 then + + yaw = yaw + random(-0.5, 0.5) + + yaw = self:set_yaw(yaw, 8) + end + + -- stand for great fall in front + if self.facing_fence == true + or self.at_cliff + or random(1, 100) <= self.stand_chance then + + self:set_velocity(0) + self.state = "stand" + self:set_animation("stand", true) + else + self:set_velocity(self.walk_velocity) + + if self:flight_check() + and self.animation + and self.animation.fly_start + and self.animation.fly_end then + self:set_animation("fly") + else + self:set_animation("walk") + end + end + + -- runaway when punched + elseif self.state == "runaway" then + + self.runaway_timer = self.runaway_timer + 1 + + -- stop after 5 seconds or when at cliff + if self.runaway_timer > 5 + or self.at_cliff + or self.order == "stand" then + self.runaway_timer = 0 + self:set_velocity(0) + self.state = "stand" + self:set_animation("stand") + else + self:set_velocity(self.run_velocity) + self:set_animation("walk") + end + + -- attack routines (explode, dogfight, shoot, dogshoot) + elseif self.state == "attack" then + + -- calculate distance from mob and enemy + local s = self.object:get_pos() + local p = self.attack:get_pos() or s + local dist = get_distance(p, s) + + -- stop attacking if player invisible or out of range + if dist > self.view_range + or not self.attack + or not self.attack:get_pos() + or self.attack:get_hp() <= 0 + or (self.attack:is_player() and mobs.invis[ self.attack:get_player_name() ]) then + +-- print(" ** stop attacking **", dist, self.view_range) + self.state = "stand" + self:set_velocity(0) + self:set_animation("stand") + self.attack = nil + self.v_start = false + self.timer = 0 + self.blinktimer = 0 + self.path.way = nil + + return + end + + if self.attack_type == "explode" then + + local vec = { + x = p.x - s.x, + z = p.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if p.x > s.x then yaw = yaw + pi end + + yaw = self:set_yaw(yaw) + + local node_break_radius = self.explosion_radius or 1 + local entity_damage_radius = self.explosion_damage_radius + or (node_break_radius * 2) + + -- start timer when in reach and line of sight + if not self.v_start + and dist <= self.reach + and self:line_of_sight(s, p, 2) then + + self.v_start = true + self.timer = 0 + self.blinktimer = 0 + self:mob_sound(self.sounds.fuse) +-- print ("=== explosion timer started", self.explosion_timer) + + -- stop timer if out of reach or direct line of sight + elseif self.allow_fuse_reset + and self.v_start + and (dist > self.reach + or not self:line_of_sight(s, p, 2)) then + self.v_start = false + self.timer = 0 + self.blinktimer = 0 + self.blinkstatus = false + self.object:settexturemod("") + end + + -- walk right up to player unless the timer is active + if self.v_start and (self.stop_to_explode or dist < 1.5) then + self:set_velocity(0) + else + self:set_velocity(self.run_velocity) + end + + if self.animation and self.animation.run_start then + self:set_animation("run") + else + self:set_animation("walk") + end + + if self.v_start then + + self.timer = self.timer + dtime + self.blinktimer = (self.blinktimer or 0) + dtime + + if self.blinktimer > 0.2 then + + self.blinktimer = 0 + + if self.blinkstatus then + self.object:set_texture_mod("") + else + self.object:set_texture_mod("^[brighten") + end + + self.blinkstatus = not self.blinkstatus + end + +-- print ("=== explosion timer", self.timer) + + if self.timer > self.explosion_timer then + + local pos = self.object:get_pos() + + -- dont damage anything if area protected or next to water + if minetest.find_node_near(pos, 1, {"group:water"}) + or minetest.is_protected(pos, "") then + + node_break_radius = 1 + end + + self.object:remove() + + if minetest.get_modpath("tnt") and tnt and tnt.boom + and not minetest.is_protected(pos, "") then + + tnt.boom(pos, { + radius = node_break_radius, + damage_radius = entity_damage_radius, + sound = self.sounds.explode + }) + else + + minetest.sound_play(self.sounds.explode, { + pos = pos, + gain = 1.0, + max_hear_distance = self.sounds.distance or 32 + }) + + entity_physics(pos, entity_damage_radius) + effect(pos, 32, "tnt_smoke.png", nil, nil, node_break_radius, 1, 0) + end + + return + end + end + + elseif self.attack_type == "dogfight" + or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 2) + or (self.attack_type == "dogshoot" and dist <= self.reach and self:dogswitch() == 0) then + + if self.fly + and dist > self.reach then + + local p1 = s + local me_y = floor(p1.y) + local p2 = p + local p_y = floor(p2.y + 1) + local v = self.object:get_velocity() + + if self:flight_check() then + + if me_y < p_y then + + self.object:set_velocity({ + x = v.x, + y = 1 * self.walk_velocity, + z = v.z + }) + + elseif me_y > p_y then + + self.object:set_velocity({ + x = v.x, + y = -1 * self.walk_velocity, + z = v.z + }) + end + else + if me_y < p_y then + + self.object:set_velocity({ + x = v.x, + y = 0.01, + z = v.z + }) + + elseif me_y > p_y then + + self.object:set_velocity({ + x = v.x, + y = -0.01, + z = v.z + }) + end + end + + end + + -- rnd: new movement direction + if self.path.following + and self.path.way + and self.attack_type ~= "dogshoot" then + + -- no paths longer than 50 + if #self.path.way > 50 + or dist < self.reach then + self.path.following = false + return + end + + local p1 = self.path.way[1] + + if not p1 then + self.path.following = false + return + end + + if abs(p1.x-s.x) + abs(p1.z - s.z) < 0.6 then + -- reached waypoint, remove it from queue + table.remove(self.path.way, 1) + end + + -- set new temporary target + p = {x = p1.x, y = p1.y, z = p1.z} + end + + local vec = { + x = p.x - s.x, + z = p.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if p.x > s.x then yaw = yaw + pi end + + yaw = self:set_yaw(yaw) + + -- move towards enemy if beyond mob reach + if dist > self.reach then + + -- path finding by rnd + if self.pathfinding -- only if mob has pathfinding enabled + and enable_pathfinding then + + self:smart_mobs(s, p, dist, dtime) + end + + if self.at_cliff then + + self:set_velocity(0) + self:set_animation("stand") + else + + if self.path.stuck then + self:set_velocity(self.walk_velocity) + else + self:set_velocity(self.run_velocity) + end + + if self.animation and self.animation.run_start then + self:set_animation("run") + else + self:set_animation("walk") + end + end + + else -- rnd: if inside reach range + + self.path.stuck = false + self.path.stuck_timer = 0 + self.path.following = false -- not stuck anymore + + self:set_velocity(0) + + if not self.custom_attack then + + if self.timer > 1 then + + self.timer = 0 + self:set_animation("punch") + + local p2 = p + local s2 = s + + p2.y = p2.y + .5 + s2.y = s2.y + .5 + + if self:line_of_sight(p2, s2) == true then + + -- play attack sound + self:mob_sound(self.sounds.attack) + + -- punch player (or what player is attached to) + local attached = self.attack:get_attach() + if attached then + self.attack = attached + end + self.attack:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self.damage} + }, nil) + end + end + else -- call custom attack every second + if self.custom_attack + and self.timer > 1 then + + self.timer = 0 + + self:custom_attack(p) + end + end + end + + elseif self.attack_type == "shoot" + or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 1) + or (self.attack_type == "dogshoot" and dist > self.reach and self:dogswitch() == 0) then + + p.y = p.y - .5 + s.y = s.y + .5 + + local dist = get_distance(p, s) + local vec = { + x = p.x - s.x, + y = p.y - s.y, + z = p.z - s.z + } + + yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + + if p.x > s.x then yaw = yaw + pi end + + yaw = self:set_yaw(yaw) + + self:set_velocity(0) + + if self.shoot_interval + and self.timer > self.shoot_interval + and random(1, 100) <= 60 then + + self.timer = 0 + self:set_animation("shoot") + + -- play shoot attack sound + self:mob_sound(self.sounds.shoot_attack) + + local p = self.object:get_pos() + + p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2 + + if minetest.registered_entities[self.arrow] then + + local obj = minetest.add_entity(p, self.arrow) + local ent = obj:get_luaentity() + local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5 + local v = ent.velocity or 1 -- or set to default + + ent.switch = 1 + ent.owner_id = tostring(self.object) -- add unique owner id to arrow + + -- offset makes shoot aim accurate + vec.y = vec.y + self.shoot_offset + vec.x = vec.x * (v / amount) + vec.y = vec.y * (v / amount) + vec.z = vec.z * (v / amount) + + obj:set_velocity(vec) + end + end + end + end +end + + +-- falling and fall damage +function mob_class:falling(pos) + + if self.fly or self.disable_falling then + return + end + + -- floating in water (or falling) + local v = self.object:get_velocity() + + if v.y > 0 then + + -- apply gravity when moving up + self.object:set_acceleration({ + x = 0, + y = -10, + z = 0 + }) + + elseif v.y <= 0 and v.y > self.fall_speed then + + -- fall downwards at set speed + self.object:set_acceleration({ + x = 0, + y = self.fall_speed, + z = 0 + }) + else + -- stop accelerating once max fall speed hit + self.object:set_acceleration({x = 0, y = 0, z = 0}) + end + + -- in water then float up + if self.standing_in + and minetest.registered_nodes[self.standing_in].groups.water then + + if self.floats == 1 then + + self.object:set_acceleration({ + x = 0, + y = -self.fall_speed / (max(1, v.y) ^ 8), -- 8 was 2 + z = 0 + }) + end + else + + -- fall damage onto solid ground + if self.fall_damage == 1 + and self.object:get_velocity().y == 0 then + + local d = (self.old_y or 0) - self.object:get_pos().y + + if d > 5 then + + self.health = self.health - floor(d - 5) + + effect(pos, 5, "tnt_smoke.png", 1, 2, 2, nil) + + if self:check_for_death({type = "fall"}) then + return + end + end + + self.old_y = self.object:get_pos().y + end + end +end + + +-- is Took Ranks mod active? +local tr = minetest.get_modpath("toolranks") + +-- deal damage and effects when mob punched +function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) + + -- mob health check + if self.health <= 0 then + return + end + + -- custom punch function + if self.do_punch + and self:do_punch(hitter, tflp, tool_capabilities, dir) == false then + return + end + + -- error checking when mod profiling is enabled + if not tool_capabilities then + minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled") + return + end + + -- is mob protected? + if self.protected and hitter:is_player() + and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then + minetest.chat_send_player(hitter:get_player_name(), S("Mob has been protected!")) + return + end + + local weapon = hitter:get_wielded_item() + local weapon_def = weapon:get_definition() or {} + local punch_interval = 1.4 + + -- calculate mob damage + local damage = 0 + local armor = self.object:get_armor_groups() or {} + local tmp + + -- quick error check incase it ends up 0 (serialize.h check test) + if tflp == 0 then + tflp = 0.2 + end + + if use_cmi then + damage = cmi.calculate_damage(self.object, hitter, tflp, tool_capabilities, dir) + else + + for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do + + tmp = tflp / (tool_capabilities.full_punch_interval or 1.4) + + if tmp < 0 then + tmp = 0.0 + elseif tmp > 1 then + tmp = 1.0 + end + + damage = damage + (tool_capabilities.damage_groups[group] or 0) + * tmp * ((armor[group] or 0) / 100.0) + end + end + + -- check for tool immunity or special damage + for n = 1, #self.immune_to do + + if self.immune_to[n][1] == weapon_def.name then + + damage = self.immune_to[n][2] or 0 + break + + -- if "all" then no tool does damage unless it's specified in list + elseif self.immune_to[n][1] == "all" then + damage = self.immune_to[n][2] or 0 + end + end + + -- healing + if damage <= -1 then + self.health = self.health - floor(damage) + return + end + +-- print ("Mob Damage is", damage) + + if use_cmi + and cmi.notify_punch(self.object, hitter, tflp, tool_capabilities, dir, damage) then + return + end + + -- add weapon wear + punch_interval = tool_capabilities.full_punch_interval or 1.4 + + -- toolrank support + local wear = floor((punch_interval / 75) * 9000) + + if mobs.is_creative(hitter:get_player_name()) then + + if tr then + wear = 1 + else + wear = 0 + end + end + + if tr then + if weapon_def.original_description then + toolranks.new_afteruse(weapon, hitter, nil, {wear = wear}) + end + else + weapon:add_wear(wear) + end + + hitter:set_wielded_item(weapon) + + -- only play hit sound and show blood effects if damage is 1 or over + if damage >= 1 then + + -- weapon sounds + if weapon_def.sounds then + + local s = random(0, #weapon_def.sounds) + + minetest.sound_play(weapon_def.sounds[s], { + object = self.object, + max_hear_distance = 8 + }) + else + minetest.sound_play("default_punch", { + object = self.object, + max_hear_distance = 5 + }) + end + + -- blood_particles + if not disable_blood and self.blood_amount > 0 then + + local pos = self.object:get_pos() + + pos.y = pos.y + (-self.collisionbox[2] + self.collisionbox[5]) * .5 + + -- do we have a single blood texture or multiple? + if type(self.blood_texture) == "table" then + + local blood = self.blood_texture[random(1, #self.blood_texture)] + + effect(pos, self.blood_amount, blood, nil, nil, 1, nil) + else + effect(pos, self.blood_amount, self.blood_texture, nil, nil, 1, nil) + end + end + + -- do damage + self.health = self.health - floor(damage) + + -- exit here if dead, check for tools with fire damage + local hot = tool_capabilities and tool_capabilities.damage_groups + and tool_capabilities.damage_groups.fire + + if self:check_for_death({type = "punch", + puncher = hitter, hot = hot}) then + return + end + + --[[ add healthy afterglow when hit (can cause hit lag with larger textures) + minetest.after(0.1, function() + + if not self.object:get_luaentity() then return end + + self.object:settexturemod("^[colorize:#c9900070") + + core.after(0.3, function() + self.object:settexturemod("") + end) + end) ]] + + end -- END if damage + + -- knock back effect (only on full punch) + if self.knock_back + and tflp >= punch_interval then + + local v = self.object:get_velocity() + local kb = damage or 1 + local up = 2 + + -- if already in air then dont go up anymore when hit + if v.y > 0 + or self.fly then + up = 0 + end + + -- direction error check + dir = dir or {x = 0, y = 0, z = 0} + + -- use tool knockback value or default + kb = tool_capabilities.damage_groups["knockback"] or kb -- (kb * 1.5) + + self.object:set_velocity({ + x = dir.x * kb, + y = up, + z = dir.z * kb + }) + + self.pause_timer = 0.25 + end + + -- if skittish then run away + if self.runaway == true + and self.order ~= "stand" then + + local lp = hitter:get_pos() + local s = self.object:get_pos() + local vec = { + x = lp.x - s.x, + y = lp.y - s.y, + z = lp.z - s.z + } + + local yaw = (atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate + + if lp.x > s.x then + yaw = yaw + pi + end + + yaw = self:set_yaw(yaw, 6) + self.state = "runaway" + self.runaway_timer = 0 + self.following = nil + end + + local name = hitter:get_player_name() or "" + + -- attack puncher and call other mobs for help + if self.passive == false + and self.state ~= "flop" + and self.child == false + and self.attack_players == true + and hitter:get_player_name() ~= self.owner + and not mobs.invis[ name ] then + + -- attack whoever punched mob + self.state = "" + self:do_attack(hitter) + + -- alert others to the attack + local objs = minetest.get_objects_inside_radius(hitter:get_pos(), self.view_range) + local obj = nil + + for n = 1, #objs do + + obj = objs[n]:get_luaentity() + + if obj and obj._cmi_is_mob then + + -- only alert members of same mob + if obj.group_attack == true + and obj.state ~= "attack" + and obj.owner ~= name + and obj.name == self.name then + obj:do_attack(hitter) + end + + -- have owned mobs attack player threat + if obj.owner == name and obj.owner_loyal then + obj:do_attack(self.object) + end + end + end + end +end + + +-- get entity staticdata +function mob_class:get_staticdata() + + -- remove mob when out of range unless tamed + if remove_far + and self.remove_ok + and self.type ~= "npc" + and self.state ~= "attack" + and not self.tamed + and self.lifetimer < 20000 then + + --print ("REMOVED " .. self.name) + + self.object:remove() + + return ""-- nil + end + + self.remove_ok = true + self.attack = nil + self.following = nil + self.state = "stand" + + -- used to rotate older mobs + if self.drawtype + and self.drawtype == "side" then + self.rotate = math.rad(90) + end + + if use_cmi then + self.serialized_cmi_components = cmi.serialize_components(self._cmi_components) + end + + local tmp = {} + + for _,stat in pairs(self) do + + local t = type(stat) + + if t ~= "function" + and t ~= "nil" + and t ~= "userdata" + and _ ~= "_cmi_components" then + tmp[_] = self[_] + end + end + + --print('===== '..self.name..'\n'.. dump(tmp)..'\n=====\n') + return minetest.serialize(tmp) +end + + +-- activate mob and reload settings +function mob_class:mob_activate(staticdata, def, dtime) + + -- remove monsters in peaceful mode + if self.type == "monster" + and peaceful_only then + + self.object:remove() + + return + end + + -- load entity variables + local tmp = minetest.deserialize(staticdata) + + if tmp then + for _,stat in pairs(tmp) do + self[_] = stat + end + end + + -- force current model into mob + self.mesh = def.mesh + self.base_mesh = def.mesh + self.collisionbox = def.collisionbox + self.selectionbox = def.selectionbox + + -- select random texture, set model and size + if not self.base_texture then + + -- compatiblity with old simple mobs textures + if def.textures and type(def.textures[1]) == "string" then + def.textures = {def.textures} + end + + self.base_texture = def.textures and def.textures[random(1, #def.textures)] + self.base_mesh = def.mesh + self.base_size = self.visual_size + self.base_colbox = self.collisionbox + self.base_selbox = self.selectionbox + end + + -- for current mobs that dont have this set + if not self.base_selbox then + self.base_selbox = self.selectionbox or self.base_colbox + end + + -- set texture, model and size + local textures = self.base_texture + local mesh = self.base_mesh + local vis_size = self.base_size + local colbox = self.base_colbox + local selbox = self.base_selbox + + -- specific texture if gotten + if self.gotten == true + and def.gotten_texture then + textures = def.gotten_texture + end + + -- specific mesh if gotten + if self.gotten == true + and def.gotten_mesh then + mesh = def.gotten_mesh + end + + -- set child objects to half size + if self.child == true then + + vis_size = { + x = self.base_size.x * .5, + y = self.base_size.y * .5, + } + + if def.child_texture then + textures = def.child_texture[1] + end + + colbox = { + self.base_colbox[1] * .5, + self.base_colbox[2] * .5, + self.base_colbox[3] * .5, + self.base_colbox[4] * .5, + self.base_colbox[5] * .5, + self.base_colbox[6] * .5 + } + selbox = { + self.base_selbox[1] * .5, + self.base_selbox[2] * .5, + self.base_selbox[3] * .5, + self.base_selbox[4] * .5, + self.base_selbox[5] * .5, + self.base_selbox[6] * .5 + } + end + + if self.health == 0 then + self.health = random(self.hp_min, self.hp_max) + end + + -- pathfinding init + self.path = {} + self.path.way = {} -- path to follow, table of positions + self.path.lastpos = {x = 0, y = 0, z = 0} + self.path.stuck = false + self.path.following = false -- currently following path? + self.path.stuck_timer = 0 -- if stuck for too long search for path + + -- mob defaults + self.object:set_armor_groups({immortal = 1, fleshy = self.armor}) + self.old_y = self.object:get_pos().y + self.old_health = self.health + self.sounds.distance = self.sounds.distance or 10 + self.textures = textures + self.mesh = mesh + self.collisionbox = colbox + self.selectionbox = selbox + self.visual_size = vis_size + self.standing_in = "air" + + -- check existing nametag + if not self.nametag then + self.nametag = def.nametag + end + + -- set anything changed above + self.object:set_properties(self) + self:set_yaw((random(0, 360) - 180) / 180 * pi, 6) + self:update_tag() + self:set_animation("stand") + + -- run on_spawn function if found + if self.on_spawn and not self.on_spawn_run then + if self.on_spawn(self) then + self.on_spawn_run = true -- if true, set flag to run once only + end + end + + -- run after_activate + if def.after_activate then + def.after_activate(self, staticdata, def, dtime) + end + + if use_cmi then + self._cmi_components = cmi.activate_components(self.serialized_cmi_components) + cmi.notify_activate(self.object, dtime) + end +end + + +-- handle mob lifetimer and expiration +function mob_class:mob_expire(pos, dtime) + + -- when lifetimer expires remove mob (except npc and tamed) + if self.type ~= "npc" + and not self.tamed + and self.state ~= "attack" + and remove_far ~= true + and self.lifetimer < 20000 then + + self.lifetimer = self.lifetimer - dtime + + if self.lifetimer <= 0 then + + -- only despawn away from player + local objs = minetest.get_objects_inside_radius(pos, 15) + + for n = 1, #objs do + + if objs[n]:is_player() then + + self.lifetimer = 20 + + return + end + end + +-- minetest.log("action", +-- S("lifetimer expired, removed @1", self.name)) + + effect(pos, 15, "tnt_smoke.png", 2, 4, 2, 0) + + self.object:remove() + + return + end + end +end + + +-- main mob function +function mob_class:on_step(dtime) + + if use_cmi then + cmi.notify_step(self.object, dtime) + end + + local pos = self.object:get_pos() + local yaw = 0 + + -- get node at foot level every quarter second + self.node_timer = (self.node_timer or 0) + dtime + + if self.node_timer > 0.25 then + + self.node_timer = 0 + + local y_level = self.collisionbox[2] + + if self.child then + y_level = self.collisionbox[2] * 0.5 + end + + -- what is mob standing in? + self.standing_in = node_ok({ + x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name +-- print ("standing in " .. self.standing_in) + + -- if standing inside solid block then jump to escape + if minetest.registered_nodes[self.standing_in].walkable and + minetest.registered_nodes[self.standing_in].drawtype == "normal" then + + self.object:set_velocity({ + x = 0, + y = self.jump_height, + z = 0 + }) + end + + -- check and stop if standing at cliff and fear of heights + self.at_cliff = self:is_at_cliff() + + if self.at_cliff then + self:set_velocity(0) + end + + -- check for mob expiration (0.25 instead of dtime since were in a timer) + self:mob_expire(pos, 0.25) + end + + -- check if falling, flying, floating + self:falling(pos) + + -- smooth rotation by ThomasMonroe314 + + if self.delay and self.delay > 0 then + + local yaw = self.object:get_yaw() + + if self.delay == 1 then + yaw = self.target_yaw + else + local dif = abs(yaw - self.target_yaw) + + if yaw > self.target_yaw then + + if dif > pi then + dif = 2 * pi - dif -- need to add + yaw = yaw + dif / self.delay + else + yaw = yaw - dif / self.delay -- need to subtract + end + + elseif yaw < self.target_yaw then + + if dif > pi then + dif = 2 * pi - dif + yaw = yaw - dif / self.delay -- need to subtract + else + yaw = yaw + dif / self.delay -- need to add + end + end + + if yaw > (pi * 2) then yaw = yaw - (pi * 2) end + if yaw < 0 then yaw = yaw + (pi * 2) end + end + + self.delay = self.delay - 1 + self.object:set_yaw(yaw) + end + + -- end rotation + + -- knockback timer + if self.pause_timer > 0 then + + self.pause_timer = self.pause_timer - dtime + + return + end + + -- run custom function (defined in mob lua file) + if self.do_custom then + + -- when false skip going any further + if self:do_custom(dtime) == false then + return + end + end + + -- attack timer + self.timer = self.timer + dtime + + if self.state ~= "attack" then + + if self.timer < 1 then + return + end + + self.timer = 0 + end + + -- never go over 100 + if self.timer > 100 then + self.timer = 1 + end + + -- mob plays random sound at times + if random(1, 100) == 1 then + self:mob_sound(self.sounds.random) + end + + -- environmental damage timer (every 1 second) + self.env_damage_timer = self.env_damage_timer + dtime + + if (self.state == "attack" and self.env_damage_timer > 1) + or self.state ~= "attack" then + + self.env_damage_timer = 0 + + -- check for environmental damage (water, fire, lava etc.) + self:do_env_damage() + + -- node replace check (cow eats grass etc.) + self:replace(pos) + end + + self:general_attack() + + self:breed() + + self:follow_flop() + + self:do_states(dtime) + + self:do_jump() + + self:do_runaway_from(self) + + self:do_stay_near() +end + + +-- default function when mobs are blown up with TNT +function mob_class:on_blast(damage) + + --print ("----- Damage", damage) + + self.object:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = damage}, + }, nil) + + return false, true, {} +end + + +mobs.spawning_mobs = {} + +-- register mob entity +function mobs:register_mob(name, def) + + mobs.spawning_mobs[name] = true + +minetest.register_entity(name, setmetatable({ + + stepheight = def.stepheight, + name = name, + type = def.type, + attack_type = def.attack_type, + fly = def.fly, + fly_in = def.fly_in, + owner = def.owner, + order = def.order, + on_die = def.on_die, + do_custom = def.do_custom, + jump_height = def.jump_height, + drawtype = def.drawtype, -- DEPRECATED, use rotate instead + rotate = math.rad(def.rotate or 0), -- 0=front, 90=side, 180=back, 270=side2 + lifetimer = def.lifetimer, + hp_min = max(1, (def.hp_min or 5) * difficulty), + hp_max = max(1, (def.hp_max or 10) * difficulty), + collisionbox = def.collisionbox, + selectionbox = def.selectionbox or def.collisionbox, + visual = def.visual, + visual_size = def.visual_size, + mesh = def.mesh, + makes_footstep_sound = def.makes_footstep_sound, + view_range = def.view_range, + walk_velocity = def.walk_velocity, + run_velocity = def.run_velocity, + damage = max(0, (def.damage or 0) * difficulty), + light_damage = def.light_damage, + light_damage_min = def.light_damage_min, + light_damage_max = def.light_damage_max, + water_damage = def.water_damage, + lava_damage = def.lava_damage, + suffocation = def.suffocation, + fall_damage = def.fall_damage, + fall_speed = def.fall_speed, + drops = def.drops, + armor = def.armor, + on_rightclick = def.on_rightclick, + arrow = def.arrow, + shoot_interval = def.shoot_interval, + sounds = def.sounds, + animation = def.animation, + follow = def.follow, + jump = def.jump, + walk_chance = def.walk_chance, + stand_chance = def.stand_chance, + attack_chance = def.attack_chance, + passive = def.passive, + knock_back = def.knock_back, + blood_amount = def.blood_amount, + blood_texture = def.blood_texture, + shoot_offset = def.shoot_offset, + floats = def.floats, + replace_rate = def.replace_rate, + replace_what = def.replace_what, + replace_with = def.replace_with, + replace_offset = def.replace_offset, + on_replace = def.on_replace, + reach = def.reach, + texture_list = def.textures, + child_texture = def.child_texture, + docile_by_day = def.docile_by_day, + fear_height = def.fear_height, + runaway = def.runaway, + pathfinding = def.pathfinding, + immune_to = def.immune_to, + explosion_radius = def.explosion_radius, + explosion_damage_radius = def.explosion_damage_radius, + explosion_timer = def.explosion_timer, + allow_fuse_reset = def.allow_fuse_reset, + stop_to_explode = def.stop_to_explode, + custom_attack = def.custom_attack, + double_melee_attack = def.double_melee_attack, + dogshoot_switch = def.dogshoot_switch, + dogshoot_count_max = def.dogshoot_count_max, + dogshoot_count2_max = def.dogshoot_count2_max or def.dogshoot_count_max, + group_attack = def.group_attack, + attack_monsters = def.attacks_monsters or def.attack_monsters, + attack_animals = def.attack_animals, + attack_players = def.attack_players, + attack_npcs = def.attack_npcs, + specific_attack = def.specific_attack, + runaway_from = def.runaway_from, + owner_loyal = def.owner_loyal, + pushable = def.pushable, + stay_near = def.stay_near, + + on_spawn = def.on_spawn, + + on_blast = def.on_blast, -- class redifinition + + do_punch = def.do_punch, + + on_breed = def.on_breed, + + on_grown = def.on_grown, + + on_activate = function(self, staticdata, dtime) + return self:mob_activate(staticdata, def, dtime) + end, + +}, mob_class_meta)) + +end -- END mobs:register_mob function + + +-- count how many mobs of one type are inside an area +-- will also return true for second value if player is inside area +local count_mobs = function(pos, type) + + local total = 0 + local objs = minetest.get_objects_inside_radius(pos, aoc_range * 2) + local ent + local players + + for n = 1, #objs do + + if not objs[n]:is_player() then + + ent = objs[n]:get_luaentity() + + -- count mob type and add to total also + if ent and ent.name and ent.name == type then + total = total + 1 + end + else + players = true + end + end + + return total, players +end + + +-- global functions + +function mobs:spawn_abm_check(pos, node, name) + -- global function to add additional spawn checks + -- return true to stop spawning mob +end + + +function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, + interval, chance, aoc, min_height, max_height, day_toggle, on_spawn) + + -- Do mobs spawn at all? + if not mobs_spawn then + return + end + + -- chance/spawn number override in minetest.conf for registered mob + local numbers = minetest.settings:get(name) + + if numbers then + numbers = numbers:split(",") + chance = tonumber(numbers[1]) or chance + aoc = tonumber(numbers[2]) or aoc + + if chance == 0 then + minetest.log("warning", string.format("[mobs] %s has spawning disabled", name)) + return + end + + minetest.log("action", + string.format("[mobs] Chance setting for %s changed to %s (total: %s)", + name, chance, aoc)) + + end + + minetest.register_abm({ + + label = name .. " spawning", + nodenames = nodes, + neighbors = neighbors, + interval = interval, + chance = max(1, (chance * mob_chance_multiplier)), + catch_up = false, + + action = function(pos, node, active_object_count, active_object_count_wider) + + -- is mob actually registered? + if not mobs.spawning_mobs[name] + or not minetest.registered_entities[name] then +--print ("--- mob doesn't exist", name) + return + end + + -- additional custom checks for spawning mob + if mobs:spawn_abm_check(pos, node, name) == true then + return + end + + -- do not spawn if too many entities in area + if active_object_count_wider >= max_per_block then +--print("--- too many entities in area", active_object_count_wider) + return + end + + -- get total number of this mob in area + local num_mob, is_pla = count_mobs(pos, name) + + if not is_pla then +--print ("--- no players within active area, will not spawn " .. name) + return + end + + if num_mob >= aoc then +--print ("--- too many " .. name .. " in area", num_mob .. "/" .. aoc) + return + end + + -- if toggle set to nil then ignore day/night check + if day_toggle ~= nil then + + local tod = (minetest.get_timeofday() or 0) * 24000 + + if tod > 4500 and tod < 19500 then + -- daylight, but mob wants night + if day_toggle == false then +--print ("--- mob needs night", name) + return + end + else + -- night time but mob wants day + if day_toggle == true then +--print ("--- mob needs day", name) + return + end + end + end + + -- spawn above node + pos.y = pos.y + 1 + + -- are we spawning within height limits? + if pos.y > max_height + or pos.y < min_height then +--print ("--- height limits not met", name, pos.y) + return + end + + -- are light levels ok? + local light = minetest.get_node_light(pos) + if not light + or light > max_light + or light < min_light then +--print ("--- light limits not met", name, light) + return + end + + -- only spawn away from player + local objs = minetest.get_objects_inside_radius(pos, 8) + + for n = 1, #objs do + + if objs[n]:is_player() then +--print ("--- player too close", name) + return + end + end + + -- do we have enough height clearance to spawn mob? + local ent = minetest.registered_entities[name] + local height = max(1, math.ceil( + (ent.collisionbox[5] or 0.25) - + (ent.collisionbox[2] or -0.25) - 1)) + + for n = 0, height do + + local pos2 = {x = pos.x, y = pos.y + n, z = pos.z} + + if minetest.registered_nodes[node_ok(pos2).name].walkable == true then +--print ("--- inside block", name, node_ok(pos2).name) + return + end + end + + -- mobs cannot spawn in protected areas when enabled + if not spawn_protected + and minetest.is_protected(pos, "") then +--print ("--- inside protected area", name) + return + end + + -- spawn mob half block higher than ground + pos.y = pos.y + 0.5 + + local mob = minetest.add_entity(pos, name) +--[[ + print ("[mobs] Spawned " .. name .. " at " + .. minetest.pos_to_string(pos) .. " on " + .. node.name .. " near " .. neighbors[1]) +]] + if on_spawn then + + local ent = mob:get_luaentity() + + on_spawn(ent, pos) + end + end + }) +end + + +-- compatibility with older mob registration +function mobs:register_spawn(name, nodes, max_light, min_light, chance, + active_object_count, max_height, day_toggle) + + mobs:spawn_specific(name, nodes, {"air"}, min_light, max_light, 30, + chance, active_object_count, -31000, max_height, day_toggle) +end + + +-- MarkBu's spawn function +function mobs:spawn(def) + + mobs:spawn_specific( + def.name, + def.nodes or {"group:soil", "group:stone"}, + def.neighbors or {"air"}, + def.min_light or 0, + def.max_light or 15, + def.interval or 30, + def.chance or 5000, + def.active_object_count or 1, + def.min_height or -31000, + def.max_height or 31000, + def.day_toggle, + def.on_spawn) +end + + +-- register arrow for shoot attack +function mobs:register_arrow(name, def) + + if not name or not def then return end -- errorcheck + + minetest.register_entity(name, { + + physical = false, + visual = def.visual, + visual_size = def.visual_size, + textures = def.textures, + velocity = def.velocity, + hit_player = def.hit_player, + hit_node = def.hit_node, + hit_mob = def.hit_mob, + drop = def.drop or false, -- drops arrow as registered item when true + collisionbox = def.collisionbox or {0, 0, 0, 0, 0, 0}, + timer = 0, + switch = 0, + owner_id = def.owner_id, + rotate = def.rotate, + automatic_face_movement_dir = def.rotate + and (def.rotate - (pi / 180)) or false, + + on_activate = def.on_activate, + + on_punch = def.on_punch or function(self, hitter, tflp, tool_capabilities, dir) + end, + + on_step = def.on_step or function(self, dtime) + + self.timer = self.timer + 1 + + local pos = self.object:get_pos() + + if self.switch == 0 + or self.timer > 150 then + + self.object:remove() ; -- print ("removed arrow") + + return + end + + -- does arrow have a tail (fireball) + if def.tail + and def.tail == 1 + and def.tail_texture then + + minetest.add_particle({ + pos = pos, + velocity = {x = 0, y = 0, z = 0}, + acceleration = {x = 0, y = 0, z = 0}, + expirationtime = def.expire or 0.25, + collisiondetection = false, + texture = def.tail_texture, + size = def.tail_size or 5, + glow = def.glow or 0 + }) + end + + if self.hit_node then + + local node = node_ok(pos).name + + if minetest.registered_nodes[node].walkable then + + self:hit_node(pos, node) + + if self.drop == true then + + pos.y = pos.y + 1 + + self.lastpos = (self.lastpos or pos) + + minetest.add_item(self.lastpos, self.object:get_luaentity().name) + end + + self.object:remove() ; -- print ("hit node") + + return + end + end + + if self.hit_player or self.hit_mob then + + for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do + + if self.hit_player + and player:is_player() then + + self:hit_player(player) + self.object:remove() ; -- print ("hit player") + return + end + + local entity = player:get_luaentity() + + if entity + and self.hit_mob + and entity._cmi_is_mob == true + and tostring(player) ~= self.owner_id + and entity.name ~= self.object:get_luaentity().name then + + self:hit_mob(player) + + self.object:remove() ; --print ("hit mob") + + return + end + end + end + + self.lastpos = pos + end + }) +end + + +-- compatibility function +function mobs:explosion(pos, radius) + + local self = {sounds = {explode = "tnt_explode"}} + + mobs:boom(self, pos, radius) +end + + +-- no damage to nodes explosion +function mobs:safe_boom(self, pos, radius) + + minetest.sound_play(self.sounds and self.sounds.explode or "tnt_explode", { + pos = pos, + gain = 1.0, + max_hear_distance = self.sounds and self.sounds.distance or 32 + }) + + entity_physics(pos, radius) + + effect(pos, 32, "tnt_smoke.png", radius * 3, radius * 5, radius, 1, 0) +end + + +-- make explosion with protection and tnt mod check +function mobs:boom(self, pos, radius) + + if mobs_griefing + and minetest.get_modpath("tnt") and tnt and tnt.boom + and not minetest.is_protected(pos, "") then + + tnt.boom(pos, { + radius = radius, + damage_radius = radius, + sound = self.sounds and self.sounds.explode, + explode_center = true, + }) + else + mobs:safe_boom(self, pos, radius) + end +end + + +-- Register spawn eggs + +-- Note: This also introduces the “spawn_egg” group: +-- * spawn_egg=1: Spawn egg (generic mob, no metadata) +-- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata) +function mobs:register_egg(mob, desc, background, addegg, no_creative) + + local grp = {spawn_egg = 1} + + -- do NOT add this egg to creative inventory (e.g. dungeon master) + if creative and no_creative == true then + grp.not_in_creative_inventory = 1 + end + + local invimg = background + + if addegg == 1 then + invimg = "mobs_chicken_egg.png^(" .. invimg .. + "^[mask:mobs_chicken_egg_overlay.png)" + end + + -- register new spawn egg containing mob information + minetest.register_craftitem(mob .. "_set", { + + description = S("@1 (Tamed)", desc), + inventory_image = invimg, + groups = {spawn_egg = 2, not_in_creative_inventory = 1}, + stack_max = 1, + + on_place = function(itemstack, placer, pointed_thing) + + local pos = pointed_thing.above + + -- am I clicking on something with existing on_rightclick function? + local under = minetest.get_node(pointed_thing.under) + local def = minetest.registered_nodes[under.name] + if def and def.on_rightclick then + return def.on_rightclick(pointed_thing.under, under, placer, itemstack) + end + + if pos + and not minetest.is_protected(pos, placer:get_player_name()) then + + if not minetest.registered_entities[mob] then + return + end + + pos.y = pos.y + 1 + + local data = itemstack:get_metadata() + local mob = minetest.add_entity(pos, mob, data) + local ent = mob:get_luaentity() + + -- set owner if not a monster + if ent.type ~= "monster" then + ent.owner = placer:get_player_name() + ent.tamed = true + end + + -- since mob is unique we remove egg once spawned + itemstack:take_item() + end + + return itemstack + end, + }) + + + -- register old stackable mob egg + minetest.register_craftitem(mob, { + + description = desc, + inventory_image = invimg, + groups = grp, + + on_place = function(itemstack, placer, pointed_thing) + + local pos = pointed_thing.above + + -- am I clicking on something with existing on_rightclick function? + local under = minetest.get_node(pointed_thing.under) + local def = minetest.registered_nodes[under.name] + if def and def.on_rightclick then + return def.on_rightclick(pointed_thing.under, under, placer, itemstack) + end + + if pos + and not minetest.is_protected(pos, placer:get_player_name()) then + + if not minetest.registered_entities[mob] then + return + end + + pos.y = pos.y + 1 + + local mob = minetest.add_entity(pos, mob) + local ent = mob:get_luaentity() + + -- don't set owner if monster or sneak pressed + if ent.type ~= "monster" + and not placer:get_player_control().sneak then + ent.owner = placer:get_player_name() + ent.tamed = true + end + + -- if not in creative then take item + if not mobs.is_creative(placer:get_player_name()) then + itemstack:take_item() + end + end + + return itemstack + end, + }) + +end + + +-- force capture a mob if space available in inventory, or drop as spawn egg +function mobs:force_capture(self, clicker) + + -- add special mob egg with all mob information + local new_stack = ItemStack(self.name .. "_set") + + local tmp = {} + + for _,stat in pairs(self) do + local t = type(stat) + if t ~= "function" + and t ~= "nil" + and t ~= "userdata" then + tmp[_] = self[_] + end + end + + local data_str = minetest.serialize(tmp) + + new_stack:set_metadata(data_str) + + local inv = clicker:get_inventory() + + if inv:room_for_item("main", new_stack) then + inv:add_item("main", new_stack) + else + minetest.add_item(clicker:get_pos(), new_stack) + end + + self.object:remove() + + self:mob_sound("default_place_node_hard") +end + + +-- capture critter (thanks to blert2112 for idea) +function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, + force_take, replacewith) + + if self.child + or not clicker:is_player() + or not clicker:get_inventory() then + return false + end + + -- get name of clicked mob + local mobname = self.name + + -- if not nil change what will be added to inventory + if replacewith then + mobname = replacewith + end + + local name = clicker:get_player_name() + local tool = clicker:get_wielded_item() + + -- are we using hand, net or lasso to pick up mob? + if tool:get_name() ~= "" + and tool:get_name() ~= "mobs:net" + and tool:get_name() ~= "mobs:lasso" then + return false + end + + -- is mob tamed? + if self.tamed == false + and force_take == false then + + minetest.chat_send_player(name, S("Not tamed!")) + + return false + end + + -- cannot pick up if not owner + if self.owner ~= name + and force_take == false then + + minetest.chat_send_player(name, S("@1 is owner!", self.owner)) + + return false + end + + if clicker:get_inventory():room_for_item("main", mobname) then + + -- was mob clicked with hand, net, or lasso? + local chance = 0 + + if tool:get_name() == "" then + chance = chance_hand + + elseif tool:get_name() == "mobs:net" then + + chance = chance_net + + tool:add_wear(4000) -- 17 uses + + clicker:set_wielded_item(tool) + + elseif tool:get_name() == "mobs:lasso" then + + chance = chance_lasso + + tool:add_wear(650) -- 100 uses + + clicker:set_wielded_item(tool) + + end + + -- calculate chance.. add to inventory if successful? + if chance and chance > 0 and random(1, 100) <= chance then + + -- default mob egg + local new_stack = ItemStack(mobname) + + -- add special mob egg with all mob information + -- unless 'replacewith' contains new item to use + if not replacewith then + + new_stack = ItemStack(mobname .. "_set") + + local tmp = {} + + for _,stat in pairs(self) do + local t = type(stat) + if t ~= "function" + and t ~= "nil" + and t ~= "userdata" then + tmp[_] = self[_] + end + end + + local data_str = minetest.serialize(tmp) + + new_stack:set_metadata(data_str) + end + + local inv = clicker:get_inventory() + + if inv:room_for_item("main", new_stack) then + inv:add_item("main", new_stack) + else + minetest.add_item(clicker:get_pos(), new_stack) + end + + self.object:remove() + + self:mob_sound("default_place_node_hard") + + return new_stack + + -- when chance above fails or set to 0, miss! + elseif chance and chance ~= 0 then + minetest.chat_send_player(name, S("Missed!")) + + self:mob_sound("mobs_swing") + return false + + -- when chance set to nil always return a miss (used for npc walk/follow) + elseif not chance then + return false + end + end + + return true +end + + +-- protect tamed mob with rune item +function mobs:protect(self, clicker) + + local name = clicker:get_player_name() + local tool = clicker:get_wielded_item() + + if tool:get_name() ~= "mobs:protector" then + return false + end + + if self.tamed == false then + minetest.chat_send_player(name, S("Not tamed!")) + return true -- false + end + + if self.protected == true then + minetest.chat_send_player(name, S("Already protected!")) + return true -- false + end + + if not mobs.is_creative(clicker:get_player_name()) then + tool:take_item() -- take 1 protection rune + clicker:set_wielded_item(tool) + end + + self.protected = true + + local pos = self.object:get_pos() + pos.y = pos.y + self.collisionbox[2] + 0.5 + + effect(self.object:get_pos(), 25, "mobs_protect_particle.png", 0.5, 4, 2, 15) + + self:mob_sound("mobs_spell") + + return true +end + + +local mob_obj = {} +local mob_sta = {} + +-- feeding, taming and breeding (thanks blert2112) +function mobs:feed_tame(self, clicker, feed_count, breed, tame) + + -- can eat/tame with item in hand + if self.follow + and self:follow_holding(clicker) then + + -- if not in creative then take item + if not mobs.is_creative(clicker:get_player_name()) then + + local item = clicker:get_wielded_item() + + item:take_item() + + clicker:set_wielded_item(item) + end + + -- increase health + self.health = self.health + 4 + + if self.health >= self.hp_max then + + self.health = self.hp_max + + if self.htimer < 1 then + + minetest.chat_send_player(clicker:get_player_name(), + S("@1 at full health (@2)", + self.name:split(":")[2], tostring(self.health))) + + self.htimer = 5 + end + end + + self.object:set_hp(self.health) + + self:update_tag() + + -- make children grow quicker + if self.child == true then + + self.hornytimer = self.hornytimer + 20 + + return true + end + + -- feed and tame + self.food = (self.food or 0) + 1 + + if self.food >= feed_count then + + self.food = 0 + + if breed and self.hornytimer == 0 then + self.horny = true + end + + if tame then + + if self.tamed == false then + minetest.chat_send_player(clicker:get_player_name(), + S("@1 has been tamed!", + self.name:split(":")[2])) + end + + self.tamed = true + + if not self.owner or self.owner == "" then + self.owner = clicker:get_player_name() + end + end + + -- make sound when fed so many times + self:mob_sound(self.sounds.random) + end + + return true + end + + local item = clicker:get_wielded_item() + + -- if mob has been tamed you can name it with a nametag + if item:get_name() == "mobs:nametag" + and clicker:get_player_name() == self.owner then + + local name = clicker:get_player_name() + + -- store mob and nametag stack in external variables + mob_obj[name] = self + mob_sta[name] = item + + local tag = self.nametag or "" + + minetest.show_formspec(name, "mobs_nametag", "size[8,4]" + .. "field[0.5,1;7.5,0;name;" + .. minetest.formspec_escape(S("Enter name:")) .. ";" .. tag .. "]" + .. "button_exit[2.5,3.5;3,1;mob_rename;" + .. minetest.formspec_escape(S("Rename")) .. "]") + end + + return false +end + + +-- inspired by blockmen's nametag mod +minetest.register_on_player_receive_fields(function(player, formname, fields) + + -- right-clicked with nametag and name entered? + if formname == "mobs_nametag" + and fields.name + and fields.name ~= "" then + + local name = player:get_player_name() + + if not mob_obj[name] + or not mob_obj[name].object then + return + end + + -- make sure nametag is being used to name mob + local item = player:get_wielded_item() + + if item:get_name() ~= "mobs:nametag" then + return + end + + -- limit name entered to 64 characters long + if string.len(fields.name) > 64 then + fields.name = string.sub(fields.name, 1, 64) + end + + -- update nametag + mob_obj[name].nametag = fields.name + + mob_obj[name]:update_tag() + + -- if not in creative then take item + if not mobs.is_creative(name) then + + mob_sta[name]:take_item() + + player:set_wielded_item(mob_sta[name]) + end + + -- reset external variables + mob_obj[name] = nil + mob_sta[name] = nil + end +end) + + +-- compatibility function for old entities to new modpack entities +function mobs:alias_mob(old_name, new_name) + + -- check old_name entity doesnt already exist + if minetest.registered_entities[old_name] then + return + end + + -- spawn egg + minetest.register_alias(old_name, new_name) + + -- entity + minetest.register_entity(":" .. old_name, { + + physical = false, + + on_activate = function(self) + + if minetest.registered_entities[new_name] then + minetest.add_entity(self.object:get_pos(), new_name) + end + + self.object:remove() + end + }) +end diff --git a/mods/mobs/api.txt b/mods/mobs/api.txt new file mode 100644 index 00000000..7b84ca68 --- /dev/null +++ b/mods/mobs/api.txt @@ -0,0 +1,768 @@ + +Mobs Redo API +============= + +Welcome to the world of mobs in minetest and hopefully an easy guide to defining +your own mobs and having them appear in your worlds. + + +Registering Mobs +---------------- + +To register a mob and have it ready for use requires the following function: + + mobs:register_mob(name, definition) + +The 'name' of a mob usually starts with the mod name it's running from followed +by it's own name e.g. + + "mobs_monster:sand_monster" or "mymod:totally_awesome_beast" + +... and the 'definition' is a table which holds all of the settings and +functions needed for the mob to work properly which contains the following: + + 'nametag' contains the name which is shown above mob. + 'type' holds the type of mob that inhabits your world e.g. + "animal" usually docile and walking around. + "monster" attacks player or npc on sight. + "npc" walk around and will defend themselves if hit first, they + kill monsters. + 'hp_min' has the minimum health value the mob can spawn with. + 'hp_max' has the maximum health value the mob can spawn with. + 'armor' holds strength of mob, 100 is normal, lower is more powerful + and needs more hits and better weapons to kill. + 'passive' when true allows animals to defend themselves when hit, + otherwise they amble onwards. + 'walk_velocity' is the speed that your mob can walk around. + 'run_velocity' is the speed your mob can run with, usually when attacking. + 'stand_chance' has a 0-100 chance value your mob will stand from walking. + 'walk_chance' has a 0-100 chance value your mob will walk from standing, + set to 0 for jumping mobs only. + 'jump' when true allows your mob to jump updwards. + 'jump_height' holds the height your mob can jump, 0 to disable jumping. + 'stepheight' height of a block that your mob can easily walk up onto, + defaults to 1.1. + 'fly' when true allows your mob to fly around instead of walking. + 'fly_in' holds the node name that the mob flies (or swims) around + in e.g. "air" or "default:water_source". + 'stay_near' when set allows mobs the chance to stay around certain nodes. + 'nodes' string or table of nodes to stay nearby e.g. "farming:straw" + 'chance' chance of searching for above node(s), default is 10. + 'runaway' if true causes animals to turn and run away when hit. + 'pushable' when true mobs can be pushed by player or other mobs. + 'view_range' how many nodes in distance the mob can see a player. + 'damage' how many health points the mob does to a player or another + mob when melee attacking. + 'knock_back' when true has mobs falling backwards when hit, the greater + the damage the more they move back. + 'fear_height' is how high a cliff or edge has to be before the mob stops + walking, 0 to turn off height fear. + 'fall_speed' has the maximum speed the mob can fall at, default is -10. + 'fall_damage' when true causes falling to inflict damage. + 'water_damage' holds the damage per second infliced to mobs when standing in + water. + 'lava_damage' holds the damage per second inflicted to mobs when standing + in lava or fire or an ignition source. + 'light_damage' holds the damage per second inflicted to mobs when light + level is between the min and max values below + 'light_damage_min' minimum light value when mob is affected (default: 14) + 'light_damage_max' maximum light value when mob is affected (default: 15) + 'suffocation' when true causes mobs to suffocate inside solid blocks. + 'floats' when set to 1 mob will float in water, 0 has them sink. + 'follow' mobs follow player when holding any of the items which appear + on this table, the same items can be fed to a mob to tame or + breed e.g. {"farming:wheat", "default:apple"} + + 'reach' is how far the mob can attack player when standing + nearby, default is 3 nodes. + 'docile_by_day' when true has mobs wandering around during daylight + hours and only attacking player at night or when + provoked. + 'attack_chance' 0 to 100 chance the mob will attack (default is 5). + 'attack_monsters' when true mob will attack monsters. + 'attack_animals' when true mob will attack animals. + 'attack_npcs' when true mob will attack npcs within range. + 'attack_players' when true mob will attack players nearby. + 'owner_loyal' when true non-docile tamed mobs attack anything player + punches when nearby. + 'group_attack' when true has same mob type grouping together to attack + offender. + 'attack_type' tells the api what a mob does when attacking the player + or another mob: + 'dogfight' is a melee attack when player is within mob reach. + 'shoot' has mob shoot pre-defined arrows at player when inside + view_range. + 'dogshoot' has melee attack when inside reach and shoot attack + when inside view_range. + 'explode' causes mob to stop and explode when inside reach. + 'explosion_radius' the radius of explosion node destruction, + defaults to 1 + 'explosion_damage_radius' the radius of explosion entity & player damage, + defaults to explosion_radius * 2 + 'explosion_timer' number of seconds before mob explodes while its target + is still inside reach or explosion_damage_radius, + defaults to 3. + 'allow_fuse_reset' Allow 'explode' attack_type to reset fuse and resume + chasing if target leaves the blast radius or line of + sight. Defaults to true. + 'stop_to_explode' When set to true (default), mob must stop and wait for + explosion_timer in order to explode. If false, mob will + continue chasing. + 'arrow' holds the pre-defined arrow object to shoot when + attacking. + 'dogshoot_switch' allows switching between attack types by using timers + (1 for shoot, 2 for dogfight) + 'dogshoot_count_max' contains how many seconds before switching from + dogfight to shoot. + 'dogshoot_count2_max' contains how many seconds before switching from shoot + to dogfight. + 'shoot_interval' has the number of seconds between shots. + 'shoot_offset' holds the y position added as to where the + arrow/fireball appears on mob. + 'specific_attack' has a table of entity names that mob can also attack + e.g. {"player", "mobs_animal:chicken"}. + 'runaway_from' contains a table with mob names to run away from, add + "player" to list to runaway from player also. + 'blood_amount' contains the number of blood droplets to appear when + mob is hit. + 'blood_texture' has the texture name to use for droplets e.g. + "mobs_blood.png", or table {"blood1.png", "blood2.png"} + 'pathfinding' set to 1 for mobs to use pathfinder feature to locate + player, set to 2 so they can build/break also (only + works with dogfight attack and when 'mobs_griefing' + in minetest.conf is not false). Adding {unbreakable=1} + to node groups stops them being broken by mobs. + 'immune_to' is a table that holds specific damage when being hit by + certain items e.g. + {"default:sword_wood", 0} -- causes no damage. + {"default:gold_lump", -10} -- heals by 10 health points. + {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks. + {"all"} -- stops all weapons causing damage apart from those on list. + + 'makes_footstep_sound' when true you can hear mobs walking. + 'sounds' this is a table with sounds of the mob + 'distance' maximum distance sounds can be heard, default is 10. + 'random' random sound that plays during gameplay. + 'war_cry' what you hear when mob starts to attack player. + 'attack' what you hear when being attacked. + 'shoot_attack' sound played when mob shoots. + 'damage' sound heard when mob is hurt. + 'death' played when mob is killed. + 'jump' played when mob jumps. + 'fuse' sound played when mob explode timer starts. + 'explode' sound played when mob explodes. + + 'drops' table of items that are dropped when mob is killed, fields are: + 'name' name of item to drop. + 'chance' chance of drop, 1 for always, 2 for 1-in-2 chance etc. + 'min' minimum number of items dropped, set to 0 for rare drops. + 'max' maximum number of items dropped. + Note: If weapon has {fire=1} damage group set then cooked items will drop. + Note2: A function can now be passed which can also return drops table, e.g. + drops = function(pos) + -- do something + return { {name = "farming:bread"}, {name = "default:dirt", chance = 2} } + end + + 'visual' holds the look of the mob you wish to create: + 'cube' looks like a normal node + 'sprite' sprite which looks same from all angles. + 'upright_sprite' flat model standing upright. + 'wielditem' how it looks when player holds it in hand. + 'mesh' uses separate object file to define mob. + 'visual_size' has the size of the mob, defaults to {x = 1, y = 1} + 'collisionbox' has the box in which mob can be interacted with the + world e.g. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} + 'selectionbox' has the box in which player can interact with mob + 'textures' holds a table list of textures to be used for mob, or you + could use multiple lists inside another table for random + selection e.g. { {"texture1.png"}, {"texture2.png"} } + 'child_texture' holds the texture table for when baby mobs are used. + 'gotten_texture' holds the texture table for when self.gotten value is + true, used for milking cows or shearing sheep. + 'mesh' holds the name of the external object used for mob model + e.g. "mobs_cow.b3d" + 'gotten_mesh" holds the name of the external object used for when + self.gotten is true for mobs. + 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back, + 270 = other side. + 'double_melee_attack' when true has the api choose between 'punch' and + 'punch2' animations. [DEPRECATED] + + 'animation' holds a table containing animation names and settings for use with mesh models: + 'stand_start' start frame for when mob stands still. + 'stand_end' end frame of stand animation. + 'stand_speed' speed of animation in frames per second. + 'walk_start' when mob is walking around. + 'walk_end' + 'walk_speed' + 'run_start' when a mob runs or attacks. + 'run_end' + 'run_speed' + 'fly_start' when a mob is flying. + 'fly_end' + 'fly_speed' + 'punch_start' when a mob melee attacks. + 'punch_end' + 'punch_speed' + 'punch2_start' alternative melee attack animation. + 'punch2_end' + 'punch2_speed' + 'shoot_start' shooting animation. + 'shoot_end' + 'shoot_speed' + 'die_start' death animation + 'die_end' + 'die_speed' + 'die_loop' when set to false stops the animation looping. + + Using '_loop = false' setting will stop any of the above animations from + looping. + + 'speed_normal' is used for animation speed for compatibility with some + older mobs. + + Note: Up to 5 different animations can be used per action e.g. + stand_start, stand_end, stand1_start, stand1_end .. up to stand4_start + + +Node Replacement +---------------- + +Mobs can look around for specific nodes as they walk and replace them to mimic +eating. + + 'replace_what' group of items to replace e.g. + {"farming:wheat_8", "farming:carrot_8"} + or you can use the specific options of what, with and + y offset by using this instead: + { + {"group:grass", "air", 0}, + {"default:dirt_with_grass", "default:dirt", -1} + } + 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg" + 'replace_rate' how random should the replace rate be (typically 10) + 'replace_offset' +/- value to check specific node to replace + + 'on_replace(self, pos, oldnode, newnode)' is called when mob is about to + replace a node. + 'self' ObjectRef of mob + 'pos' Position of node to replace + 'oldnode' Current node + 'newnode' What the node will become after replacing + + If false is returned, the mob will not replace the node. + + By default, replacing sets self.gotten to true and resets the object + properties. (DEPRECATED, use on_replace to make changes). + + +Custom Definition Functions +--------------------------- + +Along with the above mob registry settings we can also use custom functions to +enhance mob functionality and have them do many interesting things: + + 'on_die' a function that is called when the mob is killed the + parameters are (self, pos) + 'on_rightclick' its same as in minetest.register_entity() + 'on_blast' is called when an explosion happens near mob when using TNT + functions, parameters are (object, damage) and returns + (do_damage, do_knockback, drops) + 'on_spawn' is a custom function that runs on mob spawn with 'self' as + variable, return true at end of function to run only once. + 'after_activate' is a custom function that runs once mob has been activated + with these paramaters (self, staticdata, def, dtime) + 'on_breed' called when two similar mobs breed, paramaters are + (parent1, parent2) objects, return false to stop child from + being resized and owner/tamed flags and child textures being + applied. Function itself must spawn new child mob. + 'on_grown' is called when a child mob has grown up, only paramater is + (self). + 'do_punch' called when mob is punched with paramaters (self, hitter, + time_from_last_punch, tool_capabilities, direction), return + false to stop punch damage and knockback from taking place. + 'custom_attack' when set this function is called instead of the normal mob + melee attack, parameters are (self, to_attack). + 'on_die' a function that is called when mob is killed (self, pos) + 'do_custom' a custom function that is called every tick while mob is + active and which has access to all of the self.* variables + e.g. (self.health for health or self.standing_in for node + status), return with 'false' to skip remainder of mob API. + + +Internal Variables +------------------ + +The mob api also has some preset variables and functions that it will remember +for each mob. + + 'self.health' contains current health of mob (cannot exceed + self.hp_max) + 'self.texture_list' contains list of all mob textures + 'self.child_texture' contains mob child texture when growing up + 'self.base_texture' contains current skin texture which was randomly + selected from textures list + 'self.gotten' this is used for obtaining milk from cow and wool from + sheep + 'self.horny' when animal fed enough it is set to true and animal can + breed with same animal + 'self.hornytimer' background timer that controls breeding functions and + mob childhood timings + 'self.child' used for when breeding animals have child, will use + child_texture and be half size + 'self.owner' string used to set owner of npc mobs, typically used for + dogs + 'self.order' set to "follow" or "stand" so that npc will follow owner + or stand it's ground + 'self.nametag' contains the name of the mob which it can show above + + +Spawning Mobs in World +---------------------- + +mobs:register_spawn(name, nodes, max_light, min_light, chance, + active_object_count, max_height, day_toggle) + +mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, + chance, active_object_count, min_height, max_height, day_toggle, on_spawn) + +These functions register a spawn algorithm for the mob. Without this function +the call the mobs won't spawn. + + 'name' is the name of the animal/monster + 'nodes' is a list of nodenames on that the animal/monster can + spawn on top of + 'neighbors' is a list of nodenames on that the animal/monster will + spawn beside (default is {"air"} for + mobs:register_spawn) + 'max_light' is the maximum of light + 'min_light' is the minimum of light + 'interval' is same as in register_abm() (default is 30 for + mobs:register_spawn) + 'chance' is same as in register_abm() + 'active_object_count' number of this type of mob to spawn at one time inside + map area + 'min_height' is the minimum height the mob can spawn + 'max_height' is the maximum height the mob can spawn + 'day_toggle' true for day spawning, false for night or nil for + anytime + 'on_spawn' is a custom function which runs after mob has spawned + and gives self and pos values. + +A simpler way to handle mob spawns has been added with the mobs:spawn(def) +command which uses above names to make settings clearer: + + mobs:spawn({name = "mobs_monster:tree_monster", + nodes = {"group:leaves"}, + max_light = 7, + }) + + +For each mob that spawns with this function is a field in mobs.spawning_mobs. +It tells if the mob should spawn or not. Default is true. So other mods can +only use the API of this mod by disabling the spawning of the default mobs in +this mod. + + +mobs:spawn_abm_check(pos, node, name) + +This global function can be changed to contain additional checks for mobs to +spawn e.g. mobs that spawn only in specific areas and the like. By returning +true the mob will not spawn. + + 'pos' holds the position of the spawning mob + 'node' contains the node the mob is spawning on top of + 'name' is the name of the animal/monster + + +Making Arrows +------------- + +mobs:register_arrow(name, definition) + +This function registers a arrow for mobs with the attack type shoot. + + 'name' is the name of the arrow + 'definition' is a table with the following values: + 'visual' same is in minetest.register_entity() + 'visual_size' same is in minetest.register_entity() + 'textures' same is in minetest.register_entity() + 'velocity' the velocity of the arrow + 'drop' if set to true any arrows hitting a node will drop as item + 'hit_player' a function that is called when the arrow hits a player; + this function should hurt the player, the parameters are + (self, player) + 'hit_mob' a function that is called when the arrow hits a mob; + this function should hurt the mob, the parameters are + (self, player) + 'hit_node' a function that is called when the arrow hits a node, the + parameters are (self, pos, node) + 'tail' when set to 1 adds a trail or tail to mob arrows + 'tail_texture' texture string used for above effect + 'tail_size' has size for above texture (defaults to between 5 and 10) + 'expire' contains float value for how long tail appears for + (defaults to 0.25) + 'glow' has value for how brightly tail glows 1 to 10 (default is + 0 for no glow) + 'rotate' integer value in degrees to rotate arrow + 'on_step' is a custom function when arrow is active, nil for + default. + 'on_punch' is a custom function when arrow is punched, nil by default + 'collisionbox' is hitbox table for arrow, {0,0,0,0,0,0} by default. + + +Spawn Eggs +---------- + +mobs:register_egg(name, description, background, addegg, no_creative) + +This function registers a spawn egg which can be used by admin to properly spawn in a mob. + + 'name' this is the name of your new mob to spawn e.g. "mob:sheep" + 'description' the name of the new egg you are creating e.g. "Spawn Sheep" + 'background' the texture displayed for the egg in inventory + 'addegg' would you like an egg image in front of your texture (1 = yes, + 0 = no) + 'no_creative' when set to true this stops spawn egg appearing in creative + mode for destructive mobs like Dungeon Masters. + + +Explosion Function +------------------ + +mobs:explosion(pos, radius) -- DEPRECATED!!! use mobs:boom() instead + +mobs:boom(self, pos, radius) + 'self' mob entity + 'pos' centre position of explosion + 'radius' radius of explosion (typically set to 3) + +This function generates an explosion which removes nodes in a specific radius +and damages any entity caught inside the blast radius. Protection will limit +node destruction but not entity damage. + + +Capturing Mobs +-------------- + +mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, + force_take, replacewith) + +This function is generally called inside the on_rightclick section of the mob +api code, it provides a chance of capturing the mob by hand, using the net or +lasso items, and can also have the player take the mob by force if tamed and +replace with another item entirely. + + 'self' mob information + 'clicker' player information + 'chance_hand' chance of capturing mob by hand (1 to 100) 0 to disable + 'chance_net' chance of capturing mob using net (1 to 100) 0 to disable + 'chance_lasso' chance of capturing mob using magic lasso (1 to 100) 0 to + disable + 'force_take' take mob by force, even if tamed (true or false) + 'replacewith' once captured replace mob with this item instead (overrides + new mob eggs with saved information) + +mobs:force_capture(self, clicker) + +Same as above but does no checks, it simply captures any and all mobs and places +inside a spawn egg containing all of the mob information. + + +Feeding and Taming/Breeding +--------------------------- + +mobs:feed_tame(self, clicker, feed_count, breed, tame) + +This function allows the mob to be fed the item inside self.follow be it apple, +wheat or whatever a set number of times and be tamed or bred as a result. +Will return true when mob is fed with item it likes. + + 'self' mob information + 'clicker' player information + 'feed_count' number of times mob must be fed to tame or breed + 'breed' true or false stating if mob can be bred and a child created + afterwards + 'tame' true or false stating if mob can be tamed so player can pick + them up + + +Protecting Mobs +--------------- + +mobs:protect(self, clicker) + +This function can be used to right-click any tamed mob with mobs:protector item, +this will protect the mob from harm inside of a protected area from other +players. Will return true when mob right-clicked with mobs:protector item. + + 'self' mob information + 'clicker' player information + + +Riding Mobs +----------- + +Mobs can now be ridden by players and the following shows its functions and +usage: + + +mobs:attach(self, player) + +This function attaches a player to the mob so it can be ridden. + + 'self' mob information + 'player' player information + + +mobs:detach(player, offset) + +This function will detach the player currently riding a mob to an offset +position. + + 'player' player information + 'offset' position table containing offset values + + +mobs:drive(self, move_animation, stand_animation, can_fly, dtime) + +This function allows an attached player to move the mob around and animate it at +same time. + + 'self' mob information + 'move_animation' string containing movement animation e.g. "walk" + 'stand_animation' string containing standing animation e.g. "stand" + 'can_fly' if true then jump and sneak controls will allow mob to fly + up and down + 'dtime' tick time used inside drive function + + +mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation) + +This function allows an attached player to fly the mob around using directional +controls. + + 'self' mob information + 'dtime' tick time used inside fly function + 'speed' speed of flight + 'can_shoot' true if mob can fire arrow (sneak and left mouse button + fires) + 'arrow_entity' name of arrow entity used for firing + 'move_animation' string containing name of pre-defined animation e.g. "walk" + or "fly" etc. + 'stand_animation' string containing name of pre-defined animation e.g. + "stand" or "blink" etc. + +Note: animation names above are from the pre-defined animation lists inside mob +registry without extensions. + + +mobs:set_animation(self, name) + +This function sets the current animation for mob, defaulting to "stand" if not +found. + + 'self' mob information + 'name' name of animation + + +Certain variables need to be set before using the above functions: + + 'self.v2' toggle switch used to define below values for the + first time + 'self.max_speed_forward' max speed mob can move forward + 'self.max_speed_reverse' max speed mob can move backwards + 'self.accel' acceleration speed + 'self.terrain_type' integer containing terrain mob can walk on + (1 = water, 2 or 3 = land) + 'self.driver_attach_at' position offset for attaching player to mob + 'self.driver_eye_offset' position offset for attached player view + 'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1} + + +mobs:line_of_sight(self, pos1, pos2, stepsize) [DEPRECATED] + +This function is for use within the mobs definition for special use cases and +returns true if a mob can see the player or victim. + +...'self' mob information + 'pos1' position of mob + 'pos2' position of vistim or player + 'stepsize' usually set to 1 + +Use this instead: + + mob_class:line_of_sight(pos1, pos2, stepsize) + + +External Settings for "minetest.conf" +------------------------------------ + + 'enable_damage' if true monsters will attack players (default is true) + 'only_peaceful_mobs' if true only animals will spawn in game (default is + false) + 'mobs_disable_blood' if false blood effects appear when mob is hit (default + is false) + 'mobs_spawn_protected' if set to false then mobs will not spawn in protected + areas (default is true) + 'remove_far_mobs' if true then untamed mobs that are outside players + visual range will be removed (default is true) + 'mobname' can change specific mob chance rate (0 to disable) and + spawn number e.g. mobs_animal:cow = 1000,5 + 'mob_difficulty' sets difficulty level (health and hit damage + multiplied by this number), defaults to 1.0. + 'mob_show_health' if false then punching mob will not show health status + (true by default) + 'mob_chance_multiplier' multiplies chance of all mobs spawning and can be set + to 0.5 to have mobs spawn more or 2.0 to spawn less. + e.g. 1 in 7000 * 0.5 = 1 in 3500 so better odds of + spawning. + 'mobs_spawn' if false then mobs no longer spawn without spawner or + spawn egg. + 'mobs_drop_items' when false mobs no longer drop items when they die. + 'mobs_griefing' when false mobs cannot break blocks when using either + pathfinding level 2, replace functions or mobs:boom + function. + +Players can override the spawn chance for each mob registered by adding a line +to their minetest.conf file with a new value, the lower the value the more each +mob will spawn e.g. + +mobs_animal:sheep 11000 +mobs_monster:sand_monster 100 + +...you can also change how many of a certain mob appear in an active mapblock by +adding a comma and then a new value e.g. + +mobs_animal:cow 8000,4 <-- 4 cows per mapblock at 8000 spawn chance +mobs_monster:dirt_monster ,20 <-- 20 dirt monsters per mapblock + + +Rideable Horse Example Mob +-------------------------- + +mobs:register_mob("mob_horse:horse", { + type = "animal", + visual = "mesh", + visual_size = {x = 1.20, y = 1.20}, + mesh = "mobs_horse.x", + collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4}, + animation = { + speed_normal = 15, + speed_run = 30, + stand_start = 25, + stand_end = 75, + walk_start = 75, + walk_end = 100, + run_start = 75, + run_end = 100, + }, + textures = { + {"mobs_horse.png"}, + {"mobs_horsepeg.png"}, + {"mobs_horseara.png"} + }, + fear_height = 3, + runaway = true, + fly = false, + walk_chance = 60, + view_range = 5, + follow = {"farming:wheat"}, + passive = true, + hp_min = 12, + hp_max = 16, + armor = 200, + lava_damage = 5, + fall_damage = 5, + water_damage = 1, + makes_footstep_sound = true, + drops = { + {name = "mobs:meat_raw", chance = 1, min = 2, max = 3} + }, + sounds = { + random = "horse_neigh.ogg", + damage = "horse_whinney.ogg", + }, + + do_custom = function(self, dtime) + + -- set needed values if not already present + if not self.v2 then + self.v2 = 0 + self.max_speed_forward = 6 + self.max_speed_reverse = 2 + self.accel = 6 + self.terrain_type = 3 + self.driver_attach_at = {x = 0, y = 20, z = -2} + self.driver_eye_offset = {x = 0, y = 3, z = 0} + self.driver_scale = {x = 1, y = 1} + end + + -- if driver present allow control of horse + if self.driver then + + mobs.drive(self, "walk", "stand", false, dtime) + + return false -- skip rest of mob functions + end + + return true + end, + + on_die = function(self, pos) + + -- drop saddle when horse is killed while riding + -- also detach from horse properly + if self.driver then + minetest.add_item(pos, "mobs:saddle") + mobs.detach(self.driver, {x = 1, y = 0, z = 1}) + end + + end, + + on_rightclick = function(self, clicker) + + -- make sure player is clicking + if not clicker or not clicker:is_player() then + return + end + + -- feed, tame or heal horse + if mobs:feed_tame(self, clicker, 10, true, true) then + return + end + + -- make sure tamed horse is being clicked by owner only + if self.tamed and self.owner == clicker:get_player_name() then + + local inv = clicker:get_inventory() + + -- detatch player already riding horse + if self.driver and clicker == self.driver then + + mobs.detach(clicker, {x = 1, y = 0, z = 1}) + + -- add saddle back to inventory + if inv:room_for_item("main", "mobs:saddle") then + inv:add_item("main", "mobs:saddle") + else + minetest.add_item(clicker.getpos(), "mobs:saddle") + end + + -- attach player to horse + elseif not self.driver + and clicker:get_wielded_item():get_name() == "mobs:saddle" then + + self.object:set_properties({stepheight = 1.1}) + mobs.attach(self, clicker) + + -- take saddle from inventory + inv:remove_item("main", "mobs:saddle") + end + end + + -- used to capture horse with magic lasso + mobs:capture_mob(self, clicker, 0, 0, 80, false, nil) + end +}) diff --git a/mods/mobs/crafts.lua b/mods/mobs/crafts.lua new file mode 100644 index 00000000..09e00ff3 --- /dev/null +++ b/mods/mobs/crafts.lua @@ -0,0 +1,327 @@ + +local S = mobs.intllib + +-- name tag +minetest.register_craftitem("mobs:nametag", { + description = S("Name Tag"), + inventory_image = "mobs_nametag.png", + groups = {flammable = 2} +}) + +if minetest.get_modpath("dye") and minetest.get_modpath("farming") then + minetest.register_craft({ + type = "shapeless", + output = "mobs:nametag", + recipe = {"default:paper", "dye:black", "farming:string"} + }) +end + +-- leather +minetest.register_craftitem("mobs:leather", { + description = S("Leather"), + inventory_image = "mobs_leather.png", + groups = {flammable = 2} +}) + +-- raw meat +minetest.register_craftitem("mobs:meat_raw", { + description = S("Raw Meat"), + inventory_image = "mobs_meat_raw.png", + on_use = minetest.item_eat(3), + groups = {food_meat_raw = 1, flammable = 2} +}) + +-- cooked meat +minetest.register_craftitem("mobs:meat", { + description = S("Meat"), + inventory_image = "mobs_meat.png", + on_use = minetest.item_eat(8), + groups = {food_meat = 1, flammable = 2} +}) + +minetest.register_craft({ + type = "cooking", + output = "mobs:meat", + recipe = "mobs:meat_raw", + cooktime = 5 +}) + +-- lasso +minetest.register_tool("mobs:lasso", { + description = S("Lasso (right-click animal to put in inventory)"), + inventory_image = "mobs_magic_lasso.png", + groups = {flammable = 2} +}) + +if minetest.get_modpath("farming") then + minetest.register_craft({ + output = "mobs:lasso", + recipe = { + {"farming:string", "", "farming:string"}, + {"", "default:beskar", ""}, + {"farming:string", "", "farming:string"} + } + }) +end + +minetest.register_alias("mobs:magic_lasso", "mobs:lasso") + +-- net +minetest.register_tool("mobs:net", { + description = S("Net (right-click animal to put in inventory)"), + inventory_image = "mobs_net.png", + groups = {flammable = 2} +}) + +if minetest.get_modpath("farming") then + minetest.register_craft({ + output = "mobs:net", + recipe = { + {"group:stick", "", "group:stick"}, + {"group:stick", "", "group:stick"}, + {"farming:string", "group:stick", "farming:string"} + } + }) +end + +-- shears (right click to shear animal) +minetest.register_tool("mobs:shears", { + description = S("Steel Shears (right-click to shear)"), + inventory_image = "mobs_shears.png", + groups = {flammable = 2} +}) + +minetest.register_craft({ + output = "mobs:shears", + recipe = { + {"", "default:durasteel_ingot", ""}, + {"", "group:stick", "default:durasteel_ingot"} + } +}) + +-- protection rune +minetest.register_craftitem("mobs:protector", { + description = S("Mob Protection Rune"), + inventory_image = "mobs_protector.png", + groups = {flammable = 2} +}) + +minetest.register_craft({ + output = "mobs:protector", + recipe = { + {"default:stone", "default:stone", "default:stone"}, + {"default:stone", "default:goldblock", "default:stone"}, + {"default:stone", "default:stone", "default:stone"} + } +}) + +-- saddle +minetest.register_craftitem("mobs:saddle", { + description = S("Saddle"), + inventory_image = "mobs_saddle.png", + groups = {flammable = 2} +}) + +minetest.register_craft({ + output = "mobs:saddle", + recipe = { + {"mobs:leather", "mobs:leather", "mobs:leather"}, + {"mobs:leather", "default:durasteel_ingot", "mobs:leather"}, + {"mobs:leather", "default:durasteel_ingot", "mobs:leather"} + } +}) + +-- mob fence (looks like normal fence but collision is 2 high) +default.register_fence("mobs:fence_wood", { + description = S("Mob Fence"), + texture = "default_wood.png", + material = "default:fence_wood", + groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, + sounds = default.node_sound_wood_defaults(), + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 1.9, 0.5}, + } + } +}) + +-- mob fence top (has enlarged collisionbox to stop mobs getting over) +minetest.register_node("mobs:fence_top", { + description = S("Mob Fence Top"), + drawtype = "nodebox", + tiles = {"default_wood.png"}, + paramtype = "light", + is_ground_content = false, + groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, + sounds = default.node_sound_wood_defaults(), + node_box = { + type = "fixed", + fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} + }, + collision_box = { + type = "fixed", + fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4} + }, + selection_box = { + type = "fixed", + fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4} + } +}) + +minetest.register_craft({ + output = "mobs:fence_top 12", + recipe = { + {"group:wood", "group:wood", "group:wood"}, + {"", "default:fence_wood", ""} + } +}) + +-- items that can be used as fuel +minetest.register_craft({ + type = "fuel", + recipe = "mobs:nametag", + burntime = 3 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:lasso", + burntime = 7 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:net", + burntime = 8 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:leather", + burntime = 4 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:saddle", + burntime = 7 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:fence_wood", + burntime = 7 +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mobs:fence_top", + burntime = 2 +}) + +-- this tool spawns same mob and adds owner, protected, nametag info +-- then removes original entity, this is used for fixing any issues. + +local tex_obj + +minetest.register_tool(":mobs:mob_reset_stick", { + description = S("Mob Reset Stick"), + inventory_image = "default_stick.png^[colorize:#ff000050", + stack_max = 1, + groups = {not_in_creative_inventory = 1}, + + on_use = function(itemstack, user, pointed_thing) + + if pointed_thing.type ~= "object" then + return + end + + local obj = pointed_thing.ref + + local control = user:get_player_control() + local sneak = control and control.sneak + + -- spawn same mob with saved stats, with random texture + if obj and not sneak then + + local self = obj:get_luaentity() + local obj2 = minetest.add_entity(obj:get_pos(), self.name) + + if obj2 then + + local ent2 = obj2:get_luaentity() + + ent2.protected = self.protected + ent2.owner = self.owner + ent2.nametag = self.nametag + ent2.gotten = self.gotten + ent2.tamed = self.tamed + ent2.health = self.health + ent2.order = self.order + + if self.child then + obj2:set_velocity({x = 0, y = self.jump_height, z = 0}) + end + + obj2:set_properties({nametag = self.nametag}) + + obj:remove() + end + end + + -- display form to enter texture name ending in .png + if obj and sneak then + + tex_obj = obj + + local name = user:get_player_name() + local tex = "" + + minetest.show_formspec(name, "mobs_texture", "size[8,4]" + .. "field[0.5,1;7.5,0;name;" + .. minetest.formspec_escape(S("Enter texture:")) .. ";" .. tex .. "]" + .. "button_exit[2.5,3.5;3,1;mob_texture_change;" + .. minetest.formspec_escape(S("Change")) .. "]") + end + end +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + + -- right-clicked with nametag and name entered? + if formname == "mobs_texture" + and fields.name + and fields.name ~= "" then + + local name = player:get_player_name() + + -- does mob still exist? + if not tex_obj + or not tex_obj:get_luaentity() then + return + end + + -- make sure nametag is being used to name mob + local item = player:get_wielded_item() + + if item:get_name() ~= "mobs:mob_reset_stick" then + return + end + + -- limit name entered to 64 characters long + if string.len(fields.name) > 64 then + fields.name = string.sub(fields.name, 1, 64) + end + + -- update texture + local self = tex_obj:get_luaentity() + + self.base_texture = {fields.name} + + tex_obj:set_properties({textures = {fields.name}}) + + -- reset external variable + tex_obj = nil + end +end) diff --git a/mods/mobs/depends.txt b/mods/mobs/depends.txt new file mode 100644 index 00000000..2f208027 --- /dev/null +++ b/mods/mobs/depends.txt @@ -0,0 +1,9 @@ +default +tnt? +dye? +farming? +invisibility? +intllib? +lucky_block? +cmi? +toolranks? diff --git a/mods/mobs/description.txt b/mods/mobs/description.txt new file mode 100644 index 00000000..919852a1 --- /dev/null +++ b/mods/mobs/description.txt @@ -0,0 +1 @@ +Adds a mob api for mods to add animals or monsters etc. \ No newline at end of file diff --git a/mods/mobs/init.lua b/mods/mobs/init.lua new file mode 100644 index 00000000..f63fb164 --- /dev/null +++ b/mods/mobs/init.lua @@ -0,0 +1,19 @@ + +local path = minetest.get_modpath("mobs") + +-- Mob API +dofile(path .. "/api.lua") + +-- Rideable Mobs +dofile(path .. "/mount.lua") + +-- Mob Items +dofile(path .. "/crafts.lua") + +-- Mob Spawner +dofile(path .. "/spawner.lua") + +-- Lucky Blocks +dofile(path .. "/lucky_block.lua") + +minetest.log("action", "[MOD] Mobs Redo loaded") diff --git a/mods/mobs/intllib.lua b/mods/mobs/intllib.lua new file mode 100644 index 00000000..6669d720 --- /dev/null +++ b/mods/mobs/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/mods/mobs/lucky_block.lua b/mods/mobs/lucky_block.lua new file mode 100644 index 00000000..b823e832 --- /dev/null +++ b/mods/mobs/lucky_block.lua @@ -0,0 +1,18 @@ + +if minetest.get_modpath("lucky_block") then + + lucky_block:add_blocks({ + {"dro", {"mobs:meat_raw"}, 5}, + {"dro", {"mobs:meat"}, 5}, + {"dro", {"mobs:nametag"}, 1}, + {"dro", {"mobs:leather"}, 5}, + {"dro", {"default:stick"}, 10}, + {"dro", {"mobs:net"}, 1}, + {"dro", {"mobs:lasso"}, 1}, + {"dro", {"mobs:shears"}, 1}, + {"dro", {"mobs:protector"}, 1}, + {"dro", {"mobs:fence_wood"}, 10}, + {"dro", {"mobs:fence_top"}, 12}, + {"lig"} + }) +end diff --git a/mods/mobs/mod.conf b/mods/mobs/mod.conf new file mode 100644 index 00000000..f3a3ad74 --- /dev/null +++ b/mods/mobs/mod.conf @@ -0,0 +1 @@ +name = mobs diff --git a/mods/mobs/mount.lua b/mods/mobs/mount.lua new file mode 100644 index 00000000..29b80ed2 --- /dev/null +++ b/mods/mobs/mount.lua @@ -0,0 +1,448 @@ + +-- lib_mount by Blert2112 (edited by TenPlus1) + +local enable_crash = false +local crash_threshold = 6.5 -- ignored if enable_crash=false + +------------------------------------------------------------------------------ + +-- +-- Helper functions +-- + +local node_ok = function(pos, fallback) + + fallback = fallback or mobs.fallback_node + + local node = minetest.get_node_or_nil(pos) + + if node and minetest.registered_nodes[node.name] then + return node + end + + return {name = fallback} +end + + +local function node_is(pos) + + local node = node_ok(pos) + + if node.name == "air" then + return "air" + end + + if minetest.get_item_group(node.name, "lava") ~= 0 then + return "lava" + end + + if minetest.get_item_group(node.name, "liquid") ~= 0 then + return "liquid" + end + + if minetest.registered_nodes[node.name].walkable == true then + return "walkable" + end + + return "other" +end + + +local function get_sign(i) + + i = i or 0 + + if i == 0 then + return 0 + else + return i / math.abs(i) + end +end + + +local function get_velocity(v, yaw, y) + + local x = -math.sin(yaw) * v + local z = math.cos(yaw) * v + + return {x = x, y = y, z = z} +end + + +local function get_v(v) + return math.sqrt(v.x * v.x + v.z * v.z) +end + + +local function force_detach(player) + + local attached_to = player:get_attach() + + if not attached_to then + return + end + + local entity = attached_to:get_luaentity() + + if entity.driver + and entity.driver == player then + + entity.driver = nil + end + + player:set_detach() + default.player_attached[player:get_player_name()] = false + player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) + default.player_set_animation(player, "stand" , 30) + player:set_properties({visual_size = {x = 1, y = 1} }) + +end + +------------------------------------------------------------------------------- + + +minetest.register_on_leaveplayer(function(player) + force_detach(player) +end) + +minetest.register_on_shutdown(function() + local players = minetest.get_connected_players() + for i = 1, #players do + force_detach(players[i]) + end +end) + +minetest.register_on_dieplayer(function(player) + force_detach(player) + return true +end) + +------------------------------------------------------------------------------- + +function mobs.attach(entity, player) + + local attach_at, eye_offset = {}, {} + + entity.player_rotation = entity.player_rotation or {x = 0, y = 0, z = 0} + entity.driver_attach_at = entity.driver_attach_at or {x = 0, y = 0, z = 0} + entity.driver_eye_offset = entity.driver_eye_offset or {x = 0, y = 0, z = 0} + entity.driver_scale = entity.driver_scale or {x = 1, y = 1} + + local rot_view = 0 + + if entity.player_rotation.y == 90 then + rot_view = math.pi/2 + end + + attach_at = entity.driver_attach_at + eye_offset = entity.driver_eye_offset + entity.driver = player + + force_detach(player) + + player:set_attach(entity.object, "", attach_at, entity.player_rotation) + default.player_attached[player:get_player_name()] = true + player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0}) + + player:set_properties({ + visual_size = { + x = entity.driver_scale.x, + y = entity.driver_scale.y + } + }) + + minetest.after(0.2, function() + default.player_set_animation(player, "sit" , 30) + end) + + --player:set_look_yaw(entity.object:get_yaw() - rot_view) + player:set_look_horizontal(entity.object:get_yaw() - rot_view) +end + + +function mobs.detach(player, offset) + + force_detach(player) + + default.player_set_animation(player, "stand" , 30) + + local pos = player:get_pos() + + pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z} + + minetest.after(0.1, function() + player:set_pos(pos) + end) +end + + +function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) + + local rot_steer, rot_view = math.pi/2, 0 + + if entity.player_rotation.y == 90 then + rot_steer, rot_view = 0, math.pi/2 + end + + local acce_y = 0 + local velo = entity.object:get_velocity() + + entity.v = get_v(velo) * get_sign(entity.v) + + -- process controls + if entity.driver then + +--print ("---velo", get_v(velo)) + + local ctrl = entity.driver:get_player_control() + + -- move forwards + if ctrl.up then + + entity.v = entity.v + entity.accel / 10 + + -- move backwards + elseif ctrl.down then + + if entity.max_speed_reverse == 0 and entity.v == 0 then + return + end + + entity.v = entity.v - entity.accel / 10 + end + + -- fix mob rotation + local horz = entity.driver:get_look_horizontal() or 0 + entity.object:set_yaw(horz - entity.rotate) + + if can_fly then + + -- fly up + if ctrl.jump then + velo.y = velo.y + 1 + if velo.y > entity.accel then velo.y = entity.accel end + + elseif velo.y > 0 then + velo.y = velo.y - 0.1 + if velo.y < 0 then velo.y = 0 end + end + + -- fly down + if ctrl.sneak then + velo.y = velo.y - 1 + if velo.y < -entity.accel then velo.y = -entity.accel end + + elseif velo.y < 0 then + velo.y = velo.y + 0.1 + if velo.y > 0 then velo.y = 0 end + end + + else + + -- jump + if ctrl.jump then + + if velo.y == 0 then + velo.y = velo.y + entity.jump_height + acce_y = acce_y + (acce_y * 3) + 1 + end + end + end + end + + -- if not moving then set animation and return + if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then + + if stand_anim then + mobs:set_animation(entity, stand_anim) + end + + return + end + + -- set moving animation + if moving_anim then + mobs:set_animation(entity, moving_anim) + end + + -- Stop! + local s = get_sign(entity.v) + + entity.v = entity.v - 0.02 * s + + if s ~= get_sign(entity.v) then + + entity.object:set_velocity({x = 0, y = 0, z = 0}) + entity.v = 0 + return + end + + -- enforce speed limit forward and reverse + local max_spd = entity.max_speed_reverse + + if get_sign(entity.v) >= 0 then + max_spd = entity.max_speed_forward + end + + if math.abs(entity.v) > max_spd then + entity.v = entity.v - get_sign(entity.v) + end + + -- Set position, velocity and acceleration + local p = entity.object:get_pos() + local new_velo = {x = 0, y = 0, z = 0} + local new_acce = {x = 0, y = -9.8, z = 0} + + p.y = p.y - 0.5 + + local ni = node_is(p) + local v = entity.v + + if ni == "air" then + + if can_fly == true then + new_acce.y = 0 + end + + elseif ni == "liquid" or ni == "lava" then + + if ni == "lava" and entity.lava_damage ~= 0 then + + entity.lava_counter = (entity.lava_counter or 0) + dtime + + if entity.lava_counter > 1 then + + minetest.sound_play("default_punch", { + object = entity.object, + max_hear_distance = 5 + }) + + entity.object:punch(entity.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = entity.lava_damage} + }, nil) + + entity.lava_counter = 0 + end + end + + if entity.terrain_type == 2 + or entity.terrain_type == 3 then + + new_acce.y = 0 + p.y = p.y + 1 + + if node_is(p) == "liquid" then + + if velo.y >= 5 then + velo.y = 5 + elseif velo.y < 0 then + new_acce.y = 20 + else + new_acce.y = 5 + end + else + if math.abs(velo.y) < 1 then + local pos = entity.object:get_pos() + pos.y = math.floor(pos.y) + 0.5 + entity.object:set_pos(pos) + velo.y = 0 + end + end + else + v = v * 0.25 + end + end + + new_velo = get_velocity(v, entity.object:get_yaw() - rot_view, velo.y) + new_acce.y = new_acce.y + acce_y + + entity.object:set_velocity(new_velo) + entity.object:set_acceleration(new_acce) + + -- CRASH! + if enable_crash then + + local intensity = entity.v2 - v + + if intensity >= crash_threshold then + +--print("----------- crash", intensity) + + entity.object:punch(entity.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = intensity} + }, nil) + + end + end + + entity.v2 = v +end + + +-- directional flying routine by D00Med (edited by TenPlus1) + +function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim) + + local ctrl = entity.driver:get_player_control() + local velo = entity.object:get_velocity() + local dir = entity.driver:get_look_dir() + local yaw = entity.driver:get_look_horizontal() + 1.57 -- offset fix between old and new commands + local rot_steer, rot_view = math.pi / 2, 0 + + if entity.player_rotation.y == 90 then + rot_steer, rot_view = 0, math.pi / 2 + end + + if ctrl.up then + entity.object:set_velocity({ + x = dir.x * speed, + y = dir.y * speed + 2, + z = dir.z * speed + }) + + elseif ctrl.down then + entity.object:set_velocity({ + x = -dir.x * speed, + y = dir.y * speed + 2, + z = -dir.z * speed + }) + + elseif not ctrl.down or ctrl.up or ctrl.jump then + entity.object:set_velocity({x = 0, y = -2, z = 0}) + end + + entity.object:set_yaw(yaw + math.pi + math.pi / 2 - entity.rotate) + + -- firing arrows + if ctrl.LMB and ctrl.sneak and shoots then + + local pos = entity.object:get_pos() + local obj = minetest.add_entity({ + x = pos.x + 0 + dir.x * 2.5, + y = pos.y + 1.5 + dir.y, + z = pos.z + 0 + dir.z * 2.5}, arrow) + + local ent = obj:get_luaentity() + if ent then + ent.switch = 1 -- for mob specific arrows + ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding + local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6} + local yaw = entity.driver:get_look_horizontal() + obj:set_yaw(yaw + math.pi / 2) + obj:set_velocity(vec) + else + obj:remove() + end + end + + -- change animation if stopped + if velo.x == 0 and velo.y == 0 and velo.z == 0 then + + mobs:set_animation(entity, stand_anim) + else + -- moving animation + mobs:set_animation(entity, moving_anim) + end +end diff --git a/mods/mobs/readme.MD b/mods/mobs/readme.MD new file mode 100644 index 00000000..27d552f3 --- /dev/null +++ b/mods/mobs/readme.MD @@ -0,0 +1,86 @@ + +MOBS REDO for MINETEST + +Built from PilzAdam's original Simple Mobs with additional mobs by KrupnoPavel, Zeg9, ExeterDad and AspireMint. + + +This mod contains the API only for adding your own mobs into the world, so please use the additional modpacks to add animals, monsters etc. + + +https://forum.minetest.net/viewtopic.php?f=11&t=9917 + + +Crafts: + + - Nametag (paper, black dye, string) can be used right-click on a tamed mob to give them a name. + - Nets can be used to right-click tamed mobs to pick them up and place inside inventory as a spawn egg. + - Magic Lasso is similar to nets but with a better chance of picking up larger mobs. + - Shears are used to right-click sheep and return 1-3 wool. + - Protection Rune lets you protect tamed mobs from harm by other players + - Mob Fence and Fence Top (to stop mobs escaping/glitching through fences) + +Lucky Blocks: 9 + + +Changelog: +- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods) +- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07 +- 1.48- Add mobs:set_velocity(self, velocity) global function +- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage +- 1.46- Mobs only drop rare items when killed by player (drops.min = 0 makes them rare), code tweak, pathfinding no longer sees through walkable nodes +- 1.45- Added Fence Top to add on top of any fence to stop mobs escaping, new line_of_sight tweaked by Astrobe +- 1.44- Added ToolRanks support for swords when attacking mobs +- 1.43- Better 0.4.16 compatibility, added general attack function and settings +- 1.42- Added "all" option to immune_to table, tidied floating mobs to be less intensive +- 1.41- Mob pathfinding has been updated thanks to Elkien3 +- 1.40- Updated to use newer functions, requires Minetest 0.4.16+ to work. +- 1.39- Added 'on_breed', 'on_grown' and 'do_punch' custom functions per mob +- 1.38- Better entity checking, nametag setting and on_spawn function added to mob registry, tweaked light damage +- 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448 +- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked +- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack +- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code) +- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112 +- 1.32- Added new spawn check to count specific mobs AND new minetest.conf setting to chance spawn chance and numbers, added ability to protect tamed mobs +- 1.31- Added 'attack_animals' and 'specific_attack' flags for custom monster attacks, also 'mob_difficulty' .conf setting to make mobs harder. +- 1.30- Added support for invisibility mod (mobs cant attack what they cant see), tweaked and tidied code +- 1.29- Split original Mobs Redo into a modpack to make it easier to disable mob sets (animal, monster, npc) or simply use the Api itself for your own mod +- 1.28- New damage system added with ability for mob to be immune to weapons or healed by them :) +- 1.27- Added new sheep, lava flan and spawn egg textures. New Lava Pick tool smelts what you dig. New atan checking function. +- 1.26- Pathfinding feature added thanks to rnd, when monsters attack they become scary smart in finding you :) also, beehive produces honey now :) +- 1.25- Mobs no longer spawn within 12 blocks of player or despawn within same range, spawners now have player detection, Code tidy and tweak. +- 1.24- Added feature where certain animals run away when punched (runaway = true in mob definition) +- 1.23- Added mob spawner block for admin to setup spawners in-game (place and right click to enter settings) +- 1.22- Added ability to name tamed animals and npc using nametags, also npc will attack anyone who punches them apart from owner +- 1.21- Added some more error checking to reduce serialize.h error and added height checks for falling off cliffs (thanks cmdskp) +- 1.20- Error checking added to remove bad mobs, out of map limit mobs and stop serialize.h error +- 1.19- Chickens now drop egg items instead of placing the egg, also throwing eggs result in 1/8 chance of spawning chick +- 1.18- Added docile_by_day flag so that monsters will not attack automatically during daylight hours unless hit first +- 1.17- Added 'dogshoot' attack type, shoots when out of reach, melee attack when in reach, also api tweaks and self.reach added +- 1.16- Mobs follow multiple items now, Npc's can breed +- 1.15- Added Feeding/Taming/Breeding function, right-click to pick up any sheep with X mark on them and replace with new one to fix compatibility. +- 1.14- All .self variables saved in staticdata, Fixed self.health bug +- 1.13- Added capture function (thanks blert2112) chance of picking up mob with hand; net; magic lasso, replaced some .x models with newer .b3d one's +- 1.12- Added animal ownership so that players cannot steal your tamed animals +- 1.11- Added flying mobs (and swimming), fly=true and fly_in="air" or "deafult:water_source" for fishy +- 1,10- Footstep removed (use replace), explosion routine added for exploding mobs. +- 1.09- reworked breeding routine, added mob rotation value, added footstep feature, added jumping mobs with sounds feature, added magic lasso for picking up animals +- 1.08- Mob throwing attack has been rehauled so that they can damage one another, also drops and on_die function added +- 1.07- Npc's can now be set to follow player or stand by using self.order and self.owner variables +- beta- Npc mob added, kills monsters, attacks player when punched, right click with food to heal or gold lump for drop +- 1.06- Changed recovery times after breeding, and time taken to grow up (can be sped up by feeding baby animal) +- 1.05- Added ExeterDad's bunny's which can be picked up and tamed with 4 carrots from farming redo or farming_plus, also shears added to get wool from sheep and lastly Jordach/BSD's kitten +- 1.04- Added mating for sheep, cows and hogs... feed animals to make horny and hope for a baby which is half size, will grow up quick though :) +- 1.03- Added mob drop/replace feature so that chickens can drop eggs, cow/sheep can eat grass/wheat etc. +- 1.02- Sheared sheep are remembered and spawn shaven, Warthogs will attack when threatened, Api additions +- 1.01- Mobs that suffer fall damage or die in water/lava/sunlight will now drop items +- 1.0 - more work on Api so that certain mobs can float in water while some sink like a brick :) +- 0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked +- 0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound +- 0.7 - mobs.protected switch added to api.lua, when set to 1 mobs no longer spawn in protected areas, also bug fixes +- 0.6 - Api now supports multi-textured mobs, e.g oerkki, dungeon master, rats and chickens have random skins when spawning (sheep fix TODO), also new Honey block +- 0.5 - Mobs now float in water, die from falling, and some code improvements +- 0.4 - Dungeon Masters and Mese Monsters have much better aim due to shoot_offset, also they can both shoot through nodes that aren't walkable (flowers, grass etc) plus new sheep sound :) +- 0.3 - Added LOTT's Spider mob, made Cobwebs, added KPavel's Bee with Honey and Beehives (made texture), Warthogs now have sound and can be tamed, taming of shaved sheep or milked cow with 8 wheat so it will not despawn, many bug fixes :) +- 0.2 - Cooking bucket of milk into cheese now returns empty bucket +- 0.1 - Initial Release diff --git a/mods/mobs/settingtypes.txt b/mods/mobs/settingtypes.txt new file mode 100644 index 00000000..08214374 --- /dev/null +++ b/mods/mobs/settingtypes.txt @@ -0,0 +1,29 @@ +# If false then mobs no longer spawn in world without spawner or spawn egg +mobs_spawn (Spawn Mobs) bool true + +# If enabled then monsters no longer spawn in world +only_peaceful_mobs (Only spawn peaceful Mobs) bool false + +# If enabled then punching mobs no longer shows blood effects +mobs_disable_blood (Disable Mob blood) bool false + +# If disabled then Mobs no longer destroy world blocks +mobs_griefing (Griefing Mobs) bool true + +# If false then Mobs no longer spawn inside player protected areas +mobs_spawn_protected (Spawn Mobs in protected areas) bool true + +# If true Mobs will be removed once a map chunk is out of view +remove_far_mobs (Remove far Mobs) bool true + +# Sets Mob difficulty level by multiplying punch damage +mob_difficulty (Mob difficulty) float 1.0 + +# If disabled health status no longer appears above Mob when punched +mob_show_health (Show Mob health) bool true + +# Contains a value used to multiply Mob spawn values +mob_chance_multiplier (Mob chance multiplier) float 1.0 + +# When false Mob no longer drop items when killed +mobs_drop_items (Mob drops) bool true diff --git a/mods/mobs/sounds/default_punch.ogg b/mods/mobs/sounds/default_punch.ogg new file mode 100644 index 00000000..28a500bf Binary files /dev/null and b/mods/mobs/sounds/default_punch.ogg differ diff --git a/mods/mobs/sounds/license.txt b/mods/mobs/sounds/license.txt new file mode 100644 index 00000000..3b160fe2 --- /dev/null +++ b/mods/mobs/sounds/license.txt @@ -0,0 +1,7 @@ +Creative Commons sounds from Freesound.org + +mobs_swing.ogg by qubodup + - http://freesound.org/people/qubodup/sounds/60012/ + +mobs_spell.ogg by littlerobotsoundfactory + - http://freesound.org/people/LittleRobotSoundFactory/sounds/270396/ diff --git a/mods/mobs/sounds/mobs_spell.ogg b/mods/mobs/sounds/mobs_spell.ogg new file mode 100644 index 00000000..455b54f5 Binary files /dev/null and b/mods/mobs/sounds/mobs_spell.ogg differ diff --git a/mods/mobs/sounds/mobs_swing.ogg b/mods/mobs/sounds/mobs_swing.ogg new file mode 100644 index 00000000..ffe6a9ce Binary files /dev/null and b/mods/mobs/sounds/mobs_swing.ogg differ diff --git a/mods/mobs/spawner.lua b/mods/mobs/spawner.lua new file mode 100644 index 00000000..dfe20f21 --- /dev/null +++ b/mods/mobs/spawner.lua @@ -0,0 +1,178 @@ + +local S = mobs.intllib + +-- mob spawner + +local spawner_default = "mobs_animal:pumba 10 15 0 0" + +minetest.register_node("mobs:spawner", { + tiles = {"mob_spawner.png"}, + drawtype = "glasslike", + paramtype = "light", + walkable = true, + description = S("Mob Spawner"), + groups = {cracky = 1}, + + on_construct = function(pos) + + local meta = minetest.get_meta(pos) + + -- text entry formspec + meta:set_string("formspec", + "field[text;" .. S("Mob MinLight MaxLight Amount PlayerDist") .. ";${command}]") + meta:set_string("infotext", S("Spawner Not Active (enter settings)")) + meta:set_string("command", spawner_default) + end, + + on_right_click = function(pos, placer) + + if minetest.is_protected(pos, placer:get_player_name()) then + return + end + end, + + on_receive_fields = function(pos, formname, fields, sender) + + if not fields.text or fields.text == "" then + return + end + + local meta = minetest.get_meta(pos) + local comm = fields.text:split(" ") + local name = sender:get_player_name() + + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return + end + + local mob = comm[1] -- mob to spawn + local mlig = tonumber(comm[2]) -- min light + local xlig = tonumber(comm[3]) -- max light + local num = tonumber(comm[4]) -- total mobs in area + local pla = tonumber(comm[5]) -- player distance (0 to disable) + local yof = tonumber(comm[6]) or 0 -- Y offset to spawn mob + + if mob and mob ~= "" and mobs.spawning_mobs[mob] == true + and num and num >= 0 and num <= 10 + and mlig and mlig >= 0 and mlig <= 15 + and xlig and xlig >= 0 and xlig <= 15 + and pla and pla >=0 and pla <= 20 + and yof and yof > -10 and yof < 10 then + + meta:set_string("command", fields.text) + meta:set_string("infotext", S("Spawner Active (@1)", mob)) + + else + minetest.chat_send_player(name, S("Mob Spawner settings failed!")) + minetest.chat_send_player(name, + S("Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10]”")) + end + end +}) + + +local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 99) + +-- spawner abm +minetest.register_abm({ + label = "Mob spawner node", + nodenames = {"mobs:spawner"}, + interval = 10, + chance = 4, + catch_up = false, + + action = function(pos, node, active_object_count, active_object_count_wider) + + -- return if too many entities already + if active_object_count_wider >= max_per_block then + return + end + + -- get meta and command + local meta = minetest.get_meta(pos) + local comm = meta:get_string("command"):split(" ") + + -- get settings from command + local mob = comm[1] + local mlig = tonumber(comm[2]) + local xlig = tonumber(comm[3]) + local num = tonumber(comm[4]) + local pla = tonumber(comm[5]) or 0 + local yof = tonumber(comm[6]) or 0 + + -- if amount is 0 then do nothing + if num == 0 then + return + end + + -- are we spawning a registered mob? + if not mobs.spawning_mobs[mob] then + --print ("--- mob doesn't exist", mob) + return + end + + -- check objects inside 9x9 area around spawner + local objs = minetest.get_objects_inside_radius(pos, 9) + local count = 0 + local ent = nil + + -- count mob objects of same type in area + for k, obj in ipairs(objs) do + + ent = obj:get_luaentity() + + if ent and ent.name and ent.name == mob then + count = count + 1 + end + end + + -- is there too many of same type? + if count >= num then + return + end + + -- spawn mob if player detected and in range + if pla > 0 then + + local in_range = 0 + local objs = minetest.get_objects_inside_radius(pos, pla) + + for _,oir in pairs(objs) do + + if oir:is_player() then + + in_range = 1 + + break + end + end + + -- player not found + if in_range == 0 then + return + end + end + + -- find air blocks within 5 nodes of spawner + local air = minetest.find_nodes_in_area( + {x = pos.x - 5, y = pos.y + yof, z = pos.z - 5}, + {x = pos.x + 5, y = pos.y + yof, z = pos.z + 5}, + {"air"}) + + -- spawn in random air block + if air and #air > 0 then + + local pos2 = air[math.random(#air)] + local lig = minetest.get_node_light(pos2) or 0 + + pos2.y = pos2.y + 0.5 + + -- only if light levels are within range + if lig >= mlig and lig <= xlig + and minetest.registered_entities[mob] then + minetest.add_entity(pos2, mob) + end + end + end +}) diff --git a/mods/mobs/textures/mob_spawner.png b/mods/mobs/textures/mob_spawner.png new file mode 100644 index 00000000..8f0ac39b Binary files /dev/null and b/mods/mobs/textures/mob_spawner.png differ diff --git a/mods/mobs/textures/mobs_blood.png b/mods/mobs/textures/mobs_blood.png new file mode 100644 index 00000000..77cfbdaa Binary files /dev/null and b/mods/mobs/textures/mobs_blood.png differ diff --git a/mods/mobs/textures/mobs_chicken_egg.png b/mods/mobs/textures/mobs_chicken_egg.png new file mode 100644 index 00000000..be8a4e1c Binary files /dev/null and b/mods/mobs/textures/mobs_chicken_egg.png differ diff --git a/mods/mobs/textures/mobs_chicken_egg_overlay.png b/mods/mobs/textures/mobs_chicken_egg_overlay.png new file mode 100644 index 00000000..e81716a5 Binary files /dev/null and b/mods/mobs/textures/mobs_chicken_egg_overlay.png differ diff --git a/mods/mobs/textures/mobs_leather.png b/mods/mobs/textures/mobs_leather.png new file mode 100644 index 00000000..3205e5d6 Binary files /dev/null and b/mods/mobs/textures/mobs_leather.png differ diff --git a/mods/mobs/textures/mobs_magic_lasso.png b/mods/mobs/textures/mobs_magic_lasso.png new file mode 100644 index 00000000..befdc112 Binary files /dev/null and b/mods/mobs/textures/mobs_magic_lasso.png differ diff --git a/mods/mobs/textures/mobs_meat.png b/mods/mobs/textures/mobs_meat.png new file mode 100644 index 00000000..4c63fdd1 Binary files /dev/null and b/mods/mobs/textures/mobs_meat.png differ diff --git a/mods/mobs/textures/mobs_meat_raw.png b/mods/mobs/textures/mobs_meat_raw.png new file mode 100644 index 00000000..0dea4ec5 Binary files /dev/null and b/mods/mobs/textures/mobs_meat_raw.png differ diff --git a/mods/mobs/textures/mobs_nametag.png b/mods/mobs/textures/mobs_nametag.png new file mode 100644 index 00000000..74005b3a Binary files /dev/null and b/mods/mobs/textures/mobs_nametag.png differ diff --git a/mods/mobs/textures/mobs_net.png b/mods/mobs/textures/mobs_net.png new file mode 100644 index 00000000..df7c3a61 Binary files /dev/null and b/mods/mobs/textures/mobs_net.png differ diff --git a/mods/mobs/textures/mobs_noentry_particle.png b/mods/mobs/textures/mobs_noentry_particle.png new file mode 100644 index 00000000..87938ff4 Binary files /dev/null and b/mods/mobs/textures/mobs_noentry_particle.png differ diff --git a/mods/mobs/textures/mobs_protect_particle.png b/mods/mobs/textures/mobs_protect_particle.png new file mode 100644 index 00000000..debe20cb Binary files /dev/null and b/mods/mobs/textures/mobs_protect_particle.png differ diff --git a/mods/mobs/textures/mobs_protector.png b/mods/mobs/textures/mobs_protector.png new file mode 100644 index 00000000..f3937b70 Binary files /dev/null and b/mods/mobs/textures/mobs_protector.png differ diff --git a/mods/mobs/textures/mobs_saddle.png b/mods/mobs/textures/mobs_saddle.png new file mode 100644 index 00000000..e9d42f82 Binary files /dev/null and b/mods/mobs/textures/mobs_saddle.png differ diff --git a/mods/mobs/textures/mobs_shears.png b/mods/mobs/textures/mobs_shears.png new file mode 100644 index 00000000..aa16f2ec Binary files /dev/null and b/mods/mobs/textures/mobs_shears.png differ diff --git a/mods/mobs/textures/tnt_smoke.png b/mods/mobs/textures/tnt_smoke.png new file mode 100644 index 00000000..488b50fe Binary files /dev/null and b/mods/mobs/textures/tnt_smoke.png differ diff --git a/mods/mobs_monster/depends.txt b/mods/mobs_monster/depends.txt new file mode 100644 index 00000000..d0aea36f --- /dev/null +++ b/mods/mobs_monster/depends.txt @@ -0,0 +1,5 @@ +default +mobs +intllib? +lucky_block? +toolranks? diff --git a/mods/mobs_monster/description.txt b/mods/mobs_monster/description.txt new file mode 100644 index 00000000..ac3d8870 --- /dev/null +++ b/mods/mobs_monster/description.txt @@ -0,0 +1 @@ +Adds many types of monster. diff --git a/mods/mobs_monster/init.lua b/mods/mobs_monster/init.lua new file mode 100644 index 00000000..d7d28003 --- /dev/null +++ b/mods/mobs_monster/init.lua @@ -0,0 +1,25 @@ + +local path = minetest.get_modpath("mobs_monster") + +-- Intllib +local S +if minetest.global_exists("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + S = intllib.make_gettext_pair() + else + -- Old method using text files. + S = intllib.Getter() + end +else + S = function(s) return s end +end +mobs.intllib = S + +-- Monsters + +dofile(path .. "/tusken_raider.lua") + +dofile(path .. "/lucky_block.lua") + +print ("[MOD] Mobs Redo Monsters loaded") diff --git a/mods/mobs_monster/license.txt b/mods/mobs_monster/license.txt new file mode 100644 index 00000000..cb50163b --- /dev/null +++ b/mods/mobs_monster/license.txt @@ -0,0 +1,32 @@ +The MIT License (MIT) + +Copyright (c) 2016 TenPlus1 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +mobs.fireball.png was originally made by Sapier and edited by Benrob: + +-- Animals Mod by Sapier +-- +-- You may copy, use, modify or do nearly anything except removing this +-- copyright notice. +-- And of course you are NOT allow to pretend you have written it. +-- +-- (c) Sapier +-- Contact sapier a t gmx net diff --git a/mods/mobs_monster/lucky_block.lua b/mods/mobs_monster/lucky_block.lua new file mode 100644 index 00000000..c9aeceac --- /dev/null +++ b/mods/mobs_monster/lucky_block.lua @@ -0,0 +1,42 @@ + +if minetest.get_modpath("lucky_block") then + + local web = {name = "mobs:cobweb"} + local web_trap = { + size = {x = 3, y = 3, z = 3}, + data = { + web, web, web, + web, web, web, + web, web, web, + + web, web, web, + web, web, web, + web, web, web, + + web, web, web, + web, web, web, + web, web, web, + }, + } + + lucky_block:add_schematics({ + {"webtrap", web_trap, {x = 1, y = 0, z = 1}}, + }) + + lucky_block:add_blocks({ + {"sch", "webtrap", 1, true}, + {"spw", "mobs:dungeon_master", 1, nil, nil, 3, "Billy"}, + {"spw", "mobs:sand_monster", 3}, + {"spw", "mobs:stone_monster", 3, nil, nil, 3, "Bob"}, + {"spw", "mobs:dirt_monster", 3}, + {"spw", "mobs:tree_monster", 3}, + {"spw", "mobs:oerkki", 3}, + {"exp"}, + {"spw", "mobs:spider", 5}, + {"spw", "mobs:mese_monster", 2}, + {"spw", "mobs:lava_flan", 3}, + {"nod", "default:chest", 0, { + {name = "mobs:lava_orb", max = 1}}}, + }) + +end diff --git a/mods/mobs_monster/mod.conf b/mods/mobs_monster/mod.conf new file mode 100644 index 00000000..3c4fe390 --- /dev/null +++ b/mods/mobs_monster/mod.conf @@ -0,0 +1 @@ +name = mobs_monster diff --git a/mods/mobs_monster/models/mobs_character.b3d b/mods/mobs_monster/models/mobs_character.b3d new file mode 100644 index 00000000..9ab45436 Binary files /dev/null and b/mods/mobs_monster/models/mobs_character.b3d differ diff --git a/mods/mobs_monster/readme.md b/mods/mobs_monster/readme.md new file mode 100644 index 00000000..8a02c17a --- /dev/null +++ b/mods/mobs_monster/readme.md @@ -0,0 +1,40 @@ + +MONSTER MOBS + +Dirt Monster + +- Spawning at night on green grass (or grey in ethereal) these mobs wander around looking for a player to eat. Drops 1-5 dirt when killed. + +Dungeon Master + +- Spawning below -70 underground DM's have a tendency to hurl fire balls at unsuspecting players and can cause major damage, but get too close and he will switch to dogfight attack. Can drop mese or diamond when killed. + +Lava Flan + +- Cute as they may look lava flan wallow in their namesake (no, not flans) and get curious about players who wander by, forgetting that they can burn you and cause damage. They have a 1 in 5 chance of dropping lava orb when killed. + +Mese Monster + +- These mobs are territorial and spawn below -20 and will fire mese shards at passers by, so best avoided. Will drop mese when killed. + +Oerkki + +- Found in dark areas like most monsters Oerkki wander the caverns stealing away torches on the ground and attacking anyone found in that area. 1 in 3 chance of dropping obsidian. + +Sand Monster + +- The hot deserts are home to these guys who spawn at any time of the day to attack players. They drop 3-5 desert sand when killed. + +Spiders + +- Snowy spiders are found on higher cold areas, Tarantula's in higher jungle, Cave spider below -20 and Mese spider near areas containing the ore and Crystal spiders only in Ethereal's crystal biomes. Some are docile during the daytime and will drop string when killed. + +Stone Monster + +- Found underground in dark caves these mobs seem to be zombie-like in fashion with a tendency to rush a player in the area. can drop torch, iron or coal when killed. + +Tree Monster + +- Found atop tree's at night time they drop down and look for food in the form of players and animals. Can drop saplings and sometimes an apple or three. + +Lucky Blocks: 11 diff --git a/mods/mobs_monster/sounds/mobs_sandmonster.ogg b/mods/mobs_monster/sounds/mobs_sandmonster.ogg new file mode 100644 index 00000000..2feae6ae Binary files /dev/null and b/mods/mobs_monster/sounds/mobs_sandmonster.ogg differ diff --git a/mods/mobs_monster/textures/mobs_sand_particles.png b/mods/mobs_monster/textures/mobs_sand_particles.png new file mode 100644 index 00000000..d8822313 Binary files /dev/null and b/mods/mobs_monster/textures/mobs_sand_particles.png differ diff --git a/mods/mobs_monster/textures/mobs_tusken_raider.png b/mods/mobs_monster/textures/mobs_tusken_raider.png new file mode 100644 index 00000000..ec364185 Binary files /dev/null and b/mods/mobs_monster/textures/mobs_tusken_raider.png differ diff --git a/mods/mobs_monster/tusken_raider.lua b/mods/mobs_monster/tusken_raider.lua new file mode 100644 index 00000000..87cc8e5a --- /dev/null +++ b/mods/mobs_monster/tusken_raider.lua @@ -0,0 +1,123 @@ + +local S = mobs.intllib + + +-- custom particle effects +local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow) + + radius = radius or 2 + min_size = min_size or 0.5 + max_size = max_size or 1 + gravity = gravity or -10 + glow = glow or 0 + + minetest.add_particlespawner({ + amount = amount, + time = 0.25, + minpos = pos, + maxpos = pos, + minvel = {x = -radius, y = -radius, z = -radius}, + maxvel = {x = radius, y = radius, z = radius}, + minacc = {x = 0, y = gravity, z = 0}, + maxacc = {x = -20, y = gravity, z = 15}, + minexptime = 0.1, + maxexptime = 1, + minsize = min_size, + maxsize = max_size, + texture = texture, + glow = glow, + }) +end + + +-- Sand Monster by PilzAdam + +mobs:register_mob("mobs_monster:tusken_raider", { + type = "monster", + passive = false, + attack_type = "dogfight", + pathfinding = true, + --specific_attack = {"player", "mobs_npc:npc"}, + reach = 2, + damage = 1, + hp_min = 4, + hp_max = 20, + armor = 100, + collisionbox = {-0.4, -1, -0.4, 0.4, 0.8, 0.4}, + visual = "mesh", + mesh = "mobs_character.b3d", + textures = { + {"mobs_tusken_raider.png"}, + }, + blood_texture = "default_desert_sand.png", + makes_footstep_sound = true, + sounds = { + random = "mobs_sandmonster", + }, + walk_velocity = 1.5, + run_velocity = 4, + view_range = 8, --15 + jump = true, + floats = 0, + drops = { + {name = "default:desert_sand", chance = 1, min = 3, max = 5}, + }, + water_damage = 3, + lava_damage = 4, + light_damage = 0, + fear_height = 4, + animation = { + speed_normal = 30, + speed_run = 30, + stand_start = 0, + stand_end = 79, + walk_start = 168, + walk_end = 187, + run_start = 168, + run_end = 187, + punch_start = 200, + punch_end = 219, + }, +--[[ + custom_attack = function(self, p) + local pos = self.object:get_pos() + minetest.add_item(pos, "default:sand") + end, +]] + on_die = function(self, pos) + pos.y = pos.y + 0.5 + effect(pos, 30, "mobs_sand_particles.png", 0.1, 2, 3, 5) + pos.y = pos.y + 0.25 + effect(pos, 30, "mobs_sand_particles.png", 0.1, 2, 3, 5) + end, +--[[ + on_rightclick = function(self, clicker) + + local tool = clicker:get_wielded_item() + local name = clicker:get_player_name() + + if tool:get_name() == "default:sand" then + + self.owner = name + self.type = "npc" + + mobs:force_capture(self, clicker) + end + end, +]] +}) + + +mobs:spawn({ + name = "mobs_monster:tusken_raider", + nodes = {"default:desert_sand"}, + chance = 7000, + active_object_count = 2, + min_height = 0, +}) + + +mobs:register_egg("mobs_monster:tusken_raider", S("Tusken Raider"), "default_desert_sand.png", 1) + + +mobs:alias_mob("mobs:tusken_raider", "mobs_monster:tusken_raider") -- compatibility diff --git a/mods/stamina/.luacheckrc b/mods/stamina/.luacheckrc new file mode 100644 index 00000000..a6b40039 --- /dev/null +++ b/mods/stamina/.luacheckrc @@ -0,0 +1,20 @@ +unused_args = false +allow_defined_top = true + +read_globals = { + "DIR_DELIM", + "minetest", + "dump", + "vector", "nodeupdate", + "VoxelManip", "VoxelArea", + "PseudoRandom", "ItemStack", + "intllib", + "default", + "armor", + "player_monoids", +} + +globals = { + minetest = { fields = { "do_item_eat" }}, +} + diff --git a/mods/stamina/API.txt b/mods/stamina/API.txt new file mode 100644 index 00000000..334a2d0f --- /dev/null +++ b/mods/stamina/API.txt @@ -0,0 +1,64 @@ +stamina.get_saturation(player) + Gets a player's saturation + +stamina.set_saturation(player, level) + Set a player's saturation. + Updates the HUD to reflect saturation level. + +stamina.update_saturation(player, level) + Update's a player's saturation. + Callbacks are processed first. + +stamina.change_saturation(player, change) + Update a player's saturation by a delta, instead of an absolute value. + +stamina.register_on_update_saturation(function(player, level)) + Register a callback for when saturation is updated. + If the callback returns True, no further callbacks are called, + and the default behavior is bypassed. +----------------------- +stamina.is_poisoned(player) + Check if a player is poisoned + +stamina.set_poisoned(player, poisoned) + Set a player's "poisoned" status (boolean) + Updates the HUD to reflect poison status. + +stamina.poison(player, ticks, interval) + Poison a player for a certain amount of time. + Ticks is how many times to poison the player. + Interval is the time between poison ticks. + Processes callbacks before changing status. + +stamina.register_on_poison(function(player, ticks, interval)) + Register a callback for when a player is poisoned. + If the callback returns True, no further callbacks are called, + and the default behavior is bypassed. +------------------------- +stamina.get_exhaustion(player) + Gets a player's exhaustion level. + Value is between 0 and `stamina.exhaust_lvl` (default: 160) + +stamina.set_exhaustion(player, level) + Sets a player's exhaustion level. + +stamina.exhaust_player(player, change, cause) + Update a player's exhaustion by "change". + If the player's exhaustion exceeds `stamina.exhaust_lvl`, stamina + is taken and exhaustion is reset. + Cause is an optional argument indicating the origin of the exhaustion. + Callbacks are processed before exhausting the player. + +stamina.register_on_exhaust_player(function(player, change, cause)) + Register a callback for when exhaustion is updated. + If the callback returns True, no further callbacks are called, + and the default behavior is bypassed. +------------------------ +stamina.set_sprinting(name, sprinting) + Sets whether a player is sprinting or not. + Callbacks are processed before setting sprint status. + +stamina.register_on_sprinting(function(player, sprinting)) + Register a callback for when a player's sprinting status is updated. + If the callback returns True, no further callbacks are called, + and the default behavior is bypassed. diff --git a/mods/stamina/README.txt b/mods/stamina/README.txt new file mode 100644 index 00000000..388c32bf --- /dev/null +++ b/mods/stamina/README.txt @@ -0,0 +1,50 @@ +Minetest mod "Stamina" +===================== + +(C) 2015 - BlockMen +(C) 2016 - Auke Kok + + +About this mod: +--------------- +This mod adds a stamina, or "hunger" mechanic to Minetest. Actions like +crafting, walking, digging or fighting make the player exhausted. When +enough exhaustion has been accumulated, the player gets more hungry, +and loses stamina. + +If a player is low on stamina, they start taking periodical damage, +and ultimately will die if they do not eat food. + +Eating food no longer heals the player. Instead, it increases the +stamina of the player. The stamina bar shows how well fed the player +is. More bread pieces means more stamina. + + +Q&A time: Why won't I move the stamina bar to the right? + +Answer: this conflicts with the builtin breath bar. To move the +builtin breath bar, I basically have to entirely re-implement it +in lua including timers to catch breath changes for each online +player, which is all a waste of time, just to move a few pixels +around. + + +For Modders: +------------ +This mod intercepts minetest.item_eat(), and applies the hp_change +as stamina change. The value can be positive (increase stamina) or +negative (periodically damage the player by 1 hp). + +See API.txt for information on the API. + +License: +-------- +Code: +- all code LGPL-2.1+ +Textures: +- stamina_hud_poison.png - BlockMen (CC-BY 3.0) +- stamina_hud_fg.png - PilzAdam (WTFPL), modified by BlockMen +- stamina_hud_bg.png - PilzAdam (WTFPL), modified by BlockMen +Sounds: +- stamina_eat.*.ogg - http://www.freesound.org/people/sonictechtonic/sounds/242215/ CC-BY-3.0 + diff --git a/mods/stamina/bower.json b/mods/stamina/bower.json new file mode 100644 index 00000000..34362013 --- /dev/null +++ b/mods/stamina/bower.json @@ -0,0 +1,14 @@ +{ + "name": "stamina", + "description": "This mod adds a stamina, or hunger mechanic to Minetest. Actions like crafting, walking, digging or fighting make the player exhausted.", + "homepage": "https://github.com/minetest-mods/stamina", + "authors": [ + "BlockMen - 2015", + "Auke Kok - 2016" + ], + "license": "LGPL-2.1+", + "keywords": [ + "hunger", + "stamina" + ] +} \ No newline at end of file diff --git a/mods/stamina/depends.txt b/mods/stamina/depends.txt new file mode 100644 index 00000000..bdb6c204 --- /dev/null +++ b/mods/stamina/depends.txt @@ -0,0 +1,3 @@ +default +3d_armor? +player_monoids? diff --git a/mods/stamina/description.txt b/mods/stamina/description.txt new file mode 100644 index 00000000..1074b3d4 --- /dev/null +++ b/mods/stamina/description.txt @@ -0,0 +1 @@ +Adds stamina and hunger effects. diff --git a/mods/stamina/init.lua b/mods/stamina/init.lua new file mode 100644 index 00000000..2fb6efde --- /dev/null +++ b/mods/stamina/init.lua @@ -0,0 +1,522 @@ +if not minetest.settings:get_bool("enable_damage") then + minetest.log("warning", "[stamina] Stamina will not load if damage is disabled (enable_damage=false)") + return +end + +stamina = {} +local modname = minetest.get_current_modname() +local armor_mod = minetest.get_modpath("3d_armor") and minetest.global_exists("armor") and armor.def +local player_monoids_mod = minetest.get_modpath("player_monoids") and minetest.global_exists("player_monoids") + +function stamina.log(level, message, ...) + return minetest.log(level, ("[%s] %s"):format(modname, message:format(...))) +end + +local function get_setting(key, default) + local setting = minetest.settings:get("stamina." .. key) + if setting and not tonumber(setting) then + stamina.log("warning", "Invalid value for setting %s: %q. Using default %q.", key, setting, default) + end + return tonumber(setting) or default +end + +stamina.settings = { + -- see settingtypes.txt for descriptions + eat_particles = minetest.settings:get_bool("stamina.eat_particles", true), + sprint = minetest.settings:get_bool("stamina.sprint", true), + sprint_particles = minetest.settings:get_bool("stamina.sprint_particles", true), + sprint_lvl = get_setting("sprint_lvl", 6), + sprint_speed = get_setting("sprint_speed", 0.8), + sprint_jump = get_setting("sprint_jump", 0.1), + tick = get_setting("tick", 800), + tick_min = get_setting("tick_min", 4), + health_tick = get_setting("health_tick", 4), + move_tick = get_setting("move_tick", 0.5), + poison_tick = get_setting("poison_tick", 2.0), + exhaust_dig = get_setting("exhaust_dig", 3), + exhaust_place = get_setting("exhaust_place", 1), + exhaust_move = get_setting("exhaust_move", 1.5), + exhaust_jump = get_setting("exhaust_jump", 5), + exhaust_craft = get_setting("exhaust_craft", 20), + exhaust_punch = get_setting("exhaust_punch", 40), + exhaust_sprint = get_setting("exhaust_sprint", 28), + exhaust_lvl = get_setting("exhaust_lvl", 160), + heal = get_setting("heal", 1), + heal_lvl = get_setting("heal_lvl", 5), + starve = get_setting("starve", 1), + starve_lvl = get_setting("starve_lvl", 3), + visual_max = get_setting("visual_max", 20), +} +local settings = stamina.settings + +local attribute = { + saturation = "stamina:level", + hud_id = "stamina:hud_id", + poisoned = "stamina:poisoned", + exhaustion = "stamina:exhaustion", +} + +local function is_player(player) + return ( + player and + not player.is_fake_player and + player.get_attribute and -- check for pipeworks fake player + player.is_player and + player:is_player() + ) +end + +local function get_int_attribute(player, key) + local level = player:get_attribute(key) + if level then + return tonumber(level) + else + return nil + end +end +--- SATURATION API --- +function stamina.get_saturation(player) + return get_int_attribute(player, attribute.saturation) +end + +function stamina.set_saturation(player, level) + player:set_attribute(attribute.saturation, level) + player:hud_change( + player:get_attribute(attribute.hud_id), + "number", + math.min(settings.visual_max, level) + ) +end + +stamina.registered_on_update_saturations = {} +function stamina.register_on_update_saturation(fun) + table.insert(stamina.registered_on_update_saturations, fun) +end + +function stamina.update_saturation(player, level) + for _, callback in ipairs(stamina.registered_on_update_saturations) do + local result = callback(player, level) + if result then + return result + end + end + + local old = stamina.get_saturation(player) + + if level == old then -- To suppress HUD update + return + end + + -- players without interact priv cannot eat + if old < settings.heal_lvl and not minetest.check_player_privs(player, {interact=true}) then + return + end + + stamina.set_saturation(player, level) +end + +function stamina.change_saturation(player, change) + if not is_player(player) or not change or change == 0 then + return false + end + local level = stamina.get_saturation(player) + change + level = math.max(level, 0) + level = math.min(level, settings.visual_max) + stamina.update_saturation(player, level) + return true +end + +stamina.change = stamina.change_saturation -- for backwards compatablity +--- END SATURATION API --- +--- POISON API --- +function stamina.is_poisoned(player) + return player:get_attribute(attribute.poisoned) == "yes" +end + +function stamina.set_poisoned(player, poisoned) + if poisoned then + player:hud_change(player:get_attribute(attribute.hud_id), "text", "stamina_hud_poison.png") + player:set_attribute(attribute.poisoned, "yes") + else + player:hud_change(player:get_attribute(attribute.hud_id), "text", "stamina_hud_fg.png") + player:set_attribute(attribute.poisoned, "no") + end +end + +local function poison_tick(player, ticks, interval, elapsed) + if not stamina.is_poisoned(player) then + return + elseif elapsed > ticks then + stamina.set_poisoned(player, false) + else + local hp = player:get_hp() - 1 + if hp > 0 then + player:set_hp(hp) + end + minetest.after(interval, poison_tick, player, ticks, interval, elapsed + 1) + end +end + +stamina.registered_on_poisons = {} +function stamina.register_on_poison(fun) + table.insert(stamina.registered_on_poisons, fun) +end + +function stamina.poison(player, ticks, interval) + for _, fun in ipairs(stamina.registered_on_poisons) do + local rv = fun(player, ticks, interval) + if rv == true then + return + end + end + if not is_player(player) then + return + end + stamina.set_poisoned(player, true) + poison_tick(player, ticks, interval, 0) +end +--- END POISON API --- +--- EXHAUSTION API --- +stamina.exhaustion_reasons = { + craft = "craft", + dig = "dig", + heal = "heal", + jump = "jump", + move = "move", + place = "place", + punch = "punch", + sprint = "sprint", +} + +function stamina.get_exhaustion(player) + return get_int_attribute(player, attribute.exhaustion) +end + +function stamina.set_exhaustion(player, exhaustion) + player:set_attribute(attribute.exhaustion, exhaustion) +end + +stamina.registered_on_exhaust_players = {} +function stamina.register_on_exhaust_player(fun) + table.insert(stamina.registered_on_exhaust_players, fun) +end + +function stamina.exhaust_player(player, change, cause) + for _, callback in ipairs(stamina.registered_on_exhaust_players) do + local result = callback(player, change, cause) + if result then + return result + end + end + + if not is_player(player) then + return + end + + local exhaustion = stamina.get_exhaustion(player) or 0 + + exhaustion = exhaustion + change + + if exhaustion >= settings.exhaust_lvl then + exhaustion = exhaustion - settings.exhaust_lvl + stamina.change(player, -1) + end + + stamina.set_exhaustion(player, exhaustion) +end +--- END EXHAUSTION API --- +--- SPRINTING API --- +stamina.registered_on_sprintings = {} +function stamina.register_on_sprinting(fun) + table.insert(stamina.registered_on_sprintings, fun) +end + +function stamina.set_sprinting(player, sprinting) + for _, fun in ipairs(stamina.registered_on_sprintings) do + local rv = fun(player, sprinting) + if rv == true then + return + end + end + + if player_monoids_mod then + if sprinting then + player_monoids.speed:add_change(player, 1 + settings.sprint_speed, "stamina:physics") + player_monoids.jump:add_change(player, 1 + settings.sprint_jump, "stamina:physics") + else + player_monoids.speed:del_change(player, "stamina:physics") + player_monoids.jump:del_change(player, "stamina:physics") + end + else + local def + if armor_mod then + -- Get player physics from 3d_armor mod + local name = player:get_player_name() + def = { + speed=armor.def[name].speed, + jump=armor.def[name].jump, + gravity=armor.def[name].gravity + } + else + def = { + speed=1, + jump=1, + gravity=1 + } + end + + if sprinting then + def.speed = def.speed + settings.sprint_speed + def.jump = def.jump + settings.sprint_jump + end + + player:set_physics_override(def) + end + + if settings.sprint_particles and sprinting then + local pos = player:getpos() + local node = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) + local def = minetest.registered_nodes[node.name] or {} + local drawtype = def.drawtype + if drawtype ~= "airlike" and drawtype ~= "liquid" and drawtype ~= "flowingliquid" then + minetest.add_particlespawner({ + amount = 5, + time = 0.01, + minpos = {x = pos.x - 0.25, y = pos.y + 0.1, z = pos.z - 0.25}, + maxpos = {x = pos.x + 0.25, y = pos.y + 0.1, z = pos.z + 0.25}, + minvel = {x = -0.5, y = 1, z = -0.5}, + maxvel = {x = 0.5, y = 2, z = 0.5}, + minacc = {x = 0, y = -5, z = 0}, + maxacc = {x = 0, y = -12, z = 0}, + minexptime = 0.25, + maxexptime = 0.5, + minsize = 0.5, + maxsize = 1.0, + vertical = false, + collisiondetection = false, + texture = "default_dirt.png", + }) + end + end +end +--- END SPRINTING API --- + +-- Time based stamina functions +local function move_tick() + for _,player in ipairs(minetest.get_connected_players()) do + local controls = player:get_player_control() + local is_moving = controls.up or controls.down or controls.left or controls.right + local velocity = player:get_player_velocity() + velocity.y = 0 + local horizontal_speed = vector.length(velocity) + local has_velocity = horizontal_speed > 0.05 + + if controls.jump then + stamina.exhaust_player(player, settings.exhaust_jump, stamina.exhaustion_reasons.jump) + elseif is_moving and has_velocity then + stamina.exhaust_player(player, settings.exhaust_move, stamina.exhaustion_reasons.move) + end + + if settings.sprint then + local can_sprint = ( + controls.aux1 and + not player:get_attach() and + not minetest.check_player_privs(player, {fast = true}) and + stamina.get_saturation(player) > settings.sprint_lvl + ) + + if can_sprint then + stamina.set_sprinting(player, true) + if is_moving and has_velocity then + stamina.exhaust_player(player, settings.exhaust_sprint, stamina.exhaustion_reasons.sprint) + end + else + stamina.set_sprinting(player, false) + end + end + end +end + +local function stamina_tick() + -- lower saturation by 1 point after settings.tick second(s) + for _,player in ipairs(minetest.get_connected_players()) do + local saturation = stamina.get_saturation(player) + if saturation > settings.tick_min then + stamina.update_saturation(player, saturation - 1) + end + end +end + +local function health_tick() + -- heal or damage player, depending on saturation + for _,player in ipairs(minetest.get_connected_players()) do + local air = player:get_breath() or 0 + local hp = player:get_hp() + local saturation = stamina.get_saturation(player) + + -- don't heal if dead, drowning, or poisoned + local should_heal = ( + saturation >= settings.heal_lvl and + saturation >= hp and + hp > 0 and + air > 0 + and not stamina.is_poisoned(player) + ) + -- or damage player by 1 hp if saturation is < 2 (of 30) + local is_starving = ( + saturation < settings.starve_lvl and + hp > 0 + ) + + if should_heal then + player:set_hp(hp + settings.heal) + stamina.exhaust_player(player, settings.exhaust_lvl, stamina.exhaustion_reasons.heal) + elseif is_starving then + player:set_hp(hp - settings.starve) + end + end +end + +local stamina_timer = 0 +local health_timer = 0 +local action_timer = 0 + +local function stamina_globaltimer(dtime) + stamina_timer = stamina_timer + dtime + health_timer = health_timer + dtime + action_timer = action_timer + dtime + + if action_timer > settings.move_tick then + action_timer = 0 + move_tick() + end + + if stamina_timer > settings.tick then + stamina_timer = 0 + stamina_tick() + end + + if health_timer > settings.health_tick then + health_timer = 0 + health_tick() + end +end + +-- override minetest.do_item_eat() so we can redirect hp_change to stamina +stamina.core_item_eat = minetest.do_item_eat +function minetest.do_item_eat(hp_change, replace_with_item, itemstack, player, pointed_thing) + for _, callback in ipairs(minetest.registered_on_item_eats) do + local result = callback(hp_change, replace_with_item, itemstack, player, pointed_thing) + if result then + return result + end + end + + if not is_player(player) or not itemstack then + return itemstack + end + + local level = stamina.get_saturation(player) or 0 + if level >= settings.visual_max then + -- don't eat if player is full + return itemstack + end + + local itemname = itemstack:get_name() + if replace_with_item then + stamina.log("action", "%s eats %s for %s stamina, replace with %s", + player:get_player_name(), itemname, hp_change, replace_with_item) + else + stamina.log("action", "%s eats %s for %s stamina", + player:get_player_name(), itemname, hp_change) + end + minetest.sound_play("stamina_eat", {to_player = player:get_player_name(), gain = 0.7}) + + if hp_change > 0 then + stamina.change_saturation(player, hp_change) + stamina.set_exhaustion(player, 0) + else + -- assume hp_change < 0. + stamina.poison(player, -hp_change, settings.poison_tick) + end + + if settings.eat_particles then + -- particle effect when eating + local pos = player:getpos() + pos.y = pos.y + 1.5 -- mouth level + local texture = minetest.registered_items[itemname].inventory_image + local dir = player:get_look_dir() + + minetest.add_particlespawner({ + amount = 5, + time = 0.1, + minpos = pos, + maxpos = pos, + minvel = {x = dir.x - 1, y = dir.y, z = dir.z - 1}, + maxvel = {x = dir.x + 1, y = dir.y, z = dir.z + 1}, + minacc = {x = 0, y = -5, z = 0}, + maxacc = {x = 0, y = -9, z = 0}, + minexptime = 1, + maxexptime = 1, + minsize = 1, + maxsize = 2, + texture = texture, + }) + end + + itemstack:take_item() + + if replace_with_item then + if itemstack:is_empty() then + itemstack:add_item(replace_with_item) + else + local inv = player:get_inventory() + if inv:room_for_item("main", {name=replace_with_item}) then + inv:add_item("main", replace_with_item) + else + local pos = player:getpos() + pos.y = math.floor(pos.y - 1.0) + minetest.add_item(pos, replace_with_item) + end + end + end + + return itemstack +end + +minetest.register_on_joinplayer(function(player) + local level = stamina.get_saturation(player) or settings.visual_max + local id = player:hud_add({ + name = "stamina", + hud_elem_type = "statbar", + position = {x = 0.5, y = 1}, + size = {x = 24, y = 24}, + text = "stamina_hud_fg.png", + number = level, + alignment = {x = -1, y = -1}, + offset = {x = -266, y = -110}, + max = 0, + }) + stamina.set_saturation(player, level) + player:set_attribute(attribute.hud_id, id) + -- reset poisoned + stamina.set_poisoned(player, false) +end) + +minetest.register_globalstep(stamina_globaltimer) + +minetest.register_on_placenode(function(pos, oldnode, player, ext) + stamina.exhaust_player(player, settings.exhaust_place, stamina.exhaustion_reasons.place) +end) +minetest.register_on_dignode(function(pos, oldnode, player, ext) + stamina.exhaust_player(player, settings.exhaust_dig, stamina.exhaustion_reasons.dig) +end) +minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) + stamina.exhaust_player(player, settings.exhaust_craft, stamina.exhaustion_reasons.craft) +end) +minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + stamina.exhaust_player(hitter, settings.exhaust_punch, stamina.exhaustion_reasons.punch) +end) +minetest.register_on_respawnplayer(function(player) + stamina.update_saturation(player, settings.visual_max) +end) diff --git a/mods/stamina/mod.conf b/mods/stamina/mod.conf new file mode 100644 index 00000000..b049a5a0 --- /dev/null +++ b/mods/stamina/mod.conf @@ -0,0 +1 @@ +name = stamina diff --git a/mods/stamina/screenshot.png b/mods/stamina/screenshot.png new file mode 100644 index 00000000..4ea1cb01 Binary files /dev/null and b/mods/stamina/screenshot.png differ diff --git a/mods/stamina/settingtypes.txt b/mods/stamina/settingtypes.txt new file mode 100644 index 00000000..310199d8 --- /dev/null +++ b/mods/stamina/settingtypes.txt @@ -0,0 +1,23 @@ +stamina.enabled (Is stamina enabled?) bool true +stamina.sprint (Is sprint enabled?) bool true +stamina.sprint_particles (Are sprint particles enabled?) bool true +stamina.tick (time in seconds after that 1 saturation point is taken) float 800 +stamina.tick_min (stamina ticks won't reduce saturation below this level) int 4 +stamina.health_tick (time in seconds after player gets healed/damaged) float 4 +stamina.move_tick (time in seconds after the movement is checked) float 0.5 +stamina.exhaust_dig (exhaustion for digging a node) float 3 +stamina.exhaust_place (exhaustion for placing a node) float 1 +stamina.exhaust_move (exhaustion for moving) float 1.5 +stamina.exhaust_jump (exhaustion for jumping) float 5 +stamina.exhaust_craft (exhaustion for crafting) float 20 +stamina.exhaust_punch (exhaustion for punching) float 40 +stamina.exhaust_sprint (exhaustion for sprinting) float 28 +stamina.exhaust_lvl (exhaustion level at which saturation gets lowered) float 160 +stamina.heal (amount of HP a player gains per stamina.health_tick) int 1 0 20 +stamina.heal_lvl (minimum saturation needed for healing) int 5 1 20 +stamina.starve (amount of HP a player loses per stamina.health_tick) int 1 0 20 +stamina.starve_lvl (maximum stamina needed for starving) int 3 0 19 +stamina.visual_max (hud bar only extends to 20) int 20 2 20 +stamina.sprint_speed (how much faster a player can run if satiated) float 0.8 0 2 +stamina.sprint_jump (how much faster a player can jump if satiated) float 0.1 0 2 +stamina.eat_particles (Whether to generate particles when eating) bool true diff --git a/mods/stamina/sounds/stamina_eat.1.ogg b/mods/stamina/sounds/stamina_eat.1.ogg new file mode 100644 index 00000000..da2b68b2 Binary files /dev/null and b/mods/stamina/sounds/stamina_eat.1.ogg differ diff --git a/mods/stamina/sounds/stamina_eat.2.ogg b/mods/stamina/sounds/stamina_eat.2.ogg new file mode 100644 index 00000000..edca4239 Binary files /dev/null and b/mods/stamina/sounds/stamina_eat.2.ogg differ diff --git a/mods/stamina/sounds/stamina_eat.3.ogg b/mods/stamina/sounds/stamina_eat.3.ogg new file mode 100644 index 00000000..1f06ea58 Binary files /dev/null and b/mods/stamina/sounds/stamina_eat.3.ogg differ diff --git a/mods/stamina/textures/stamina_hud_bg.png b/mods/stamina/textures/stamina_hud_bg.png new file mode 100644 index 00000000..07e21e7b Binary files /dev/null and b/mods/stamina/textures/stamina_hud_bg.png differ diff --git a/mods/stamina/textures/stamina_hud_fg.png b/mods/stamina/textures/stamina_hud_fg.png new file mode 100644 index 00000000..a5cc2a12 Binary files /dev/null and b/mods/stamina/textures/stamina_hud_fg.png differ diff --git a/mods/stamina/textures/stamina_hud_poison.png b/mods/stamina/textures/stamina_hud_poison.png new file mode 100644 index 00000000..0f80ad26 Binary files /dev/null and b/mods/stamina/textures/stamina_hud_poison.png differ diff --git a/mods/unified_inventory/.gitignore b/mods/unified_inventory/.gitignore new file mode 100644 index 00000000..5236e1e4 --- /dev/null +++ b/mods/unified_inventory/.gitignore @@ -0,0 +1,2 @@ +*~ + diff --git a/mods/unified_inventory/LICENSE.txt b/mods/unified_inventory/LICENSE.txt new file mode 100644 index 00000000..32492e43 --- /dev/null +++ b/mods/unified_inventory/LICENSE.txt @@ -0,0 +1,19 @@ +Unified Inventory for Minetest +Copyright (C) 2012-2014 Maciej Kasatkin (RealBadAngel) + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Contact information: + Examine a git patch to get the contributor's email address. diff --git a/mods/unified_inventory/README.md b/mods/unified_inventory/README.md new file mode 100644 index 00000000..15802c6e --- /dev/null +++ b/mods/unified_inventory/README.md @@ -0,0 +1,96 @@ +# Unified Inventory + +Unified Inventory replaces the default survival and creative inventory. + + +## Features + + * Node, item and tool browser + * Crafting guide + * Can copy the recipe to the crafting grid + * Recipe search function by ingredients + * Up to four bags with up to 24 slots each + * Home function to teleport + * Trash slot + * Lite mode: reduces the item browser width + * Mod API for modders: see [mod_api.txt](doc/mod_api.txt) + * Setting-determinated features: see [settingtypes.txt](settingtypes.txt) + + +## Requirements + + * Minetest 5.0.0+ since commit 4403b69 + * Minetest 0.4.16+ prior commit 4403b69 + + +# Licenses + +Copyright (C) 2012-2014 Maciej Kasatkin (RealBadAngel) + +Copyright (C) 2012-? Various minetest-mods contributors + + +## Code + +GNU LGPLv2+, see [license notice](LICENSE.txt) + + +## Textures + +VanessaE: (CC-BY-4.0) + + * `ui_group.png` + +Tango Project: (Public Domain, CC-BY-4.0) + + * [`ui_reset_icon.png`](https://commons.wikimedia.org/wiki/File:Edit-clear.svg) + * [`ui_doubleleft_icon.png`](http://commons.wikimedia.org/wiki/File:Media-seek-backward.svg) + * [`ui_doubleright_icon.png`](http://commons.wikimedia.org/wiki/File:Media-seek-forward.svg) + * [`ui_left_icon.png` / `ui_right_icon.png`](http://commons.wikimedia.org/wiki/File:Media-playback-start.svg) + * [`ui_skip_backward_icon.png`](http://commons.wikimedia.org/wiki/File:Media-skip-backward.svg) + * [`ui_skip_forward_icon.png`](http://commons.wikimedia.org/wiki/File:Media-skip-forward.svg) + +From http://www.clker.com (Public Domain, CC-BY-4.0): + + * [`bags_small.png`](http://www.clker.com/clipart-moneybag-empty.html) + * [`bags_medium.png`](http://www.clker.com/clipart-backpack-1.html) + * [`bags_large.png` / `ui_bags_icon.png`](http://www.clker.com/clipart-backpack-green-brown.html) + * `ui_trash_icon.png`: and + * [`ui_search_icon.png`](http://www.clker.com/clipart-24887.html) + * [`ui_off_icon.png` / `ui_on_icon.png`](http://www.clker.com/clipart-on-off-switches.html) + * [`ui_waypoints_icon.png`](http://www.clker.com/clipart-map-pin-red.html) + * [`ui_circular_arrows_icon.png`](http://www.clker.com/clipart-circular-arrow-pattern.html) + * [`ui_pencil_icon.pnc`](http://www.clker.com/clipart-2256.html) + * [`ui_waypoint_set_icon.png`](http://www.clker.com/clipart-larger-flag.html) + +Everaldo Coelho (YellowIcon) (LGPL v2.1+): + + * [`ui_craftguide_icon.png` / `ui_craft_icon.png`](http://commons.wikimedia.org/wiki/File:Advancedsettings.png) + +Gregory H. Revera: (CC-BY-SA 3.0) + + * [`ui_moon_icon.png`](http://commons.wikimedia.org/wiki/File:FullMoon2010.jpg) + +Thomas Bresson: (CC-BY 3.0) + + * [`ui_sun_icon.png`](http://commons.wikimedia.org/wiki/File:2012-10-13_15-29-35-sun.jpg) + +Fibonacci: (Public domain, CC-BY 4.0) + + * [`ui_xyz_off_icon.png`](http://commons.wikimedia.org/wiki/File:No_sign.svg) + +Gregory Maxwell: (Public domain, CC-BY 4.0) + + * [`ui_ok_icon.png`](http://commons.wikimedia.org/wiki/File:Yes_check.svg) + +Adrien Facélina: (LGPL v2.1+) + + * [`inventory_plus_worldedit_gui.png`](http://commons.wikimedia.org/wiki/File:Erioll_world_2.svg) + +Other files from Wikimedia Commons: + + * [`ui_gohome_icon.png` / `ui_home_icon.png` / `ui_sethome_icon.png`](http://commons.wikimedia.org/wiki/File:Home_256x256.png) (GPL v2+) + +RealBadAngel: (CC-BY-4.0) + + * Everything else. \ No newline at end of file diff --git a/mods/unified_inventory/api.lua b/mods/unified_inventory/api.lua new file mode 100644 index 00000000..071900da --- /dev/null +++ b/mods/unified_inventory/api.lua @@ -0,0 +1,307 @@ +local S = minetest.get_translator("unified_inventory") +local F = minetest.formspec_escape + +-- Create detached creative inventory after loading all mods +minetest.after(0.01, function() + local rev_aliases = {} + for source, target in pairs(minetest.registered_aliases) do + if not rev_aliases[target] then rev_aliases[target] = {} end + table.insert(rev_aliases[target], source) + end + unified_inventory.items_list = {} + for name, def in pairs(minetest.registered_items) do + if (not def.groups.not_in_creative_inventory or + def.groups.not_in_creative_inventory == 0) and + def.description and def.description ~= "" then + table.insert(unified_inventory.items_list, name) + local all_names = rev_aliases[name] or {} + table.insert(all_names, name) + for _, name in ipairs(all_names) do + local recipes = minetest.get_all_craft_recipes(name) + if recipes then + for _, recipe in ipairs(recipes) do + + local unknowns + + for _,chk in pairs(recipe.items) do + local groupchk = string.find(chk, "group:") + if (not groupchk and not minetest.registered_items[chk]) + or (groupchk and not unified_inventory.get_group_item(string.gsub(chk, "group:", "")).item) + or minetest.get_item_group(chk, "not_in_craft_guide") ~= 0 then + unknowns = true + end + end + + if not unknowns then + unified_inventory.register_craft(recipe) + end + end + end + end + end + end + table.sort(unified_inventory.items_list) + unified_inventory.items_list_size = #unified_inventory.items_list + print("Unified Inventory. inventory size: "..unified_inventory.items_list_size) + for _, name in ipairs(unified_inventory.items_list) do + local def = minetest.registered_items[name] + -- Simple drops + if type(def.drop) == "string" then + local dstack = ItemStack(def.drop) + if not dstack:is_empty() and dstack:get_name() ~= name then + unified_inventory.register_craft({ + type = "digging", + items = {name}, + output = def.drop, + width = 0, + }) + + end + -- Complex drops. Yes, it's really complex! + elseif type(def.drop) == "table" then + --[[ Extract single items from the table and save them into dedicated tables + to register them later, in order to avoid duplicates. These tables counts + the total number of guaranteed drops and drops by chance (“maybes”) for each item. + For “maybes”, the final count is the theoretical maximum number of items, not + neccessarily the actual drop count. ]] + local drop_guaranteed = {} + local drop_maybe = {} + -- This is for catching an obscure corner case: If the top items table has + -- only items with rarity = 1, but max_items is set, then only the first + -- max_items will be part of the drop, any later entries are logically + -- impossible, so this variable is for keeping track of this + local max_items_left = def.drop.max_items + -- For checking whether we still encountered only guaranteed only so far; + -- for the first “maybe” item it will become false which will cause ALL + -- later items to be considered “maybes”. + -- A common idiom is: + -- { max_items 1, { items = { + -- { items={"example:1"}, rarity = 5 }, + -- { items={"example:2"}, rarity = 1 }, }}} + -- example:2 must be considered a “maybe” because max_items is set and it + -- appears after a “maybe” + local max_start = true + -- Let's iterate through the items madness! + -- Handle invalid drop entries gracefully. + local drop_items = def.drop.items or { } + for i=1,#drop_items do + if max_items_left ~= nil and max_items_left <= 0 then break end + local itit = drop_items[i] + for j=1,#itit.items do + local dstack = ItemStack(itit.items[j]) + if not dstack:is_empty() and dstack:get_name() ~= name then + local dname = dstack:get_name() + local dcount = dstack:get_count() + -- Guaranteed drops AND we are not yet in “maybe mode” + if #itit.items == 1 and itit.rarity == 1 and max_start then + if drop_guaranteed[dname] == nil then + drop_guaranteed[dname] = 0 + end + drop_guaranteed[dname] = drop_guaranteed[dname] + dcount + + if max_items_left ~= nil then + max_items_left = max_items_left - 1 + if max_items_left <= 0 then break end + end + -- Drop was a “maybe” + else + if max_items_left ~= nil then max_start = false end + if drop_maybe[dname] == nil then + drop_maybe[dname] = 0 + end + drop_maybe[dname] = drop_maybe[dname] + dcount + end + end + end + end + for itemstring, count in pairs(drop_guaranteed) do + unified_inventory.register_craft({ + type = "digging", + items = {name}, + output = itemstring .. " " .. count, + width = 0, + }) + end + for itemstring, count in pairs(drop_maybe) do + unified_inventory.register_craft({ + type = "digging_chance", + items = {name}, + output = itemstring .. " " .. count, + width = 0, + }) + end + end + end + for _, recipes in pairs(unified_inventory.crafts_for.recipe) do + for _, recipe in ipairs(recipes) do + local ingredient_items = {} + for _, spec in pairs(recipe.items) do + local matches_spec = unified_inventory.canonical_item_spec_matcher(spec) + for _, name in ipairs(unified_inventory.items_list) do + if matches_spec(name) then + ingredient_items[name] = true + end + end + end + for name, _ in pairs(ingredient_items) do + if unified_inventory.crafts_for.usage[name] == nil then + unified_inventory.crafts_for.usage[name] = {} + end + table.insert(unified_inventory.crafts_for.usage[name], recipe) + end + end + end +end) + + +-- load_home +local function load_home() + local input = io.open(unified_inventory.home_filename, "r") + if not input then + unified_inventory.home_pos = {} + return + end + while true do + local x = input:read("*n") + if not x then break end + local y = input:read("*n") + local z = input:read("*n") + local name = input:read("*l") + unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z} + end + io.close(input) +end +load_home() + +function unified_inventory.set_home(player, pos) + local player_name = player:get_player_name() + unified_inventory.home_pos[player_name] = vector.round(pos) + -- save the home data from the table to the file + local output = io.open(unified_inventory.home_filename, "w") + for k, v in pairs(unified_inventory.home_pos) do + output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n") + end + io.close(output) +end + +function unified_inventory.go_home(player) + local pos = unified_inventory.home_pos[player:get_player_name()] + if pos then + player:set_pos(pos) + end +end + +-- register_craft +function unified_inventory.register_craft(options) + if not options.output then + return + end + local itemstack = ItemStack(options.output) + if itemstack:is_empty() then + return + end + if options.type == "normal" and options.width == 0 then + options = { type = "shapeless", items = options.items, output = options.output, width = 0 } + end + if not unified_inventory.crafts_for.recipe[itemstack:get_name()] then + unified_inventory.crafts_for.recipe[itemstack:get_name()] = {} + end + table.insert(unified_inventory.crafts_for.recipe[itemstack:get_name()],options) +end + + +local craft_type_defaults = { + width = 3, + height = 3, + uses_crafting_grid = false, +} + + +function unified_inventory.craft_type_defaults(name, options) + if not options.description then + options.description = name + end + setmetatable(options, {__index = craft_type_defaults}) + return options +end + + +function unified_inventory.register_craft_type(name, options) + unified_inventory.registered_craft_types[name] = + unified_inventory.craft_type_defaults(name, options) +end + + +unified_inventory.register_craft_type("normal", { + description = F(S("Crafting")), + icon = "ui_craftgrid_icon.png", + width = 3, + height = 3, + get_shaped_craft_width = function (craft) return craft.width end, + dynamic_display_size = function (craft) + local w = craft.width + local h = math.ceil(table.maxn(craft.items) / craft.width) + local g = w < h and h or w + return { width = g, height = g } + end, + uses_crafting_grid = true, +}) + + +unified_inventory.register_craft_type("shapeless", { + description = F(S("Mixing")), + icon = "ui_craftgrid_icon.png", + width = 3, + height = 3, + dynamic_display_size = function (craft) + local maxn = table.maxn(craft.items) + local g = 1 + while g*g < maxn do g = g + 1 end + return { width = g, height = g } + end, + uses_crafting_grid = true, +}) + + +unified_inventory.register_craft_type("cooking", { + description = F(S("Cooking")), + icon = "default_furnace_front.png", + width = 1, + height = 1, +}) + + +unified_inventory.register_craft_type("digging", { + description = F(S("Digging")), + icon = "default_tool_steelpick.png", + width = 1, + height = 1, +}) + +unified_inventory.register_craft_type("digging_chance", { + description = "Digging (by chance)", + icon = "default_tool_steelpick.png^[transformFY.png", + width = 1, + height = 1, +}) + +function unified_inventory.register_page(name, def) + unified_inventory.pages[name] = def +end + + +function unified_inventory.register_button(name, def) + if not def.action then + def.action = function(player) + unified_inventory.set_inventory_formspec(player, name) + end + end + def.name = name + table.insert(unified_inventory.buttons, def) +end + + +function unified_inventory.is_creative(playername) + return minetest.check_player_privs(playername, {creative=true}) + or minetest.settings:get_bool("creative_mode") +end diff --git a/mods/unified_inventory/bags.lua b/mods/unified_inventory/bags.lua new file mode 100644 index 00000000..1ebbdd3f --- /dev/null +++ b/mods/unified_inventory/bags.lua @@ -0,0 +1,276 @@ +--[[ +Bags for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +License: GPLv3 +--]] + +local S = minetest.get_translator("unified_inventory") +local F = minetest.formspec_escape + +unified_inventory.register_page("bags", { + get_formspec = function(player) + local player_name = player:get_player_name() + return { formspec = table.concat({ + "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]", + "label[0,0;" .. F(S("Bags")) .. "]", + "button[0,2;2,0.5;bag1;" .. F(S("Bag @1", 1)) .. "]", + "button[2,2;2,0.5;bag2;" .. F(S("Bag @1", 2)) .. "]", + "button[4,2;2,0.5;bag3;" .. F(S("Bag @1", 3)) .. "]", + "button[6,2;2,0.5;bag4;" .. F(S("Bag @1", 4)) .. "]", + "listcolors[#00000000;#00000000]", + "list[detached:" .. F(player_name) .. "_bags;bag1;0.5,1;1,1;]", + "list[detached:" .. F(player_name) .. "_bags;bag2;2.5,1;1,1;]", + "list[detached:" .. F(player_name) .. "_bags;bag3;4.5,1;1,1;]", + "list[detached:" .. F(player_name) .. "_bags;bag4;6.5,1;1,1;]" + }) } + end, +}) + +unified_inventory.register_button("bags", { + type = "image", + image = "ui_bags_icon.png", + tooltip = S("Bags"), + hide_lite=true +}) + +local function get_player_bag_stack(player, i) + return minetest.get_inventory({ + type = "detached", + name = player:get_player_name() .. "_bags" + }):get_stack("bag" .. i, 1) +end + +for bag_i = 1, 4 do + unified_inventory.register_page("bag" .. bag_i, { + get_formspec = function(player) + local stack = get_player_bag_stack(player, bag_i) + local image = stack:get_definition().inventory_image + local fs = { + "image[7,0;1,1;" .. image .. "]", + "label[0,0;" .. F(S("Bag @1", bag_i)) .. "]", + "listcolors[#00000000;#00000000]", + "list[current_player;bag" .. bag_i .. "contents;0,1;8,3;]", + "listring[current_name;bag" .. bag_i .. "contents]", + "listring[current_player;main]" + } + local slots = stack:get_definition().groups.bagslots + if slots == 8 then + fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]" + elseif slots == 16 then + fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]" + elseif slots == 24 then + fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]" + end + local player_name = player:get_player_name() -- For if statement. + if unified_inventory.trash_enabled + or unified_inventory.is_creative(player_name) + or minetest.get_player_privs(player_name).give then + fs[#fs + 1] = "background[6.06,0;0.92,0.92;ui_bags_trash.png]" + .. "list[detached:trash;main;6,0.1;1,1;]" + end + local inv = player:get_inventory() + for i = 1, 4 do + local def = get_player_bag_stack(player, i):get_definition() + if def.groups.bagslots then + local list_name = "bag" .. i .. "contents" + local size = inv:get_size(list_name) + local used = 0 + for si = 1, size do + local stk = inv:get_stack(list_name, si) + if not stk:is_empty() then + used = used + 1 + end + end + local img = def.inventory_image + local label = F(S("Bag @1", i)) .. "\n" .. used .. "/" .. size + fs[#fs + 1] = string.format("image_button[%i,0;1,1;%s;bag%i;%s]", + i + 1, img, i, label) + end + end + return { formspec = table.concat(fs) } + end, + }) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "" then + return + end + for i = 1, 4 do + if fields["bag" .. i] then + local stack = get_player_bag_stack(player, i) + if not stack:get_definition().groups.bagslots then + return + end + unified_inventory.set_inventory_formspec(player, "bag" .. i) + return + end + end +end) + +local function save_bags_metadata(player, bags_inv) + local is_empty = true + local bags = {} + for i = 1, 4 do + local bag = "bag" .. i + if not bags_inv:is_empty(bag) then + -- Stack limit is 1, otherwise use stack:to_string() + bags[i] = bags_inv:get_stack(bag, 1):get_name() + is_empty = false + end + end + local meta = player:get_meta() + if is_empty then + meta:set_string("unified_inventory:bags", nil) + else + meta:set_string("unified_inventory:bags", + minetest.serialize(bags)) + end +end + +local function load_bags_metadata(player, bags_inv) + local player_inv = player:get_inventory() + local meta = player:get_meta() + local bags_meta = meta:get_string("unified_inventory:bags") + local bags = bags_meta and minetest.deserialize(bags_meta) or {} + local dirty_meta = false + if not bags_meta then + -- Backwards compatiblity + for i = 1, 4 do + local bag = "bag" .. i + if not player_inv:is_empty(bag) then + -- Stack limit is 1, otherwise use stack:to_string() + bags[i] = player_inv:get_stack(bag, 1):get_name() + dirty_meta = true + end + end + end + -- Fill detached slots + for i = 1, 4 do + local bag = "bag" .. i + bags_inv:set_size(bag, 1) + bags_inv:set_stack(bag, 1, bags[i] or "") + end + + if dirty_meta then + -- Requires detached inventory to be set up + save_bags_metadata(player, bags_inv) + end + + -- Clean up deprecated garbage after saving + for i = 1, 4 do + local bag = "bag" .. i + player_inv:set_size(bag, 0) + end +end + +minetest.register_on_joinplayer(function(player) + local player_inv = player:get_inventory() + local player_name = player:get_player_name() + local bags_inv = minetest.create_detached_inventory(player_name .. "_bags",{ + on_put = function(inv, listname, index, stack, player) + player:get_inventory():set_size(listname .. "contents", + stack:get_definition().groups.bagslots) + save_bags_metadata(player, inv) + end, + allow_put = function(inv, listname, index, stack, player) + local new_slots = stack:get_definition().groups.bagslots + if not new_slots then + return 0 + end + local player_inv = player:get_inventory() + local old_slots = player_inv:get_size(listname .. "contents") + + if new_slots >= old_slots then + return 1 + end + + -- using a smaller bag, make sure it fits + local old_list = player_inv:get_list(listname .. "contents") + local new_list = {} + local slots_used = 0 + local use_new_list = false + + for i, v in ipairs(old_list) do + if v and not v:is_empty() then + slots_used = slots_used + 1 + use_new_list = i > new_slots + new_list[slots_used] = v + end + end + if new_slots >= slots_used then + if use_new_list then + player_inv:set_list(listname .. "contents", new_list) + end + return 1 + end + -- New bag is smaller: Disallow inserting + return 0 + end, + allow_take = function(inv, listname, index, stack, player) + if player:get_inventory():is_empty(listname .. "contents") then + return stack:get_count() + end + return 0 + end, + on_take = function(inv, listname, index, stack, player) + player:get_inventory():set_size(listname .. "contents", 0) + save_bags_metadata(player, inv) + end, + allow_move = function() + return 0 + end, + }, player_name) + + load_bags_metadata(player, bags_inv) +end) + +-- register bag tools +minetest.register_tool("unified_inventory:bag_small", { + description = S("Small Bag"), + inventory_image = "bags_small.png", + groups = {bagslots=8}, +}) + +minetest.register_tool("unified_inventory:bag_medium", { + description = S("Medium Bag"), + inventory_image = "bags_medium.png", + groups = {bagslots=16}, +}) + +minetest.register_tool("unified_inventory:bag_large", { + description = S("Large Bag"), + inventory_image = "bags_large.png", + groups = {bagslots=24}, +}) + +-- register bag crafts +if minetest.get_modpath("farming") ~= nil then + minetest.register_craft({ + output = "unified_inventory:bag_small", + recipe = { + {"", "farming:cotton", ""}, + {"group:wool", "group:wool", "group:wool"}, + {"group:wool", "group:wool", "group:wool"}, + }, + }) + + minetest.register_craft({ + output = "unified_inventory:bag_medium", + recipe = { + {"", "", ""}, + {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"}, + {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"}, + }, + }) + + minetest.register_craft({ + output = "unified_inventory:bag_large", + recipe = { + {"", "", ""}, + {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"}, + {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"}, + }, + }) +end diff --git a/mods/unified_inventory/callbacks.lua b/mods/unified_inventory/callbacks.lua new file mode 100644 index 00000000..8bfe6b60 --- /dev/null +++ b/mods/unified_inventory/callbacks.lua @@ -0,0 +1,216 @@ +local function default_refill(stack) + stack:set_count(stack:get_stack_max()) + local itemdef = minetest.registered_items[stack:get_name()] + if itemdef + and (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" + and stack:get_wear() ~= 0 then + stack:set_wear(0) + end + return stack +end + +minetest.register_on_joinplayer(function(player) + local player_name = player:get_player_name() + unified_inventory.players[player_name] = {} + unified_inventory.current_index[player_name] = 1 + unified_inventory.filtered_items_list[player_name] = + unified_inventory.items_list + unified_inventory.activefilter[player_name] = "" + unified_inventory.active_search_direction[player_name] = "nochange" + unified_inventory.apply_filter(player, "", "nochange") + unified_inventory.current_searchbox[player_name] = "" + unified_inventory.alternate[player_name] = 1 + unified_inventory.current_item[player_name] = nil + unified_inventory.current_craft_direction[player_name] = "recipe" + unified_inventory.set_inventory_formspec(player, + unified_inventory.default) + + -- Refill slot + local refill = minetest.create_detached_inventory(player_name.."refill", { + allow_put = function(inv, listname, index, stack, player) + local player_name = player:get_player_name() + if unified_inventory.is_creative(player_name) then + return stack:get_count() + else + return 0 + end + end, + on_put = function(inv, listname, index, stack, player) + local player_name = player:get_player_name() + local handle_refill = (minetest.registered_items[stack:get_name()] or {}).on_refill or default_refill + stack = handle_refill(stack) + inv:set_stack(listname, index, stack) + minetest.sound_play("electricity", + {to_player=player_name, gain = 1.0}) + end, + }, player_name) + refill:set_size("main", 1) +end) + +local function apply_new_filter(player, search_text, new_dir) + local player_name = player:get_player_name() + minetest.sound_play("click", {to_player=player_name, gain = 0.1}) + unified_inventory.apply_filter(player, search_text, new_dir) + unified_inventory.current_searchbox[player_name] = search_text + unified_inventory.set_inventory_formspec(player, + unified_inventory.current_page[player_name]) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local player_name = player:get_player_name() + + local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name) + + if formname ~= "" then + return + end + + -- always take new search text, even if not searching on it yet + if fields.searchbox + and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then + unified_inventory.current_searchbox[player_name] = fields.searchbox + end + + for i, def in pairs(unified_inventory.buttons) do + if fields[def.name] then + def.action(player) + minetest.sound_play("click", + {to_player=player_name, gain = 0.1}) + return + end + end + + -- Inventory page controls + local start = math.floor( + unified_inventory.current_index[player_name] / ui_peruser.items_per_page + 1) + local start_i = start + local pagemax = math.floor( + (#unified_inventory.filtered_items_list[player_name] - 1) + / (ui_peruser.items_per_page) + 1) + + if fields.start_list then + start_i = 1 + end + if fields.rewind1 then + start_i = start_i - 1 + end + if fields.forward1 then + start_i = start_i + 1 + end + if fields.rewind3 then + start_i = start_i - 3 + end + if fields.forward3 then + start_i = start_i + 3 + end + if fields.end_list then + start_i = pagemax + end + if start_i < 1 then + start_i = 1 + end + if start_i > pagemax then + start_i = pagemax + end + if start_i ~= start then + minetest.sound_play("paperflip1", + {to_player=player_name, gain = 1.0}) + unified_inventory.current_index[player_name] = (start_i - 1) * ui_peruser.items_per_page + 1 + unified_inventory.set_inventory_formspec(player, + unified_inventory.current_page[player_name]) + end + + -- Check clicked item image button + local clicked_item + for name, value in pairs(fields) do + local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$") + if new_dir and mangled_item then + clicked_item = unified_inventory.demangle_for_formspec(mangled_item) + if string.sub(clicked_item, 1, 6) == "group:" then + -- Change search filter to this group + apply_new_filter(player, clicked_item, new_dir) + return + end + if new_dir == "recipe" or new_dir == "usage" then + unified_inventory.current_craft_direction[player_name] = new_dir + end + break + end + end + if clicked_item then + minetest.sound_play("click", + {to_player=player_name, gain = 0.1}) + local page = unified_inventory.current_page[player_name] + local player_creative = unified_inventory.is_creative(player_name) + if not player_creative then + page = "craftguide" + end + if page == "craftguide" then + unified_inventory.current_item[player_name] = clicked_item + unified_inventory.alternate[player_name] = 1 + unified_inventory.set_inventory_formspec(player, "craftguide") + elseif player_creative then + -- Creative page: Add entire stack to inventory + local inv = player:get_inventory() + local stack = ItemStack(clicked_item) + stack:set_count(stack:get_stack_max()) + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + end + end + end + + if fields.searchbutton + or fields.key_enter_field == "searchbox" then + unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name], "nochange") + unified_inventory.set_inventory_formspec(player, + unified_inventory.current_page[player_name]) + minetest.sound_play("paperflip2", + {to_player=player_name, gain = 1.0}) + elseif fields.searchresetbutton then + apply_new_filter(player, "", "nochange") + end + + -- alternate buttons + if not (fields.alternate or fields.alternate_prev) then + return + end + minetest.sound_play("click", + {to_player=player_name, gain = 0.1}) + local item_name = unified_inventory.current_item[player_name] + if not item_name then + return + end + local crafts = unified_inventory.crafts_for[unified_inventory.current_craft_direction[player_name]][item_name] + if not crafts then + return + end + local alternates = #crafts + if alternates <= 1 then + return + end + local alternate + if fields.alternate then + alternate = unified_inventory.alternate[player_name] + 1 + if alternate > alternates then + alternate = 1 + end + elseif fields.alternate_prev then + alternate = unified_inventory.alternate[player_name] - 1 + if alternate < 1 then + alternate = alternates + end + end + unified_inventory.alternate[player_name] = alternate + unified_inventory.set_inventory_formspec(player, + unified_inventory.current_page[player_name]) +end) + +if minetest.delete_detached_inventory then + minetest.register_on_leaveplayer(function(player) + local player_name = player:get_player_name() + minetest.delete_detached_inventory(player_name.."_bags") + minetest.delete_detached_inventory(player_name.."craftrecipe") + minetest.delete_detached_inventory(player_name.."refill") + end) +end diff --git a/mods/unified_inventory/depends.txt b/mods/unified_inventory/depends.txt new file mode 100644 index 00000000..cb3d2b4f --- /dev/null +++ b/mods/unified_inventory/depends.txt @@ -0,0 +1,5 @@ +default +creative? +sfinv? +datastorage? +farming? diff --git a/mods/unified_inventory/description.txt b/mods/unified_inventory/description.txt new file mode 100644 index 00000000..b541fdf2 --- /dev/null +++ b/mods/unified_inventory/description.txt @@ -0,0 +1 @@ +Unified Inventory replaces the default survival and creative inventory. It adds a nicer interface and a number of features, such as a crafting guide. diff --git a/mods/unified_inventory/doc/mod_api.txt b/mods/unified_inventory/doc/mod_api.txt new file mode 100644 index 00000000..c0be129b --- /dev/null +++ b/mods/unified_inventory/doc/mod_api.txt @@ -0,0 +1,95 @@ +unified_inventory API +===================== + +This file provides information about the API of unified_inventory. + + +Misc functions +-------------- +Grouped by use-case, afterwards sorted alphabetically. + +* `unified_inventory.is_creative(name)` + * Checks whether creative is enabled or the player has `creative` + + +Pages +----- + +Register a new page: The callback inside this function is called on user input. + + unified_inventory.register_page("pagename", { + get_formspec = function(player) + -- ^ `player` is an `ObjectRef` + -- Compute the formspec string here + return { + formspec = "button[2,2;2,1;mybutton;Press me]", + -- ^ Final form of the formspec to display + draw_inventory = false, -- default `true` + -- ^ Optional. Hides the player's `main` inventory list + draw_item_list = false, -- default `true` + -- ^ Optional. Hides the item list on the right side + formspec_prepend = false, -- default `false` + -- ^ Optional. When `false`: Disables the formspec prepend + } + end, + }) + + +Buttons +------- + +Register a new button for the bottom row: + + unified_inventory.register_button("skins", { + type = "image", + image = "skins_skin_button.png", + tooltip = "Skins", + hide_lite = true + -- ^ Button is hidden when following two conditions are met: + -- Configuration line `unified_inventory_lite = true` + -- Player does not have the privilege `ui_full` + }) + + + +Crafting +-------- + +The code blocks below document each possible parameter using exemplary values. + +Provide information to display custom craft types: + + unified_inventory.register_craft_type("mytype", { + -- ^ Unique identifier for `register_craft` + description = "Sample Craft", + -- ^ Text shown below the crafting arrow + icon = "dummy.png", + -- ^ Image shown above the crafting arrow + width = 3, + height = 3, + -- ^ Maximal input dimensions of the recipes + dynamic_display_size = function(craft) + -- ^ `craft` is the definition from `register_craft` + return { + width = 2, + height = 3 + } + end, + -- ^ Optional callback to change the displayed recipe size + uses_crafting_grid = true, + }) + +Register a non-standard craft recipe: + + unified_inventory.register_craft({ + output = "default:foobar", + type = "mytype", + -- ^ Standard craft type or custom (see `register_craft_type`) + items = { + { "default:foo" }, + { "default:bar" } + }, + width = 3, + -- ^ Same as `minetest.register_recipe` + }) + diff --git a/mods/unified_inventory/group.lua b/mods/unified_inventory/group.lua new file mode 100644 index 00000000..3864267a --- /dev/null +++ b/mods/unified_inventory/group.lua @@ -0,0 +1,127 @@ +local S = minetest.get_translator("unified_inventory") + +function unified_inventory.canonical_item_spec_matcher(spec) + local specname = ItemStack(spec):get_name() + if specname:sub(1, 6) ~= "group:" then + return function (itemname) + return itemname == specname + end + end + + local group_names = specname:sub(7):split(",") + return function (itemname) + local itemdef = minetest.registered_items[itemname] + for _, group_name in ipairs(group_names) do + if (itemdef.groups[group_name] or 0) == 0 then + return false + end + end + return true + end +end + +function unified_inventory.item_matches_spec(item, spec) + local itemname = ItemStack(item):get_name() + return unified_inventory.canonical_item_spec_matcher(spec)(itemname) +end + +function unified_inventory.extract_groupnames(groupname) + local specname = ItemStack(groupname):get_name() + if specname:sub(1, 6) ~= "group:" then + return nil, 0 + end + local group_names = specname:sub(7):split(",") + return table.concat(group_names, S(" and ")), #group_names +end + +unified_inventory.registered_group_items = { + mesecon_conductor_craftable = "mesecons:wire_00000000_off", + stone = "default:cobble", + wood = "default:wood", + book = "default:book", + sand = "default:sand", + leaves = "default:leaves", + tree = "default:tree", + vessel = "vessels:glass_bottle", + wool = "wool:white", +} + +function unified_inventory.register_group_item(groupname, itemname) + unified_inventory.registered_group_items[groupname] = itemname +end + + +-- This is used when displaying craft recipes, where an ingredient is +-- specified by group rather than as a specific item. A single-item group +-- is represented by that item, with the single-item status signalled +-- in the "sole" field. If the group contains no items at all, the item +-- field will be nil. +-- +-- Within a multiple-item group, we prefer to use an item that has the +-- same specific name as the group, and if there are more than one of +-- those items we prefer the one registered for the group by a mod. +-- Among equally-preferred items, we just pick the one with the +-- lexicographically earliest name. +-- +-- The parameter to this function isn't just a single group name. +-- It may be a comma-separated list of group names. This is really a +-- "group:..." ingredient specification, minus the "group:" prefix. + +local function compute_group_item(group_name_list) + local group_names = group_name_list:split(",") + local candidate_items = {} + for itemname, itemdef in pairs(minetest.registered_items) do + if (itemdef.groups.not_in_creative_inventory or 0) == 0 then + local all = true + for _, group_name in ipairs(group_names) do + if (itemdef.groups[group_name] or 0) == 0 then + all = false + end + end + if all then table.insert(candidate_items, itemname) end + end + end + local num_candidates = #candidate_items + if num_candidates == 0 then + return {sole = true} + elseif num_candidates == 1 then + return {item = candidate_items[1], sole = true} + end + local is_group = {} + local registered_rep = {} + for _, group_name in ipairs(group_names) do + is_group[group_name] = true + local rep = unified_inventory.registered_group_items[group_name] + if rep then registered_rep[rep] = true end + end + local bestitem = "" + local bestpref = 0 + for _, item in ipairs(candidate_items) do + local pref + if registered_rep[item] then + pref = 4 + elseif string.sub(item, 1, 8) == "default:" and is_group[string.sub(item, 9)] then + pref = 3 + elseif is_group[item:gsub("^[^:]*:", "")] then + pref = 2 + else + pref = 1 + end + if pref > bestpref or (pref == bestpref and item < bestitem) then + bestitem = item + bestpref = pref + end + end + return {item = bestitem, sole = false} +end + + +local group_item_cache = {} + +function unified_inventory.get_group_item(group_name) + if not group_item_cache[group_name] then + group_item_cache[group_name] = compute_group_item(group_name) + end + return group_item_cache[group_name] +end + diff --git a/mods/unified_inventory/image_credits.txt b/mods/unified_inventory/image_credits.txt new file mode 100644 index 00000000..12fbc650 --- /dev/null +++ b/mods/unified_inventory/image_credits.txt @@ -0,0 +1,69 @@ +bags_small.png: + http://www.clker.com/clipart-moneybag-empty.html + +bags_medium.png: + http://www.clker.com/clipart-backpack-1.html + +bags_large.png / ui_bags_icon.png: + http://www.clker.com/clipart-backpack-green-brown.html + +ui_craftguide_icon.png / ui_craft_icon.png + http://commons.wikimedia.org/wiki/File:Advancedsettings.png + +ui_doubleleft_icon.png + http://commons.wikimedia.org/wiki/File:Media-seek-backward.svg + +ui_doubleright_icon.png + http://commons.wikimedia.org/wiki/File:Media-seek-forward.svg + +ui_left_icon.png / ui_right_icon.png + http://commons.wikimedia.org/wiki/File:Media-playback-start.svg + +ui_skip_backward_icon.png + http://commons.wikimedia.org/wiki/File:Media-skip-backward.svg + +ui_skip_forward_icon.png + http://commons.wikimedia.org/wiki/File:Media-skip-forward.svg + +ui_reset_icon.png + https://commons.wikimedia.org/wiki/File:Edit-clear.svg + +ui_gohome_icon.png / ui_home_icon.png / ui_sethome_icon.png + http://commons.wikimedia.org/wiki/File:Home_256x256.png + +ui_moon_icon.png + http://commons.wikimedia.org/wiki/File:FullMoon2010.jpg + +ui_sun_icon.png + http://commons.wikimedia.org/wiki/File:2012-10-13_15-29-35-sun.jpg + +ui_trash_icon.png + http://www.clker.com/clipart-29090.html + http://www.clker.com/clipart-trash.html + +ui_search_icon.png + http://www.clker.com/clipart-24887.html + +ui_off_icon.png / ui_on_icon.png + http://www.clker.com/clipart-on-off-switches.html + +ui_waypoints_icon.png + http://www.clker.com/clipart-map-pin-red.html + +ui_circular_arrows_icon.png + http://www.clker.com/clipart-circular-arrow-pattern.html + +ui_pencil_icon.pnc + http://www.clker.com/clipart-2256.html + +ui_waypoint_set_icon.png + http://www.clker.com/clipart-larger-flag.html + +ui_xyz_off_icon.png + http://commons.wikimedia.org/wiki/File:No_sign.svg + +ui_ok_icon.png + http://commons.wikimedia.org/wiki/File:Yes_check.svg + +inventory_plus_worldedit_gui.png + http://commons.wikimedia.org/wiki/File:Erioll_world_2.svg diff --git a/mods/unified_inventory/init.lua b/mods/unified_inventory/init.lua new file mode 100644 index 00000000..1a80abbb --- /dev/null +++ b/mods/unified_inventory/init.lua @@ -0,0 +1,79 @@ +-- Unified Inventory for Minetest >= 0.4.16 + +local modpath = minetest.get_modpath(minetest.get_current_modname()) +local worldpath = minetest.get_worldpath() + +-- Data tables definitions +unified_inventory = { + activefilter = {}, + active_search_direction = {}, + alternate = {}, + current_page = {}, + current_searchbox = {}, + current_index = {}, + current_item = {}, + current_craft_direction = {}, + registered_craft_types = {}, + crafts_for = {usage = {}, recipe = {} }, + players = {}, + items_list_size = 0, + items_list = {}, + filtered_items_list_size = {}, + filtered_items_list = {}, + pages = {}, + buttons = {}, + + -- Homepos stuff + home_pos = {}, + home_filename = worldpath.."/unified_inventory_home.home", + + -- Default inventory page + default = "craft", + + -- "Lite" mode + lite_mode = minetest.settings:get_bool("unified_inventory_lite"), + + -- Trash enabled + trash_enabled = (minetest.settings:get_bool("unified_inventory_trash") ~= false), + + pagecols = 8, + pagerows = 10, + page_y = 0, + formspec_y = 1, + main_button_x = 0, + main_button_y = 9, + craft_result_x = 0.3, + craft_result_y = 0.5, + form_header_y = 0 +} + +-- Disable default creative inventory +local creative = rawget(_G, "creative") or rawget(_G, "creative_inventory") +if creative then + function creative.set_creative_formspec(player, start_i, pagenum) + return + end +end + +-- Disable sfinv inventory +local sfinv = rawget(_G, "sfinv") +if sfinv then + sfinv.enabled = false +end + +dofile(modpath.."/group.lua") +dofile(modpath.."/api.lua") +dofile(modpath.."/internal.lua") +dofile(modpath.."/callbacks.lua") +dofile(modpath.."/match_craft.lua") +dofile(modpath.."/register.lua") + +if minetest.settings:get_bool("unified_inventory_bags") ~= false then + dofile(modpath.."/bags.lua") +end + +dofile(modpath.."/item_names.lua") + +if minetest.get_modpath("datastorage") then + dofile(modpath.."/waypoints.lua") +end diff --git a/mods/unified_inventory/internal.lua b/mods/unified_inventory/internal.lua new file mode 100644 index 00000000..05dc5f59 --- /dev/null +++ b/mods/unified_inventory/internal.lua @@ -0,0 +1,374 @@ +local S = minetest.get_translator("unified_inventory") +local F = minetest.formspec_escape + +-- This pair of encoding functions is used where variable text must go in +-- button names, where the text might contain formspec metacharacters. +-- We can escape button names for the formspec, to avoid screwing up +-- form structure overall, but they then don't get de-escaped, and so +-- the input we get back from the button contains the formspec escaping. +-- This is a game engine bug, and in the anticipation that it might be +-- fixed some day we don't want to rely on it. So for safety we apply +-- an encoding that avoids all formspec metacharacters. +function unified_inventory.mangle_for_formspec(str) + return string.gsub(str, "([^A-Za-z0-9])", function (c) return string.format("_%d_", string.byte(c)) end) +end +function unified_inventory.demangle_for_formspec(str) + return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end) +end + +function unified_inventory.get_per_player_formspec(player_name) + local lite = unified_inventory.lite_mode and not minetest.check_player_privs(player_name, {ui_full=true}) + + local ui = {} + ui.pagecols = unified_inventory.pagecols + ui.pagerows = unified_inventory.pagerows + ui.page_y = unified_inventory.page_y + ui.formspec_y = unified_inventory.formspec_y + ui.main_button_x = unified_inventory.main_button_x + ui.main_button_y = unified_inventory.main_button_y + ui.craft_result_x = unified_inventory.craft_result_x + ui.craft_result_y = unified_inventory.craft_result_y + ui.form_header_y = unified_inventory.form_header_y + + if lite then + ui.pagecols = 4 + ui.pagerows = 6 + ui.page_y = 0.25 + ui.formspec_y = 0.47 + ui.main_button_x = 8.2 + ui.main_button_y = 6.5 + ui.craft_result_x = 2.8 + ui.craft_result_y = 3.4 + ui.form_header_y = -0.1 + end + + ui.items_per_page = ui.pagecols * ui.pagerows + return ui, lite +end + +function unified_inventory.get_formspec(player, page) + + if not player then + return "" + end + + local player_name = player:get_player_name() + local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name) + + unified_inventory.current_page[player_name] = page + local pagedef = unified_inventory.pages[page] + + if not pagedef then + return "" -- Invalid page name + end + + local formspec = { + "size[14,10]", + pagedef.formspec_prepend and "" or "no_prepend[]", + "background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]" -- Background + } + local n = 4 + + if draw_lite_mode then + formspec[1] = "size[11,7.7]" + formspec[3] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]" + end + + if unified_inventory.is_creative(player_name) + and page == "craft" then + formspec[n] = "background[0,"..(ui_peruser.formspec_y + 2)..";1,1;ui_single_slot.png]" + n = n+1 + end + + local perplayer_formspec = unified_inventory.get_per_player_formspec(player_name) + local fsdata = pagedef.get_formspec(player, perplayer_formspec) + + formspec[n] = fsdata.formspec + n = n+1 + + local button_row = 0 + local button_col = 0 + + -- Main buttons + + local filtered_inv_buttons = {} + + for i, def in pairs(unified_inventory.buttons) do + if not (draw_lite_mode and def.hide_lite) then + table.insert(filtered_inv_buttons, def) + end + end + + for i, def in pairs(filtered_inv_buttons) do + + if draw_lite_mode and i > 4 then + button_row = 1 + button_col = 1 + end + + if def.type == "image" then + if (def.condition == nil or def.condition(player) == true) then + formspec[n] = "image_button[" + formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4) + formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;" + formspec[n+3] = F(def.image)..";" + formspec[n+4] = F(def.name)..";]" + formspec[n+5] = "tooltip["..F(def.name) + formspec[n+6] = ";"..(def.tooltip or "").."]" + n = n+7 + else + formspec[n] = "image[" + formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4) + formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;" + formspec[n+3] = F(def.image).."^[colorize:#808080:alpha]" + n = n+4 + + end + end + end + + if fsdata.draw_inventory ~= false then + -- Player inventory + formspec[n] = "listcolors[#00000000;#00000000]" + formspec[n+1] = "list[current_player;main;0,"..(ui_peruser.formspec_y + 3.5)..";8,4;]" + n = n+2 + end + + if fsdata.draw_item_list == false then + return table.concat(formspec, "") + end + + -- Controls to flip items pages + local start_x = 9.2 + + if not draw_lite_mode then + formspec[n] = + "image_button[" .. (start_x + 0.6 * 0) + .. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]" + .. "tooltip[start_list;" .. F(S("First page")) .. "]" + + .. "image_button[" .. (start_x + 0.6 * 1) + .. ",9;.8,.8;ui_doubleleft_icon.png;rewind3;]" + .. "tooltip[rewind3;" .. F(S("Back three pages")) .. "]" + .. "image_button[" .. (start_x + 0.6 * 2) + .. ",9;.8,.8;ui_left_icon.png;rewind1;]" + .. "tooltip[rewind1;" .. F(S("Back one page")) .. "]" + + .. "image_button[" .. (start_x + 0.6 * 3) + .. ",9;.8,.8;ui_right_icon.png;forward1;]" + .. "tooltip[forward1;" .. F(S("Forward one page")) .. "]" + .. "image_button[" .. (start_x + 0.6 * 4) + .. ",9;.8,.8;ui_doubleright_icon.png;forward3;]" + .. "tooltip[forward3;" .. F(S("Forward three pages")) .. "]" + + .. "image_button[" .. (start_x + 0.6 * 5) + .. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]" + .. "tooltip[end_list;" .. F(S("Last page")) .. "]" + else + formspec[n] = + "image_button[" .. (8.2 + 0.65 * 0) + .. ",5.8;.8,.8;ui_skip_backward_icon.png;start_list;]" + .. "tooltip[start_list;" .. F(S("First page")) .. "]" + .. "image_button[" .. (8.2 + 0.65 * 1) + .. ",5.8;.8,.8;ui_left_icon.png;rewind1;]" + .. "tooltip[rewind1;" .. F(S("Back one page")) .. "]" + .. "image_button[" .. (8.2 + 0.65 * 2) + .. ",5.8;.8,.8;ui_right_icon.png;forward1;]" + .. "tooltip[forward1;" .. F(S("Forward one page")) .. "]" + .. "image_button[" .. (8.2 + 0.65 * 3) + .. ",5.8;.8,.8;ui_skip_forward_icon.png;end_list;]" + .. "tooltip[end_list;" .. F(S("Last page")) .. "]" + end + n = n+1 + + -- Search box + formspec[n] = "field_close_on_enter[searchbox;false]" + n = n+1 + + if not draw_lite_mode then + formspec[n] = "field[9.5,8.325;3,1;searchbox;;" + .. F(unified_inventory.current_searchbox[player_name]) .. "]" + formspec[n+1] = "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]" + .. "tooltip[searchbutton;" ..F(S("Search")) .. "]" + formspec[n+2] = "image_button[12.9,8.1;.8,.8;ui_reset_icon.png;searchresetbutton;]" + .. "tooltip[searchbutton;" ..F(S("Search")) .. "]" + .. "tooltip[searchresetbutton;" ..F(S("Reset search and display everything")) .. "]" + else + formspec[n] = "field[8.5,5.225;2.2,1;searchbox;;" + .. F(unified_inventory.current_searchbox[player_name]) .. "]" + formspec[n+1] = "image_button[10.3,5;.8,.8;ui_search_icon.png;searchbutton;]" + .. "tooltip[searchbutton;" ..F(S("Search")) .. "]" + formspec[n+2] = "image_button[11,5;.8,.8;ui_reset_icon.png;searchresetbutton;]" + .. "tooltip[searchbutton;" ..F(S("Search")) .. "]" + .. "tooltip[searchresetbutton;" ..F(S("Reset search and display everything")) .. "]" + end + n = n+3 + + local no_matches = S("No matching items") + if draw_lite_mode then + no_matches = S("No matches.") + end + + -- Items list + if #unified_inventory.filtered_items_list[player_name] == 0 then + formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";" .. F(no_matches) .. "]" + else + local dir = unified_inventory.active_search_direction[player_name] + local list_index = unified_inventory.current_index[player_name] + local page = math.floor(list_index / (ui_peruser.items_per_page) + 1) + local pagemax = math.floor( + (#unified_inventory.filtered_items_list[player_name] - 1) + / (ui_peruser.items_per_page) + 1) + local item = {} + for y = 0, ui_peruser.pagerows - 1 do + for x = 0, ui_peruser.pagecols - 1 do + local name = unified_inventory.filtered_items_list[player_name][list_index] + local item = minetest.registered_items[name] + if item then + -- Clicked on current item: Flip crafting direction + if name == unified_inventory.current_item[player_name] then + local cdir = unified_inventory.current_craft_direction[player_name] + if cdir == "recipe" then + dir = "usage" + elseif cdir == "usage" then + dir = "recipe" + end + else + -- Default: use active search direction by default + dir = unified_inventory.active_search_direction[player_name] + end + + local button_name = "item_button_" .. dir .. "_" + .. unified_inventory.mangle_for_formspec(name) + formspec[n] = ("item_image_button[%f,%f;.81,.81;%s;%s;]"):format( + 8.2 + x * 0.7, ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7, + name, button_name + ) + formspec[n + 1] = ("tooltip[%s;%s \\[%s\\]]"):format( + button_name, minetest.formspec_escape(item.description), + item.mod_origin or "??" + ) + n = n + 2 + list_index = list_index + 1 + end + end + end + formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";"..F(S("Page")) .. ": " + .. S("@1 of @2",page,pagemax).."]" + end + n= n+1 + + if unified_inventory.activefilter[player_name] ~= "" then + formspec[n] = "label[8.2,"..(ui_peruser.form_header_y + 0.4)..";" .. F(S("Filter")) .. ":]" + formspec[n+1] = "label[9.1,"..(ui_peruser.form_header_y + 0.4)..";"..F(unified_inventory.activefilter[player_name]).."]" + end + return table.concat(formspec, "") +end + +function unified_inventory.set_inventory_formspec(player, page) + if player then + player:set_inventory_formspec(unified_inventory.get_formspec(player, page)) + end +end + +--apply filter to the inventory list (create filtered copy of full one) +function unified_inventory.apply_filter(player, filter, search_dir) + if not player then + return false + end + local player_name = player:get_player_name() + local lfilter = string.lower(filter) + local ffilter + if lfilter:sub(1, 6) == "group:" then + local groups = lfilter:sub(7):split(",") + ffilter = function(name, def) + for _, group in ipairs(groups) do + if not def.groups[group] + or def.groups[group] <= 0 then + return false + end + end + return true + end + else + ffilter = function(name, def) + local lname = string.lower(name) + local ldesc = string.lower(def.description) + return string.find(lname, lfilter, 1, true) or string.find(ldesc, lfilter, 1, true) + end + end + unified_inventory.filtered_items_list[player_name]={} + for name, def in pairs(minetest.registered_items) do + if (not def.groups.not_in_creative_inventory + or def.groups.not_in_creative_inventory == 0) + and def.description + and def.description ~= "" + and ffilter(name, def) then + table.insert(unified_inventory.filtered_items_list[player_name], name) + end + end + table.sort(unified_inventory.filtered_items_list[player_name]) + unified_inventory.filtered_items_list_size[player_name] = #unified_inventory.filtered_items_list[player_name] + unified_inventory.current_index[player_name] = 1 + unified_inventory.activefilter[player_name] = filter + unified_inventory.active_search_direction[player_name] = search_dir + unified_inventory.set_inventory_formspec(player, + unified_inventory.current_page[player_name]) +end + +function unified_inventory.items_in_group(groups) + local items = {} + for name, item in pairs(minetest.registered_items) do + for _, group in pairs(groups:split(',')) do + if item.groups[group] then + table.insert(items, name) + end + end + end + return items +end + +function unified_inventory.sort_inventory(inv) + local inlist = inv:get_list("main") + local typecnt = {} + local typekeys = {} + for _, st in ipairs(inlist) do + if not st:is_empty() then + local n = st:get_name() + local w = st:get_wear() + local m = st:get_metadata() + local k = string.format("%s %05d %s", n, w, m) + if not typecnt[k] then + typecnt[k] = { + name = n, + wear = w, + metadata = m, + stack_max = st:get_stack_max(), + count = 0, + } + table.insert(typekeys, k) + end + typecnt[k].count = typecnt[k].count + st:get_count() + end + end + table.sort(typekeys) + local outlist = {} + for _, k in ipairs(typekeys) do + local tc = typecnt[k] + while tc.count > 0 do + local c = math.min(tc.count, tc.stack_max) + table.insert(outlist, ItemStack({ + name = tc.name, + wear = tc.wear, + metadata = tc.metadata, + count = c, + })) + tc.count = tc.count - c + end + end + if #outlist > #inlist then return end + while #outlist < #inlist do + table.insert(outlist, ItemStack(nil)) + end + inv:set_list("main", outlist) +end diff --git a/mods/unified_inventory/item_names.lua b/mods/unified_inventory/item_names.lua new file mode 100644 index 00000000..d374b140 --- /dev/null +++ b/mods/unified_inventory/item_names.lua @@ -0,0 +1,76 @@ +-- Based on 4itemnames mod by 4aiman + +local item_names = {} -- [player_name] = { hud, dtime, itemname } +local dlimit = 3 -- HUD element will be hidden after this many seconds +local air_hud_mod = minetest.get_modpath("4air") +local hud_mod = minetest.get_modpath("hud") +local hudbars_mod = minetest.get_modpath("hudbars") + +local function set_hud(player) + local player_name = player:get_player_name() + local off = {x=0, y=-70} + if air_hud_mod or hud_mod then + off.y = off.y - 20 + elseif hudbars_mod then + off.y = off.y + 13 + end + item_names[player_name] = { + hud = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5, y=1}, + offset = off, + alignment = {x=0, y=0}, + number = 0xFFFFFF, + text = "", + }), + dtime = dlimit, + index = 1, + itemname = "" + } +end + +minetest.register_on_joinplayer(function(player) + minetest.after(0, set_hud, player) +end) + +minetest.register_on_leaveplayer(function(player) + item_names[player:get_player_name()] = nil +end) + +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local data = item_names[player:get_player_name()] + if not data or not data.hud then + data = {} -- Update on next step + set_hud(player) + end + + local index = player:get_wield_index() + local stack = player:get_wielded_item() + local itemname = stack:get_name() + + if data.hud and data.dtime < dlimit then + data.dtime = data.dtime + dtime + if data.dtime > dlimit then + player:hud_change(data.hud, 'text', "") + end + end + + if data.hud and (itemname ~= data.itemname or index ~= data.index) then + data.itemname = itemname + data.index = index + data.dtime = 0 + + local desc = stack.get_meta + and stack:get_meta():get_string("description") + + if not desc or desc == "" then + -- Try to use default description when none is set in the meta + local def = minetest.registered_items[itemname] + desc = def and def.description or "" + end + player:hud_change(data.hud, 'text', desc) + end + end +end) + diff --git a/mods/unified_inventory/match_craft.lua b/mods/unified_inventory/match_craft.lua new file mode 100644 index 00000000..2dd40b04 --- /dev/null +++ b/mods/unified_inventory/match_craft.lua @@ -0,0 +1,409 @@ +-- match_craft.lua +-- Find and automatically move inventory items to the crafting grid +-- according to the recipe. + +--[[ +Retrieve items from inventory lists and calculate their total count. +Return a table of "item name" - "total count" pairs. + +Arguments: + inv: minetest inventory reference + lists: names of inventory lists to use + +Example usage: + -- Count items in "main" and "craft" lists of player inventory + unified_inventory.count_items(player_inv_ref, {"main", "craft"}) + +Example output: + { + ["default:pine_wood"] = 2, + ["default:acacia_wood"] = 4, + ["default:chest"] = 3, + ["default:axe_diamond"] = 2, -- unstackable item are counted too + ["wool:white"] = 6 + } +]]-- +function unified_inventory.count_items(inv, lists) + local counts = {} + + for i = 1, #lists do + local name = lists[i] + local size = inv:get_size(name) + local list = inv:get_list(name) + + for j = 1, size do + local stack = list[j] + + if not stack:is_empty() then + local item = stack:get_name() + local count = stack:get_count() + + counts[item] = (counts[item] or 0) + count + end + end + end + + return counts +end + +--[[ +Retrieve craft recipe items and their positions in the crafting grid. +Return a table of "craft item name" - "set of positions" pairs. + +Note that if craft width is not 3 then positions are recalculated as +if items were placed on a 3x3 grid. Also note that craft can contain +groups of items with "group:" prefix. + +Arguments: + craft: minetest craft recipe + +Example output: + -- Bed recipe + { + ["wool:white"] = {[1] = true, [2] = true, [3] = true} + ["group:wood"] = {[4] = true, [5] = true, [6] = true} + } +--]] +function unified_inventory.count_craft_positions(craft) + local positions = {} + local craft_items = craft.items + local craft_type = unified_inventory.registered_craft_types[craft.type] + or unified_inventory.craft_type_defaults(craft.type, {}) + local display_width = craft_type.dynamic_display_size + and craft_type.dynamic_display_size(craft).width + or craft_type.width + local craft_width = craft_type.get_shaped_craft_width + and craft_type.get_shaped_craft_width(craft) + or display_width + local i = 0 + + for y = 1, 3 do + for x = 1, craft_width do + i = i + 1 + local item = craft_items[i] + + if item ~= nil then + local pos = 3 * (y - 1) + x + local set = positions[item] + + if set ~= nil then + set[pos] = true + else + positions[item] = {[pos] = true} + end + end + end + end + + return positions +end + +--[[ +For every craft item find all matching inventory items. +- If craft item is a group then find all inventory items that matches + this group. +- If craft item is not a group (regular item) then find only this item. + +If inventory doesn't contain needed item then found set is empty for +this item. + +Return a table of "craft item name" - "set of matching inventory items" +pairs. + +Arguments: + inv_items: table with items names as keys + craft_items: table with items names or groups as keys + +Example output: + { + ["group:wood"] = { + ["default:pine_wood"] = true, + ["default:acacia_wood"] = true + }, + ["wool:white"] = { + ["wool:white"] = true + } + } +--]] +function unified_inventory.find_usable_items(inv_items, craft_items) + local get_group = minetest.get_item_group + local result = {} + + for craft_item in pairs(craft_items) do + local group = craft_item:match("^group:(.+)") + local found = {} + + if group ~= nil then + for inv_item in pairs(inv_items) do + if get_group(inv_item, group) > 0 then + found[inv_item] = true + end + end + else + if inv_items[craft_item] ~= nil then + found[craft_item] = true + end + end + + result[craft_item] = found + end + + return result +end + +--[[ +Match inventory items with craft grid positions. +For every position select the matching inventory item with maximum +(total_count / (times_matched + 1)) value. + +If for some position matching item cannot be found or match count is 0 +then return nil. + +Return a table of "matched item name" - "set of craft positions" pairs +and overall match count. + +Arguments: + inv_counts: table of inventory items counts from "count_items" + craft_positions: table of craft positions from "count_craft_positions" + +Example output: + match_table = { + ["wool:white"] = {[1] = true, [2] = true, [3] = true} + ["default:acacia_wood"] = {[4] = true, [6] = true} + ["default:pine_wood"] = {[5] = true} + } + match_count = 2 +--]] +function unified_inventory.match_items(inv_counts, craft_positions) + local usable = unified_inventory.find_usable_items(inv_counts, craft_positions) + local match_table = {} + local match_count + local matches = {} + + for craft_item, pos_set in pairs(craft_positions) do + local use_set = usable[craft_item] + + for pos in pairs(pos_set) do + local pos_item + local pos_count + + for use_item in pairs(use_set) do + local count = inv_counts[use_item] + local times_matched = matches[use_item] or 0 + local new_pos_count = math.floor(count / (times_matched + 1)) + + if pos_count == nil or pos_count < new_pos_count then + pos_item = use_item + pos_count = new_pos_count + end + end + + if pos_item == nil or pos_count == 0 then + return nil + end + + local set = match_table[pos_item] + + if set ~= nil then + set[pos] = true + else + match_table[pos_item] = {[pos] = true} + end + + matches[pos_item] = (matches[pos_item] or 0) + 1 + end + end + + for match_item, times_matched in pairs(matches) do + local count = inv_counts[match_item] + local item_count = math.floor(count / times_matched) + + if match_count == nil or item_count < match_count then + match_count = item_count + end + end + + return match_table, match_count +end + +--[[ +Remove item from inventory lists. +Return stack of actually removed items. + +This function replicates the inv:remove_item function but can accept +multiple lists. + +Arguments: + inv: minetest inventory reference + lists: names of inventory lists + stack: minetest item stack +--]] +function unified_inventory.remove_item(inv, lists, stack) + local removed = ItemStack(nil) + local leftover = ItemStack(stack) + + for i = 1, #lists do + if leftover:is_empty() then + break + end + + local cur_removed = inv:remove_item(lists[i], leftover) + removed:add_item(cur_removed) + leftover:take_item(cur_removed:get_count()) + end + + return removed +end + +--[[ +Add item to inventory lists. +Return leftover stack. + +This function replicates the inv:add_item function but can accept +multiple lists. + +Arguments: + inv: minetest inventory reference + lists: names of inventory lists + stack: minetest item stack +--]] +function unified_inventory.add_item(inv, lists, stack) + local leftover = ItemStack(stack) + + for i = 1, #lists do + if leftover:is_empty() then + break + end + + leftover = inv:add_item(lists[i], leftover) + end + + return leftover +end + +--[[ +Move items from source list to destination list if possible. +Skip positions specified in exclude set. + +Arguments: + inv: minetest inventory reference + src_list: name of source list + dst_list: name of destination list + exclude: set of positions to skip +--]] +function unified_inventory.swap_items(inv, src_list, dst_list, exclude) + local size = inv:get_size(src_list) + local empty = ItemStack(nil) + + for i = 1, size do + if exclude == nil or exclude[i] == nil then + local stack = inv:get_stack(src_list, i) + + if not stack:is_empty() then + inv:set_stack(src_list, i, empty) + local leftover = inv:add_item(dst_list, stack) + + if not leftover:is_empty() then + inv:set_stack(src_list, i, leftover) + end + end + end + end +end + +--[[ +Move matched items to the destination list. + +If destination list position is already occupied with some other item +then function tries to (in that order): +1. Move it to the source list +2. Move it to some other unused position in destination list itself +3. Drop it to the ground if nothing else is possible. + +Arguments: + player: minetest player object + src_list: name of source list + dst_list: name of destination list + match_table: table of matched items + amount: amount of items per every position +--]] +function unified_inventory.move_match(player, src_list, dst_list, match_table, amount) + local inv = player:get_inventory() + local item_drop = minetest.item_drop + local src_dst_list = {src_list, dst_list} + local dst_src_list = {dst_list, src_list} + + local needed = {} + local moved = {} + + -- Remove stacks needed for craft + for item, pos_set in pairs(match_table) do + local stack = ItemStack(item) + local stack_max = stack:get_stack_max() + local bounded_amount = math.min(stack_max, amount) + stack:set_count(bounded_amount) + + for pos in pairs(pos_set) do + needed[pos] = unified_inventory.remove_item(inv, dst_src_list, stack) + end + end + + -- Add already removed stacks + for pos, stack in pairs(needed) do + local occupied = inv:get_stack(dst_list, pos) + inv:set_stack(dst_list, pos, stack) + + if not occupied:is_empty() then + local leftover = unified_inventory.add_item(inv, src_dst_list, occupied) + + if not leftover:is_empty() then + inv:set_stack(dst_list, pos, leftover) + local oversize = unified_inventory.add_item(inv, src_dst_list, stack) + + if not oversize:is_empty() then + item_drop(oversize, player, player:get_pos()) + end + end + end + + moved[pos] = true + end + + -- Swap items from unused positions to src (moved positions excluded) + unified_inventory.swap_items(inv, dst_list, src_list, moved) +end + +--[[ +Find craft match and move matched items to the destination list. + +If match cannot be found or match count is smaller than the desired +amount then do nothing. + +If amount passed is -1 then amount is defined by match count itself. +This is used to indicate "craft All" case. + +Arguments: + player: minetest player object + src_list: name of source list + dst_list: name of destination list + craft: minetest craft recipe + amount: desired amount of output items +--]] +function unified_inventory.craftguide_match_craft(player, src_list, dst_list, craft, amount) + local inv = player:get_inventory() + local src_dst_list = {src_list, dst_list} + + local counts = unified_inventory.count_items(inv, src_dst_list) + local positions = unified_inventory.count_craft_positions(craft) + local match_table, match_count = unified_inventory.match_items(counts, positions) + + if match_table == nil or match_count < amount then + return + end + + if amount == -1 then + amount = match_count + end + + unified_inventory.move_match(player, src_list, dst_list, match_table, amount) +end diff --git a/mods/unified_inventory/mod.conf b/mods/unified_inventory/mod.conf new file mode 100644 index 00000000..4fe3375f --- /dev/null +++ b/mods/unified_inventory/mod.conf @@ -0,0 +1,4 @@ +name = unified_inventory +depends = default +optional_depends = creative, sfinv, datastorage, farming +description = Unified Inventory replaces the default survival and creative inventory. It adds a nicer interface and a number of features, such as a crafting guide. diff --git a/mods/unified_inventory/register.lua b/mods/unified_inventory/register.lua new file mode 100644 index 00000000..d89c05e5 --- /dev/null +++ b/mods/unified_inventory/register.lua @@ -0,0 +1,489 @@ +local S = minetest.get_translator("unified_inventory") +local NS = function(s) return s end +local F = minetest.formspec_escape + +minetest.register_privilege("creative", { + description = S("Can use the creative inventory"), + give_to_singleplayer = false, +}) + +minetest.register_privilege("ui_full", { + description = S("Forces Unified Inventory to be displayed in Full mode if Lite mode is configured globally"), + give_to_singleplayer = false, +}) + + +local trash = minetest.create_detached_inventory("trash", { + --allow_put = function(inv, listname, index, stack, player) + -- if unified_inventory.is_creative(player:get_player_name()) then + -- return stack:get_count() + -- else + -- return 0 + -- end + --end, + on_put = function(inv, listname, index, stack, player) + inv:set_stack(listname, index, nil) + local player_name = player:get_player_name() + minetest.sound_play("trash", {to_player=player_name, gain = 1.0}) + end, +}) +trash:set_size("main", 1) + +unified_inventory.register_button("craft", { + type = "image", + image = "ui_craft_icon.png", + tooltip = S("Crafting Grid") +}) + +unified_inventory.register_button("craftguide", { + type = "image", + image = "ui_craftguide_icon.png", + tooltip = S("Crafting Guide") +}) + +unified_inventory.register_button("home_gui_set", { + type = "image", + image = "ui_sethome_icon.png", + tooltip = S("Set home position"), + hide_lite=true, + action = function(player) + local player_name = player:get_player_name() + if minetest.check_player_privs(player_name, {home=true}) then + unified_inventory.set_home(player, player:get_pos()) + local home = unified_inventory.home_pos[player_name] + if home ~= nil then + minetest.sound_play("dingdong", + {to_player=player_name, gain = 1.0}) + minetest.chat_send_player(player_name, + S("Home position set to: @1", minetest.pos_to_string(home))) + end + else + minetest.chat_send_player(player_name, + S("You don't have the \"home\" privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + end + end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {home=true}) + end, +}) + +unified_inventory.register_button("home_gui_go", { + type = "image", + image = "ui_gohome_icon.png", + tooltip = S("Go home"), + hide_lite=true, + action = function(player) + local player_name = player:get_player_name() + if minetest.check_player_privs(player_name, {home=true}) then + minetest.sound_play("teleport", + {to_player=player:get_player_name(), gain = 1.0}) + unified_inventory.go_home(player) + else + minetest.chat_send_player(player_name, + S("You don't have the \"home\" privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + end + end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {home=true}) + end, +}) + +unified_inventory.register_button("misc_set_day", { + type = "image", + image = "ui_sun_icon.png", + tooltip = S("Set time to day"), + hide_lite=true, + action = function(player) + local player_name = player:get_player_name() + if minetest.check_player_privs(player_name, {settime=true}) then + minetest.sound_play("birds", + {to_player=player_name, gain = 1.0}) + minetest.set_timeofday((6000 % 24000) / 24000) + minetest.chat_send_player(player_name, + S("Time of day set to 6am")) + else + minetest.chat_send_player(player_name, + S("You don't have the settime privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + end + end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {settime=true}) + end, +}) + +unified_inventory.register_button("misc_set_night", { + type = "image", + image = "ui_moon_icon.png", + tooltip = S("Set time to night"), + hide_lite=true, + action = function(player) + local player_name = player:get_player_name() + if minetest.check_player_privs(player_name, {settime=true}) then + minetest.sound_play("owl", + {to_player=player_name, gain = 1.0}) + minetest.set_timeofday((21000 % 24000) / 24000) + minetest.chat_send_player(player_name, + S("Time of day set to 9pm")) + else + minetest.chat_send_player(player_name, + S("You don't have the settime privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + end + end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {settime=true}) + end, +}) + +unified_inventory.register_button("clear_inv", { + type = "image", + image = "ui_trash_icon.png", + tooltip = S("Clear inventory"), + action = function(player) + local player_name = player:get_player_name() + if not unified_inventory.is_creative(player_name) then + minetest.chat_send_player(player_name, + S("This button has been disabled outside" + .." of creative mode to prevent" + .." accidental inventory trashing." + .."\nUse the trash slot instead.")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) + return + end + player:get_inventory():set_list("main", {}) + minetest.chat_send_player(player_name, S('Inventory cleared!')) + minetest.sound_play("trash_all", + {to_player=player_name, gain = 1.0}) + end, + condition = function(player) + return unified_inventory.is_creative(player:get_player_name()) + end, +}) + +unified_inventory.register_page("craft", { + get_formspec = function(player, perplayer_formspec) + + local formspecy = perplayer_formspec.formspec_y + local formheadery = perplayer_formspec.form_header_y + + local player_name = player:get_player_name() + local formspec = "background[2,"..formspecy..";6,3;ui_crafting_form.png]" + formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]" + formspec = formspec.."label[0,"..formheadery..";" ..F(S("Crafting")).."]" + formspec = formspec.."listcolors[#00000000;#00000000]" + formspec = formspec.."list[current_player;craftpreview;6,"..formspecy..";1,1;]" + formspec = formspec.."list[current_player;craft;2,"..formspecy..";3,3;]" + if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then + formspec = formspec.."label[7,"..(formspecy + 1.5)..";" .. F(S("Trash:")) .. "]" + formspec = formspec.."background[7,"..(formspecy + 2)..";1,1;ui_single_slot.png]" + formspec = formspec.."list[detached:trash;main;7,"..(formspecy + 2)..";1,1;]" + end + formspec = formspec.."listring[current_name;craft]" + formspec = formspec.."listring[current_player;main]" + if unified_inventory.is_creative(player_name) then + formspec = formspec.."label[0,"..(formspecy + 1.5)..";" .. F(S("Refill:")) .. "]" + formspec = formspec.."list[detached:"..F(player_name).."refill;main;0,"..(formspecy +2)..";1,1;]" + end + return {formspec=formspec} + end, +}) + +-- stack_image_button(): generate a form button displaying a stack of items +-- +-- The specified item may be a group. In that case, the group will be +-- represented by some item in the group, along with a flag indicating +-- that it's a group. If the group contains only one item, it will be +-- treated as if that item had been specified directly. + +local function stack_image_button(x, y, w, h, buttonname_prefix, item) + local name = item:get_name() + local count = item:get_count() + local show_is_group = false + local displayitem = name.." "..count + local selectitem = name + if name:sub(1, 6) == "group:" then + local group_name = name:sub(7) + local group_item = unified_inventory.get_group_item(group_name) + show_is_group = not group_item.sole + displayitem = group_item.item or "unknown" + selectitem = group_item.sole and displayitem or name + end + local label = show_is_group and "G" or "" + local buttonname = F(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem)) + local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]", + x, y, w, h, + F(displayitem), buttonname, label) + if show_is_group then + local groupstring, andcount = unified_inventory.extract_groupnames(name) + local grouptip + if andcount == 1 then + grouptip = S("Any item belonging to the @1 group", groupstring) + elseif andcount > 1 then + grouptip = S("Any item belonging to the groups @1", groupstring) + end + grouptip = F(grouptip) + if andcount >= 1 then + button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip) + end + end + return button +end + +local recipe_text = { + recipe = NS("Recipe @1 of @2"), + usage = NS("Usage @1 of @2"), +} +local no_recipe_text = { + recipe = S("No recipes"), + usage = S("No usages"), +} +local role_text = { + recipe = S("Result"), + usage = S("Ingredient"), +} +local next_alt_text = { + recipe = S("Show next recipe"), + usage = S("Show next usage"), +} +local prev_alt_text = { + recipe = S("Show previous recipe"), + usage = S("Show previous usage"), +} +local other_dir = { + recipe = "usage", + usage = "recipe", +} + +unified_inventory.register_page("craftguide", { + get_formspec = function(player, perplayer_formspec) + + local formspecy = perplayer_formspec.formspec_y + local formheadery = perplayer_formspec.form_header_y + local craftresultx = perplayer_formspec.craft_result_x + local craftresulty = perplayer_formspec.craft_result_y + + local player_name = player:get_player_name() + local player_privs = minetest.get_player_privs(player_name) + local fs = { + "background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]", + "label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]", + "listcolors[#00000000;#00000000]" + } + local item_name = unified_inventory.current_item[player_name] + if not item_name then + return { formspec = table.concat(fs) } + end + + local item_name_shown + if minetest.registered_items[item_name] + and minetest.registered_items[item_name].description then + item_name_shown = S("@1 (@2)", + minetest.registered_items[item_name].description, item_name) + else + item_name_shown = item_name + end + + local dir = unified_inventory.current_craft_direction[player_name] + local rdir = dir == "recipe" and "usage" or "recipe" + + local crafts = unified_inventory.crafts_for[dir][item_name] + local alternate = unified_inventory.alternate[player_name] + local alternates, craft + if crafts and #crafts > 0 then + alternates = #crafts + craft = crafts[alternate] + end + local has_give = player_privs.give or unified_inventory.is_creative(player_name) + + fs[#fs + 1] = "background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]" + fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]", + craftresultx, craftresulty, F(role_text[dir]), item_name_shown) + fs[#fs + 1] = stack_image_button(0, formspecy, 1.1, 1.1, + "item_button_" .. rdir .. "_", ItemStack(item_name)) + + if not craft then + -- No craft recipes available for this item. + fs[#fs + 1] = "label[5.5,"..(formspecy + 2.35)..";" + .. F(no_recipe_text[dir]) .. "]" + local no_pos = dir == "recipe" and 4.5 or 6.5 + local item_pos = dir == "recipe" and 6.5 or 4.5 + fs[#fs + 1] = "image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]" + fs[#fs + 1] = stack_image_button(item_pos, formspecy, 1.1, 1.1, + "item_button_" .. other_dir[dir] .. "_", ItemStack(item_name)) + if has_give then + fs[#fs + 1] = "label[0," .. (formspecy + 2.10) .. ";" .. F(S("Give me:")) .. "]" + .. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]" + .. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]" + .. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]" + end + return { formspec = table.concat(fs) } + end + + local craft_type = unified_inventory.registered_craft_types[craft.type] or + unified_inventory.craft_type_defaults(craft.type, {}) + if craft_type.icon then + fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]", + 5.7, (formspecy + 0.05), 0.5, 0.5, craft_type.icon) + end + fs[#fs + 1] = "label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]" + fs[#fs + 1] = stack_image_button(6.5, formspecy, 1.1, 1.1, + "item_button_usage_", ItemStack(craft.output)) + + local display_size = craft_type.dynamic_display_size + and craft_type.dynamic_display_size(craft) + or { width = craft_type.width, height = craft_type.height } + local craft_width = craft_type.get_shaped_craft_width + and craft_type.get_shaped_craft_width(craft) + or display_size.width + + -- This keeps recipes aligned to the right, + -- so that they're close to the arrow. + local xoffset = 5.5 + -- Offset factor for crafting grids with side length > 4 + local of = (3/math.max(3, math.max(display_size.width, display_size.height))) + local od = 0 + -- Minimum grid size at which size optimazation measures kick in + local mini_craft_size = 6 + if display_size.width >= mini_craft_size then + od = math.max(1, display_size.width - 2) + xoffset = xoffset - 0.1 + end + -- Size modifier factor + local sf = math.min(1, of * (1.05 + 0.05*od)) + -- Button size + local bsize_h = 1.1 * sf + local bsize_w = bsize_h + if display_size.width >= mini_craft_size then + bsize_w = 1.175 * sf + end + if (bsize_h > 0.35 and display_size.width) then + for y = 1, display_size.height do + for x = 1, display_size.width do + local item + if craft and x <= craft_width then + item = craft.items[(y-1) * craft_width + x] + end + -- Flipped x, used to build formspec buttons from right to left + local fx = display_size.width - (x-1) + -- x offset, y offset + local xof = (fx-1) * of + of + local yof = (y-1) * of + 1 + if item then + fs[#fs + 1] = stack_image_button( + xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h, + "item_button_recipe_", + ItemStack(item)) + else + -- Fake buttons just to make grid + fs[#fs + 1] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]", + xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h) + end + end + end + else + -- Error + fs[#fs + 1] = string.format("label[2,%f;%s]", + formspecy, F(S("This recipe is too\nlarge to be displayed."))) + end + + if craft_type.uses_crafting_grid and display_size.width <= 3 then + fs[#fs + 1] = "label[0," .. (formspecy + 0.9) .. ";" .. F(S("To craft grid:")) .. "]" + .. "button[0, " .. (formspecy + 1.5) .. ";0.6,0.5;craftguide_craft_1;1]" + .. "button[0.6," .. (formspecy + 1.5) .. ";0.7,0.5;craftguide_craft_10;10]" + .. "button[1.3," .. (formspecy + 1.5) .. ";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]" + end + if has_give then + fs[#fs + 1] = "label[0," .. (formspecy + 2.1) .. ";" .. F(S("Give me:")) .. "]" + .. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]" + .. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]" + .. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]" + end + + if alternates and alternates > 1 then + fs[#fs + 1] = "label[5.5," .. (formspecy + 1.6) .. ";" + .. F(S(recipe_text[dir], alternate, alternates)) .. "]" + .. "image_button[5.5," .. (formspecy + 2) .. ";1,1;ui_left_icon.png;alternate_prev;]" + .. "image_button[6.5," .. (formspecy + 2) .. ";1,1;ui_right_icon.png;alternate;]" + .. "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]" + .. "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]" + end + return { formspec = table.concat(fs) } + end, +}) + +local function craftguide_giveme(player, formname, fields) + local player_name = player:get_player_name() + local player_privs = minetest.get_player_privs(player_name) + if not player_privs.give and + not unified_inventory.is_creative(player_name) then + minetest.log("action", "[unified_inventory] Denied give action to player " .. + player_name) + return + end + + local amount + for k, v in pairs(fields) do + amount = k:match("craftguide_giveme_(.*)") + if amount then break end + end + + amount = tonumber(amount) or 0 + if amount == 0 then return end + + local output = unified_inventory.current_item[player_name] + if (not output) or (output == "") then return end + + local player_inv = player:get_inventory() + + player_inv:add_item("main", {name = output, count = amount}) +end + +local function craftguide_craft(player, formname, fields) + local amount + for k, v in pairs(fields) do + amount = k:match("craftguide_craft_(.*)") + if amount then break end + end + if not amount then return end + + amount = tonumber(amount) or -1 -- fallback for "all" + if amount == 0 or amount < -1 or amount > 99 then return end + + local player_name = player:get_player_name() + + local output = unified_inventory.current_item[player_name] or "" + if output == "" then return end + + local crafts = unified_inventory.crafts_for[ + unified_inventory.current_craft_direction[player_name]][output] or {} + if #crafts == 0 then return end + + local alternate = unified_inventory.alternate[player_name] + + local craft = crafts[alternate] + if craft.width > 3 then return end + + unified_inventory.craftguide_match_craft(player, "main", "craft", craft, amount) + + unified_inventory.set_inventory_formspec(player, "craft") +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "" then + return + end + + for k, v in pairs(fields) do + if k:match("craftguide_craft_") then + craftguide_craft(player, formname, fields) + return + end + if k:match("craftguide_giveme_") then + craftguide_giveme(player, formname, fields) + return + end + end +end) diff --git a/mods/unified_inventory/screenshot.png b/mods/unified_inventory/screenshot.png new file mode 100644 index 00000000..972cbb46 Binary files /dev/null and b/mods/unified_inventory/screenshot.png differ diff --git a/mods/unified_inventory/settingtypes.txt b/mods/unified_inventory/settingtypes.txt new file mode 100644 index 00000000..910989fd --- /dev/null +++ b/mods/unified_inventory/settingtypes.txt @@ -0,0 +1,11 @@ +#Enabling lite mode enables a smaller and simpler version of the Unified +#Inventory, optimized for small displays. +unified_inventory_lite (Lite mode) bool false + +#If enabled, bags will be made available which can be used to extend +#inventory storage size. +unified_inventory_bags (Enable bags) bool true + +#If enabled, the trash slot can be used by those without both creative +#and the give privilege. +unified_inventory_trash (Enable trash) bool true diff --git a/mods/unified_inventory/sounds/birds.ogg b/mods/unified_inventory/sounds/birds.ogg new file mode 100644 index 00000000..4a933954 Binary files /dev/null and b/mods/unified_inventory/sounds/birds.ogg differ diff --git a/mods/unified_inventory/sounds/click.ogg b/mods/unified_inventory/sounds/click.ogg new file mode 100644 index 00000000..3db63a07 Binary files /dev/null and b/mods/unified_inventory/sounds/click.ogg differ diff --git a/mods/unified_inventory/sounds/dingdong.ogg b/mods/unified_inventory/sounds/dingdong.ogg new file mode 100644 index 00000000..2c9d7ef7 Binary files /dev/null and b/mods/unified_inventory/sounds/dingdong.ogg differ diff --git a/mods/unified_inventory/sounds/electricity.ogg b/mods/unified_inventory/sounds/electricity.ogg new file mode 100644 index 00000000..4cd7c846 Binary files /dev/null and b/mods/unified_inventory/sounds/electricity.ogg differ diff --git a/mods/unified_inventory/sounds/owl.ogg b/mods/unified_inventory/sounds/owl.ogg new file mode 100644 index 00000000..f30d0b3c Binary files /dev/null and b/mods/unified_inventory/sounds/owl.ogg differ diff --git a/mods/unified_inventory/sounds/paperflip1.ogg b/mods/unified_inventory/sounds/paperflip1.ogg new file mode 100644 index 00000000..eaed13f8 Binary files /dev/null and b/mods/unified_inventory/sounds/paperflip1.ogg differ diff --git a/mods/unified_inventory/sounds/paperflip2.ogg b/mods/unified_inventory/sounds/paperflip2.ogg new file mode 100644 index 00000000..321bc487 Binary files /dev/null and b/mods/unified_inventory/sounds/paperflip2.ogg differ diff --git a/mods/unified_inventory/sounds/teleport.ogg b/mods/unified_inventory/sounds/teleport.ogg new file mode 100644 index 00000000..ca32f745 Binary files /dev/null and b/mods/unified_inventory/sounds/teleport.ogg differ diff --git a/mods/unified_inventory/sounds/trash.ogg b/mods/unified_inventory/sounds/trash.ogg new file mode 100644 index 00000000..51e4f24a Binary files /dev/null and b/mods/unified_inventory/sounds/trash.ogg differ diff --git a/mods/unified_inventory/sounds/trash_all.ogg b/mods/unified_inventory/sounds/trash_all.ogg new file mode 100644 index 00000000..85c3f66c Binary files /dev/null and b/mods/unified_inventory/sounds/trash_all.ogg differ diff --git a/mods/unified_inventory/textures/bags_large.png b/mods/unified_inventory/textures/bags_large.png new file mode 100644 index 00000000..187021c0 Binary files /dev/null and b/mods/unified_inventory/textures/bags_large.png differ diff --git a/mods/unified_inventory/textures/bags_medium.png b/mods/unified_inventory/textures/bags_medium.png new file mode 100644 index 00000000..d908883f Binary files /dev/null and b/mods/unified_inventory/textures/bags_medium.png differ diff --git a/mods/unified_inventory/textures/bags_small.png b/mods/unified_inventory/textures/bags_small.png new file mode 100644 index 00000000..9e4f4f61 Binary files /dev/null and b/mods/unified_inventory/textures/bags_small.png differ diff --git a/mods/unified_inventory/textures/ui_1_icon.png b/mods/unified_inventory/textures/ui_1_icon.png new file mode 100644 index 00000000..ed4ceb9e Binary files /dev/null and b/mods/unified_inventory/textures/ui_1_icon.png differ diff --git a/mods/unified_inventory/textures/ui_2_icon.png b/mods/unified_inventory/textures/ui_2_icon.png new file mode 100644 index 00000000..f4566d83 Binary files /dev/null and b/mods/unified_inventory/textures/ui_2_icon.png differ diff --git a/mods/unified_inventory/textures/ui_3_icon.png b/mods/unified_inventory/textures/ui_3_icon.png new file mode 100644 index 00000000..ff6ebbba Binary files /dev/null and b/mods/unified_inventory/textures/ui_3_icon.png differ diff --git a/mods/unified_inventory/textures/ui_4_icon.png b/mods/unified_inventory/textures/ui_4_icon.png new file mode 100644 index 00000000..3a12bfd2 Binary files /dev/null and b/mods/unified_inventory/textures/ui_4_icon.png differ diff --git a/mods/unified_inventory/textures/ui_5_icon.png b/mods/unified_inventory/textures/ui_5_icon.png new file mode 100644 index 00000000..c3891528 Binary files /dev/null and b/mods/unified_inventory/textures/ui_5_icon.png differ diff --git a/mods/unified_inventory/textures/ui_bags_icon.png b/mods/unified_inventory/textures/ui_bags_icon.png new file mode 100644 index 00000000..2882a239 Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_icon.png differ diff --git a/mods/unified_inventory/textures/ui_bags_lg_form.png b/mods/unified_inventory/textures/ui_bags_lg_form.png new file mode 100644 index 00000000..24dab308 Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_lg_form.png differ diff --git a/mods/unified_inventory/textures/ui_bags_main_form.png b/mods/unified_inventory/textures/ui_bags_main_form.png new file mode 100644 index 00000000..8c168d29 Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_main_form.png differ diff --git a/mods/unified_inventory/textures/ui_bags_med_form.png b/mods/unified_inventory/textures/ui_bags_med_form.png new file mode 100644 index 00000000..27a1591c Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_med_form.png differ diff --git a/mods/unified_inventory/textures/ui_bags_sm_form.png b/mods/unified_inventory/textures/ui_bags_sm_form.png new file mode 100644 index 00000000..6234eb88 Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_sm_form.png differ diff --git a/mods/unified_inventory/textures/ui_bags_trash.png b/mods/unified_inventory/textures/ui_bags_trash.png new file mode 100644 index 00000000..0bc11c56 Binary files /dev/null and b/mods/unified_inventory/textures/ui_bags_trash.png differ diff --git a/mods/unified_inventory/textures/ui_blank_image.png b/mods/unified_inventory/textures/ui_blank_image.png new file mode 100644 index 00000000..83d9d1a6 Binary files /dev/null and b/mods/unified_inventory/textures/ui_blank_image.png differ diff --git a/mods/unified_inventory/textures/ui_blue_icon_background.png b/mods/unified_inventory/textures/ui_blue_icon_background.png new file mode 100644 index 00000000..2f872a46 Binary files /dev/null and b/mods/unified_inventory/textures/ui_blue_icon_background.png differ diff --git a/mods/unified_inventory/textures/ui_circular_arrows_icon.png b/mods/unified_inventory/textures/ui_circular_arrows_icon.png new file mode 100644 index 00000000..c6846e62 Binary files /dev/null and b/mods/unified_inventory/textures/ui_circular_arrows_icon.png differ diff --git a/mods/unified_inventory/textures/ui_craft_icon.png b/mods/unified_inventory/textures/ui_craft_icon.png new file mode 100644 index 00000000..a2283e30 Binary files /dev/null and b/mods/unified_inventory/textures/ui_craft_icon.png differ diff --git a/mods/unified_inventory/textures/ui_craftgrid_icon.png b/mods/unified_inventory/textures/ui_craftgrid_icon.png new file mode 100644 index 00000000..5111f1e9 Binary files /dev/null and b/mods/unified_inventory/textures/ui_craftgrid_icon.png differ diff --git a/mods/unified_inventory/textures/ui_craftguide_form.png b/mods/unified_inventory/textures/ui_craftguide_form.png new file mode 100644 index 00000000..d9be53f7 Binary files /dev/null and b/mods/unified_inventory/textures/ui_craftguide_form.png differ diff --git a/mods/unified_inventory/textures/ui_craftguide_icon.png b/mods/unified_inventory/textures/ui_craftguide_icon.png new file mode 100644 index 00000000..d6c89e6e Binary files /dev/null and b/mods/unified_inventory/textures/ui_craftguide_icon.png differ diff --git a/mods/unified_inventory/textures/ui_crafting_form.png b/mods/unified_inventory/textures/ui_crafting_form.png new file mode 100644 index 00000000..90432879 Binary files /dev/null and b/mods/unified_inventory/textures/ui_crafting_form.png differ diff --git a/mods/unified_inventory/textures/ui_doubleleft_icon.png b/mods/unified_inventory/textures/ui_doubleleft_icon.png new file mode 100644 index 00000000..64d50c05 Binary files /dev/null and b/mods/unified_inventory/textures/ui_doubleleft_icon.png differ diff --git a/mods/unified_inventory/textures/ui_doubleright_icon.png b/mods/unified_inventory/textures/ui_doubleright_icon.png new file mode 100644 index 00000000..af209302 Binary files /dev/null and b/mods/unified_inventory/textures/ui_doubleright_icon.png differ diff --git a/mods/unified_inventory/textures/ui_form_bg.png b/mods/unified_inventory/textures/ui_form_bg.png new file mode 100644 index 00000000..d973b34a Binary files /dev/null and b/mods/unified_inventory/textures/ui_form_bg.png differ diff --git a/mods/unified_inventory/textures/ui_gohome_icon.png b/mods/unified_inventory/textures/ui_gohome_icon.png new file mode 100644 index 00000000..c5126ae5 Binary files /dev/null and b/mods/unified_inventory/textures/ui_gohome_icon.png differ diff --git a/mods/unified_inventory/textures/ui_green_icon_background.png b/mods/unified_inventory/textures/ui_green_icon_background.png new file mode 100644 index 00000000..ea28c822 Binary files /dev/null and b/mods/unified_inventory/textures/ui_green_icon_background.png differ diff --git a/mods/unified_inventory/textures/ui_group.png b/mods/unified_inventory/textures/ui_group.png new file mode 100644 index 00000000..b6b8d28c Binary files /dev/null and b/mods/unified_inventory/textures/ui_group.png differ diff --git a/mods/unified_inventory/textures/ui_home_icon.png b/mods/unified_inventory/textures/ui_home_icon.png new file mode 100644 index 00000000..b9ce4f3d Binary files /dev/null and b/mods/unified_inventory/textures/ui_home_icon.png differ diff --git a/mods/unified_inventory/textures/ui_left_icon.png b/mods/unified_inventory/textures/ui_left_icon.png new file mode 100644 index 00000000..373b71ef Binary files /dev/null and b/mods/unified_inventory/textures/ui_left_icon.png differ diff --git a/mods/unified_inventory/textures/ui_main_inventory.png b/mods/unified_inventory/textures/ui_main_inventory.png new file mode 100644 index 00000000..b7860cad Binary files /dev/null and b/mods/unified_inventory/textures/ui_main_inventory.png differ diff --git a/mods/unified_inventory/textures/ui_misc_form.png b/mods/unified_inventory/textures/ui_misc_form.png new file mode 100644 index 00000000..2d6ad018 Binary files /dev/null and b/mods/unified_inventory/textures/ui_misc_form.png differ diff --git a/mods/unified_inventory/textures/ui_moon_icon.png b/mods/unified_inventory/textures/ui_moon_icon.png new file mode 100644 index 00000000..cec7009d Binary files /dev/null and b/mods/unified_inventory/textures/ui_moon_icon.png differ diff --git a/mods/unified_inventory/textures/ui_no.png b/mods/unified_inventory/textures/ui_no.png new file mode 100644 index 00000000..aa98ed62 Binary files /dev/null and b/mods/unified_inventory/textures/ui_no.png differ diff --git a/mods/unified_inventory/textures/ui_off_icon.png b/mods/unified_inventory/textures/ui_off_icon.png new file mode 100644 index 00000000..187e59a6 Binary files /dev/null and b/mods/unified_inventory/textures/ui_off_icon.png differ diff --git a/mods/unified_inventory/textures/ui_ok_icon.png b/mods/unified_inventory/textures/ui_ok_icon.png new file mode 100644 index 00000000..4073899c Binary files /dev/null and b/mods/unified_inventory/textures/ui_ok_icon.png differ diff --git a/mods/unified_inventory/textures/ui_on_icon.png b/mods/unified_inventory/textures/ui_on_icon.png new file mode 100644 index 00000000..0f5c48ff Binary files /dev/null and b/mods/unified_inventory/textures/ui_on_icon.png differ diff --git a/mods/unified_inventory/textures/ui_pencil_icon.png b/mods/unified_inventory/textures/ui_pencil_icon.png new file mode 100644 index 00000000..dfcc19bc Binary files /dev/null and b/mods/unified_inventory/textures/ui_pencil_icon.png differ diff --git a/mods/unified_inventory/textures/ui_red_icon_background.png b/mods/unified_inventory/textures/ui_red_icon_background.png new file mode 100644 index 00000000..8d4d8070 Binary files /dev/null and b/mods/unified_inventory/textures/ui_red_icon_background.png differ diff --git a/mods/unified_inventory/textures/ui_reset_icon.png b/mods/unified_inventory/textures/ui_reset_icon.png new file mode 100644 index 00000000..e966685c Binary files /dev/null and b/mods/unified_inventory/textures/ui_reset_icon.png differ diff --git a/mods/unified_inventory/textures/ui_right_icon.png b/mods/unified_inventory/textures/ui_right_icon.png new file mode 100644 index 00000000..cbdab76d Binary files /dev/null and b/mods/unified_inventory/textures/ui_right_icon.png differ diff --git a/mods/unified_inventory/textures/ui_search_icon.png b/mods/unified_inventory/textures/ui_search_icon.png new file mode 100644 index 00000000..2934bdcf Binary files /dev/null and b/mods/unified_inventory/textures/ui_search_icon.png differ diff --git a/mods/unified_inventory/textures/ui_sethome_icon.png b/mods/unified_inventory/textures/ui_sethome_icon.png new file mode 100644 index 00000000..4c0f6e58 Binary files /dev/null and b/mods/unified_inventory/textures/ui_sethome_icon.png differ diff --git a/mods/unified_inventory/textures/ui_single_slot.png b/mods/unified_inventory/textures/ui_single_slot.png new file mode 100644 index 00000000..63da98d9 Binary files /dev/null and b/mods/unified_inventory/textures/ui_single_slot.png differ diff --git a/mods/unified_inventory/textures/ui_skip_backward_icon.png b/mods/unified_inventory/textures/ui_skip_backward_icon.png new file mode 100644 index 00000000..eac6e4c7 Binary files /dev/null and b/mods/unified_inventory/textures/ui_skip_backward_icon.png differ diff --git a/mods/unified_inventory/textures/ui_skip_forward_icon.png b/mods/unified_inventory/textures/ui_skip_forward_icon.png new file mode 100644 index 00000000..3f85a9f7 Binary files /dev/null and b/mods/unified_inventory/textures/ui_skip_forward_icon.png differ diff --git a/mods/unified_inventory/textures/ui_sun_icon.png b/mods/unified_inventory/textures/ui_sun_icon.png new file mode 100644 index 00000000..11c7eef2 Binary files /dev/null and b/mods/unified_inventory/textures/ui_sun_icon.png differ diff --git a/mods/unified_inventory/textures/ui_trash_icon.png b/mods/unified_inventory/textures/ui_trash_icon.png new file mode 100644 index 00000000..c5ac97c6 Binary files /dev/null and b/mods/unified_inventory/textures/ui_trash_icon.png differ diff --git a/mods/unified_inventory/textures/ui_waypoint_set_icon.png b/mods/unified_inventory/textures/ui_waypoint_set_icon.png new file mode 100644 index 00000000..4649a4d4 Binary files /dev/null and b/mods/unified_inventory/textures/ui_waypoint_set_icon.png differ diff --git a/mods/unified_inventory/textures/ui_waypoints_icon.png b/mods/unified_inventory/textures/ui_waypoints_icon.png new file mode 100644 index 00000000..91d6e3b9 Binary files /dev/null and b/mods/unified_inventory/textures/ui_waypoints_icon.png differ diff --git a/mods/unified_inventory/textures/ui_xyz_icon.png b/mods/unified_inventory/textures/ui_xyz_icon.png new file mode 100644 index 00000000..003ea633 Binary files /dev/null and b/mods/unified_inventory/textures/ui_xyz_icon.png differ diff --git a/mods/unified_inventory/textures/ui_xyz_off_icon.png b/mods/unified_inventory/textures/ui_xyz_off_icon.png new file mode 100644 index 00000000..3c1836eb Binary files /dev/null and b/mods/unified_inventory/textures/ui_xyz_off_icon.png differ diff --git a/mods/unified_inventory/textures/ui_xyz_on_icon.png b/mods/unified_inventory/textures/ui_xyz_on_icon.png new file mode 100644 index 00000000..003ea633 Binary files /dev/null and b/mods/unified_inventory/textures/ui_xyz_on_icon.png differ diff --git a/mods/unified_inventory/waypoints.lua b/mods/unified_inventory/waypoints.lua new file mode 100644 index 00000000..e23ef4b2 --- /dev/null +++ b/mods/unified_inventory/waypoints.lua @@ -0,0 +1,247 @@ +local S = minetest.get_translator("unified_inventory") +local F = minetest.formspec_escape + +local hud_colors = { + {"#FFFFFF", 0xFFFFFF, S("White")}, + {"#DBBB00", 0xf1d32c, S("Yellow")}, + {"#DD0000", 0xDD0000, S("Red")}, + {"#2cf136", 0x2cf136, S("Green")}, + {"#2c4df1", 0x2c4df1, S("Blue")}, +} + +local hud_colors_max = #hud_colors + +-- Stores temporary player data (persists until player leaves) +local waypoints_temp = {} + +unified_inventory.register_page("waypoints", { + get_formspec = function(player) + local player_name = player:get_player_name() + + -- build a "fake" temp entry if the server took too long + -- during sign-on and returned an empty entry + if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end + + local waypoints = datastorage.get(player_name, "waypoints") + local formspec = "background[0,4.5;8,4;ui_main_inventory.png]" .. + "image[0,0;1,1;ui_waypoints_icon.png]" .. + "label[1,0;" .. F(S("Waypoints")) .. "]" + + -- Tabs buttons: + for i = 1, 5, 1 do + formspec = formspec .. + "image_button[0.0," .. 0.2 + i * 0.7 .. ";.8,.8;" .. + (i == waypoints.selected and "ui_blue_icon_background.png^" or "") .. + "ui_" .. i .. "_icon.png;" .. + "select_waypoint" .. i .. ";]" .. + "tooltip[select_waypoint" .. i .. ";" + .. S("Select Waypoint #@1", i).."]" + end + + local i = waypoints.selected or 1 + local waypoint = waypoints[i] or {} + local temp = waypoints_temp[player_name][i] or {} + local default_name = S("Waypoint @1", i) + + -- Main buttons: + formspec = formspec .. + "image_button[4.5,3.7;.8,.8;".. + "ui_waypoint_set_icon.png;".. + "set_waypoint"..i..";]".. + "tooltip[set_waypoint" .. i .. ";" + .. F(S("Set waypoint to current location")).."]" + + formspec = formspec .. + "image_button[5.2,3.7;.8,.8;".. + (waypoint.active and "ui_on_icon.png" or "ui_off_icon.png")..";".. + "toggle_waypoint"..i..";]".. + "tooltip[toggle_waypoint" .. i .. ";" + .. F(S("Make waypoint @1", + waypoint.active and S("invisible") or S("visible"))).."]" + + formspec = formspec .. + "image_button[5.9,3.7;.8,.8;".. + (waypoint.display_pos and "ui_green_icon_background.png" or "ui_red_icon_background.png").."^ui_xyz_icon.png;".. + "toggle_display_pos" .. i .. ";]".. + "tooltip[toggle_display_pos" .. i .. ";" + .. F(S("@1 display of waypoint coordinates", + waypoint.display_pos and S("Disable") or S("Enable"))) .."]" + + formspec = formspec .. + "image_button[6.6,3.7;.8,.8;".. + "ui_circular_arrows_icon.png;".. + "toggle_color"..i..";]".. + "tooltip[toggle_color" .. i .. ";" + .. F(S("Change color of waypoint display")).."]" + + formspec = formspec .. + "image_button[7.3,3.7;.8,.8;".. + "ui_pencil_icon.png;".. + "rename_waypoint"..i..";]".. + "tooltip[rename_waypoint" .. i .. ";" + .. F(S("Edit waypoint name")).."]" + + -- Waypoint's info: + if waypoint.active then + formspec = formspec .. "label[1,0.8;"..F(S("Waypoint active")).."]" + else + formspec = formspec .. "label[1,0.8;"..F(S("Waypoint inactive")).."]" + end + + if temp.edit then + formspec = formspec .. + "field[1.3,3.2;6,.8;rename_box" .. i .. ";;" + ..(waypoint.name or default_name).."]" .. + "image_button[7.3,2.9;.8,.8;".. + "ui_ok_icon.png;".. + "confirm_rename"..i.. ";]".. + "tooltip[confirm_rename" .. i .. ";" + .. F(S("Finish editing")).."]" + end + + formspec = formspec .. "label[1,1.3;"..F(S("World position"))..": " .. + minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" .. + "label[1,1.8;"..F(S("Name"))..": ".. (waypoint.name or default_name) .. "]" .. + "label[1,2.3;"..F(S("HUD text color"))..": " .. + hud_colors[waypoint.color or 1][3] .. "]" + + return {formspec=formspec} + end, +}) + +unified_inventory.register_button("waypoints", { + type = "image", + image = "ui_waypoints_icon.png", + tooltip = S("Waypoints"), + hide_lite=true +}) + +local function update_hud(player, waypoints, temp, i) + local waypoint = waypoints[i] + if not waypoint then return end + temp[i] = temp[i] or {} + temp = temp[i] + local pos = waypoint.world_pos or vector.new() + local name + if waypoint.display_pos then + name = minetest.pos_to_string(pos) + if waypoint.name then + name = name..", "..waypoint.name + end + else + name = waypoint.name or "Waypoint "..i + end + if temp.hud then + player:hud_remove(temp.hud) + end + if waypoint.active then + temp.hud = player:hud_add({ + hud_elem_type = "waypoint", + number = hud_colors[waypoint.color or 1][2] , + name = name, + text = "m", + world_pos = pos + }) + else + temp.hud = nil + end +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "" then return end + + local player_name = player:get_player_name() + local update_formspec = false + local need_update_hud = false + local hit = false + + local waypoints = datastorage.get(player_name, "waypoints") + local temp = waypoints_temp[player_name] + for i = 1, 5, 1 do + if fields["select_waypoint"..i] then + hit = true + waypoints.selected = i + update_formspec = true + end + + if fields["toggle_waypoint"..i] then + hit = true + waypoints[i] = waypoints[i] or {} + waypoints[i].active = not (waypoints[i].active) + need_update_hud = true + update_formspec = true + end + + if fields["set_waypoint"..i] then + hit = true + local pos = player:get_pos() + pos.x = math.floor(pos.x) + pos.y = math.floor(pos.y) + pos.z = math.floor(pos.z) + waypoints[i] = waypoints[i] or {} + waypoints[i].world_pos = pos + need_update_hud = true + update_formspec = true + end + + if fields["rename_waypoint"..i] then + hit = true + temp[i] = temp[i] or {} + temp[i].edit = true + update_formspec = true + end + + if fields["toggle_display_pos"..i] then + hit = true + waypoints[i] = waypoints[i] or {} + waypoints[i].display_pos = not waypoints[i].display_pos + need_update_hud = true + update_formspec = true + end + + if fields["toggle_color"..i] then + hit = true + waypoints[i] = waypoints[i] or {} + local color = waypoints[i].color or 1 + color = color + 1 + if color > hud_colors_max then + color = 1 + end + waypoints[i].color = color + need_update_hud = true + update_formspec = true + end + + if fields["confirm_rename"..i] then + hit = true + waypoints[i] = waypoints[i] or {} + temp[i].edit = false + waypoints[i].name = fields["rename_box"..i] + need_update_hud = true + update_formspec = true + end + if need_update_hud then + update_hud(player, waypoints, temp, i) + end + if update_formspec then + unified_inventory.set_inventory_formspec(player, "waypoints") + end + if hit then return end + end +end) + + +minetest.register_on_joinplayer(function(player) + local player_name = player:get_player_name() + local waypoints = datastorage.get(player_name, "waypoints") + local temp = {} + waypoints_temp[player_name] = temp + for i = 1, 5 do + update_hud(player, waypoints, temp, i) + end +end) + +minetest.register_on_leaveplayer(function(player) + waypoints_temp[player:get_player_name()] = nil +end) +