1
0
Fork 0

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,
primary = {},
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},
weight = 2,
description = "Repair the item while gaining XP orbs.",

View File

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

View File

@ -14,6 +14,22 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
-- 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 first = true
-- Apply snippets
@ -61,11 +77,16 @@ tt.reload_itemstack_description = function(itemstack)
local itemstring = itemstack:get_name()
local def = itemstack:get_definition()
local meta = itemstack:get_meta()
if def._mcl_generate_description then
if def and def._mcl_generate_description then
def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) and meta:get_string("name") == "" then
local orig_desc = def._tt_original_description
local desc = apply_snippets(orig_desc, itemstring, itemstack:get_tool_capabilities(), itemstack)
local toolcaps = itemstack:get_tool_capabilities()
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
meta:set_string("description", desc)
end

View File

@ -2,3 +2,4 @@ mcl_core
mcl_worlds
mesecons
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
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
local count = stack:get_count()
player:get_inventory():set_stack("main", j, ItemStack("mcl_compass:"..compass_image.." "..count))
local itemname = "mcl_compass:"..compass_image
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

View File

@ -23,7 +23,7 @@ minetest.register_on_dieplayer(function(player)
local z = math.random(0, 9)/3
pos.x = pos.x + x
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()]
if def and def.on_drop then
stack = def.on_drop(stack, player, pos)