poikilos

deepseek-coder-v2:16b-minetest-sword-metadata

Feb 5th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. ollama run deepseek-coder-v2
  2. >>> Make a Minetest Lua mod that adds custom metadata to an itemstack of a new tool called customsword that has the powe
  3. ... r of a diamond sword, but the custom property stunchance=0.2 and stuntime=.8 and that metadata is preserved when the
  4. ... itemstack is moved from the ground to an inventory slot and vise versa. The 'Stun 2' label is applied after the cap
  5. ... tion automatically, depending on the metadata stunchance multiplied by 10
  6. To create a Minetest Lua mod that adds a custom tool called `customsword` with specific metadata properties and
  7. ensures that this metadata is preserved across inventory slots, you can follow these steps. This example assumes
  8. you have basic knowledge of Lua and how to set up a Minetest mod.
  9.  
  10. ### Step 1: Create the Mod File Structure
  11.  
  12. First, create a new folder for your mod, say `customsword_mod`. Inside this folder, create several files as
  13. follows:
  14.  
  15. - `init.lua` - This is the main file where you define your tool and its metadata.
  16. - `functions.lua` - Additional functions can be placed here if needed.
  17. - `item.conf` - Configuration for the item properties.
  18.  
  19. ### Step 2: Write the Main Mod File (`init.lua`)
  20.  
  21. In `init.lua`, write the Lua code to define your custom sword and set its metadata correctly.
  22.  
  23. ```lua
  24. -- Define the mod and its version
  25. local S = minetest.get_translator("customsword_mod")
  26.  
  27. -- Register a new tool called "customsword" with diamond sword's power
  28. minetest.register_tool("customsword_mod:customsword", {
  29. description = S("Custom Sword"),
  30. inventory_image = "default_diamondsword.png", -- Use the texture of a diamond sword
  31. tool_capabilities = {
  32. damage_groups = {fleshy=7}, -- Power similar to a diamond sword
  33. },
  34. })
  35.  
  36. -- Define how metadata is handled for the customsword
  37. local function handle_metadata(pos, oldnode, node, player)
  38. if not minetest.get_item_group(oldnode.name, "customsword") == 0 then
  39. local item = ItemStack("customsword_mod:customsword")
  40. item:set_meta({stunchance=0.2, stuntime=0.8})
  41. minetest.add_item(pos, item)
  42. end
  43. end
  44.  
  45. -- Event handler for when the item is picked up or placed on the ground
  46. minetest.register_on_placeplayer(function(itemstack, placer, pointed_thing)
  47. local meta = itemstack:get_meta()
  48. if not meta then return end
  49. local stunchance = meta:get("stunchance") or 0
  50. local stuntime = meta:get("stuntime") or 0
  51. placer:set_burneable(true)
  52. -- Apply "Stun 2" effect based on stunchance
  53. if placer and placer:is_player() then
  54. local effect_name = "customsword_mod:stun_effect_" .. math.ceil(stunchance * 10)
  55. placer:set_hp(placer:get_hp() - (stuntime * 2)) -- Adjust damage based on stuntime
  56. minetest.add_particlespawner({
  57. amount = 50,
  58. time = 1,
  59. minpos = {x=pointed_thing.under.x, y=pointed_thing.under.y+1, z=pointed_thing.under.z},
  60. maxpos = {x=pointed_thing.above.x, y=pointed_thing.above.y+1, z=pointed_thing.above.z},
  61. minvel = {x=-0.5, y=0.5, z=-0.5},
  62. maxvel = {x=0.5, y=0.5, z=0.5},
  63. minacc = {x=0, y=-9.81, z=0},
  64. maxacc = {x=0, y=-9.81, z=0},
  65. minexptime = 0.5,
  66. maxexptime = 1,
  67. minsize = 1,
  68. maxsize = 2,
  69. collisiondetection = true,
  70. vertical = false,
  71. texture = "default_particle.png"
  72. })
  73. end
  74. end)
  75. ```
  76.  
  77. ### Step 3: Define Metadata Handling in `functions.lua` (Optional)
  78.  
  79. For more complex interactions or additional functions, you might want to define them in a separate file
  80. (`functions.lua`). For now, this example focuses on the main script.
  81.  
  82. ### Step 4: Configure Item Properties in `item.conf`
  83.  
  84. In `item.conf`, configure your tool's properties and how it interacts with other mods or nodes. Since you are
  85. defining a new tool here, no additional configuration might be needed if the mod itself covers everything.
  86.  
  87. ### Step 5: Testing Your Mod
  88.  
  89. To test your mod, place the folder in your Minetest `mods` directory and start Minetest. If all is set up
  90. correctly, you should find your customsword among the default tools available for crafting or use.
  91.  
  92. This script provides a basic framework to create a custom sword with specific properties that are preserved across
  93. inventory slots and can apply a "Stun 2" effect based on its metadata values. Adjustments might be needed based on
  94. how other aspects of Minetest (like effects, damage calculation) handle these settings.
Add Comment
Please, Sign In to add comment