123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- local jewelry_formspec =
- 'size[8,8.5]'..
- 'list[current_name;jewelry;.5,0;1,1;]'..
- 'list[current_name;crystal;1.5,0;1,1;]'..
- 'list[current_name;mese;3,0;1,1;]'..
- 'image[3,0;1,1;armor_mese_outline.png]'..
- 'list[current_name;orb;4,0;1,1;]'..
- 'image[4,0;1,1;armor_orb_outline.png]'..
- 'list[current_name;output;6,.5;1,1;]'..
- 'list[current_name;relics;1,3;6,1;]'..
- 'list[current_player;main;0,4.5;8,4;]'..
- 'button[5.75,1.55;1.5,.75;forge;Forge]'..
- 'textarea[.5,1;5.5,2.25;;;'..
- 'Input a plain ring, amulet or pair of gloves, and a Gemstone with the perk you want added.'..
- '\nYou\'ll also need a mese crystal and lava orb.'..
- '\nRelics can be added to tweak the chances that control how powerful the outputted item will be.'..
- ' Relics are not typically consumed and can be used time and time again.]'..
- 'label[0,3;Relics\n--->]'
- minetest.register_node('stations:jewelry', {
- description = 'Jewelry Workshop',
- drawtype = 'mesh',
- mesh = 'stations_jewelry.obj',
- tiles = {'stations_jewelry.png'},
- use_texture_alpha = 'opaque',
- sounds = default.node_sound_metal_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.5, 1.5, .5, .5},
- }
- },
- collision_box = {
- type = 'fixed',
- {-.5, -.5, -.5, 1.5, .5, .5},
- },
- groups = {oddly_breakable_by_hand=3, cracky=1},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('jewelry', 1)
- inv:set_size('mese', 1)
- inv:set_size('orb', 1)
- inv:set_size('crystal', 1)
- inv:set_size('output', 1)
- inv:set_size('relics', 6)
- meta:set_string('infotext', 'Jewelry Workshop')
- meta:set_string('formspec', jewelry_formspec)
- end,
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_to_side(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
- and inv:is_empty('crystal') and inv:is_empty('output') then
- return true
- else
- return false
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_side_node(pos, oldnode)
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local input = stack:get_name()
- if listname == 'jewelry' then
- if input == 'armor:ring_gol' or input == 'armor:ring_tit' or input == 'armor:gloves'
- or input == 'armor:amulet_gol' or input == 'armor:amulet_tit' then
- return 99
- else
- return 0
- end
- elseif listname == 'mese' then
- if input == 'default:mese_crystal' then
- return 99
- else
- return 0
- end
- elseif listname == 'orb' then
- if input == 'mobs:lava_orb' then
- return 99
- else
- return 0
- end
- elseif listname == 'crystal' then
- if input == 'epic:float_crystal' or input == 'epic:bloodstone' or input == 'epic:huntite'
- or input == 'ocean:prismarine_crystals' or input == 'epic:garnet' or input == 'quartz:quartz_crystal_piece' then
- return 99
- else
- return 0
- end
- elseif listname == 'output' then
- return 0
- end
- return 1
- end,
- allow_metadata_inventory_move = function(pos, listname, index, stack, player)
- return 0
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
- and inv:is_empty('crystal') and inv:is_empty('output') and inv:is_empty ('relics') then
- return true
- else
- return false
- end
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory(pos)
- local output = inv:get_stack('output', 1)
- local output_count = output:get_count()
- if fields['forge'] and output_count == 0 then
- local jewelry = inv:get_stack('jewelry', 1)
- local mese = inv:get_stack('mese', 1)
- local orb = inv:get_stack('orb', 1)
- local crystal = inv:get_stack('crystal', 1)
- local relics = inv:get_list('relics')
- local jewelry_name = jewelry:get_name()
- local mese_name = mese:get_name()
- local orb_name = orb:get_name()
- local crystal_name = crystal:get_name()
- local perk = 'nothing'
- if crystal_name == 'epic:float_crystal' then
- perk = 'gravity'
- elseif crystal_name == 'epic:bloodstone' then
- perk = 'healing'
- elseif crystal_name == 'epic:huntite' then
- perk = 'fire'
- elseif crystal_name == 'ocean:prismarine_crystals' then
- perk = 'water'
- elseif crystal_name == 'epic:garnet' then
- perk = 'speed'
- elseif crystal_name == 'quartz:quartz_crystal_piece' then
- perk = 'jump'
- end
- local level = 0
- if type(relics) == 'table' then
- for i, stack in pairs(relics) do
- local def = stack:get_definition()
- if def.groups['relic_general'] then
- level = level + def.groups['relic_general']
- end
- if def.groups['relic_'..perk] then
- level = level + def.groups['relic_'..perk]
- end
- end
- end
- --If you're looking at the code to see how this works please don't spoil it for other players.
- --If I expect that is going on, I'll be forced to change things around, and not release the code.
- local random = math.random(0, 100)
- local chance = random + level
- local tier = 1
- if chance < 0 then
- tier = 0
- elseif chance > 0 and chance <= 80 then
- tier = 1
- elseif chance > 80 and chance <= 90 then
- tier = 2
- elseif chance > 90 and chance <= 98 then
- tier = 3
- elseif chance > 98 and chance <= 100 then
- tier = 4
- end
- local phase = moon_phases.get_phase()
- local time_of_day = minetest.get_timeofday()
- if phase == 4 and (time_of_day < .2 or time_of_day > .8) then
- tier = tier + 1
- end
- if perk ~= 'nothing' and jewelry_name ~= '' and mese_name ~= '' and orb_name ~= '' and tier ~= 0 then
- jewelry:take_item(1)
- mese:take_item(1)
- orb:take_item(1)
- crystal:take_item(1)
- inv:set_stack('jewelry', 1, jewelry)
- inv:set_stack('mese', 1, mese)
- inv:set_stack('orb', 1, orb)
- inv:set_stack('crystal', 1, crystal)
- inv:set_stack('output', 1, jewelry_name..'_'..perk..'_'..tier)
- minetest.log("action", sender:get_player_name() .. " crafts "..jewelry_name..'_'..perk..'_'..tier)
- end
- end
- end,
- on_rotate = function(pos, node)
- return false
- end,
- })
- minetest.register_node('stations:jewelry_locked', {
- description = 'Jewelry Workshop (Locked)',
- drawtype = 'mesh',
- mesh = 'stations_jewelry.obj',
- tiles = {'stations_jewelry.png'},
- use_texture_alpha = 'opaque',
- sounds = default.node_sound_metal_defaults(),
- paramtype2 = 'facedir',
- paramtype = 'light',
- selection_box = {
- type = 'fixed',
- fixed = {
- {-.5, -.5, -.5, 1.5, .5, .5},
- }
- },
- collision_box = {
- type = 'fixed',
- {-.5, -.5, -.5, 1.5, .5, .5},
- },
- groups = {oddly_breakable_by_hand=3, cracky=1},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size('main', 8*4)
- inv:set_size('jewelry', 1)
- inv:set_size('mese', 1)
- inv:set_size('orb', 1)
- inv:set_size('crystal', 1)
- inv:set_size('output', 1)
- inv:set_size('relics', 6)
- meta:set_string('infotext', 'Jewelry Workshop (Locked)')
- meta:set_string('formspec', jewelry_formspec)
- end,
- after_place_node = function(pos, placer, itemstack)
- if not epic.space_to_side(pos) then
- minetest.remove_node(pos)
- return itemstack
- end
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
- and inv:is_empty('crystal') and inv:is_empty('output') then
- return true
- else
- return false
- end
- end,
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- epic.remove_side_node(pos, oldnode)
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local player_name = player:get_player_name()
- if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
- return 0
- else
- local input = stack:get_name()
- if listname == 'jewelry' then
- if input == 'armor:ring_gol' or input == 'armor:ring_tit' or input == 'armor:gloves'
- or input == 'armor:amulet_gol' or input == 'armor:amulet_tit' then
- return 99
- else
- return 0
- end
- elseif listname == 'mese' then
- if input == 'default:mese_crystal' then
- return 99
- else
- return 0
- end
- elseif listname == 'orb' then
- if input == 'mobs:lava_orb' then
- return 99
- else
- return 0
- end
- elseif listname == 'crystal' then
- if input == 'epic:float_crystal' or input == 'epic:bloodstone' or input == 'epic:huntite'
- or input == 'ocean:prismarine_crystals' or input == 'epic:garnet' or input == 'quartz:quartz_crystal_piece' then
- return 99
- else
- return 0
- end
- elseif listname == 'output' then
- return 0
- else
- return 1
- end
- end
- end,
- allow_metadata_inventory_move = function(pos, listname, index, stack, player)
- return 0
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
- and inv:is_empty('crystal') and inv:is_empty('output') and inv:is_empty ('relics') then
- return true
- else
- return false
- end
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local player_name = sender:get_player_name()
- if not minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory(pos)
- local output = inv:get_stack('output', 1)
- local output_count = output:get_count()
- if fields['forge'] and output_count == 0 then
- local jewelry = inv:get_stack('jewelry', 1)
- local mese = inv:get_stack('mese', 1)
- local orb = inv:get_stack('orb', 1)
- local crystal = inv:get_stack('crystal', 1)
- local relics = inv:get_list('relics')
- local jewelry_name = jewelry:get_name()
- local mese_name = mese:get_name()
- local orb_name = orb:get_name()
- local crystal_name = crystal:get_name()
- local perk = 'nothing'
- if crystal_name == 'epic:float_crystal' then
- perk = 'gravity'
- elseif crystal_name == 'epic:bloodstone' then
- perk = 'healing'
- elseif crystal_name == 'epic:huntite' then
- perk = 'fire'
- elseif crystal_name == 'ocean:prismarine_crystals' then
- perk = 'water'
- elseif crystal_name == 'epic:garnet' then
- perk = 'speed'
- elseif crystal_name == 'quartz:quartz_crystal_piece' then
- perk = 'jump'
- end
- local level = 0
- if type(relics) == 'table' then
- for i, stack in pairs(relics) do
- local def = stack:get_definition()
- if def.groups['relic_general'] then
- level = level + def.groups['relic_general']
- end
- if def.groups['relic_'..perk] then
- level = level + def.groups['relic_'..perk]
- end
- end
- end
- --If you're looking at the code to see how this works please don't spoil it for other players.
- --If I expect that is going on, I'll be forced to change things around, and not release the code.
- local random = math.random(0, 100)
- local chance = random + level
- local tier = 1
- if chance < 0 then
- tier = 0
- elseif chance > 0 and chance <= 80 then
- tier = 1
- elseif chance > 80 and chance <= 90 then
- tier = 2
- elseif chance > 90 and chance <= 98 then
- tier = 3
- elseif chance > 98 and chance <= 100 then
- tier = 4
- end
- local phase = moon_phases.get_phase()
- local time_of_day = minetest.get_timeofday()
- if phase == 4 and (time_of_day < .2 or time_of_day > .8) then
- tier = tier + 1
- end
- if perk ~= 'nothing' and jewelry_name ~= '' and mese_name ~= '' and orb_name ~= '' and tier ~= 0 then
- jewelry:take_item(1)
- mese:take_item(1)
- orb:take_item(1)
- crystal:take_item(1)
- inv:set_stack('jewelry', 1, jewelry)
- inv:set_stack('mese', 1, mese)
- inv:set_stack('orb', 1, orb)
- inv:set_stack('crystal', 1, crystal)
- inv:set_stack('output', 1, jewelry_name..'_'..perk..'_'..tier)
- minetest.log("action", sender:get_player_name() .. " crafts "..jewelry_name..'_'..perk..'_'..tier)
- end
- end
- end
- end,
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local player_name = player:get_player_name()
- if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
- return 0
- else
- return 99
- end
- end,
- on_rotate = function(pos, node)
- return false
- end,
- })
- unified_inventory.register_craft_type("jewelry", {
- description = "Jewelry Workshop",
- icon = 'stations_jewelry_icon.png',
- width = 4,
- height = 1,
- uses_crafting_grid = false
- })
|