User Tools

Site Tools


zh_cn:tutorial:inventory

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
zh_cn:tutorial:inventory [2023/08/28 10:14] – [从物品栏(或任何物品栏)中提取和放入] wjz_pzh_cn:tutorial:inventory [2023/08/28 10:14] (current) – [从物品栏(或任何物品栏)中提取和放入] wjz_p
Line 196: Line 196:
     [...]     [...]
     @Override     @Override
-    public boolean activate(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()) {
             ...             ...
         } else {         } else {
-            // 如果玩家没有持有任何东西,我们依次将方块实体中的物品给予玩家 +            // If the player is not holding anything we'll get give him the items in the block entity one by one 
- +  
-             // 查找第一个有物品的槽位,并给予玩家 +             // Find the first slot that has an item and give it to the player 
-            if (!blockEntity.getInvStack(1).isEmpty()) { +            if (!blockEntity.getStack(1).isEmpty()) { 
-                // 给予玩家物品栏中的物品堆 +                // Give the player the stack in the inventory 
-                player.inventory.offerOrDrop(world, blockEntity.getInvStack(1));+                player.getInventory().offerOrDrop(blockEntity.getStack(1));
                 // Remove the stack from the inventory                 // Remove the stack from the inventory
-                blockEntity.removeInvStack(1); +                blockEntity.removeStack(1); 
-            } else if (!blockEntity.getInvStack(0).isEmpty()) { +            } else if (!blockEntity.getStack(0).isEmpty()) { 
-                player.inventory.offerOrDrop(world, blockEntity.getInvStack(0)); +                player.getInventory().offerOrDrop(blockEntity.getStack(0)); 
-                blockEntity.removeInvStack(0);+                blockEntity.removeStack(0);
             }             }
         }         }
-         +  
-        return true;+        return ActionResult.SUCCESS;
     }     }
 } }
zh_cn/tutorial/inventory.txt · Last modified: 2023/08/28 10:14 by wjz_p