User Tools

Site Tools


tutorial:inventory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:inventory [2021/04/19 02:19] – onUse has a return type of ActionResult platymemotutorial:inventory [2023/11/06 23:28] (current) binaris00
Line 103: Line 103:
     default void setStack(int slot, ItemStack stack) {     default void setStack(int slot, ItemStack stack) {
         getItems().set(slot, stack);         getItems().set(slot, stack);
-        if (stack.getCount() > getMaxCountPerStack()) { +        if (stack.getCount() > stack.getMaxCount()) { 
-            stack.setCount(getMaxCountPerStack());+            stack.setCount(stack.getMaxCount());
         }         }
     }     }
Line 158: Line 158:
     [...]     [...]
     @Override     @Override
-    public void fromTag(BlockState state, CompoundTag tag) { +    public void readNbt(NbtCompound nbt) { 
-        super.fromTag(state, tag); +        super.readNbt(nbt); 
-        Inventories.fromTag(tag,items);+        Inventories.readNbt(nbt, items);
     }     }
  
     @Override     @Override
-    public CompoundTag toTag(CompoundTag tag) { +    public NbtCompound writeNbt(NbtCompound nbt) { 
-        Inventories.toTag(tag,items); +        Inventories.writeNbt(nbt, items); 
-        return super.toTag(tag);+        return super.writeNbt(nbt);
     }     }
 } }
Line 224: Line 224:
             if (!blockEntity.getStack(1).isEmpty()) {             if (!blockEntity.getStack(1).isEmpty()) {
                 // Give the player the stack in the inventory                 // Give the player the stack in the inventory
-                player.inventory.offerOrDrop(world, blockEntity.getStack(1));+                player.getInventory().offerOrDrop(blockEntity.getStack(1));
                 // Remove the stack from the inventory                 // Remove the stack from the inventory
                 blockEntity.removeStack(1);                 blockEntity.removeStack(1);
             } else if (!blockEntity.getStack(0).isEmpty()) {             } else if (!blockEntity.getStack(0).isEmpty()) {
-                player.inventory.offerOrDrop(world, blockEntity.getStack(0));+                player.getInventory().offerOrDrop(blockEntity.getStack(0));
                 blockEntity.removeStack(0);                 blockEntity.removeStack(0);
             }             }
Line 246: Line 246:
     [...]     [...]
     @Override     @Override
-    public int[] getInvAvailableSlots(Direction var1) {+    public int[] getInvAvailableSlots(Direction side) {
         // Just return an array of all slots         // Just return an array of all slots
         int[] result = new int[getItems().size()];         int[] result = new int[getItems().size()];
tutorial/inventory.1618798778.txt.gz · Last modified: 2021/04/19 02:19 by platymemo