-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Inventory article #246
base: main
Are you sure you want to change the base?
Conversation
❌ Deploy Preview for nimble-elf-d9d491 failed.
|
Thank you for your contribution! We are temporarily not accepting PRs until we finish the update process. Follow #242 for more information. You may keep this PR open. |
Hi! The documentation has been updated to version 1.21.4. Please rebase your PR and update your code to align with the latest version. Alternatively, you can create a new branch based on the latest commit from the Once you've completed the updates and are confident everything is ready, feel free to unmark this as a draft. Thanks again for your contribution! |
Basically the same content as the article on the fabric wiki: https://wiki.fabricmc.net/tutorial:inventory Uses the same `ImplementedInventory` class as that one to implement `Inventory` on the custom block entity Now updated for latest!
Maybe we should get a Checkstyle rule to allow comments after blocks? It's making me do stuff like this: // :::1 if (condition) { // code... } // :::1 ...which is IMO kinda ugly
updated for 1.21.4 :) |
|
||
<VideoPlayer src="/assets/develop/blocks/inventory_2.mp4" /> | ||
|
||
## Sided Inventories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Sided Inventories | |
## Sided Inventories {#sided-inventories} |
|
||
Now, when you right-click the block with an item, you'll no longer have an item! If you run `/data get block` on the block, you'll see the item in the `Items` field in the NBT. | ||
|
||
![Duplicator block & /data get block output showing the item in the inventory](/assets/develop/blocks/inventory_1.png) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![Duplicator block & /data get block output showing the item in the inventory](/assets/develop/blocks/inventory_1.png) | |
![Duplicator block and output of `/data get block` showing the item in the inventory](/assets/develop/blocks/inventory_1.png) |
|
||
Here, if the player is holding an item and there is an empty slot, we move the item from the player's hand to the block's inventory and return `ItemActionResult.SUCCESS`. | ||
|
||
Now, when you right-click the block with an item, you'll no longer have an item! If you run `/data get block` on the block, you'll see the item in the `Items` field in the NBT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, when you right-click the block with an item, you'll no longer have an item! If you run `/data get block` on the block, you'll see the item in the `Items` field in the NBT. | |
Now, when you right-click the block with an item, you'll no longer have it! If you run `/data get block` on the block, you'll see the item in the `Items` field in the NBT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good so far!
I think it would be interesting to also expand this page to explain how storing things like ItemStacks, Fluids, Energy, and so on, could be stored and retrieved. Also on that note, an example on how to use the Fabric Transfer API might be useful for that too. Or this could get its extra page, if necessary.
|
||
@[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/block/entity/custom/DuplicatorBlockEntity.java) | ||
|
||
The `DuplicatorBlock` should now have a `getTicker` method that returns a reference to `DuplicatorBlockEntity::tick`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a ticking functionality here?
From what I can see, it's just copying the slot and is returning it asap.
So this could be handled in the block interaction method in the custom block class, right?
Or do something like duplicating the slot every 10 ticks and then storing it in the inventory, until it's being retrieved or the stack has hit its max size.
|
||
# Block Inventories {#inventories} | ||
|
||
In Minecraft, all blocks that can store items have an `Inventory`. This includes blocks like chests, furnaces, and hoppers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be just me, but this kind of makes it sound like the Inventory
interface is always needed to store any kind of ItemStack. Maybe mention it as "best practice" or something?
Added an article about implementing
Inventory
in block entities. Some stuff (e.g.ImplementedInventory
) copied over from wiki's "tutorial:inventory".Tutorial covers using the
ImplementedInventory
& implementingSidedInventory
, as well as some basic user interaction (inserting items on right-click).