package net.minecraft.world;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public class CompoundContainer implements Container {
    private final Container container1;
    private final Container container2;
    
    public CompoundContainer(Container aje1, Container aje2) {
        if (aje1 == null) {
            aje1 = aje2;
        }
        if (aje2 == null) {
            aje2 = aje1;
        }
        this.container1 = aje1;
        this.container2 = aje2;
    }
    
    @Override
    public int getContainerSize() {
        return this.container1.getContainerSize() + this.container2.getContainerSize();
    }
    
    @Override
    public boolean isEmpty() {
        return this.container1.isEmpty() && this.container2.isEmpty();
    }
    
    public boolean contains(final Container aje) {
        return this.container1 == aje || this.container2 == aje;
    }
    
    @Override
    public ItemStack getItem(final int integer) {
        if (integer >= this.container1.getContainerSize()) {
            return this.container2.getItem(integer - this.container1.getContainerSize());
        }
        return this.container1.getItem(integer);
    }
    
    @Override
    public ItemStack removeItem(final int integer1, final int integer2) {
        if (integer1 >= this.container1.getContainerSize()) {
            return this.container2.removeItem(integer1 - this.container1.getContainerSize(), integer2);
        }
        return this.container1.removeItem(integer1, integer2);
    }
    
    @Override
    public ItemStack removeItemNoUpdate(final int integer) {
        if (integer >= this.container1.getContainerSize()) {
            return this.container2.removeItemNoUpdate(integer - this.container1.getContainerSize());
        }
        return this.container1.removeItemNoUpdate(integer);
    }
    
    @Override
    public void setItem(final int integer, final ItemStack ben) {
        if (integer >= this.container1.getContainerSize()) {
            this.container2.setItem(integer - this.container1.getContainerSize(), ben);
        }
        else {
            this.container1.setItem(integer, ben);
        }
    }
    
    @Override
    public int getMaxStackSize() {
        return this.container1.getMaxStackSize();
    }
    
    @Override
    public void setChanged() {
        this.container1.setChanged();
        this.container2.setChanged();
    }
    
    @Override
    public boolean stillValid(final Player ayj) {
        return this.container1.stillValid(ayj) && this.container2.stillValid(ayj);
    }
    
    @Override
    public void startOpen(final Player ayj) {
        this.container1.startOpen(ayj);
        this.container2.startOpen(ayj);
    }
    
    @Override
    public void stopOpen(final Player ayj) {
        this.container1.stopOpen(ayj);
        this.container2.stopOpen(ayj);
    }
    
    @Override
    public boolean canPlaceItem(final int integer, final ItemStack ben) {
        if (integer >= this.container1.getContainerSize()) {
            return this.container2.canPlaceItem(integer - this.container1.getContainerSize(), ben);
        }
        return this.container1.canPlaceItem(integer, ben);
    }
    
    @Override
    public void clearContent() {
        this.container1.clearContent();
        this.container2.clearContent();
    }
}
