Compass support

This commit is contained in:
Lizzy Fleckenstein 2020-11-01 14:23:43 +01:00
parent 26f3d821a4
commit 3fd1963da9
6 changed files with 37 additions and 8 deletions

View File

@ -275,7 +275,7 @@ mcl_enchanting.enchantments.mending = {
max_level = 1, max_level = 1,
primary = {}, primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true}, secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {non_combat_armor = true, compass = true, clock = true}, disallow = {},
incompatible = {infinity = true}, incompatible = {infinity = true},
weight = 2, weight = 2,
description = "Repair the item while gaining XP orbs.", description = "Repair the item while gaining XP orbs.",

View File

@ -8,6 +8,9 @@ function mcl_enchanting.enchantments_snippet(_, _, itemstack)
text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n" text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n"
end end
if text ~= "" then if text ~= "" then
if not itemstack:get_definition()._tt_original_description then
text = text:sub(1, text:len() - 1)
end
return text, false return text, false
end end
end end

View File

@ -14,6 +14,22 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
-- Apply item description updates -- Apply item description updates
local function equals(t1, t2)
for k, v in pairs(t1) do
local equal
local v2 = rawget(t2, k)
if type(v) == "table" then
equal = equals(v, v2)
else
equal = (v == v2)
end
if not equal then
return false
end
end
return true
end
local function apply_snippets(desc, itemstring, toolcaps, itemstack) local function apply_snippets(desc, itemstring, toolcaps, itemstack)
local first = true local first = true
-- Apply snippets -- Apply snippets
@ -61,11 +77,16 @@ tt.reload_itemstack_description = function(itemstack)
local itemstring = itemstack:get_name() local itemstring = itemstack:get_name()
local def = itemstack:get_definition() local def = itemstack:get_definition()
local meta = itemstack:get_meta() local meta = itemstack:get_meta()
if def._mcl_generate_description then if def and def._mcl_generate_description then
def._mcl_generate_description(itemstack) def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) and meta:get_string("name") == "" then elseif should_change(itemstring, def) and meta:get_string("name") == "" then
local orig_desc = def._tt_original_description local toolcaps = itemstack:get_tool_capabilities()
local desc = apply_snippets(orig_desc, itemstring, itemstack:get_tool_capabilities(), itemstack) local hand_toolcaps = ItemStack(""):get_tool_capabilities()
if equals(toolcaps, hand_toolcaps) then
toolcaps = nil
end
local orig_desc = def._tt_original_description or def.description
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)
if desc ~= orig_desc then if desc ~= orig_desc then
meta:set_string("description", desc) meta:set_string("description", desc)
end end

View File

@ -2,3 +2,4 @@ mcl_core
mcl_worlds mcl_worlds
mesecons mesecons
doc? doc?
mcl_enchanting

View File

@ -56,8 +56,12 @@ minetest.register_globalstep(function(dtime)
for j,stack in ipairs(player:get_inventory():get_list("main")) do for j,stack in ipairs(player:get_inventory():get_list("main")) do
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
local count = stack:get_count() local itemname = "mcl_compass:"..compass_image
player:get_inventory():set_stack("main", j, ItemStack("mcl_compass:"..compass_image.." "..count)) if mcl_enchanting.is_enchanted(stack) then
itemname = itemname .. "_enchanted"
end
stack:set_name(itemname)
player:get_inventory():set_stack("main", j, stack)
end end
end end
end end

View File

@ -23,7 +23,7 @@ minetest.register_on_dieplayer(function(player)
local z = math.random(0, 9)/3 local z = math.random(0, 9)/3
pos.x = pos.x + x pos.x = pos.x + x
pos.z = pos.z + z pos.z = pos.z + z
if not void_deadly and drop and mcl_enchanting.get_enchantment(stack, "curse_of_vanishing") > 0 then if not void_deadly and drop and mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then
local def = minetest.registered_items[stack:get_name()] local def = minetest.registered_items[stack:get_name()]
if def and def.on_drop then if def and def.on_drop then
stack = def.on_drop(stack, player, pos) stack = def.on_drop(stack, player, pos)