nodes.lua 3.83 KB
Newer Older
Evert Prants's avatar
Evert Prants committed
1 2 3 4 5 6 7 8 9 10 11 12

-- Enchanted Wood
minetest.register_node("magicalities:tree_enchanted", {
	description = "Enchanted Tree",
	tiles = {"magicalities_tree_top.png", "magicalities_tree_top.png", "magicalities_table_wood.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
13

Evert Prants's avatar
Evert Prants committed
14 15 16 17 18
-- circumvent a weird issue
local function add_fix(inv, item)
	inv:add_item("main", item)
end

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
-- Researchable bookshelf
-- Supposed to be a generated node that gives Research Notes
minetest.register_node("magicalities:bookshelf", {
	description = "Wise Bookshelf",
	tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
		"default_wood.png", "default_bookshelf.png", "default_bookshelf.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3, not_in_creative_inventory = 1},
	sounds = default.node_sound_wood_defaults(),
	drop = "default:bookshelf",
	on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
		if not clicker or clicker:get_player_name() == "" then return itemstack end
		local name = clicker:get_player_name()
		local count = math.random(0, 3)

		-- Swap the node with an ordinary bookshelf after inspecting
		node.name = "default:bookshelf"
		minetest.swap_node(pos, node)
		minetest.registered_nodes[node.name].on_construct(pos)

		-- A chance of not getting anything from this bookshelf
		if count == 0 then
			minetest.chat_send_player(name, "This bookshelf did not contain anything interesting.")
			return itemstack
		end

		-- Add some books into the new bookshelf
		local bookinv = minetest.get_meta(pos):get_inventory()
		bookinv:add_item("books", ItemStack("default:book " .. count))

		-- Give player Research Notes
		local item = ItemStack("magicalities:note")
		item:set_count(count)

		local inv = clicker:get_inventory()
		if inv:room_for_item("main", item) then
Evert Prants's avatar
Evert Prants committed
56
			minetest.after(0.1, add_fix, inv, item)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
		else
			minetest.item_drop(item, clicker, clicker:get_pos())
		end

		minetest.chat_send_player(name, "You have read some of the books in this bookshelf and wrote up some notes.")

		return itemstack
	end
})

local nboxcollsel = {
	type = "fixed",
	fixed = {
		{-0.375, -0.5, 0.1875, -0.1875, -0.375, 0.375}, -- pot-base
		{-0.3125, -0.375, 0.25, -0.25, -0.3125, 0.3125}, -- pot-head
	}
}

local nbox = {
	type = "fixed",
	fixed = {
		{-0.375, -0.5, 0.1875, -0.1875, -0.375, 0.375}, -- pot-base
		{-0.3125, -0.375, 0.25, -0.25, -0.3125, 0.3125}, -- pot-head
		{-0.28125, -0.3125, 0.125, -0.28125, 0.1875, 0.4375}, -- feather
		{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5}, -- paper-base
	}
}

minetest.register_node("magicalities:quill", {
	description = "Quill",
	tiles = {
		"magicalities_quill_top.png",
		"magicalities_quill_top.png^[transformFY",
		"magicalities_quill_right.png",
		"magicalities_quill_right.png^[transformFX",
		"magicalities_quill_front.png^[transformFX",
		"magicalities_quill_front.png"
	},
	drawtype = "nodebox",
	paramtype = "light",
	sunlight_propagates = true,
	paramtype2 = "facedir",
	is_ground_content = false,
	node_box = nbox,
	selection_box = nboxcollsel,
	collision_box = nboxcollsel,
	groups = { not_in_creative_inventory = 1 },
})

minetest.register_node("magicalities:quill_research", {
	tiles = {
		"magicalities_quill_top_research.png",
		"magicalities_quill_top.png^[transformFY",
		"magicalities_quill_right.png",
		"magicalities_quill_right.png^[transformFX",
		"magicalities_quill_front.png^[transformFX",
		"magicalities_quill_front.png"
	},
	drawtype = "nodebox",
	paramtype = "light",
	sunlight_propagates = true,
	paramtype2 = "facedir",
	is_ground_content = false,
	drop = "magicalities:quill",
	node_box = nbox,
	selection_box = nboxcollsel,
	collision_box = nboxcollsel,
	groups = { not_in_creative_inventory = 1 },
})