First version is out!

master
CosmosScripter 2021-06-23 21:05:04 -03:00 committed by GitHub
commit 97c5434cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 277 additions and 0 deletions

12
LICENSE.txt Normal file
View File

@ -0,0 +1,12 @@
3d_printer Copyright (C) 2021 Cosmos
3d_printer mod by Cosmos- Adds a 3d_printer, a battery, and a blueprint registering api to Minetest.
DISCLAIMER: This software is free, and will always be free. If you paid anything for obtaining this software, you have been bamboozled!
=====================================================================
All code provided in this package is is licensed under LGPL-2.1
Full license: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
All textures and models provided in this package are licensed under CC-BY-SA-4.0
Full license: https://creativecommons.org/licenses/by-sa/4.0/legalcode

24
README.md Normal file
View File

@ -0,0 +1,24 @@
3D Printer mod [v1.0] by Cosmos
==========================
This mod adds a 3D printer, which allows you to craft items only using plastic sheet, as long as you have a blueprint of the item and enough battery.
To use a 3D printer, insert a blueprint, a charged battery, and the exact plastic sheet count required.
After that, punch the printer and check it's inventory, the item output will be in the plastic input.
---------------------------------------------
See: license.txt for license.
Check out api.txt if you want to create your own blueprints.
Check crafting.txt to see crafting info.
---------------------------------------------
Depends on: default, dye, basic_materials.
---------------------------------------------
==HOW TO INSTALL THE MOD==
1.Download the mod, it may be a ZIP file.
2. Extract the folder inside to somewhere on the computer (if its a ZIP file).
3.Make sure that when you open the folder, you can directly find "README.md" in the listing. If you just see another folder, move that folder up one level and delete the old one.
4.Rename the folder to "3d_printer" incase it has another name.
5.Move the mod to "minetest/mods/" or "~/.minetest/mods/".
6.Here we go!
============================

12
api.txt Normal file
View File

@ -0,0 +1,12 @@
To register your own blueprint use:
plastic_printer_data.register_blueprint(item, description, cost, drawing_image)
See the example below:
plastic_printer_data.register_blueprint("foomod:foobar", "Foo", "5", "foo_bar.png")
The result will be an item whose name will be "foomod:foobar_blueprint", description will be "Foo blueprint", cost will be "basic_materials:plastic_sheet 5"
The parameter drawing_image is optional, it overlays the blueprint image. If nil, the item inventory image will be a blank blueprint.
Every parameter filled in the function needs to be a string, except for drawing_image, which can be nil.

24
crafting.txt Normal file
View File

@ -0,0 +1,24 @@
3D Printer crafting:
{"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"},
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
{"basic_materials:gear_steel", "basic_materials:plastic_sheet", "basic_materials:gear_steel"}
-------------------------
Blank blueprint crafting:
{"default:paper", "default:paper", "default:paper"},
{"default:paper", "dye:blue", "default:paper"},
{"default:paper", "default:paper", "default:paper"}
-------------------------
Battery crafting (shapeless):
{"default:copper_ingot", "default:mese_crystal_fragment"}
NOTE: Batteries can be recicled, place a battery in any crafting slot and it will be transformed into "default:mese_crystal_fragment"
-------------------------
Any registered blueprint can be crafted using a blank blueprint and the desired item, so you can create copies of an item incase you have plastic
Suggestion for developers: You can use blueprints as a way to unlock items by finding hidden blueprints

3
depends.txt Normal file
View File

@ -0,0 +1,3 @@
default
dye
basic_materials

1
description.txt Normal file
View File

@ -0,0 +1 @@
Adds a 3D printer and blueprints to the game

201
init.lua Normal file
View File

