mirror of
https://bitbucket.org/minetest_gamers/x_enchanting.git
synced 2025-06-29 22:30:35 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
4303c5f8bf | |||
1e5a76ed18 |
57
init.lua
57
init.lua
@ -95,6 +95,63 @@ minetest.register_on_mods_loaded(function()
|
|||||||
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
|
end
|
||||||
end)
|
end)
|
||||||
|
12
table.lua
12
table.lua
@ -337,8 +337,11 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
local item_stack = inv:get_stack('item', 1)
|
||||||
|
local item_stack_meta = item_stack:get_meta()
|
||||||
|
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
||||||
|
|
||||||
if not inv:is_empty('item') then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = minetest.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
@ -346,7 +349,6 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
)
|
)
|
||||||
|
|
||||||
local item_stack = inv:get_stack('item', 1)
|
|
||||||
local data = XEnchanting:get_enchantment_data(
|
local data = XEnchanting:get_enchantment_data(
|
||||||
player,
|
player,
|
||||||
#bookshelfs,
|
#bookshelfs,
|
||||||
@ -370,8 +372,11 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
local item_stack = inv:get_stack('item', 1)
|
||||||
|
local item_stack_meta = item_stack:get_meta()
|
||||||
|
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
||||||
|
|
||||||
if not inv:is_empty('item') then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = minetest.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
@ -379,7 +384,6 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
)
|
)
|
||||||
|
|
||||||
local item_stack = inv:get_stack('item', 1)
|
|
||||||
local data = XEnchanting:get_enchantment_data(
|
local data = XEnchanting:get_enchantment_data(
|
||||||
player,
|
player,
|
||||||
#bookshelfs,
|
#bookshelfs,
|
||||||
|
Reference in New Issue
Block a user