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 amz1, Container amz2) {
        if (amz1 == null) {
            amz1 = amz2;
        }
        if (amz2 == null) {
            amz2 = amz1;
        }
        this.container1 = amz1;
        this.container2 = amz2;
    }
    
    @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 amz) {
        return this.container1 == amz || this.container2 == amz;
    }
    
    @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 bki) {
        if (integer >= this.container1.getContainerSize()) {
            this.container2.setItem(integer - this.container1.getContainerSize(), bki);
        }
        else {
            this.container1.setItem(integer, bki);
        }
    }
    
    @Override
    public int getMaxStackSize() {
        return this.container1.getMaxStackSize();
    }
    
    @Override
    public void setChanged() {
        this.container1.setChanged();
        this.container2.setChanged();
    }
    
    @Override
    public boolean stillValid(final Player bec) {
        return this.container1.stillValid(bec) && this.container2.stillValid(bec);
    }
    
    @Override
    public void startOpen(final Player bec) {
        this.container1.startOpen(bec);
        this.container2.startOpen(bec);
    }
    
    @Override
    public void stopOpen(final Player bec) {
        this.container1.stopOpen(bec);
        this.container2.stopOpen(bec);
    }
    
    @Override
    public boolean canPlaceItem(final int integer, final ItemStack bki) {
        if (integer >= this.container1.getContainerSize()) {
            return this.container2.canPlaceItem(integer - this.container1.getContainerSize(), bki);
        }
        return this.container1.canPlaceItem(integer, bki);
    }
    
    @Override
    public void clearContent() {
        this.container1.clearContent();
        this.container2.clearContent();
    }
}