@ -0,0 +1,201 @@
plastic_printer_data={}
blueprint_items = {
price={},
result={}
}
--Functions
local function can_dig(pos, player)--Prevent a loss of items by accident
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
if inv:is_empty("main") and inv:is_empty("material") and inv:is_empty("battery") then
return true
else
return false
end
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)--I would actually only let you put the allowed stuff, but it was lagging and crashing the game
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "main" then
return stack:get_count()
elseif listname == "material" then
return stack:get_count()
elseif listname == "battery" then
return stack:get_count()
end
end
--Nodebox
local printer_box = {-0.5, -0.5, -0.5, 0.5, -0.42, 0.5}
local printer_box2 = {-0.45, -0.5, -0.45, -0.4, -0.4, -0.4}
local printer_box3 = {0.4, -0.5, -0.45, 0.45, -0.4, -0.4}
local printer_box4 = {-0.45, -0.5, 0.4, -0.4, -0.4, 0.45}
local printer_box5 = {0.4, -0.5, 0.4, 0.45, -0.4, 0.45}
local printer_bar1 = {-0.43, -0.5, 0.4, -0.4, 0.5, 0.43}
local printer_bar2 = {0.4, -0.5, 0.4, 0.43, 0.5, 0.43}
local printer_bar3 = {-0.43, -0.5, -0.43, -0.4, 0.5, -0.4}
local printer_bar4 = {0.4, -0.5, -0.43, 0.43, 0.5, -0.4}
local printer_box_plate = {-0.2, -0.5, -0.2, 0.2, -0.4, 0.2}
local printer_top_box = {-0.5, 0.37, -0.5, 0.5, 0.5, 0.5}
local printer_top_plate = {-0.4, 0.32, -0.4, 0.4, 0.37, 0.4}
local printer_pen = {-0.05, 0.27, -0.05, 0.05, 0.37, 0.05}
--End of nodebox
function plastic_printer_data:register_blueprint(item, description, cost, drawing_image)--If you want to add a drawing image, I recommend using the color #C7CDD2
if drawing_image ~= nil then
minetest.register_craftitem(item.."_blueprint", {
inventory_image = "printer_blueprint.png^"..drawing_image,
description = description.." blueprint\n".."Requires "..cost.." plastic sheet to be printed",--Added this info about plastic cost so people can know how much they need
stack_max = 1,
groups = {printer_blueprint=1},
})
else
minetest.register_craftitem(item.."_blueprint", {
inventory_image = "printer_blueprint.png",
description = description.." blueprint\n".."Requires "..cost.." plastic sheet to be printed",--Fun fact: it took me a while to notice people can't guess the cost
stack_max = 1,
groups = {printer_blueprint=1},
})
end
blueprint_items.price[item.."_blueprint"] = "basic_materials:plastic_sheet "..cost
blueprint_items.result[item.."_blueprint"] = item
minetest.register_craft( {
type = "shapeless",
output = item.."_blueprint",
recipe = {"3d_printer:blueprint", item},
})
end
--Items
minetest.register_craftitem("3d_printer:blueprint", {
inventory_image = "printer_blueprint.png",
description = "Blank blueprint",
stack_max = 1,
groups = {printer_blueprint=1},
})
minetest.register_tool("3d_printer:battery", {
inventory_image = "printer_battery.png",
description = "Battery",
stack_max = 1,
groups = {printer_battery=1},
})
--Crafting
minetest.register_craft( {
output = "3d_printer:printer",
recipe = {
{"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"},
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
{"basic_materials:gear_steel", "basic_materials:plastic_sheet", "basic_materials:gear_steel"}
}
})
minetest.register_craft( {
output = "3d_printer:blueprint",
recipe = {
{"default:paper", "default:paper", "default:paper"},
{"default:paper", "dye:blue", "default:paper"},
{"default:paper", "default:paper", "default:paper"}
}
})
minetest.register_craft( {
type = "shapeless",
output = "3d_printer:battery",
recipe = {"default:copper_ingot", "default:mese_crystal_fragment"},
})
minetest.register_craft( {
type = "shapeless",
output = "default:mese_crystal_fragment",
recipe = {"3d_printer:battery"},
})
--The printer
minetest.register_node("3d_printer:printer", {
description = "3D Printer",
tiles = {"3d_printer_top.png","3d_printer_bottom.png","3d_printer_side.png","3d_printer_side.png","3d_printer_side.png","3d_printer_side.png"},
groups = {oddly_breakable_by_hand=1, snappy=1, cracky=1},
sounds = default_stone_sounds,
paramtype = "light",
paramtype2 = "facedir",
drawtype = "nodebox",
is_ground_content = false,
node_box = {
type = "fixed",--Fun fact: I didn't use any kind of nodebox editor to build this, so it took me about an hour
fixed = {
printer_box,
printer_box2,
printer_box3,
printer_box4,
printer_box5,
printer_bar1,
printer_bar2,
printer_bar3,
printer_bar4,
printer_box_plate,
printer_top_box,
printer_top_plate,
printer_pen,
},
},
allow_metadata_inventory_put = allow_metadata_inventory_put,
can_dig = can_dig,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "size[8,9]"
.. default.gui_bg
.. default.gui_bg_img
.. default.gui_slots
.. "label[3.75,0;Blueprint]"
.. "list[current_name;main;3.5,0.5;1,1;]"
.. "label[2.75,2;Plastic]"
.. "list[current_name;material;2.5,2.5;1,1;]"
.. "image[3.75,1.5;1,1;gui_printer_arrow.png^[transformr180]"
.. "image[3.5,2.3;1,1;gui_printer_arrow.png^[transformr90]"
.. "label[4.75,2;Battery]"
.. "list[current_name;battery;4.5,2.5;1,1;]"
.. "list[current_player;main;0,5;8,1;]"
.. "list[current_player;main;0,6.2;8,3;8]")
local inventory = meta:get_inventory()
inventory:set_size("main", 1)
inventory:set_size("material", 1)
inventory:set_size("battery", 1)
end,
on_punch = function(pos, node, puncher)--The original plan was to use a kind of furnance thing, but I don't have experience with formspec and the mod was causing lag
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local blueprint_used = inv:get_stack("main", 1):to_table()
local plastic_used = inv:get_stack("material", 1):to_table()
local battery = inv:get_stack("battery", 1):to_table()
if not plastic_used then return end
local plastic_count = plastic_used.count
--minetest.chat_send_player(puncher:get_player_name(), "working")
if battery.wear >= 58981.5 then
minetest.chat_send_player(puncher:get_player_name(), "Battery low")--Batteries wear out when the printer works
minetest.chat_send_player(puncher:get_player_name(), "Battery replacement needed")
return
end
if not (inv:is_empty("main") or inv:is_empty("material") or inv:is_empty("battery")) then
--minetest.chat_send_player(puncher:get_player_name(), "first check")
--minetest.chat_send_player(puncher:get_player_name(), plastic_used.name)
if plastic_used.name.." "..plastic_count == blueprint_items.price[blueprint_used.name] then
--minetest.chat_send_player(puncher:get_player_name(), "second check")
if battery.name == "3d_printer:battery" then
--minetest.chat_send_player(puncher:get_player_name(), "third check")
inv:set_stack("material", 1, blueprint_items.result[blueprint_used.name])
battery.wear = battery.wear + (65535/10)
inv:set_stack("battery", 1, battery)
end
else
minetest.chat_send_player(puncher:get_player_name(), "Lack of plastic/Excessive plastic")
end
end
end,
})
--Battery blueprint used for testing
--plastic_printer_data:register_blueprint("3d_printer:battery", "Test", "5", nil)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
textures/3d_printer_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B