mirror of
https://bitbucket.org/minetest_gamers/x_enchanting.git
synced 2025-06-30 23:00:24 +02:00
Add grindstone
This commit is contained in:
86
api.lua
86
api.lua
@ -1,3 +1,4 @@
|
||||
---@diagnostic disable
|
||||
--[[
|
||||
X Enchanting. Adds Enchanting Mechanics and API.
|
||||
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
||||
@ -195,7 +196,8 @@ XEnchanting = {
|
||||
weight = 1,
|
||||
secondary = true,
|
||||
-- all applicable
|
||||
groups = nil
|
||||
groups = nil,
|
||||
cursed = true
|
||||
},
|
||||
knockback = {
|
||||
name = S('Knockback'),
|
||||
@ -552,7 +554,6 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
||||
stack_meta:set_int('is_enchanted', 1)
|
||||
stack_meta:set_string('x_enchanting', minetest.serialize(final_enchantments_meta))
|
||||
|
||||
|
||||
if tool_def and tool_def.inventory_image and tool_def.inventory_image ~= '' then
|
||||
stack_meta:set_string('inventory_image', tool_def.inventory_image .. '^((' .. tool_def.inventory_image .. '^[contrast:127:127)^[mask:x_enchanting_glint.png^[opacity:80)')
|
||||
end
|
||||
@ -875,12 +876,13 @@ local function get_list_bg(x, y)
|
||||
return out
|
||||
end
|
||||
|
||||
local function get_formspec_bg(player_name)
|
||||
local function get_formspec_bg(player_name, bg_img)
|
||||
local bg_image = bg_img and bg_img or 'x_enchanting_gui_formbg.png'
|
||||
local info = minetest.get_player_information(player_name)
|
||||
local bg = 'background[5,5;1,1;x_enchanting_gui_formbg.png;true]'
|
||||
local bg = 'background[5,5;1,1;' .. bg_image .. ';true]'
|
||||
|
||||
if info.formspec_version > 1 then
|
||||
bg = 'background9[5,5;1,1;x_enchanting_gui_formbg.png;true;10]'
|
||||
bg = 'background9[5,5;1,1;' .. bg_image .. ';true;10]'
|
||||
end
|
||||
|
||||
return bg
|
||||
@ -967,3 +969,77 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||
|
||||
return table.concat(formspec, '')
|
||||
end
|
||||
|
||||
function XEnchanting.get_grindstone_formspec(self, pos, player_name, data)
|
||||
local _data = data or {}
|
||||
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
||||
local model = 'model[0,0;2,3;x_enchanting_grindstone;x_enchanting_grindstone.obj;x_enchanting_grindstone_mesh.png;0,0;true;false;]'
|
||||
|
||||
local formspec = {}
|
||||
formspec[#formspec + 1] = 'size[8,9]'
|
||||
formspec[#formspec + 1] = 'bgcolor[#080808BB;true]'
|
||||
formspec[#formspec + 1] = 'listcolors[#FFFFFF00;#FFFFFF1A;#FFFFFF00;#30434C;#FFF]'
|
||||
formspec[#formspec + 1] = get_formspec_bg(player_name)
|
||||
formspec[#formspec + 1] = 'style_type[label;font=mono,bold]'
|
||||
formspec[#formspec + 1] = 'style[slot_1,slot_2,slot_3;font=mono,bold;textcolor=#4D413A]'
|
||||
formspec[#formspec + 1] = 'label[0, 0;' .. S('Disenchant') .. ']'
|
||||
-- item
|
||||
formspec[#formspec + 1] = 'list[nodemeta:' .. spos .. ';item;0.5, 2.5;1, 1;]'
|
||||
formspec[#formspec + 1] = 'image[0.5, 2.5;1,1;x_enchanting_gui_cloth_bg.png]'
|
||||
-- result
|
||||
if _data.result_disabled then
|
||||
formspec[#formspec + 1] = 'image[4.75, 1.25;1.5,1.5;x_enchanting_gui_cloth_bg_corssed.png]'
|
||||
else
|
||||
formspec[#formspec + 1] = 'list[nodemeta:' .. spos .. ';result;5, 1.5;1, 1;]'
|
||||
formspec[#formspec + 1] = 'image[5, 1.5;1,1;x_enchanting_gui_cloth_bg.png]'
|
||||
end
|
||||
|
||||
-- inventories
|
||||
formspec[#formspec + 1] = 'list[current_player;main;0, 4.85;8, 1;]'
|
||||
formspec[#formspec + 1] = 'list[current_player;main;0, 6.08;8, 3;8]'
|
||||
formspec[#formspec + 1] = 'listring[nodemeta:' .. spos .. ';result]'
|
||||
formspec[#formspec + 1] = 'listring[current_player;main]'
|
||||
formspec[#formspec + 1] = 'listring[nodemeta:' .. spos .. ';item]'
|
||||
formspec[#formspec + 1] = 'listring[current_player;main]'
|
||||
|
||||
formspec[#formspec + 1] = get_hotbar_bg(0, 4.85)
|
||||
formspec[#formspec + 1] = get_list_bg(0, 6.08)
|
||||
formspec[#formspec + 1] = model
|
||||
|
||||
return table.concat(formspec, '')
|
||||
end
|
||||
|
||||
function XEnchanting.has_all_cursed_ench(self, itemstack)
|
||||
if itemstack:is_empty() then
|
||||
return false
|
||||
end
|
||||
|
||||
local item_stack_meta = itemstack:get_meta()
|
||||
local stack_enchantment_data = minetest.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
||||
local stack_enchantment_data_length = get_table_length(stack_enchantment_data)
|
||||
local cursed_ench = 0
|
||||
|
||||
-- Get cursed enchantments
|
||||
for id, value in pairs(stack_enchantment_data) do
|
||||
local ench_def = self.enchantment_defs[id]
|
||||
|
||||
if ench_def.cursed then
|
||||
cursed_ench = cursed_ench + 1
|
||||
end
|
||||
end
|
||||
|
||||
return cursed_ench == stack_enchantment_data_length
|
||||
end
|
||||
|
||||
--
|
||||
-- Sounds
|
||||
--
|
||||
|
||||
function XEnchanting.node_sound_wood_defaults(table)
|
||||
table = table or {}
|
||||
table.footstep = table.footstep or { name = 'x_enchanting_wood_footstep', gain = 0.15 }
|
||||
table.dig = table.dig or { name = 'x_enchanting_wood_hit', gain = 0.5 }
|
||||
table.dug = table.dug or { name = 'x_enchanting_wood_place', gain = 0.1 }
|
||||
table.place = table.place or { name = 'x_enchanting_wood_place', gain = 0.15 }
|
||||
return table
|
||||
end
|
||||
|
Reference in New Issue
Block a user