diff --git a/depends.txt b/depends.txt index 4ad96d5..8a1d3bc 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,3 @@ default +screwdriver +xpanes diff --git a/init.lua b/init.lua index 7798ba5..4e0ce57 100644 --- a/init.lua +++ b/init.lua @@ -1,911 +1,271 @@ ---table length thing -function tablelength(T) - local count = 0 - for _ in pairs(T) do count = count + 1 end - return count -end ---if in table thing -function intable(tbl, item) - for key, value in pairs(tbl) do - if value == item then return key end - end - return false -end - +--[[ +Goals: +Make this as physically involved as possible, holding to "magic" mindset, random, unknown outcomes ---DONE current goal, give a pickaxe a random table of enchantments - +-use cauldron from the old enchantments mod +-make player have to throw in lapiz from the lapiz mod to activate cauldron +-have the cauldron bubble when activated +-have the cauldron "explode", do a huge thing of particles and explode sound when +player throws in item +-have cauldron enchant single item, throw item at player +-then go back to being deactivated ---DONE for the cherry pick enchantment, do an on_dignode function for all players, then check for the enchantment, drop the item that was mined using player:dig_node +-make cauldrons bubble +-bubble particles on idle along with a lot of bubble particles when active ---do multiple levels for these +Enchantments: +/ = hardcoded for now, until items are modifyable +(metadata) +/luck = more items per mine +/furnace = instant cook items if possible +/delicate = get source node if drop is differant than source ---DONE make the thing slowly raise the tool with a sound, make a noise with particles and throw the tool at the player +(hard defined) +###quickmine = mine faster +dueler = faster tool recover time +hard hitter = do more damage to players/entities ---possibly a max level enchant? maybe? +]]-- ---damage group enchant? +--meta test +minetest.register_craftitem("enchantment:test", { + description = "Testcraftitem", + inventory_image = "default_stone.png", + + on_use = function(itemstack, user, pointed_thing) + print(itemstack:to_table().metadata) + --if itemstack:get_metadata() == "" then + itemstack:set_metadata("test") + print("SETTING META") + --end ---DONE make the enchantment box use the moving water texture, with an overlay, to make it look like it's magic - ---make the enchantment box randomly eat items instead of enchanting them - ---make the enchantment box explode, and kill player's in area on rare occasions - ---make the enchant box clear the player's inventory on RARE occasions - ---modify treecapitator to use voxel manip - ---make bad effects also happen - - -enchant = {} - -enchant.enchantments_pick = { -"speed", --speed (check a .after thing to tell how fast you'll dig it.) -"durable", --resistance or infinity - 1 is resistance 2 is infinity -"luck", --get multiple items -"cherry pick", --similar to silk touch in MC -} -enchant.pick = { -"default:pick_bronze", -"default:pick_diamond", -"default:pick_mese", -"default:pick_steel", -"default:pick_stone", -"default:pick_wood", -} - ---since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. ---pickaxe enchantments -for x = 1,tablelength(enchant.pick) do - print(enchant.pick[x]) - --try to do this some other, maybe - for a = 0,1 do --speed - for b = 0,1 do --durable - for c = 0,1 do --luck - for d = 0,1 do --cherry pick - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool - - --name the tool, and define it - local tool = enchant.pick[x] - local name = minetest.registered_items[enchant.pick[x]]["description"] - if a == 1 then - name = name.."\n-Speed" - end - if b == 1 then - name = name.."\n-Durable" - end - if c == 1 then - name = name.."\n-Luck" - end - if d == 1 then - name = name.."\n-Cherry Pick" - end - --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - --add the enchant to the tools - don't add to the logic above to improve readability - --global because of bugs with registered tools or something - - local table = {} - local uses = 0 - local maxlevel = 0 - --if enchanted with speed, half time, if not, use standard tool time. - if a == 1 then - for i = 1,3 do - if minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"][i] then - table[i] = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"][i]/2 - end - end - else - table = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"] - end - --if enchanted with durable, double the uses, if not, use standard uses. - if b == 1 then - uses = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["uses"] * 2 - else - uses = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["uses"] - end - --possibly turn this into enchant - maxlevel = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["maxlevel"] - - minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { - description = name, - inventory_image = minetest.registered_items[enchant.pick[x]]["inventory_image"], - groups = {not_in_creative_inventory=1,enchanted_pick=1,luck=c,cherry_pick=d}, --don't clutter the inventory - tool_capabilities = { - --full_punch_interval = 1.3, - --max_drop_level=0, - groupcaps={ - cracky = {times=table, uses=uses, maxlevel=maxlevel}, - }, - damage_groups = {fleshy=3}, - }, - }) - end - end - end - end - end -end - ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -enchant.enchantments_shovel = { -"speed", --speed (check a .after thing to tell how fast you'll dig it.) -"durable", --resistance or infinity - 1 is resistance 2 is infinity -"luck", --get multiple items -"cherry pick", --similar to silk touch in MC -} -enchant.shovel = { -"default:shovel_bronze", -"default:shovel_diamond", -"default:shovel_mese", -"default:shovel_steel", -"default:shovel_stone", -"default:shovel_wood", -} - ---since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. ---pickaxe enchantments -for x = 1,tablelength(enchant.shovel) do - print(enchant.shovel[x]) - --try to do this some other, maybe - for a = 0,1 do --speed - for b = 0,1 do --durable - for c = 0,1 do --luck - for d = 0,1 do --cherry pick - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool - - --name the tool, and define it - local tool = enchant.shovel[x] - local name = minetest.registered_items[enchant.shovel[x]]["description"] - if a == 1 then - name = name.."\n-Speed" - end - if b == 1 then - name = name.."\n-Durable" - end - if c == 1 then - name = name.."\n-Luck" - end - if d == 1 then - name = name.."\n-Cherry Pick" - end - --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - --add the enchant to the tools - don't add to the logic above to improve readability - --global because of bugs with registered tools or something - - local table = {} - local uses = 0 - local maxlevel = 0 - --if enchanted with speed, half time, if not, use standard tool time. - if a == 1 then - for i = 1,3 do - if minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"][i] then - table[i] = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"][i]/2 - end - end - else - table = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"] - end - --if enchanted with durable, double the uses, if not, use standard uses. - if b == 1 then - uses = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["uses"] * 2 - else - uses = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["uses"] - end - --possibly turn this into enchant - maxlevel = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["maxlevel"] - - minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { - description = name, - inventory_image = minetest.registered_items[enchant.shovel[x]]["inventory_image"], - groups = {not_in_creative_inventory=1,enchanted_shovel=1,luck=c,cherry_pick=d}, --don't clutter the inventory - tool_capabilities = { - --full_punch_interval = 1.3, - --max_drop_level=0, - groupcaps={ - crumbly = {times=table, uses=uses, maxlevel=maxlevel}, - }, - damage_groups = {fleshy=3}, - }, - }) - end - end - end - end - end -end ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -enchant.enchantments_axe = { -"speed", --speed (check a .after thing to tell how fast you'll dig it.) -"durable", --resistance or infinity - 1 is resistance 2 is infinity -"luck", --get multiple items -"tree feller", --My favorite MC mod - replaces cherry pick -} -enchant.axe = { -"default:axe_bronze", -"default:axe_diamond", -"default:axe_mese", -"default:axe_steel", -"default:axe_stone", -"default:axe_wood", -} - ---since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. ---pickaxe enchantments -for x = 1,tablelength(enchant.axe) do - --print(enchant.axe[x]) - --try to do this some other, maybe - for a = 0,1 do --speed - for b = 0,1 do --durable - for c = 0,1 do --luck - for d = 0,1 do --tree feller - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool - - --name the tool, and define it - local tool = enchant.axe[x] - local name = minetest.registered_items[enchant.axe[x]]["description"] - if a == 1 then - name = name.."\n-Speed" - end - if b == 1 then - name = name.."\n-Durable" - end - if c == 1 then - name = name.."\n-Luck" - end - if d == 1 then - name = name.."\n-Tree Feller" - end - --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - --add the enchant to the tools - don't add to the logic above to improve readability - --global because of bugs with registered tools or something - - local table = {} - local uses = 0 - local maxlevel = 0 - --if enchanted with speed, half time, if not, use standard tool time. - if a == 1 then - for i = 1,3 do - if minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"][i] then - table[i] = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"][i]/2 - end - end - else - table = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"] - end - --if enchanted with durable, double the uses, if not, use standard uses. - if b == 1 then - uses = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["uses"] * 2 - else - uses = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["uses"] - end - --possibly turn this into enchant - maxlevel = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["maxlevel"] - - minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { - description = name, - inventory_image = minetest.registered_items[enchant.axe[x]]["inventory_image"], - groups = {not_in_creative_inventory=1,enchanted_axe=1,luck=c,tree_feller=d}, --don't clutter the inventory - tool_capabilities = { - --full_punch_interval = 1.3, - --max_drop_level=0, - groupcaps={ - choppy = {times=table, uses=uses, maxlevel=maxlevel}, - }, - damage_groups = {fleshy=3}, - }, - }) - end - end - end - end - end -end - - - - -local enchant_top = { - name = "default_water_source_animated.png^[colorize:red:120^enchant_table_top.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 2.0, - }, -} -function clear_inv(player) - local inv = player:get_inventory() - local size = inv:get_size("main") - for i = 1,size do - local stack = inv:get_stack("main", i) - inv:set_stack("main", i, "") - end -end - -function decimate_player_with_crucible(pos) - local radius = 3 - local min = {x=pos.x-radius,y=pos.y-radius,z=pos.z-radius} - local max = {x=pos.x+radius,y=pos.y+radius,z=pos.z+radius} - local vm = minetest.get_voxel_manip() - local emin, emax = vm:read_from_map(min,max) - local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} - local data = vm:get_data() - - for x = -radius,radius do - for y = -radius,radius do - for z = -radius,radius do - if x*x+y*y+z*z <= radius * radius + radius then --from sfan5's nuke mod (1.6) - local p_pos = area:index(pos.x+x,pos.y+y,pos.z+z) - data[p_pos] = minetest.get_content_id("air") - end - end - end - end - - vm:set_data(data) - vm:calc_lighting() - vm:write_to_map() - vm:update_map() - minetest.forceload_block(pos) - - --kill players and delete objects - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, radius)) do - if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then - object:remove() - end - if object:is_player() then - object:set_hp(0) - clear_inv(object) - end - end -end - - -minetest.register_node("enchant:crucible", { - description = "Crucible", - - --Thanks to Gambit and kilbith for this - tiles = {enchant_top,"enchant_table_bottom.png","enchant_table_side.png","enchant_table_side.png","enchant_table_side.png","enchant_table_side.png",}, - paramtype2 = "facedir", - is_ground_content = true, - groups = {snappy=1,choppy=3,flammable=2}, - paramtype = "light", - drawtype = "nodebox", - selection_box = {type="regular"}, - node_box = { - type = "fixed", - fixed = { - --jukebox core - divide by 16 because 16 pixels - {-8/16, -8/16, -8/16, 8/16, 7/16, 8/16}, - --top - {-8/16, 6/16, -8/16, 8/16, 7/16, 8/16}, - --top trim - {6/16, 7/16, -8/16, 8/16, 8/16, 8/16}, - {-8/16, 7/16, 6/16, 8/16, 8/16, 8/16}, - {-8/16, 7/16, -8/16, -6/16, 8/16, 8/16}, - {-8/16, 7/16, -8/16, 8/16, 8/16, -6/16}, - }, - }, - on_place = minetest.rotate_node, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local name = itemstack:get_name() - --only enchantable items - if intable(enchant.pick, name) ~= false or intable(enchant.shovel, name) ~= false or intable(enchant.axe, name) ~= false then - local chance = math.random() - if chance <= 0.85 then - local meta = itemstack:get_metadata() - --only enchant unenchanted tools - if intable(enchant.pick, name) ~= false and meta == "" then - --set up a random amount of perks, with random perks, in a random order, random. - local enc_tab = {} - local counter = 1 - for i = 1,math.random(1,tablelength(enchant.enchantments_pick)) do - local perk = enchant.enchantments_pick[math.random(1,tablelength(enchant.enchantments_pick))] - if intable(enc_tab, perk) == false then - enc_tab[counter] = perk - counter = counter + 1 - end - end - local tool = itemstack:get_name() - local a, b, c, d = 0,0,0,0 - if intable(enc_tab, enchant.enchantments_pick[1]) then --speed - a = 1 - end - if intable(enc_tab, enchant.enchantments_pick[2]) then --durable - b = 1 - end - if intable(enc_tab, enchant.enchantments_pick[3]) then --luck - c = 1 - end - if intable(enc_tab, enchant.enchantments_pick[4]) then --cherry pick - d = 1 - end - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool - local name = itemstack:get_name() - itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) - local pos = pointed_thing.under - pos.y = pos.y + 0.7 - --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - local item = minetest.add_item(pos,name) - if item == nil then - print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - print("BUG!") - return - end - local item = item:get_luaentity().object - item:setvelocity({x = 0, y = 0.1, z = 0}) - item:setacceleration({x = 0, y = 0, z = 0}) - item:set_properties({automatic_rotate = 0}) --or do 10 - local sound = minetest.sound_play("build", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 13, - minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, - maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, - minvel = {x=0, y=0, z=0}, - maxvel = {x=0, y=0, z=0}, - minacc = {x=0, y=0.1, z=0}, - maxacc = {x=0, y=1, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - minetest.after(13, function() - --don't do anything if the player cancelled the event - if item:get_luaentity() == nil then - return - end - minetest.sound_stop(sound) - minetest.sound_play("enchant", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 0.1, - minpos = item:getpos(), - maxpos = item:getpos(), - minvel = {x=-1, y=-1, z=-1}, - maxvel = {x=1, y=1, z=1}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - --make it so you cannot get the enchantment before it's done with the cinematic - local newpos = item:getpos() - local newpos2= clicker:getpos() - item:remove() - local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) - item:setacceleration({x = 0, y = -10, z = 0}) - end) - - - - return(itemstack) - else - --do nothing - end - end - if intable(enchant.shovel, name) ~= false and meta == "" then - --set up a random amount of perks, with random perks, in a random order, random. - local enc_tab = {} - local counter = 1 - for i = 1,math.random(1,tablelength(enchant.enchantments_shovel)) do - local perk = enchant.enchantments_shovel[math.random(1,tablelength(enchant.enchantments_shovel))] - if intable(enc_tab, perk) == false then - enc_tab[counter] = perk - counter = counter + 1 - end - end - local tool = itemstack:get_name() - local a, b, c, d = 0,0,0,0 - if intable(enc_tab, enchant.enchantments_shovel[1]) then --speed - a = 1 - end - if intable(enc_tab, enchant.enchantments_shovel[2]) then --durable - b = 1 - end - if intable(enc_tab, enchant.enchantments_shovel[3]) then --luck - c = 1 - end - if intable(enc_tab, enchant.enchantments_shovel[4]) then --cherry pick - d = 1 - end - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool - local name = itemstack:get_name() - itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) - local pos = pointed_thing.under - pos.y = pos.y + 0.7 - --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - local item = minetest.add_item(pos,name) - if item == nil then - print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - print("BUG!") - return - end - local item = item:get_luaentity().object - item:setvelocity({x = 0, y = 0.1, z = 0}) - item:setacceleration({x = 0, y = 0, z = 0}) - item:set_properties({automatic_rotate = 0}) --or do 10 - local sound = minetest.sound_play("build", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 13, - minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, - maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, - minvel = {x=0, y=0, z=0}, - maxvel = {x=0, y=0, z=0}, - minacc = {x=0, y=0.1, z=0}, - maxacc = {x=0, y=1, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - minetest.after(13, function() - --don't do anything if the player cancelled the event - if item:get_luaentity() == nil then - return - end - minetest.sound_stop(sound) - minetest.sound_play("enchant", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 0.1, - minpos = item:getpos(), - maxpos = item:getpos(), - minvel = {x=-1, y=-1, z=-1}, - maxvel = {x=1, y=1, z=1}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - --make it so you cannot get the enchantment before it's done with the cinematic - local newpos = item:getpos() - local newpos2= clicker:getpos() - item:remove() - local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) - item:setacceleration({x = 0, y = -10, z = 0}) - end) - - - - return(itemstack) - - else - --do nothing - end - end - if intable(enchant.axe, name) ~= false and meta == "" then - --set up a random amount of perks, with random perks, in a random order, random. - local enc_tab = {} - local counter = 1 - for i = 1,math.random(1,tablelength(enchant.enchantments_axe)) do - local perk = enchant.enchantments_axe[math.random(1,tablelength(enchant.enchantments_axe))] - if intable(enc_tab, perk) == false then - enc_tab[counter] = perk - counter = counter + 1 - end - end - local tool = itemstack:get_name() - local a, b, c, d = 0,0,0,0 - if intable(enc_tab, enchant.enchantments_axe[1]) then --speed - a = 1 - end - if intable(enc_tab, enchant.enchantments_axe[2]) then --durable - b = 1 - end - if intable(enc_tab, enchant.enchantments_axe[3]) then --luck - c = 1 - end - if intable(enc_tab, enchant.enchantments_axe[4]) then --cherry pick - d = 1 - end - if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool - local name = itemstack:get_name() - itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) - local pos = pointed_thing.under - pos.y = pos.y + 0.7 - --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - local item = minetest.add_item(pos,name) - if item == nil then - print(tool.."_"..a.."_"..b.."_"..c.."_"..d) - print("BUG!") - return - end - local item = item:get_luaentity().object - item:setvelocity({x = 0, y = 0.1, z = 0}) - item:setacceleration({x = 0, y = 0, z = 0}) - item:set_properties({automatic_rotate = 0}) --or do 10 - local sound = minetest.sound_play("build", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 13, - minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, - maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, - minvel = {x=0, y=0, z=0}, - maxvel = {x=0, y=0, z=0}, - minacc = {x=0, y=0.1, z=0}, - maxacc = {x=0, y=1, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - minetest.after(13, function() - --don't do anything if the player cancelled the event - if item:get_luaentity() == nil then - return - end - minetest.sound_stop(sound) - minetest.sound_play("enchant", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 100, - time = 0.1, - minpos = item:getpos(), - maxpos = item:getpos(), - minvel = {x=-1, y=-1, z=-1}, - maxvel = {x=1, y=1, z=1}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - --make it so you cannot get the enchantment before it's done with the cinematic - local newpos = item:getpos() - local newpos2= clicker:getpos() - item:remove() - local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) - item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) - item:setacceleration({x = 0, y = -10, z = 0}) - end) - - - - return(itemstack) - - else - --do nothing - end - end - -- then do the enchantments for other tools - - --now let's make it do some enchanted actions! - --local meta_table = minetest.deserialize(itemstack:get_metadata()) - --for i = 1,tablelength(meta_table) do --do all the enchantment actions ----- This should probably be some kind of function! ------ - -- if meta_table[i] == "speed" then - -- print("this item has speed") - -- end - --end - - --return(itemstack) - elseif chance > 0.85 and chance < 0.998 then - --it ate the item! such bad luck - itemstack:take_item() - minetest.sound_play("chomp", { - pos = pos, - max_hear_distance = 20, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 200, - time = 5, - minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, - maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, - minvel = {x=0, y=0, z=0}, - maxvel = {x=0, y=0, z=0}, - minacc = {x=0, y=0.5, z=0}, - maxacc = {x=0, y=3, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "heart.png", - }) - elseif chance >= 0.999 then - --warning: this function is brutal - --you must have broken 200 mirrors and crashed with a salt truck, let's destroy your life - minetest.sound_play("bad_luck", { - pos = pos, - max_hear_distance = 55, - gain = 1, - }) - minetest.add_particlespawner({ - amount = 200, - time = 10, - minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, - maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, - minvel = {x=0, y=0, z=0}, - maxvel = {x=0, y=0, z=0}, - minacc = {x=0, y=0.5, z=0}, - maxacc = {x=0, y=3, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png^[colorize:red:120", - }) - minetest.after(10, function() --give them the illusion that they might live - - --explosion stuff (use this for fireworks/tnt/nukes) - decimate_player_with_crucible(pos) - minetest.add_particlespawner({ - amount = 200, - time = 0.1, - minpos = pos, - maxpos = pos, - minvel = {x=-5, y=-5, z=-5}, - maxvel = {x=5, y=5, z=5}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 3, - maxexptime = 5, - minsize = 1, - maxsize = 1, - collisiondetection = false, - vertical = false, - texture = "bubble.png", - }) - minetest.sound_play("boom", { - pos = pos, - max_hear_distance = 55, - gain = 1, - }) - end) - end - end + print(dump(itemstack:to_table())) end, }) -minetest.register_craft({ - output = "enchant:crucible", - recipe = { - {"default:stone","default:stone","default:stone"}, - {"default:stone","bucket:bucket_water","default:stone"}, - {"default:wood","default:wood","default:wood"}, - } -}) ---do some enchantments +--max level for enchants, things like quickmine use time/level to calc how much performance increase +--the item has, don't get too crazy with it because it adds (enchant_level_max*item number) more items per item that +--get enchanted +local enchant_level_max = 3 -----------------USE HANDLE NODE DROPS INSTEAD!!! ---let's rehandle the item drop -function unenchanted_add(pos,drops,digger) - local inv = digger:get_inventory() - if inv:room_for_item("main", drops[1]) == true then - inv:add_item("main", drops[1]) - else - minetest.add_item(pos, drops[1]) - end +--do enchantments + +--do this to stop items defs from acting strange +local tool_list = minetest.registered_tools +local tool_list_clone = {} +for item in pairs(tool_list) do + table.insert(tool_list_clone, item) end -function enchanted_add(pos,drops,digger) - local inv = digger:get_inventory() - local source_node = minetest.get_node(pos).name - if inv:room_for_item("main", source_node) == true then - inv:add_item("main", source_node) - else - minetest.add_item(pos, source_node) - end -end -function treecapitate(pos,drops,digger) - if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then - for i = 1,20 do - if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then - unenchanted_add(pos,drops,digger) - minetest.remove_node(pos) - pos.y = pos.y + 1 +--defs +for _,item in pairs(tool_list_clone) do + + local shovel = string.match(item, "shovel") + + local axe = string.match(item, "axe") + + local pick = string.match(item, "pick") + + local enchantment = string.match(item, "enchantment") + + --do a seperate thing of enchantments for this + local sword = string.match(item, "sword") + + --if enchantable then create every variation of it that can be made + if pick or shovel or axe then + local description = minetest.registered_tools[item].description + + + local wield_image = minetest.registered_tools[item].wield_image + local inventory_image = minetest.registered_tools[item].inventory_image + local full_punch_interval = minetest.registered_tools[item].tool_capabilities.full_punch_interval + local max_drop_level = minetest.registered_tools[item].tool_capabilities.max_drop_level + + for quickmine = 0,enchant_level_max do + for furnace = 0,1 do + for luck = 0,1 do + for delicate = 0,1 do -- on or off + if quickmine+furnace+luck+delicate > 0 then -- stop from duplicating items + local temp_description = description + local groupcaps = {} + + local groups = {flammable = 2} + + --quickmine enchant + if quickmine >= 0 then + if quickmine > 0 then + temp_description = temp_description.."\nQuick Mine "..quickmine end - end - end -end -function super_treecapitate(pos,drops,digger) - if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then - for i = 1,20 do - if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then - unenchanted_add(pos,drops,digger) - if math.random() > 0.5 then - unenchanted_add(pos,drops,digger) - end - minetest.remove_node(pos) - pos.y = pos.y + 1 - end - end - end -end -function minetest.handle_node_drops(pos, drops, digger) - local itemstack = digger:get_wielded_item() - local name = itemstack:get_name() - --mix the shovel and pickaxe enchants into one - if minetest.get_item_group(name, "enchanted_pick") == 1 or minetest.get_item_group(name, "enchanted_shovel") == 1 or minetest.get_item_group(name, "enchanted_axe") == 1 then - --this player just dug with an enchanted pickaxe or shovel - check if axe with treefeller first - if minetest.get_item_group(name, "tree_feller") == 0 then - if minetest.get_item_group(name, "cherry_pick") == 0 then - unenchanted_add(pos,drops,digger) - if minetest.get_item_group(name, "luck") == 1 then - if math.random() > 0.5 then - unenchanted_add(pos,drops,digger) - end - end - elseif minetest.get_item_group(name, "cherry_pick") == 1 then - enchanted_add(pos,drops,digger) - --add luck to this - if minetest.get_item_group(name, "luck") == 1 then - if math.random() > 0.5 then - enchanted_add(pos,drops,digger) - end + for g in pairs(minetest.registered_tools[item].tool_capabilities.groupcaps) do + groupcaps[g] = {} + --avoid overwriting + local timer = minetest.registered_tools[item].tool_capabilities.groupcaps[g].times + local times = {} + for t,n in pairs(timer) do + times[t] = n/(quickmine+1) end + + --other vars, maybe code these into the game as enchantments? + groupcaps[g].times = times + + groupcaps[g].uses = minetest.registered_tools[item].tool_capabilities.groupcaps[g].uses + groupcaps[g].maxlevel = minetest.registered_tools[item].tool_capabilities.groupcaps[g].maxlevel end else - if minetest.get_item_group(name, "luck") == 1 then - super_treecapitate(pos,drops,digger) - else - treecapitate(pos,drops,digger) - end + groupcaps = minetest.registered_tools[item].tool_capabilities.groupcaps + end + + --these three will be done on dignode + --furnace enchant + if furnace > 0 then + groups["furnace"] = furnace + temp_description = temp_description.."\nFurnace" + end + + --luck enchant + if luck > 0 then + groups["luck"] = luck + temp_description = temp_description.."\nLuck" + end + + --delicate enchant + if delicate > 0 then + groups["delicate"] = delicate + temp_description = temp_description.."\nDelicate" + end + + --define the item - thanks to kaeza + minetest.register_tool("enchantment:"..item:match("^.-:(.*)").."_"..quickmine..furnace..luck..delicate, { + description = temp_description, + inventory_image = inventory_image, + wield_image = wield_image, + tool_capabilities = { + full_punch_interval = full_punch_interval, + max_drop_level=max_drop_level, + groupcaps=groupcaps, + damage_groups = {fleshy=2}, + }, + groups = groups, + sound = {breaks = "default_tool_breaks"}, + }) + + end + end + end + end end - else - unenchanted_add(pos,drops,digger) end end +--luck,furnace,delicate enchantment - make compatible with default and item drop +if minetest.get_modpath("item_drop") then +minetest.register_on_dignode(function(pos, oldnode, digger) + local item + if string.match(digger:get_wielded_item():to_string(), "enchantment") then + item = digger:get_wielded_item():to_table().name + else + return -- don't do anything else if hand + end + + local name = minetest.registered_tools[item].description + local drop_count = 1 + local drop + + local luck = false + local cook = false + local delicate = false + + --luck enchantment + if string.match(name, "Luck") then + luck = true + drop_count = math.random(1,4) + end + + --Delicate enchantment + if string.match(name, "Delicate") then + drop = oldnode.name + delicate = true + else + drop = minetest.get_node_drops(oldnode.name, name)[1] + end + + --furnace enchantment + if string.match(name, "Furnace") then + local temper, _ = minetest.get_craft_result({ method = "cooking", width = 1, items = {drop}}) + --if the item can be smelted, smelt + if temper and temper.item:to_table() then + temper = temper.item:to_table().name + + drop = temper + cook = true + end + end + + --add item + minetest.add_item(pos, drop.." "..drop_count) + end) +else + minetest.register_on_dignode(function(pos, oldnode, digger) + local item + if string.match(digger:get_wielded_item():to_string(), "enchantment") then + item = digger:get_wielded_item():to_table().name + else + return -- don't do anything else if hand + end + local name = minetest.registered_tools[item].description + local drop_count = 1 + local drop + + local luck = false + local cook = false + local delicate = false + + + --luck enchantment + if string.match(name, "Luck") then + luck = true + drop_count = math.random(1,4) + end + + --Delicate enchantment + if string.match(name, "Delicate") then + drop = oldnode.name + delicate = true + else + drop = minetest.get_node_drops(oldnode.name, name)[1] + end + + --furnace enchantment + if string.match(name, "Furnace") then + local temper, _ = minetest.get_craft_result({ method = "cooking", width = 1, items = {drop}}) + --if the item can be smelted, smelt + if temper and temper.item:to_table() then + temper = temper.item:to_table().name + + drop = temper + cook = true + end + end + + --process it all + local inv = digger:get_inventory() + if inv and inv:room_for_item("main", drop.." "..drop_count) then + inv:add_item("main", drop.." "..drop_count) + + --stop players from duplicating items - basic item add override + if cook == true or delicate == true then + if drop ~= minetest.get_node_drops(oldnode.name, name)[1] then + inv:remove_item("main", minetest.get_node_drops(oldnode.name, name)[1]) + end + end + else--no room, drop + minetest.add_item(pos, drop.." "..drop_count) + end + end) +end +--generate items when enchanting by doing math.random(0,maxlevel)..math.random(0,maxlevel)...... diff --git a/init.lua.old b/init.lua.old new file mode 100644 index 0000000..7798ba5 --- /dev/null +++ b/init.lua.old @@ -0,0 +1,911 @@ +--table length thing +function tablelength(T) + local count = 0 + for _ in pairs(T) do count = count + 1 end + return count +end +--if in table thing +function intable(tbl, item) + for key, value in pairs(tbl) do + if value == item then return key end + end + return false +end + + +--DONE current goal, give a pickaxe a random table of enchantments - + +--DONE for the cherry pick enchantment, do an on_dignode function for all players, then check for the enchantment, drop the item that was mined using player:dig_node + +--do multiple levels for these + +--DONE make the thing slowly raise the tool with a sound, make a noise with particles and throw the tool at the player + +--possibly a max level enchant? maybe? + +--damage group enchant? + +--DONE make the enchantment box use the moving water texture, with an overlay, to make it look like it's magic + +--make the enchantment box randomly eat items instead of enchanting them + +--make the enchantment box explode, and kill player's in area on rare occasions + +--make the enchant box clear the player's inventory on RARE occasions + +--modify treecapitator to use voxel manip + +--make bad effects also happen + + +enchant = {} + +enchant.enchantments_pick = { +"speed", --speed (check a .after thing to tell how fast you'll dig it.) +"durable", --resistance or infinity - 1 is resistance 2 is infinity +"luck", --get multiple items +"cherry pick", --similar to silk touch in MC +} +enchant.pick = { +"default:pick_bronze", +"default:pick_diamond", +"default:pick_mese", +"default:pick_steel", +"default:pick_stone", +"default:pick_wood", +} + +--since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. +--pickaxe enchantments +for x = 1,tablelength(enchant.pick) do + print(enchant.pick[x]) + --try to do this some other, maybe + for a = 0,1 do --speed + for b = 0,1 do --durable + for c = 0,1 do --luck + for d = 0,1 do --cherry pick + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool + + --name the tool, and define it + local tool = enchant.pick[x] + local name = minetest.registered_items[enchant.pick[x]]["description"] + if a == 1 then + name = name.."\n-Speed" + end + if b == 1 then + name = name.."\n-Durable" + end + if c == 1 then + name = name.."\n-Luck" + end + if d == 1 then + name = name.."\n-Cherry Pick" + end + --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + --add the enchant to the tools - don't add to the logic above to improve readability + --global because of bugs with registered tools or something + + local table = {} + local uses = 0 + local maxlevel = 0 + --if enchanted with speed, half time, if not, use standard tool time. + if a == 1 then + for i = 1,3 do + if minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"][i] then + table[i] = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"][i]/2 + end + end + else + table = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["times"] + end + --if enchanted with durable, double the uses, if not, use standard uses. + if b == 1 then + uses = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["uses"] * 2 + else + uses = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["uses"] + end + --possibly turn this into enchant + maxlevel = minetest.registered_tools[enchant.pick[x]]["tool_capabilities"]["groupcaps"]["cracky"]["maxlevel"] + + minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { + description = name, + inventory_image = minetest.registered_items[enchant.pick[x]]["inventory_image"], + groups = {not_in_creative_inventory=1,enchanted_pick=1,luck=c,cherry_pick=d}, --don't clutter the inventory + tool_capabilities = { + --full_punch_interval = 1.3, + --max_drop_level=0, + groupcaps={ + cracky = {times=table, uses=uses, maxlevel=maxlevel}, + }, + damage_groups = {fleshy=3}, + }, + }) + end + end + end + end + end +end + +--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +enchant.enchantments_shovel = { +"speed", --speed (check a .after thing to tell how fast you'll dig it.) +"durable", --resistance or infinity - 1 is resistance 2 is infinity +"luck", --get multiple items +"cherry pick", --similar to silk touch in MC +} +enchant.shovel = { +"default:shovel_bronze", +"default:shovel_diamond", +"default:shovel_mese", +"default:shovel_steel", +"default:shovel_stone", +"default:shovel_wood", +} + +--since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. +--pickaxe enchantments +for x = 1,tablelength(enchant.shovel) do + print(enchant.shovel[x]) + --try to do this some other, maybe + for a = 0,1 do --speed + for b = 0,1 do --durable + for c = 0,1 do --luck + for d = 0,1 do --cherry pick + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool + + --name the tool, and define it + local tool = enchant.shovel[x] + local name = minetest.registered_items[enchant.shovel[x]]["description"] + if a == 1 then + name = name.."\n-Speed" + end + if b == 1 then + name = name.."\n-Durable" + end + if c == 1 then + name = name.."\n-Luck" + end + if d == 1 then + name = name.."\n-Cherry Pick" + end + --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + --add the enchant to the tools - don't add to the logic above to improve readability + --global because of bugs with registered tools or something + + local table = {} + local uses = 0 + local maxlevel = 0 + --if enchanted with speed, half time, if not, use standard tool time. + if a == 1 then + for i = 1,3 do + if minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"][i] then + table[i] = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"][i]/2 + end + end + else + table = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["times"] + end + --if enchanted with durable, double the uses, if not, use standard uses. + if b == 1 then + uses = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["uses"] * 2 + else + uses = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["uses"] + end + --possibly turn this into enchant + maxlevel = minetest.registered_tools[enchant.shovel[x]]["tool_capabilities"]["groupcaps"]["crumbly"]["maxlevel"] + + minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { + description = name, + inventory_image = minetest.registered_items[enchant.shovel[x]]["inventory_image"], + groups = {not_in_creative_inventory=1,enchanted_shovel=1,luck=c,cherry_pick=d}, --don't clutter the inventory + tool_capabilities = { + --full_punch_interval = 1.3, + --max_drop_level=0, + groupcaps={ + crumbly = {times=table, uses=uses, maxlevel=maxlevel}, + }, + damage_groups = {fleshy=3}, + }, + }) + end + end + end + end + end +end +--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +enchant.enchantments_axe = { +"speed", --speed (check a .after thing to tell how fast you'll dig it.) +"durable", --resistance or infinity - 1 is resistance 2 is infinity +"luck", --get multiple items +"tree feller", --My favorite MC mod - replaces cherry pick +} +enchant.axe = { +"default:axe_bronze", +"default:axe_diamond", +"default:axe_mese", +"default:axe_steel", +"default:axe_stone", +"default:axe_wood", +} + +--since tools can't be modified on the fly, I have to do this. 384 tools from 6. GREAT. +--pickaxe enchantments +for x = 1,tablelength(enchant.axe) do + --print(enchant.axe[x]) + --try to do this some other, maybe + for a = 0,1 do --speed + for b = 0,1 do --durable + for c = 0,1 do --luck + for d = 0,1 do --tree feller + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't duplicate the tool + + --name the tool, and define it + local tool = enchant.axe[x] + local name = minetest.registered_items[enchant.axe[x]]["description"] + if a == 1 then + name = name.."\n-Speed" + end + if b == 1 then + name = name.."\n-Durable" + end + if c == 1 then + name = name.."\n-Luck" + end + if d == 1 then + name = name.."\n-Tree Feller" + end + --print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + --add the enchant to the tools - don't add to the logic above to improve readability + --global because of bugs with registered tools or something + + local table = {} + local uses = 0 + local maxlevel = 0 + --if enchanted with speed, half time, if not, use standard tool time. + if a == 1 then + for i = 1,3 do + if minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"][i] then + table[i] = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"][i]/2 + end + end + else + table = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["times"] + end + --if enchanted with durable, double the uses, if not, use standard uses. + if b == 1 then + uses = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["uses"] * 2 + else + uses = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["uses"] + end + --possibly turn this into enchant + maxlevel = minetest.registered_tools[enchant.axe[x]]["tool_capabilities"]["groupcaps"]["choppy"]["maxlevel"] + + minetest.register_tool(":"..tool.."_"..a.."_"..b.."_"..c.."_"..d, { + description = name, + inventory_image = minetest.registered_items[enchant.axe[x]]["inventory_image"], + groups = {not_in_creative_inventory=1,enchanted_axe=1,luck=c,tree_feller=d}, --don't clutter the inventory + tool_capabilities = { + --full_punch_interval = 1.3, + --max_drop_level=0, + groupcaps={ + choppy = {times=table, uses=uses, maxlevel=maxlevel}, + }, + damage_groups = {fleshy=3}, + }, + }) + end + end + end + end + end +end + + + + +local enchant_top = { + name = "default_water_source_animated.png^[colorize:red:120^enchant_table_top.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 2.0, + }, +} +function clear_inv(player) + local inv = player:get_inventory() + local size = inv:get_size("main") + for i = 1,size do + local stack = inv:get_stack("main", i) + inv:set_stack("main", i, "") + end +end + +function decimate_player_with_crucible(pos) + local radius = 3 + local min = {x=pos.x-radius,y=pos.y-radius,z=pos.z-radius} + local max = {x=pos.x+radius,y=pos.y+radius,z=pos.z+radius} + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map(min,max) + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} + local data = vm:get_data() + + for x = -radius,radius do + for y = -radius,radius do + for z = -radius,radius do + if x*x+y*y+z*z <= radius * radius + radius then --from sfan5's nuke mod (1.6) + local p_pos = area:index(pos.x+x,pos.y+y,pos.z+z) + data[p_pos] = minetest.get_content_id("air") + end + end + end + end + + vm:set_data(data) + vm:calc_lighting() + vm:write_to_map() + vm:update_map() + minetest.forceload_block(pos) + + --kill players and delete objects + for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, radius)) do + if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then + object:remove() + end + if object:is_player() then + object:set_hp(0) + clear_inv(object) + end + end +end + + +minetest.register_node("enchant:crucible", { + description = "Crucible", + + --Thanks to Gambit and kilbith for this + tiles = {enchant_top,"enchant_table_bottom.png","enchant_table_side.png","enchant_table_side.png","enchant_table_side.png","enchant_table_side.png",}, + paramtype2 = "facedir", + is_ground_content = true, + groups = {snappy=1,choppy=3,flammable=2}, + paramtype = "light", + drawtype = "nodebox", + selection_box = {type="regular"}, + node_box = { + type = "fixed", + fixed = { + --jukebox core - divide by 16 because 16 pixels + {-8/16, -8/16, -8/16, 8/16, 7/16, 8/16}, + --top + {-8/16, 6/16, -8/16, 8/16, 7/16, 8/16}, + --top trim + {6/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, 6/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, -6/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, -6/16}, + }, + }, + on_place = minetest.rotate_node, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local name = itemstack:get_name() + --only enchantable items + if intable(enchant.pick, name) ~= false or intable(enchant.shovel, name) ~= false or intable(enchant.axe, name) ~= false then + local chance = math.random() + if chance <= 0.85 then + local meta = itemstack:get_metadata() + --only enchant unenchanted tools + if intable(enchant.pick, name) ~= false and meta == "" then + --set up a random amount of perks, with random perks, in a random order, random. + local enc_tab = {} + local counter = 1 + for i = 1,math.random(1,tablelength(enchant.enchantments_pick)) do + local perk = enchant.enchantments_pick[math.random(1,tablelength(enchant.enchantments_pick))] + if intable(enc_tab, perk) == false then + enc_tab[counter] = perk + counter = counter + 1 + end + end + local tool = itemstack:get_name() + local a, b, c, d = 0,0,0,0 + if intable(enc_tab, enchant.enchantments_pick[1]) then --speed + a = 1 + end + if intable(enc_tab, enchant.enchantments_pick[2]) then --durable + b = 1 + end + if intable(enc_tab, enchant.enchantments_pick[3]) then --luck + c = 1 + end + if intable(enc_tab, enchant.enchantments_pick[4]) then --cherry pick + d = 1 + end + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool + local name = itemstack:get_name() + itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) + local pos = pointed_thing.under + pos.y = pos.y + 0.7 + --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + local item = minetest.add_item(pos,name) + if item == nil then + print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + print("BUG!") + return + end + local item = item:get_luaentity().object + item:setvelocity({x = 0, y = 0.1, z = 0}) + item:setacceleration({x = 0, y = 0, z = 0}) + item:set_properties({automatic_rotate = 0}) --or do 10 + local sound = minetest.sound_play("build", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 13, + minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, + maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, + minvel = {x=0, y=0, z=0}, + maxvel = {x=0, y=0, z=0}, + minacc = {x=0, y=0.1, z=0}, + maxacc = {x=0, y=1, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + minetest.after(13, function() + --don't do anything if the player cancelled the event + if item:get_luaentity() == nil then + return + end + minetest.sound_stop(sound) + minetest.sound_play("enchant", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 0.1, + minpos = item:getpos(), + maxpos = item:getpos(), + minvel = {x=-1, y=-1, z=-1}, + maxvel = {x=1, y=1, z=1}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + --make it so you cannot get the enchantment before it's done with the cinematic + local newpos = item:getpos() + local newpos2= clicker:getpos() + item:remove() + local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) + item:setacceleration({x = 0, y = -10, z = 0}) + end) + + + + return(itemstack) + else + --do nothing + end + end + if intable(enchant.shovel, name) ~= false and meta == "" then + --set up a random amount of perks, with random perks, in a random order, random. + local enc_tab = {} + local counter = 1 + for i = 1,math.random(1,tablelength(enchant.enchantments_shovel)) do + local perk = enchant.enchantments_shovel[math.random(1,tablelength(enchant.enchantments_shovel))] + if intable(enc_tab, perk) == false then + enc_tab[counter] = perk + counter = counter + 1 + end + end + local tool = itemstack:get_name() + local a, b, c, d = 0,0,0,0 + if intable(enc_tab, enchant.enchantments_shovel[1]) then --speed + a = 1 + end + if intable(enc_tab, enchant.enchantments_shovel[2]) then --durable + b = 1 + end + if intable(enc_tab, enchant.enchantments_shovel[3]) then --luck + c = 1 + end + if intable(enc_tab, enchant.enchantments_shovel[4]) then --cherry pick + d = 1 + end + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool + local name = itemstack:get_name() + itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) + local pos = pointed_thing.under + pos.y = pos.y + 0.7 + --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + local item = minetest.add_item(pos,name) + if item == nil then + print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + print("BUG!") + return + end + local item = item:get_luaentity().object + item:setvelocity({x = 0, y = 0.1, z = 0}) + item:setacceleration({x = 0, y = 0, z = 0}) + item:set_properties({automatic_rotate = 0}) --or do 10 + local sound = minetest.sound_play("build", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 13, + minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, + maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, + minvel = {x=0, y=0, z=0}, + maxvel = {x=0, y=0, z=0}, + minacc = {x=0, y=0.1, z=0}, + maxacc = {x=0, y=1, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + minetest.after(13, function() + --don't do anything if the player cancelled the event + if item:get_luaentity() == nil then + return + end + minetest.sound_stop(sound) + minetest.sound_play("enchant", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 0.1, + minpos = item:getpos(), + maxpos = item:getpos(), + minvel = {x=-1, y=-1, z=-1}, + maxvel = {x=1, y=1, z=1}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + --make it so you cannot get the enchantment before it's done with the cinematic + local newpos = item:getpos() + local newpos2= clicker:getpos() + item:remove() + local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) + item:setacceleration({x = 0, y = -10, z = 0}) + end) + + + + return(itemstack) + + else + --do nothing + end + end + if intable(enchant.axe, name) ~= false and meta == "" then + --set up a random amount of perks, with random perks, in a random order, random. + local enc_tab = {} + local counter = 1 + for i = 1,math.random(1,tablelength(enchant.enchantments_axe)) do + local perk = enchant.enchantments_axe[math.random(1,tablelength(enchant.enchantments_axe))] + if intable(enc_tab, perk) == false then + enc_tab[counter] = perk + counter = counter + 1 + end + end + local tool = itemstack:get_name() + local a, b, c, d = 0,0,0,0 + if intable(enc_tab, enchant.enchantments_axe[1]) then --speed + a = 1 + end + if intable(enc_tab, enchant.enchantments_axe[2]) then --durable + b = 1 + end + if intable(enc_tab, enchant.enchantments_axe[3]) then --luck + c = 1 + end + if intable(enc_tab, enchant.enchantments_axe[4]) then --cherry pick + d = 1 + end + if a.."_"..b.."_"..c.."_"..d ~= "0_0_0_0" then -- no enchantments, then don't put out a normal tool + local name = itemstack:get_name() + itemstack:take_item()--set_name(tool.."_"..a.."_"..b.."_"..c.."_"..d) + local pos = pointed_thing.under + pos.y = pos.y + 0.7 + --local item = minetest.add_item(pos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + local item = minetest.add_item(pos,name) + if item == nil then + print(tool.."_"..a.."_"..b.."_"..c.."_"..d) + print("BUG!") + return + end + local item = item:get_luaentity().object + item:setvelocity({x = 0, y = 0.1, z = 0}) + item:setacceleration({x = 0, y = 0, z = 0}) + item:set_properties({automatic_rotate = 0}) --or do 10 + local sound = minetest.sound_play("build", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 13, + minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, + maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, + minvel = {x=0, y=0, z=0}, + maxvel = {x=0, y=0, z=0}, + minacc = {x=0, y=0.1, z=0}, + maxacc = {x=0, y=1, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + minetest.after(13, function() + --don't do anything if the player cancelled the event + if item:get_luaentity() == nil then + return + end + minetest.sound_stop(sound) + minetest.sound_play("enchant", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 100, + time = 0.1, + minpos = item:getpos(), + maxpos = item:getpos(), + minvel = {x=-1, y=-1, z=-1}, + maxvel = {x=1, y=1, z=1}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + --make it so you cannot get the enchantment before it's done with the cinematic + local newpos = item:getpos() + local newpos2= clicker:getpos() + item:remove() + local item = minetest.add_item(newpos, tool.."_"..a.."_"..b.."_"..c.."_"..d) + item:setvelocity({x=newpos2.x-newpos.x,y=(newpos2.y-newpos.y)+6,z=newpos2.z-newpos.z}) + item:setacceleration({x = 0, y = -10, z = 0}) + end) + + + + return(itemstack) + + else + --do nothing + end + end + -- then do the enchantments for other tools + + --now let's make it do some enchanted actions! + --local meta_table = minetest.deserialize(itemstack:get_metadata()) + --for i = 1,tablelength(meta_table) do --do all the enchantment actions ----- This should probably be some kind of function! ------ + -- if meta_table[i] == "speed" then + -- print("this item has speed") + -- end + --end + + --return(itemstack) + elseif chance > 0.85 and chance < 0.998 then + --it ate the item! such bad luck + itemstack:take_item() + minetest.sound_play("chomp", { + pos = pos, + max_hear_distance = 20, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 200, + time = 5, + minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, + maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, + minvel = {x=0, y=0, z=0}, + maxvel = {x=0, y=0, z=0}, + minacc = {x=0, y=0.5, z=0}, + maxacc = {x=0, y=3, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "heart.png", + }) + elseif chance >= 0.999 then + --warning: this function is brutal + --you must have broken 200 mirrors and crashed with a salt truck, let's destroy your life + minetest.sound_play("bad_luck", { + pos = pos, + max_hear_distance = 55, + gain = 1, + }) + minetest.add_particlespawner({ + amount = 200, + time = 10, + minpos = {x=pos.x-(6/16), y=pos.y-0.1, z=pos.z-(6/16)}, + maxpos = {x=pos.x+(6/16), y=pos.y-0.1, z=pos.z+(6/16)}, + minvel = {x=0, y=0, z=0}, + maxvel = {x=0, y=0, z=0}, + minacc = {x=0, y=0.5, z=0}, + maxacc = {x=0, y=3, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png^[colorize:red:120", + }) + minetest.after(10, function() --give them the illusion that they might live + + --explosion stuff (use this for fireworks/tnt/nukes) + decimate_player_with_crucible(pos) + minetest.add_particlespawner({ + amount = 200, + time = 0.1, + minpos = pos, + maxpos = pos, + minvel = {x=-5, y=-5, z=-5}, + maxvel = {x=5, y=5, z=5}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 3, + maxexptime = 5, + minsize = 1, + maxsize = 1, + collisiondetection = false, + vertical = false, + texture = "bubble.png", + }) + minetest.sound_play("boom", { + pos = pos, + max_hear_distance = 55, + gain = 1, + }) + end) + end + end + end, +}) +minetest.register_craft({ + output = "enchant:crucible", + recipe = { + {"default:stone","default:stone","default:stone"}, + {"default:stone","bucket:bucket_water","default:stone"}, + {"default:wood","default:wood","default:wood"}, + } +}) + +--do some enchantments + +----------------USE HANDLE NODE DROPS INSTEAD!!! +--let's rehandle the item drop +function unenchanted_add(pos,drops,digger) + local inv = digger:get_inventory() + + if inv:room_for_item("main", drops[1]) == true then + inv:add_item("main", drops[1]) + else + minetest.add_item(pos, drops[1]) + end +end +function enchanted_add(pos,drops,digger) + local inv = digger:get_inventory() + local source_node = minetest.get_node(pos).name + + if inv:room_for_item("main", source_node) == true then + inv:add_item("main", source_node) + else + minetest.add_item(pos, source_node) + end +end +function treecapitate(pos,drops,digger) + if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then + for i = 1,20 do + if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then + unenchanted_add(pos,drops,digger) + minetest.remove_node(pos) + pos.y = pos.y + 1 + end + end + end +end +function super_treecapitate(pos,drops,digger) + if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then + for i = 1,20 do + if minetest.get_item_group(minetest.get_node(pos).name, "choppy") ~= 0 then + unenchanted_add(pos,drops,digger) + if math.random() > 0.5 then + unenchanted_add(pos,drops,digger) + end + minetest.remove_node(pos) + pos.y = pos.y + 1 + end + end + end +end +function minetest.handle_node_drops(pos, drops, digger) + local itemstack = digger:get_wielded_item() + local name = itemstack:get_name() + --mix the shovel and pickaxe enchants into one + if minetest.get_item_group(name, "enchanted_pick") == 1 or minetest.get_item_group(name, "enchanted_shovel") == 1 or minetest.get_item_group(name, "enchanted_axe") == 1 then + --this player just dug with an enchanted pickaxe or shovel - check if axe with treefeller first + if minetest.get_item_group(name, "tree_feller") == 0 then + if minetest.get_item_group(name, "cherry_pick") == 0 then + unenchanted_add(pos,drops,digger) + if minetest.get_item_group(name, "luck") == 1 then + if math.random() > 0.5 then + unenchanted_add(pos,drops,digger) + end + end + elseif minetest.get_item_group(name, "cherry_pick") == 1 then + enchanted_add(pos,drops,digger) + --add luck to this + if minetest.get_item_group(name, "luck") == 1 then + if math.random() > 0.5 then + enchanted_add(pos,drops,digger) + end + end + end + else + if minetest.get_item_group(name, "luck") == 1 then + super_treecapitate(pos,drops,digger) + else + treecapitate(pos,drops,digger) + end + end + else + unenchanted_add(pos,drops,digger) + end + +end + + + + diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..de11803 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = enchantment