Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UndoChest extends UndoBlock {
- private ItemStack[] is;
- public UndoChest(BlockState state) {
- super(state);
- ItemStack[] tmp = ((InventoryHolder) state).getInventory().getContents();
- for (ItemStack id : tmp) {
- if (id != null)
- Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount());
- }
- final int len = tmp.length;
- this.is = new ItemStack[len];
- for (int i = 0; i < len; i++) {
- is[i] = tmp[i] == null ? null : tmp[i].clone();
- }
- for (ItemStack id : is) {
- if (id != null)
- Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount());
- }
- }
- @Override
- public void undo() {
- if (is != null && state != null) {
- state.update(true);
- for (ItemStack id : is) {
- if (id != null)
- Util.info("Type: " + id.getType().name() + " Amount: " + id.getAmount());
- }
- Inventory inv2 = ((InventoryHolder) state.getBlock().getState()).getInventory();
- inv2.setContents(is);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement