package com.thebrokenrail.twine.util.boat.inventory;

import com.thebrokenrail.twine.util.boat.BoatChestMode;
import com.thebrokenrail.twine.util.boat.BoatUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;

public class BoatInventoryWrapper implements Inventory {
    private final Inventory inventory;
    private final Entity entity;
    private final BoatChestMode mode;

    public BoatInventoryWrapper(Entity entity, Inventory inventory, BoatChestMode mode) {
        this.entity = entity;
        this.inventory = inventory;
        this.mode = mode;
    }

    @Override
    public int size() {
        return inventory.size();
    }

    @Override
    public boolean isEmpty() {
        return inventory.isEmpty();
    }

    @Override
    public ItemStack getStack(int slot) {
        return inventory.getStack(slot);
    }

    @Override
    public ItemStack removeStack(int slot, int amount) {
        return inventory.removeStack(slot, amount);
    }

    @Override
    public ItemStack removeStack(int slot) {
        return inventory.removeStack(slot);
    }

    @Override
    public void setStack(int slot, ItemStack stack) {
        inventory.setStack(slot, stack);
    }

    @Override
    public void markDirty() {
        inventory.markDirty();
    }

    @Override
    public boolean canPlayerUse(PlayerEntity player) {
        return BoatUtil.canPlayerUse(player, entity, mode);
    }

    @Override
    public void onOpen(PlayerEntity player) {
        inventory.onOpen(player);
        if (mode.getOpenSound() != null) {
            BoatUtil.playSound(entity, mode.getOpenSound());
        }
    }

    @Override
    public void onClose(PlayerEntity player) {
        inventory.onClose(player);
        if (mode.getCloseSound() != null) {
            BoatUtil.playSound(entity, mode.getCloseSound());
        }
    }

    @Override
    public void clear() {
        inventory.clear();
    }
}
