import range from '../modules/arrayRange.js';
import dimensionSystem from './dimension/dimensionSystem.js';
import eventSystem from './event/eventSystem.js';
import entitySystem from './entity/entitySystem.js';
import playerSystem from './player/playerSystem.js';
import scoresSystem from './scores/scoresSystem.js';
import uiSystem from './ui/uiSystem.js';
import Global from './variable/Global.js';

export default class registerSystem {
    constructor() {
        this.dimension = dimensionSystem;
        this.event = new eventSystem();
        this.entity = new entitySystem();
        this.player = new playerSystem();
    };
    
    GlobalVar(...args) {
        return new Global(...args);
    }
    
    
    ui() {
        return new uiSystem();
    }
    
    getDimension(...args) {
        return this.dimension.get(...args);
    }
    
    getTimer(value) {
        return value / 20;
    }
    
    scores(...args) {
        return this.entity.scores(...args);
    }
    
    scoresStatic(...args) {
        return scoresSystem;
    }
    
    runCommand(...args) {
        return this.entity.runCommand(...args);
    }
    
    runCommands(...args) {
        return this.entity.runCommands(...args);
    }
    
    runCommandFromViewEntity(...args) {
        return this.entity.runCommandFromViewEntity(...args);
    }
    
    getRotation(...args) {
        return this.entity.getRotation(...args);
    }
    
    getRotation2(...args) {
        return this.entity.getRotation2(...args);
    }
    
    getRotation3(...args) {
        return this.entity.getRotation3(...args);
    }
    
    getLc(...args) {
        return this.entity.getLc(...args);
    }
    
    getLc2(...args) {
        return this.entity.getLc2(...args);
    }
    
    getEntityName(...args) {
        return this.entity.getEntityName(...args);
    }
    
    getHandItem(...args) {
        return this.entity.getHandItem(...args);
    }
    
    shoot(...args) {
        return this.entity.shoot(...args);
    }
    
    getEntities(...args) {
        return this.entity.getEntitiesFromQuery(...args);
    }
    
    getEntitiesAtPosition(...args) {
        return this.entity.getEntitiesAtPosition(...args);
    }
    
    getEntitiesFromViewVector(...args) {
        return this.entity.getEntitiesFromViewVector(...args);
    }
    
    getBlockFromViewVector(...args) {
        return this.entity.getBlockFromViewVector(...args);
    }
    
    getPlayers(...args) {
        return this.player.getPlayersFromQuery(...args);
    }
    
    testfor(...args) {
        return this.player.testfor(...args);
    }
    
    findInventory(entity, item) {
        try {
            let getInventory = (entity) => {
                let items = new Array();
                let inventory = entity.getComponent("inventory");
                for (let i in range(0,inventory.container.size)) {
                    items.push(inventory.container.getItem(i));
                }
                return items;
            }
            let items = getInventory(entity);
            let itemData = item.data ? item.data : 0;
            let itemAmount = item.amount != '*' ? item.amount : '*';
            
            let res = itemAmount != '*' ? items.filter(it => it && it.id == item.id && it.data == itemData && it.amount == itemAmount) : items.filter(it => it && it.id == item.id && it.data == itemData);
            
            return (res.length > 0 ? items.indexOf(res[0]) : -1) > -1 ? true : false;
        } catch (e) {}
    }
    
    listenForEvent(...args) {
        return this.event.listenForEvent(...args);
    }
    
    tick(...args) {
        return this.event.tick(...args);
    }
    
}

