Search in sources :

Example 1 with BaseMetaTileEntity

use of gregtech.api.metatileentity.BaseMetaTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_MetaTileEntity_TurboCharger method onPostTick.

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
    if (aBaseMetaTileEntity.isServerSide()) {
        mCharge = aBaseMetaTileEntity.getStoredEU() / 2 > aBaseMetaTileEntity.getEUCapacity() / 3 || !aBaseMetaTileEntity.isAllowedToWork();
        mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3 && aBaseMetaTileEntity.isAllowedToWork();
        mBatteryCount = 0;
        mChargeableCount = 0;
        for (ItemStack tStack : mInventory) if (GT_ModHandler.isElectricItem(tStack, mTier)) {
            if (GT_ModHandler.isChargerItem(tStack))
                mBatteryCount++;
            mChargeableCount++;
        }
        if (this.getBaseMetaTileEntity() instanceof BaseMetaTileEntity) {
            BaseMetaTileEntity mBaseMetaTileEntity = (BaseMetaTileEntity) getBaseMetaTileEntity();
            if (mBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) {
                MetaTileEntity mMetaTileEntity = (MetaTileEntity) mBaseMetaTileEntity.getMetaTileEntity();
                //for (int t = 0; t < 6; t++) {
                if (mMetaTileEntity.dechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                    for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) {
                        if (mMetaTileEntity.mInventory[i] != null && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                            //CODE
                            mBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 120, mBaseMetaTileEntity.getEUCapacity() - mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true);
                            if (mMetaTileEntity.mInventory[i].stackSize <= 0)
                                mMetaTileEntity.mInventory[i] = null;
                        }
                    }
                }
                if (mMetaTileEntity.rechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() > 0) {
                    for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) {
                        if (mBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) {
                            //CODE
                            mBaseMetaTileEntity.decreaseStoredEU(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 120, mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), true, false), true);
                            if (mMetaTileEntity.mInventory[i].stackSize <= 0)
                                mMetaTileEntity.mInventory[i] = null;
                        }
                    }
                //}
                }
            }
        }
    }
}
Also used : BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)1 BaseMetaTileEntity (gregtech.api.metatileentity.BaseMetaTileEntity)1 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 ItemStack (net.minecraft.item.ItemStack)1