Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
1e5a76ed18 | |||
96b8369500 | |||
03ad38cfb3 | |||
cad216468a | |||
ab3cb43705 |
@ -97,6 +97,8 @@ groups: sword
|
||||
|
||||
Cause mobs to drop more items. This value is not used in the engine; it is the responsibility of the game/mod code to implement this.
|
||||
|
||||
Supported: mobs_monster, mobs_animal
|
||||
|
||||
groups: sword
|
||||
|
||||
#### Power
|
||||
@ -224,7 +226,11 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
|
||||
- x_enchanting_scroll_mesh.png -- Derived from a texture TumeniNodes (CC BY-SA 3.0)
|
||||
- x_enchanting_scroll_particle.png
|
||||
- x_enchanting_table.png
|
||||
- x_enchanting_trade_slot.png
|
||||
- x_enchanting_gui_slot_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC BY-SA 4.0)
|
||||
- x_enchanting_gui_cloth_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC BY-SA 4.0)
|
||||
- x_enchanting_gui_cloth_trade_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC BY-SA 4.0)
|
||||
- x_enchanting_gui_formbg.png -- Derived from texture Pixel Perfection by XSSheep (CC BY-SA 4.0)
|
||||
- x_enchanting_gui_hb_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC BY-SA 4.0)
|
||||
|
||||
### Models
|
||||
|
||||
|
117
api.lua
@ -1,5 +1,3 @@
|
||||
default = minetest.global_exists('default') and default --[[@as MtgDefault]]
|
||||
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
---@type XEnchanting
|
||||
@ -475,7 +473,7 @@ function XEnchanting.get_enchanted_descriptions(self, enchantments)
|
||||
|
||||
enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted'))
|
||||
.. '\n' .. table.concat(enchantments_desc, '\n')
|
||||
enchantments_desc_masked = table.concat(enchantments_desc_masked, '') .. '...?'
|
||||
enchantments_desc_masked = table.concat(enchantments_desc_masked, '') .. '..?'
|
||||
|
||||
return {
|
||||
enchantments_desc = enchantments_desc,
|
||||
@ -536,6 +534,58 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
||||
pos = pos,
|
||||
max_hear_distance = 10
|
||||
}, true)
|
||||
|
||||
-- particles
|
||||
local particlespawner_def = {
|
||||
amount = 50,
|
||||
time = 0.5,
|
||||
minpos = { x = pos.x - 1, y = pos.y + 1, z = pos.z - 1 },
|
||||
maxpos = { x = pos.x + 1, y = pos.y + 1.5, z = pos.z + 1 },
|
||||
minvel = { x = -0.1, y = -0.5, z = -0.1 },
|
||||
maxvel = { x = 0.1, y = -1.5, z = 0.1 },
|
||||
minacc = { x = -0.1, y = -0.5, z = -0.1 },
|
||||
maxacc = { x = 0.1, y = -1.5, z = 0.1 },
|
||||
minexptime = 0.5,
|
||||
maxexptime = 1,
|
||||
minsize = 0.5,
|
||||
maxsize = 1,
|
||||
texture = 'x_enchanting_scroll_particle.png^[colorize:#A179E9:256',
|
||||
glow = 1
|
||||
}
|
||||
|
||||
if minetest.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
||||
-- new syntax, after v5.6.0
|
||||
particlespawner_def = {
|
||||
amount = 50,
|
||||
time = 0.5,
|
||||
size = {
|
||||
min = 0.5,
|
||||
max = 1,
|
||||
},
|
||||
exptime = 2,
|
||||
pos = {
|
||||
min = vector.new({ x = pos.x - 1.5, y = pos.y + 1, z = pos.z - 1.5 }),
|
||||
max = vector.new({ x = pos.x + 1.5, y = pos.y + 1.5, z = pos.z + 1.5 }),
|
||||
},
|
||||
attract = {
|
||||
kind = 'point',
|
||||
strength = 2,
|
||||
origin = vector.new({ x = pos.x, y = pos.y + 0.65, z = pos.z }),
|
||||
die_on_contact = true
|
||||
},
|
||||
texture = {
|
||||
name = 'x_enchanting_scroll_particle.png^[colorize:#A179E9:256',
|
||||
alpha_tween = {
|
||||
0.5, 1,
|
||||
style = 'fwd',
|
||||
reps = 1
|
||||
}
|
||||
},
|
||||
glow = 1
|
||||
}
|
||||
end
|
||||
|
||||
minetest.add_particlespawner(particlespawner_def)
|
||||
end
|
||||
|
||||
function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_def)
|
||||
@ -743,6 +793,39 @@ function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_d
|
||||
return data
|
||||
end
|
||||
|
||||
local function get_hotbar_bg(x, y)
|
||||
local out = ''
|
||||
|
||||
for i = 0, 7, 1 do
|
||||
out = out .. 'image[' .. x + i .. ',' .. y .. ';1,1;x_enchanting_gui_hb_bg.png]'
|
||||
end
|
||||
|
||||
return out
|
||||
end
|
||||
|
||||
local function get_list_bg(x, y)
|
||||
local out = ''
|
||||
|
||||
for row = 0, 2, 1 do
|
||||
for i = 0, 7, 1 do
|
||||
out = out .. 'image[' .. x + i .. ',' .. y + row .. ';1,1;x_enchanting_gui_slot_bg.png]'
|
||||
end
|
||||
end
|
||||
|
||||
return out
|
||||
end
|
||||
|
||||
local function get_formspec_bg(player_name)
|
||||
local info = minetest.get_player_information(player_name)
|
||||
local bg = 'background[5,5;1,1;x_enchanting_gui_formbg.png;true]'
|
||||
|
||||
if info.formspec_version > 1 then
|
||||
bg = 'background9[5,5;1,1;x_enchanting_gui_formbg.png;true;10]'
|
||||
end
|
||||
|
||||
return bg
|
||||
end
|
||||
|
||||
function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
@ -754,21 +837,29 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||
|
||||
local formspec = {
|
||||
'size[8,9]',
|
||||
'bgcolor[#080808BB;true]',
|
||||
'listcolors[#FFFFFF00;#FFFFFF1A;#FFFFFF00;#30434C;#FFF]',
|
||||
get_formspec_bg(player_name),
|
||||
'style_type[label;font=mono,bold]',
|
||||
'style[slot_1,slot_2,slot_3;font=mono,bold;textcolor=#4D413A]',
|
||||
'label[0, 0;' .. S('Enchant') .. ']',
|
||||
-- item
|
||||
'list[nodemeta:' .. spos .. ';item;0, 2.5;1, 1;]',
|
||||
'image[1,2.5;1,1;x_enchanting_trade_slot.png;]',
|
||||
'image[0, 2.5;1,1;x_enchanting_gui_cloth_bg.png]',
|
||||
-- trade
|
||||
'list[nodemeta:' .. spos .. ';trade;1, 2.5;1, 1;]',
|
||||
'image[1, 2.5;1,1;x_enchanting_gui_cloth_trade_bg.png]',
|
||||
-- inventories
|
||||
'list[current_player;main;0, 4.85;8, 1;]',
|
||||
'list[current_player;main;0, 6.08;8, 3;8]',
|
||||
'listring[nodemeta:' .. spos .. ';trade]',
|
||||
'listring[current_player;main]',
|
||||
'listring[nodemeta:' .. spos .. ';item]',
|
||||
'listring[current_player;main]'
|
||||
'listring[current_player;main]',
|
||||
}
|
||||
|
||||
if default then
|
||||
formspec[#formspec + 1] = default.get_hotbar_bg(0, 4.85)
|
||||
end
|
||||
formspec[#formspec + 1] = get_hotbar_bg(0, 4.85)
|
||||
formspec[#formspec + 1] = get_list_bg(0, 6.08)
|
||||
|
||||
-- data
|
||||
if data then
|
||||
@ -778,17 +869,17 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||
|
||||
if inv:get_stack('trade', 1):get_count() >= i then
|
||||
---@diagnostic disable-next-line: codestyle-check
|
||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. ' ' .. minetest.colorize('#FFFF00', S('level') .. ': ' .. slot.level) .. ']'
|
||||
formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||
else
|
||||
---@diagnostic disable-next-line: codestyle-check
|
||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. ' ' .. minetest.colorize('#FFFF00', S('level') .. ': ' .. slot.level) .. ']'
|
||||
formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||
end
|
||||
|
||||
formspec[#formspec + 1] = 'image[2.5,' .. -0.5 + i .. ';1,1;x_enchanting_image_trade_' .. i .. '.png;]'
|
||||
formspec[#formspec + 1] = 'image[2.3,' .. -0.5 + i .. ';1,1;x_enchanting_image_trade_' .. i .. '.png;]'
|
||||
else
|
||||
-- disabled buttons
|
||||
---@diagnostic disable-next-line: codestyle-check
|
||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
||||
formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
||||
end
|
||||
end
|
||||
|
||||
@ -797,7 +888,7 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||
for i = 1, 3, 1 do
|
||||
-- disabled buttons
|
||||
---@diagnostic disable-next-line: codestyle-check
|
||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
||||
formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
||||
end
|
||||
|
||||
model_scroll_is_open = false
|
||||
|
136
init.lua
@ -7,18 +7,153 @@ local mod_start_time = minetest.get_us_time()
|
||||
dofile(path .. '/api.lua')
|
||||
dofile(path .. '/table.lua')
|
||||
|
||||
---Check if string X starts with string Y
|
||||
---@param str string
|
||||
---@param start string
|
||||
---@return boolean
|
||||
local function starts_with(str, start)
|
||||
return str:sub(1, #start) == start
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
-- Tools override
|
||||
for name, tool_def in pairs(minetest.registered_tools) do
|
||||
if XEnchanting:has_tool_group(name) then
|
||||
XEnchanting:set_tool_enchantability(tool_def)
|
||||
end
|
||||
end
|
||||
|
||||
-- Ores override - Fortune
|
||||
for _, def in pairs(minetest.registered_ores) do
|
||||
if not XEnchanting.registered_ores[def.ore] then
|
||||
XEnchanting.registered_ores[def.ore] = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Entities override - Looting
|
||||
for name, def in pairs(minetest.registered_entities) do
|
||||
if starts_with(name, 'mobs_animal:')
|
||||
or starts_with(name, 'mobs_monster:')
|
||||
then
|
||||
if def.on_punch and def.drops then
|
||||
local prev_on_punch = def.on_punch
|
||||
|
||||
---@param self table
|
||||
---@param puncher ObjectRef|nil
|
||||
---@param time_from_last_punch number|integer|nil
|
||||
---@param tool_capabilities ToolCapabilitiesDef|nil
|
||||
---@param dir Vector
|
||||
---@param damage number|integer
|
||||
---@return boolean|nil
|
||||
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if not self
|
||||
or not self.object
|
||||
or not self.object:get_luaentity()
|
||||
or not puncher
|
||||
or not tool_capabilities
|
||||
then
|
||||
return prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
end
|
||||
|
||||
local wield_stack = puncher:get_wielded_item()
|
||||
local wield_stack_meta = wield_stack:get_meta()
|
||||
local looting = wield_stack_meta:get_float('is_looting')
|
||||
|
||||
if looting == 0 then
|
||||
return prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
|
||||
if self.health and self.health <= 0 then
|
||||
local death_by_player = self.cause_of_death
|
||||
and self.cause_of_death.puncher
|
||||
and self.cause_of_death.puncher:is_player()
|
||||
|
||||
if death_by_player and pos then
|
||||
for _, drop in ipairs(def.drops) do
|
||||
if math.random(10, 100) / 100 < looting / (looting + 1) then
|
||||
local drop_min = drop.min or 0
|
||||
local drop_max = drop.max or 0
|
||||
local count = math.random(drop_min, drop_max)
|
||||
local stack = ItemStack({
|
||||
name = drop.name,
|
||||
count = count
|
||||
})
|
||||
local chance = math.random(1, tool_capabilities.max_drop_level)
|
||||
|
||||
stack:set_count(stack:get_count() * chance)
|
||||
|
||||
if stack:get_count() > 0 then
|
||||
minetest.item_drop(stack, puncher, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif starts_with(name, 'animalia:') then
|
||||
if def.death_func and def.drops then
|
||||
local prev_death_func = def.death_func
|
||||
|
||||
---@param self table
|
||||
def.death_func = function(self)
|
||||
local puncher = self._puncher
|
||||
|
||||
if not self
|
||||
or not self.object
|
||||
or not self.object:get_luaentity()
|
||||
or not puncher
|
||||
or not puncher:is_player()
|
||||
or self._looting_dropped
|
||||
then
|
||||
return prev_death_func(self)
|
||||
end
|
||||
|
||||
local wield_stack = puncher:get_wielded_item()
|
||||
local wield_stack_meta = wield_stack:get_meta()
|
||||
local looting = wield_stack_meta:get_float('is_looting')
|
||||
|
||||
if looting == 0 then
|
||||
return prev_death_func(self)
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
prev_death_func(self)
|
||||
|
||||
local death_by_player = puncher and puncher:is_player()
|
||||
|
||||
if death_by_player and pos then
|
||||
local tool_capabilities = wield_stack:get_tool_capabilities()
|
||||
self._looting_dropped = true
|
||||
|
||||
for _, drop in ipairs(def.drops) do
|
||||
if math.random(10, 100) / 100 < looting / (looting + 1) then
|
||||
local drop_min = drop.min or 0
|
||||
local drop_max = drop.max or 0
|
||||
local count = math.random(drop_min, drop_max)
|
||||
local stack = ItemStack({
|
||||
name = drop.name,
|
||||
count = count
|
||||
})
|
||||
local chance = math.random(1, tool_capabilities.max_drop_level)
|
||||
|
||||
stack:set_count(stack:get_count() * chance)
|
||||
|
||||
if stack:get_count() > 0 then
|
||||
minetest.item_drop(stack, puncher, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player, last_login)
|
||||
@ -99,7 +234,6 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||
if (player:get_hp() + hp_change) <= 0 then
|
||||
-- Going to die
|
||||
local player_inv = player:get_inventory() --[[@as InvRef]]
|
||||
|
||||
local player_inventory_lists = { 'main', 'craft' }
|
||||
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
|
@ -1,14 +1,17 @@
|
||||
# textdomain: x_enchanting
|
||||
Sharpness=
|
||||
Looting=
|
||||
Fortune=
|
||||
Unbreaking=
|
||||
Efficiency=
|
||||
Silk Touch=
|
||||
Curse of Vanishing=
|
||||
Knockback=
|
||||
Power=
|
||||
Punch=
|
||||
Infinity=
|
||||
Enchanted=
|
||||
Enchant=
|
||||
level=
|
||||
Enchanting Table=
|
||||
owned by=
|
||||
Scroll of Enchantments=
|
||||
|
@ -1,14 +1,17 @@
|
||||
# textdomain: x_enchanting
|
||||
Sharpness=Ostrosť
|
||||
Looting=
|
||||
Fortune=Šťastie
|
||||
Unbreaking=Nelámavosť
|
||||
Efficiency=Výkonnosť
|
||||
Silk Touch=Hodvábny dotyk
|
||||
Curse of Vanishing=Kliatba zmiznutia
|
||||
Knockback=Spätný úder
|
||||
Power=
|
||||
Punch=
|
||||
Infinity=
|
||||
Enchanted=Očarený
|
||||
Enchant=Očarovať
|
||||
level=level
|
||||
Enchanting Table=Čarovný stôl
|
||||
owned by=vlastník
|
||||
Scroll of Enchantments=Čarovný Zvitok
|
||||
|
BIN
screenshot.3.png
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 385 KiB |
BIN
textures/x_enchanting_gui_cloth_bg.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
textures/x_enchanting_gui_cloth_trade_bg.png
Normal file
After Width: | Height: | Size: 165 B |
BIN
textures/x_enchanting_gui_formbg.png
Normal file
After Width: | Height: | Size: 935 B |
BIN
textures/x_enchanting_gui_hb_bg.png
Normal file
After Width: | Height: | Size: 117 B |
BIN
textures/x_enchanting_gui_slot_bg.png
Normal file
After Width: | Height: | Size: 118 B |
Before Width: | Height: | Size: 108 B After Width: | Height: | Size: 108 B |
Before Width: | Height: | Size: 109 B After Width: | Height: | Size: 109 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 178 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 227 B |
Before Width: | Height: | Size: 109 B |
@ -14,3 +14,4 @@
|
||||
---@field on_detach_child fun(self: table, child: ObjectRef): nil Function receive a "luaentity" table as `self`. `child`: an `ObjectRef` of the child that detaches
|
||||
---@field on_detach fun(self: table, parent: ObjectRef|nil): nil Function receive a "luaentity" table as `self`. `parent`: an `ObjectRef` (can be `nil`) from where it got detached. This happens before the parent object is removed from the world.
|
||||
---@field get_staticdata fun(self: table) Function receive a "luaentity" table as `self`. Should return a string that will be passed to `on_activate` when the object is instantiated the next time.
|
||||
---@field drops table Custom for mob drops
|
||||
|
@ -88,11 +88,12 @@
|
||||
---@field place_node fun(pos: Vector, node: SetNodeTable): nil Place node with the same effects that a player would cause
|
||||
---@field add_particle fun(def: ParticleDef): nil
|
||||
---@field registered_tools table<string, ItemDef> Map of registered tool definitions, indexed by name
|
||||
---@field registered_entities table<string, ObjectRef> Map of registered entity definitions, indexed by name
|
||||
---@field registered_entities table<string, EntityDef> Map of registered entity definitions, indexed by name
|
||||
---@field has_feature fun(args: table<string, boolean> | string): boolean | table returns `boolean, missing_features`, `arg`: string or table in format `{foo=true, bar=true}`, `missing_features`: `{foo=true, bar=true}`
|
||||
---@field handle_node_drops fun(pos: Vector, drops: string[], digger: ObjectRef) `drops`: list of itemstrings. Handles drops from nodes after digging: Default action is to put them into digger's inventory. Can be overridden to get different functionality (e.g. dropping items on ground)
|
||||
---@field register_on_dieplayer fun(func: fun(player: ObjectRef, reason?: string)): nil Called when a player dies. `reason`: a PlayerHPChangeReason table, see register_on_player_hpchange
|
||||
---@field register_on_player_hpchange fun(func: fun(player, hp_change, reason), modifier): number Called when the player gets damaged or healed. `player`: ObjectRef of the player. `hp_change`: the amount of change. Negative when it is damage.. `reason`: a PlayerHPChangeReason table.. The `type` field will have one of the following values: `set_hp`: A mod or the engine called `set_hp` without giving a type - use this for custom damage types.. `punch`: Was punched. `reason.object` will hold the puncher, or nil if none. `fall`, `node_damage`: `damage_per_second` from a neighbouring node. `reason.node` will hold the node name or nil. `drown` `respawn`. Any of the above types may have additional fields from mods. `reason.from` will be `mod` or `engine`. `modifier`: when true, the function should return the actual `hp_change`. Note: modifiers only get a temporary `hp_change` that can be modified by later modifiers. Modifiers can return true as a second argument to stop the execution of further functions. Non-modifiers receive the final HP change calculated by the modifiers.
|
||||
---@field get_player_information fun(player_name: string): table Table containing information about a player
|
||||
|
||||
---Minetest settings
|
||||
---@class MinetestSettings
|
||||
|
@ -15,6 +15,7 @@
|
||||
---@field scroll_animations table<string, table> Parameters for `ObjectRef` `set_animation` method
|
||||
---@field player_seeds table<string, number | integer>
|
||||
---@field registered_ores table<string, boolean> Table with registered ores, `key` ore name
|
||||
---@field settings {["x_enchanting_small_formspec"]: boolean}
|
||||
|
||||
|
||||
---Enchantment definition
|
||||
|