| 1 | package net.minecraft.world;
|
| 2 |
|
| 3 | import net.minecraft.world.entity.ContainerUser;
|
| 4 | import net.minecraft.world.entity.player.Player;
|
| 5 | import net.minecraft.world.item.ItemStack;
|
| 6 |
|
| 7 | public class CompoundContainer implements Container {
|
| 8 | private final Container container1;
|
| 9 | private final Container container2;
|
| 10 |
|
| 11 | public CompoundContainer(final Container container1, final Container container2) {
|
| 12 | this.container1 = container1;
|
| 13 | this.container2 = container2;
|
| 14 | }
|
| 15 |
|
| 16 | @Override
|
| 17 | public int getContainerSize() {
|
| 18 | return this.container1.getContainerSize() + this.container2.getContainerSize();
|
| 19 | }
|
| 20 |
|
| 21 | @Override
|
| 22 | public boolean isEmpty() {
|
| 23 | return this.container1.isEmpty() && this.container2.isEmpty();
|
| 24 | }
|
| 25 |
|
| 26 | public boolean contains(final Container container) {
|
| 27 | return this.container1 == container || this.container2 == container;
|
| 28 | }
|
| 29 |
|
| 30 | @Override
|
| 31 | public ItemStack getItem(final int slot) {
|
| 32 | return slot >= this.container1.getContainerSize() ? this.container2.getItem(slot - this.container1.getContainerSize()) : this.container1.getItem(slot);
|
| 33 | }
|
| 34 |
|
| 35 | @Override
|
| 36 | public ItemStack removeItem(final int slot, final int count) {
|
| 37 | return slot >= this.container1.getContainerSize()
|
| 38 | ? this.container2.removeItem(slot - this.container1.getContainerSize(), count)
|
| 39 | : this.container1.removeItem(slot, count);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | public ItemStack removeItemNoUpdate(final int slot) {
|
| 44 | return slot >= this.container1.getContainerSize()
|
| 45 | ? this.container2.removeItemNoUpdate(slot - this.container1.getContainerSize())
|
| 46 | : this.container1.removeItemNoUpdate(slot);
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | public void setItem(final int slot, final ItemStack itemStack) {
|
| 51 | if (slot >= this.container1.getContainerSize()) {
|
| 52 | this.container2.setItem(slot - this.container1.getContainerSize(), itemStack);
|
| 53 | } else {
|
| 54 | this.container1.setItem(slot, itemStack);
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public int getMaxStackSize() {
|
| 60 | return this.container1.getMaxStackSize();
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public void setChanged() {
|
| 65 | this.container1.setChanged();
|
| 66 | this.container2.setChanged();
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public boolean stillValid(final Player player) {
|
| 71 | return this.container1.stillValid(player) && this.container2.stillValid(player);
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public void startOpen(final ContainerUser containerUser) {
|
| 76 | this.container1.startOpen(containerUser);
|
| 77 | this.container2.startOpen(containerUser);
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | public void stopOpen(final ContainerUser containerUser) {
|
| 82 | this.container1.stopOpen(containerUser);
|
| 83 | this.container2.stopOpen(containerUser);
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public boolean canPlaceItem(final int slot, final ItemStack itemStack) {
|
| 88 | return slot >= this.container1.getContainerSize()
|
| 89 | ? this.container2.canPlaceItem(slot - this.container1.getContainerSize(), itemStack)
|
| 90 | : this.container1.canPlaceItem(slot, itemStack);
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | public void clearContent() {
|
| 95 | this.container1.clearContent();
|
| 96 | this.container2.clearContent();
|
| 97 | }
|
| 98 | }
|
| 99 |
|