[Solved] How to group grass, bed api

Post Reply
Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

[Solved] How to group grass, bed api

by Nordal » Post

I want to use grass, dry_grass, marram_grass, junglegrass as "group:grass" in the recipe of bed-api. Just like I would use "group:wood". If I use group:grass, only one craft recipe with "grass" appears in inv. If I make additional crafting recipes with group:dry_grass, grass, dry_grass and junglegrass recipes appear in inv, even doubled. I can't figure it out.
Last edited by Nordal on Mon May 11, 2020 20:40, edited 1 time in total.
CFS - still widely unknown

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: How to group grass, bed api

by Napiophelios » Post

sounds like you have six seperate recipes,
you should only need four to include all the grass variants.

1 recipe for "group:grass"
1 recipe for "group:dry_grass"
1 recipe using "default:junglegrass"
1 recipe using "default:marram_grass_1".


"group:grass" includes "default:grass_1-5"
"group:dry_grass" includes "default:dry_grass_1-5"
Marram_grass and junglegrass do not belong to a "grass group"

Gerald
Member
Posts: 93
Joined: Sun Dec 28, 2014 10:35
In-game: gerald7
Location: Germany

Re: How to group grass, bed api

by Gerald » Post

If you are changing the default and bed mods you can just add your own group - let's call it grass_craft - by adding grass_craft = 1 to the groups list in the definition of every grass node (found in the nodes.lua file).

If you want to add this stuff using your own mod you can do the following:
local groups = minetest.registered_nodes[grass_name]
groups.grass_craft = 1
minetest.override_item(grass_name, {groups = groups})

for every grass_name.
Of course this mod depends on default.

Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

Re: How to group grass, bed api

by Nordal » Post

"group:grass" includes "default:grass_1-5"
"group:dry_grass" includes "default:dry_grass_1-5"
Marram_grass and junglegrass do not belong to a "grass group"
@Naphelios, thanks for th info.
you should only need four to include all the grass variants.

1 recipe for "group:grass"
1 recipe for "group:dry_grass"
1 recipe using "default:junglegrass"
1 recipe using "default:marram_grass_1".
Yes, but somehow I don't manage to make this work. Problem seems to be somehow, that craft recipe is included in bed definition.

Code: Select all

	beds.register_bed(
		"beds:bed",    -- Bed name
		def            -- See [#Bed definition]
	)

 * `beds.can_dig(bed_pos)` Returns a boolean whether the bed at `bed_pos` may be dug
 * `beds.read_spawns() `   Returns a table containing players respawn positions
 * `beds.kick_players()`  Forces all players to leave bed
 * `beds.skip_night()`   Sets world time to morning and saves respawn position of all players currently sleeping

### Bed definition

	{
		description = "Simple Bed",
		inventory_image = "beds_bed.png",
		wield_image = "beds_bed.png",
		tiles = {
			bottom = {'Tile definition'}, -- the tiles of the bottom part of the bed.
			top = {Tile definition} -- the tiles of the bottom part of the bed.
		},
		nodebox = {
			bottom = 'regular nodebox',     -- bottom part of bed (see [Node boxes])
			top = 'regular nodebox',        -- top part of bed (see [Node boxes])
		},
		selectionbox = 'regular nodebox',  -- for both nodeboxes (see [Node boxes])
		recipe = {                                         -- Craft recipe
			{"group:wool", "group:wool", "group:wool"},
			{"group:wood", "group:wood", "group:wood"}
		}
	}
If I put group:grass into the recipe that's included in the bed's definition, I get the expected inventory craft entry. But if I register the other "grass'" recipes additionaly, outside the bed definition, it leads to this strange recipe doubling behavior in inventory. Namely, if I add the three other kinds of grass I get 7 inventory craft entries. The three additional recipes outside the bed def are doubled.

@Gerald, if I understand you right, this is a cool way to get all grass types united under one group like "grass_craft" in your example without changing the existing grass definitions. Then I could use only the one recipe included in the bed mod. I just don't understand what you mean by changing the bed mod.

EDIT: I forked sleeping mat mod to have a test case: https://gitlab.com/landor1/sleeping_mat ... r/init.lua
CFS - still widely unknown

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: How to group grass, bed api

by Napiophelios » Post

choose one for the node definition to be included in the register bed,
then write the others long form seperately.

you can add numerous alternate recipes so long
as they don't duplicate or conflict with another node/item's recipe


EDIT

I believe Gerald means to override the default nodes like this,
then just use "group: grass_craft" in the register beds node definition

Code: Select all

-- junglegrass
minetest.override_item("default:junglegrass", {
	groups = {snappy = 3, flora = 1, attached_node = 1, flammable = 1, grass_craft = 1},
})

-- grass
minetest.override_item("default:grass_1", {
    groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1,not_in_creative_inventory=1, grass = 1, grass_craft = 1},
})

