zh_cn:tutorial:inventory
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:inventory [2021/09/25 14:39] – solidblock | zh_cn:tutorial:inventory [2023/08/28 10:14] (current) – [从物品栏(或任何物品栏)中提取和放入] wjz_p | ||
---|---|---|---|
Line 164: | Line 164: | ||
[...] | [...] | ||
@Override | @Override | ||
- | public | + | public |
- | if (world.isClient) return | + | if (world.isClient) return |
Inventory blockEntity = (Inventory) world.getBlockEntity(blockPos); | Inventory blockEntity = (Inventory) world.getBlockEntity(blockPos); | ||
- | + | ||
+ | |||
if (!player.getStackInHand(hand).isEmpty()) { | if (!player.getStackInHand(hand).isEmpty()) { | ||
- | // 检查第一个打开的槽位是什么,并从玩家手中放入物品 | + | // Check what is the first open slot and put an item from the player' |
- | if (blockEntity.getInvStack(0).isEmpty()) { | + | if (blockEntity.getStack(0).isEmpty()) { |
- | // 将玩家手中的物品堆放入物品栏中 | + | // Put the stack the player is holding into the inventory |
- | blockEntity.setInvStack(0, player.getStackInHand(hand).copy()); | + | blockEntity.setStack(0, player.getStackInHand(hand).copy()); |
- | // 从玩家手中移除物品堆 | + | // Remove the stack from the player' |
player.getStackInHand(hand).setCount(0); | player.getStackInHand(hand).setCount(0); | ||
- | } else if (blockEntity.getInvStack(1).isEmpty()) { | + | } else if (blockEntity.getStack(1).isEmpty()) { |
- | blockEntity.setInvStack(1, player.getStackInHand(hand).copy()); | + | blockEntity.setStack(1, player.getStackInHand(hand).copy()); |
player.getStackInHand(hand).setCount(0); | player.getStackInHand(hand).setCount(0); | ||
} else { | } else { | ||
- | // 如果物品栏是满的,我们输出其内容 | + | // If the inventory is full we'll print it's contents |
System.out.println(" | System.out.println(" | ||
- | + blockEntity.getInvStack(0) + " and the second slot holds " + blockEntity.getInvStack(1)); | + | + blockEntity.getStack(0) + " and the second slot holds " + blockEntity.getStack(1)); |
} | } | ||
} | } | ||
- | return | + | return |
} | } | ||
} | } | ||
Line 196: | Line 196: | ||
[...] | [...] | ||
@Override | @Override | ||
- | public | + | public |
... | ... | ||
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 |
- | + | ||
- | // | + | // |
- | if (!blockEntity.getInvStack(1).isEmpty()) { | + | if (!blockEntity.getStack(1).isEmpty()) { |
- | // 给予玩家物品栏中的物品堆 | + | // Give the player the stack in the inventory |
- | player.inventory.offerOrDrop(world, | + | 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, | + | player.getInventory().offerOrDrop(blockEntity.getStack(0)); |
- | blockEntity.removeInvStack(0); | + | blockEntity.removeStack(0); |
} | } | ||
} | } | ||
- | | + | |
- | return | + | return |
} | } | ||
} | } |
zh_cn/tutorial/inventory.txt · Last modified: 2023/08/28 10:14 by wjz_p