Player Inventory Manipulation - MinecraftPhi/MinecraftPhi-modules GitHub Wiki
Manipulating the player's inventory as nbt is now possible thanks to block loot tables and the /loot command!
The steps are as follows:
-
Call
phi.modifyinv:setup/whole_inventoryas the player, and/orphi.modifyinv:setup/enderchestThis will copy the player's inventory and/or enderchest to a temporary location in the shared jukebox and sort it into separate lists for the different sections
-
Call
phi.modifyinv:load/*as the playerThis will load section
*into the shared shulker box. The sections are outlined below. -
Edit the shulker box
You can do any edits of the inventory that you like. The slot numbers will be different from the player's inventory, but they will always be in the same order as in the player's inventory. The slot numbers are outlined below.
-
Call
phi.modifyinv:apply/*as the player, orphi.modifyinv:drop/*This will save the modified slots to the player when using
apply, or drop the slots at the current position and clear those slots in the player's inventory when usingdrop -
Repeat steps 2-4 for each section that you want to edit.
The sections can be done in any order, and any sections that are not used will be left unchanged
If you just want to drop the whole inventory you can call phi.modifyinv:drop/whole_inventory as the player instead of doing the above steps. This will not drop the contents of the player's enderchest
Note: This process uses global state, and so you must complete all your manipulation before calling
phi.modifyinv:setup/whole_inventory. An easy way to do this is to put all these calls in one function with the steps in-between, and calling that function.
There are plans for functions to manipulate individual slots. Certain slots will have hardcoded functions, and other slots will be using the templates feature of the Phi transpiler. This has not been implemented yet
Sections
| Name | Player Slot Range | Shulker Box Slot Range |
|---|---|---|
| hotbar | 0b-8b |
0b-8b |
| inventory | 9b-35b |
0b-26b |
| armor | 100b-103b |
0b-3b |
| offhand | -106b |
0b |
| enderchest | 0b-26b |
0b-26b |
Individual Slots
Certain slots have special functions for manipulating just those slots.
The steps are as follows:
-
Call
phi.modifyinv:setup/*as the playerThis will copy the specified slot to the first slot of the shulker box
-
Edit the shulker box
You can do any edits of the slot that you like. The slot number will always be 0
-
Call
phi.modifyinv:apply/*as the player, orphi.modifyinv:drop/*This will save the modified slot to the player when using
apply, or drop the slot at the current position and clear the slot in the player's inventory when usingdrop
The slots that can be individually modified are:
mainhandoffhandhelmetchestplateleggingsboots
Clearing slots
Clearing individual slots can be done by just doing replaceitem ... air for the slot, but clearing a whole section of the inventory is done using the function phi.modifyinv:clear/* where * is one of the sections listed earlier