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
Next revisionBoth sides next revision
tutorial:inventory [2020/12/27 16:21] – [Inventory] Update Inventory and SidedInventory to recent yarn names (thank you Arbee!) technici4ntutorial:inventory [2021/07/31 21:06] – Changed toTag() and fromTag to writeNbt() and readNbt() jrprogrammer
Line 158: Line 158:
     [...]     [...]
     @Override     @Override
-    public void fromTag(CompoundTag tag) { +    public void readNbt(NbtCompound nbt) { 
-        super.fromTag(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 181: Line 181:
     [...]     [...]
     @Override     @Override
-    public boolean onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult) { +    public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult) { 
-        if (world.isClient) return true;+        if (world.isClient) return ActionResult.SUCCESS;
         Inventory blockEntity = (Inventory) world.getBlockEntity(blockPos);         Inventory blockEntity = (Inventory) world.getBlockEntity(blockPos);
  
Line 202: Line 202:
             }             }
         }          } 
-        return true;+        return ActionResult.SUCCESS;
     }     }
 } }
Line 214: Line 214:
     [...]     [...]
     @Override     @Override
-    public boolean onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult) {+    public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult) {
         ...         ...
         if (!player.getStackInHand(hand).isEmpty()) {         if (!player.getStackInHand(hand).isEmpty()) {
Line 233: Line 233:
         }         }
                  
-        return true;+        return ActionResult.SUCCESS;
     }     }
 } }
tutorial/inventory.txt · Last modified: 2023/11/06 23:28 by binaris00