Simplify by using textures & sounds from default mod &...

...using built-in on_dig function from unifieddyes. Also
make obsidian glass colorable.
master
Jordan Irwin 2021-04-19 23:32:21 -07:00
parent d5a532cecb
commit fc8dcede55
10 changed files with 56 additions and 112 deletions

View File

@ -7,30 +7,5 @@
Originally by celeron55, Perttu Ahola <celeron55@gmail.com> ([LGPL 2.1][lic.lgpl])
Various Minetest developers and contributors ([LGPL 2.1][lic.lgpl])
---
### **Media:**
- Mito551, ***CC BY-SA 3.0:***
- glass_footstep.ogg
- Glass breaking sounds, ***CC BY 3.0:***
- [glass_break.1.ogg](http://www.freesound.org/people/cmusounddesign/sounds/71947) by cmusounddesign
- [glass_break.2.ogg](http://www.freesound.org/people/Tomlija/sounds/97669) by Tomlija
- [glass_break.3.ogg](http://www.freesound.org/people/lsprice/sounds/88808) by lsprice
---
### **Textures:**
- Perttu Ahola ([celeron55](mailto:celeron55@gmail.com)), ***CC BY-SA 3.0:***
- glass_obsidian_detail.png
- glass_plain.png
- Calinou, ***CC BY-SA 3.0:***
- glass_plain_detail.png
- PilzAdam, ***CC BY-SA 3.0:***
- glass_obsidian.png
[lic.lgpl]: docs/license-LGPL-2.1.txt

143
nodes.lua
View File

@ -20,103 +20,72 @@ local S = core.get_translator()
local enable_colors = core.global_exists('unifieddyes') or core.get_modpath('unifieddyes')
local function dig_glass(pos, node, digger)
local inv = digger:get_inventory()
local can_dig = not core.is_protected(pos, digger:get_player_name())
local drops = {}
if digger:is_player() then
local meta = core.get_meta(pos)
if can_dig then
if not inv:room_for_item('main', node.name) then
table.insert(drops, node.name)
else
inv:add_item('main', node.name)
end
if meta then
local dye = meta:get_string('dye')
if dye and dye ~= '' then
if not inv:room_for_item('main', dye) then
table.insert(drops, dye)
else
inv:add_item('main', dye)
end
end
end
end
--- Extracts glass type from string.
--
-- @function get_glass_type
-- @local
-- @param g string to be parsed
-- @return string representing glass type or `nil`
local function get_glass_type(g)
local glass_type = nil
local idx = g:find(':')
if idx then
glass_type = g:sub(idx+1)
end
if can_dig then
core.remove_node(pos)
core.handle_node_drops(pos, drops, digger)
idx = glass_type:find('_glass')
if idx then
glass_type = glass_type:sub(1, idx-1)
end
if glass_type == 'glass' then
glass_type = 'plain'
end
return glass_type
end
local glass_def = {
description = S('Glass'),
drawtype = 'glasslike_framed_optional',
tiles = {'glass_plain.png', 'glass_plain_detail.png'},
paramtype = 'light',
paramtype2 = 'glasslikeliquidlevel',
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=3, oddly_breakable_by_hand=3},
sounds = glass.node_sounds(),
}
if enable_colors then
glass_def.paramtype2 = 'color'
glass_def.palette = 'unifieddyes_palette_extended.png'
glass_def.groups['ud_param2_colorable'] = 1
glass_def.on_dig = dig_glass
end
--- Plain glass.
--
-- @node glass:plain
core.register_node('glass:plain', glass_def)
--- Obsidian glass.
--
-- @node glass:obsidian
core.register_node('glass:obsidian', {
description = S('Obsidian Glass'),
drawtype = 'glasslike_framed_optional',
tiles = {'glass_obsidian.png', 'glass_obsidian_detail.png'},
paramtype = 'light',
paramtype2 = 'glasslikeliquidlevel',
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=3, oddly_breakable_by_hand=3},
sounds = glass.node_sounds(),
})
-- Compatibility
if core.get_modpath('default') then
local glass_overrides = {
local to_color = {
'default:glass',
'default:obsidian_glass',
}
for _, item in pairs(glass_overrides) do
core.unregister_item(item)
core.registered_nodes[item] = nil
core.registered_aliases[item] = nil
for _, old_glass in ipairs(to_color) do
local glass_type = get_glass_type(old_glass)
if not glass_type then goto continue end
local new_glass = 'glass:' .. glass_type
local glass_def = {}
for k, v in pairs(core.registered_nodes[old_glass]) do
glass_def[k] = v
end
glass_def.paramtype2 = 'color'
glass_def.palette = 'unifieddyes_palette_extended.png'
glass_def.groups['ud_param2_colorable'] = 1
glass_def.on_dig = unifieddyes.on_dig
-- register new node
core.register_node(new_glass, glass_def)
-- unregister old node
core.unregister_item(old_glass)
core.registered_nodes[old_glass] = nil
core.registered_aliases[old_glass] = nil
core.register_alias(old_glass, new_glass)
::continue::
end
-- misc. aliases
if core.registered_nodes['glass:plain'] then
core.register_alias('glass', 'glass:plain')
core.register_alias('glass:glass', 'glass:plain')
end
if core.registered_nodes['glass:obsidian'] then
core.register_alias('obsidian_glass', 'glass:obsidian')
end
end
core.register_alias('glass', 'glass:plain')
core.register_alias('glass:glass', 'glass:plain')
core.register_alias('obsidian_glass', 'glass:obsidian')
-- Nodes from 'default'
core.register_alias('default:glass', 'glass:plain')
core.register_alias('default:obsidian_glass', 'glass:obsidian')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 B