Skip to content

Crafting table - #3590

Open
Crepestrom wants to merge 17 commits into
PixelGuys:masterfrom
Crepestrom:Crafting-Table
Open

Crepestrom wants to merge 17 commits into
PixelGuys:masterfrom
Crepestrom:Crafting-Table

Conversation

@Crepestrom

Copy link
Copy Markdown
Contributor

When you open the crafting menu it will check if it has the right tags to show a recipe to the player
It also allows blocks to call open the crafting menu with its own tags (allows for gating recipes behind certain crafting tables)

@Crepestrom
Crepestrom marked this pull request as ready for review September 9, 2026 02:25
@careeoki

careeoki commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

used this to quickly whip together a table saw (#1734)
image

@Wunka Wunka moved this to Low Priority in PRs to review Sep 17, 2026
@Wunka
Wunka self-requested a review September 17, 2026 13:22
Comment thread src/items/recipes.zig Outdated
.sourceAmounts = main.worldArena.alloc(u16, inputs.len),
.resultItem = output.item,
.resultAmount = output.amount,
.craftingTags = main.worldArena.alloc(Tag, craftingTags.len),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.craftingTags = main.worldArena.alloc(Tag, craftingTags.len),
.craftingTags = main.worldArena.dupe(Tag, craftingTags),

Then you don't need to copy them later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see now
i copied the other type of code but this doesnt need that implementaiton

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapped that over

Comment thread src/items/recipes.zig Outdated
Comment on lines +225 to +228
var defaultCraftingTags = arena.alloc(main.Tag, 1);
defaultCraftingTags[0] = main.Tag.handCraftable;
const foundCraftingTags = Tag.loadTagsFromZon(arena, zon.getChild("craftingTags"));
const craftingTags = if (foundCraftingTags.len != 0) foundCraftingTags else defaultCraftingTags;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide 4 lines later if you even need your allocation, then only do it if you need it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved over so we dont unessicarily duplicate the work

Comment thread src/items.zig Outdated

return getValidRecipe(.{.sourceItems = sourceItems.items, .sourceAmounts = sourceAmounts.items, .resultItem = resultItem, .resultAmount = resultAmount});
const tagCount = try reader.readVarInt(usize);
var craftingTagTypes: main.List(Tag) = .initCapacity(main.stackAllocator, @min(256, tagCount));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no magic numbers please, where does the 256 come from? where do you have this limitation? If its by a type, then use std.math.maxInt for example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont actually know

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its gone now

Comment thread src/items/recipes.zig Outdated
Comment on lines +223 to +227
const craftingTags = if (foundCraftingTags.len != 0) foundCraftingTags else blk: {
var defaultCraftingTags = arena.alloc(main.Tag, 1);
defaultCraftingTags[0] = main.Tag.handCraftable;
break :blk defaultCraftingTags;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remembered, because you don't use an arena, you should also just be able to do:

Suggested change
const craftingTags = if (foundCraftingTags.len != 0) foundCraftingTags else blk: {
var defaultCraftingTags = arena.alloc(main.Tag, 1);
defaultCraftingTags[0] = main.Tag.handCraftable;
break :blk defaultCraftingTags;
};
const craftingTags = if (foundCraftingTags.len != 0) foundCraftingTags else &.{main.Tag.handCraftable}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah i did something like that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It never leaves the stack, so please don't dupe it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Low Priority

Development

Successfully merging this pull request may close these issues.

3 participants