for i = 2, 5 do
	minetest.override_item("default:grass_" .. i, {
groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1,not_in_creative_inventory=1, grass = 1, grass_craft = 1},
	})
end

--dry grass
minetest.override_item("default:dry_grass_1", {
    groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1,not_in_creative_inventory=1, dry_grass = 1, grass_craft = 1},
})

for i = 2, 5 do
	minetest.override_item("default:dry_grass_" .. i, {
groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1,not_in_creative_inventory=1, dry_grass = 1, grass_craft = 1},
	})
end

-- marram grass
minetest.override_item("default:marram_grass_1", {
    groups = {snappy = 3, flammable = 3, attached_node = 1, grass_craft = 1},
})

for i = 2, 3 do
    minetest.override_item("default:marram_grass_" .. i, {
        groups = {snappy = 3, flammable = 3, attached_node = 1, not_in_creative_inventory=1, grass_craft = 1},
	})
end

Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

Re: How to group grass, bed api

by Nordal » Post

@Naphelios, thank you for the code! I used it and it works without errors. This is the recipe inside the bed definition. I wrote no other, further recipe:

Code: Select all

beds.register_bed("sleeping_mat:mat", {
	description = ("Grass Sleeping Mat"),
	inventory_image = "sleeping_mat_roll.png",
	wield_image = "sleeping_mat_roll.png",
	tiles = {
		bottom = {
			"sleeping_mat_top1.png",
			"sleeping_mat_top1_side.png",
		},
		top = {
			"sleeping_mat_top2.png",
			"sleeping_mat_top2_side.png",
		},
	},
	nodebox = {
		bottom = {
			{-1/2, -1/2, -1/2, 1/2, -7/16, 1/2}
		},
		top = {
			{-1/2, -1/2, -1/2, 1/2, -7/16, 1/2}
		},
	},
	selectionbox = {-1/2, -1/2, -1/2, 1/2, -7/16, 3/2},

	recipe = {
		{"group:grass_craft", "group:grass_craft", "group:grass_craft"},
		{"group:grass_craft", "group:grass_craft", "group:grass_craft"},
		{"group:grass_craft", "group:grass_craft", ""},
	},
})
But, the inventory shows only one recipe with "default:grass_1" as recipe item. See the screenshot. I expected 4 recipe variants, one for every grass type. I suppose it's the bed api somehow limiting to one recipe only.
Attachments
screenshot inventory guide
screenshot inventory guide
Bildschirmfoto 2020-05-11.png (241.32 KiB) Viewed 449 times
CFS - still widely unknown

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: How to group grass, bed api

by Napiophelios » Post

The "G" above the image in your craft guide stands for 'group' :)

Nordal
Member
Posts: 158
Joined: Mon Jul 30, 2018 15:46
GitHub: Nordall

Re: How to group grass, bed api

by Nordal » Post

Stupid me. I am so confused already :) Thank you to you and Gerald! It now works just like I wanted to and I learned how to setup a new group. I mark this topic as solved.
CFS - still widely unknown

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests