SHOW:
|
|
- or go back to the newest paste.
1 | public class UndoChest extends UndoBlock { | |
2 | ||
3 | private ItemStack[] is; | |
4 | ||
5 | public UndoChest(BlockState state) { | |
6 | super(state); | |
7 | - | for (ItemStack id : ((InventoryHolder) state).getInventory().getContents()) { |
7 | + | ItemStack[] tmp = ((InventoryHolder) state).getInventory().getContents(); |
8 | for (ItemStack id : tmp) { | |
9 | if (id != null) | |
10 | Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount()); | |
11 | - | this.is = ((InventoryHolder) state).getInventory().getContents(); |
11 | + | |
12 | - | for (ItemStack id : ((InventoryHolder) state).getInventory().getContents()) { |
12 | + | final int len = tmp.length; |
13 | this.is = new ItemStack[len]; | |
14 | for (int i = 0; i < len; i++) { | |
15 | is[i] = tmp[i] == null ? null : tmp[i].clone(); | |
16 | } | |
17 | for (ItemStack id : is) { | |
18 | if (id != null) | |
19 | Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount()); | |
20 | } | |
21 | } | |
22 | ||
23 | @Override | |
24 | public void undo() { | |
25 | if (is != null && state != null) { | |
26 | state.update(true); | |
27 | for (ItemStack id : is) { | |
28 | if (id != null) | |
29 | Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount()); | |
30 | } | |
31 | Inventory inv2 = ((InventoryHolder) state.getBlock().getState()).getInventory(); | |
32 | inv2.setContents(is); | |
33 | } | |
34 | } | |
35 | } |